@phi-code-admin/phi-code 0.71.0 โ 0.72.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/extensions/phi/orchestrator.ts +90 -35
- package/package.json +105 -105
|
@@ -527,6 +527,8 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
|
|
|
527
527
|
const review = getModel("review");
|
|
528
528
|
|
|
529
529
|
const ts = timestamp();
|
|
530
|
+
// Inject runtime info so agents can adapt to the host OS
|
|
531
|
+
const runtimeInfo = `\n\nRuntime: ${process.platform} (${process.arch})`;
|
|
530
532
|
|
|
531
533
|
return [
|
|
532
534
|
{
|
|
@@ -534,19 +536,23 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
|
|
|
534
536
|
agent: loadAgentDef("explore"),
|
|
535
537
|
instruction: `You are the EXPLORE agent. Analyze the project requirements and existing codebase.
|
|
536
538
|
|
|
539
|
+
**FIRST ACTION (MANDATORY):** Call \`memory_search\` with project-relevant keywords to check for prior context.
|
|
540
|
+
|
|
537
541
|
**Project Request:** ${description}
|
|
538
542
|
|
|
539
543
|
**Your tasks:**
|
|
540
|
-
1.
|
|
541
|
-
2.
|
|
542
|
-
3.
|
|
544
|
+
1. Call \`memory_search\` with project-relevant keywords (MANDATORY)
|
|
545
|
+
2. List all existing files and read key ones
|
|
546
|
+
3. Identify tech stack, patterns, and constraints
|
|
547
|
+
4. Create a STRUCTURED PROJECT BRIEF in \`.phi/plans/brief-${ts}.md\`:
|
|
543
548
|
- Context: what exists now
|
|
544
549
|
- Objective: what needs to be built
|
|
545
550
|
- Requirements: specific features needed
|
|
546
551
|
- Tech decisions: frameworks, patterns to use
|
|
547
552
|
- Constraints: what to NOT break
|
|
553
|
+
5. Write your findings to \`.phi/plans/explore-${ts}.md\`
|
|
548
554
|
|
|
549
|
-
**
|
|
555
|
+
**LAST ACTION (MANDATORY):** Call \`memory_write\` to save your exploration findings for downstream agents.
|
|
550
556
|
|
|
551
557
|
**Knowledge Graph:**
|
|
552
558
|
After your analysis, use \`ontology_add\` to save key project entities AND their relations:
|
|
@@ -576,7 +582,7 @@ After your analysis, use \`ontology_add\` to save key project entities AND their
|
|
|
576
582
|
- Every function fully implemented
|
|
577
583
|
- Follow existing patterns if codebase exists
|
|
578
584
|
- [Any other specific constraints]
|
|
579
|
-
|
|
585
|
+
\`\`\`` + runtimeInfo,
|
|
580
586
|
},
|
|
581
587
|
{
|
|
582
588
|
key: "plan", label: "๐ Phase 2 โ PLAN", model: plan.preferred, fallback: plan.fallback,
|
|
@@ -616,7 +622,7 @@ After your analysis, use \`ontology_add\` to save key project entities AND their
|
|
|
616
622
|
- Dependencies: Task 1
|
|
617
623
|
\`\`\`
|
|
618
624
|
|
|
619
|
-
Before finishing, use \`memory_write\` to save your plan summary with relevant tags for future reference
|
|
625
|
+
Before finishing, use \`memory_write\` to save your plan summary with relevant tags for future reference.` + runtimeInfo,
|
|
620
626
|
},
|
|
621
627
|
{
|
|
622
628
|
key: "code", label: "๐ป Phase 3 โ CODE", model: code.preferred, fallback: code.fallback,
|
|
@@ -663,7 +669,7 @@ After implementation, use \`memory_write\` to save a summary of what was built,
|
|
|
663
669
|
**CRITICAL RULES:**
|
|
664
670
|
- Write ONE file per tool call โ NEVER combine multiple files in a single response
|
|
665
671
|
- Keep each file under 500 lines. If longer, split into modules
|
|
666
|
-
- After writing
|
|
672
|
+
- After writing ALL files, verify they exist with a single \`find . -name '*.ts' -o -name '*.js' -o -name '*.html' | sort\`` + runtimeInfo,
|
|
667
673
|
},
|
|
668
674
|
{
|
|
669
675
|
key: "test", label: "๐งช Phase 4 โ TEST", model: test.preferred, fallback: test.fallback,
|
|
@@ -710,20 +716,23 @@ After implementation, use \`memory_write\` to save a summary of what was built,
|
|
|
710
716
|
- NEVER put tool calls inside thinking blocks. Always use the proper JSON tool call format
|
|
711
717
|
- NEVER modify source code permanently for testing. Use environment variables: \`PORT=3001 node server.js\` instead of editing files
|
|
712
718
|
- NEVER create .env files with fake credentials. Use inline env vars: \`API_KEY=test node server.js\`
|
|
713
|
-
- For port conflicts
|
|
714
|
-
-
|
|
719
|
+
- For port conflicts, prefer: \`npx kill-port PORT\` (cross-platform)
|
|
720
|
+
- On Windows fallback: \`netstat -ano | findstr :PORT\` and \`taskkill /PID <pid> /F\`
|
|
721
|
+
- On Linux/Mac fallback: \`lsof -ti:PORT | xargs kill -9\`
|
|
715
722
|
- Always clean up after tests: kill background processes, remove temp files
|
|
716
723
|
|
|
717
|
-
After testing, use \`memory_write\` to save test results, bugs found, and lessons learned
|
|
724
|
+
After testing, use \`memory_write\` to save test results, bugs found, and lessons learned.` + runtimeInfo,
|
|
718
725
|
},
|
|
719
726
|
{
|
|
720
727
|
key: "review", label: "๐ Phase 5 โ REVIEW", model: review.preferred, fallback: review.fallback,
|
|
721
728
|
agent: loadAgentDef("review"),
|
|
722
729
|
instruction: `You are the REVIEW agent. Final quality review.
|
|
723
730
|
|
|
731
|
+
**FIRST ACTIONS (MANDATORY โ do these before anything else):**
|
|
732
|
+
1. Call \`memory_search\` to find all notes from previous phases (explore, plan, code, test)
|
|
733
|
+
2. Call \`ontology_query\` to understand the full project architecture and entity relationships
|
|
734
|
+
|
|
724
735
|
**Context Retrieval:**
|
|
725
|
-
1. Use \`memory_search\` to find all notes from previous phases (explore, plan, code, test)
|
|
726
|
-
2. Use \`ontology_query\` to understand the full project architecture
|
|
727
736
|
3. Review all \`.phi/plans/*.md\` files for complete context
|
|
728
737
|
|
|
729
738
|
**Project Request:** ${description}
|
|
@@ -765,11 +774,13 @@ After testing, use \`memory_write\` to save test results, bugs found, and lesson
|
|
|
765
774
|
โ
Project ready for production / โ Issues need resolution
|
|
766
775
|
\`\`\`
|
|
767
776
|
|
|
768
|
-
After your review, use \`memory_write\` to save:
|
|
777
|
+
After your review, use \`memory_write\` ONCE to save:
|
|
769
778
|
- Key lessons learned about this project type
|
|
770
779
|
- Patterns that worked well
|
|
771
780
|
- Common mistakes to avoid in future projects
|
|
772
|
-
Tag the note with relevant keywords for vector search
|
|
781
|
+
Tag the note with relevant keywords for vector search.
|
|
782
|
+
|
|
783
|
+
**Important:** Write lessons-learned ONCE. Do not call memory_write twice with the same filename or duplicate content.` + runtimeInfo,
|
|
773
784
|
},
|
|
774
785
|
];
|
|
775
786
|
}
|
|
@@ -837,10 +848,16 @@ Tag the note with relevant keywords for vector search.`,
|
|
|
837
848
|
|
|
838
849
|
function sendNextPhase(ctx: any) {
|
|
839
850
|
if (phaseQueue.length === 0) {
|
|
851
|
+
// All phases done โ clean up and notify
|
|
840
852
|
setOrchestrationActive(false);
|
|
841
853
|
phasePending = false;
|
|
842
854
|
deactivateAgent();
|
|
843
|
-
|
|
855
|
+
try {
|
|
856
|
+
ctx.ui.notify(`\nโ
**All 5 phases complete!**`, "info");
|
|
857
|
+
} catch {
|
|
858
|
+
// Fallback: inject completion message into conversation stream
|
|
859
|
+
try { pi.sendUserMessage(`โ
All 5 phases complete! The project is ready for review.`); } catch { /* best effort */ }
|
|
860
|
+
}
|
|
844
861
|
return;
|
|
845
862
|
}
|
|
846
863
|
|
|
@@ -875,31 +892,69 @@ Tag the note with relevant keywords for vector search.`,
|
|
|
875
892
|
// That's why phases 2-5 never executed.
|
|
876
893
|
|
|
877
894
|
pi.on("agent_end", async (event, ctx) => {
|
|
878
|
-
if (!orchestrationActive
|
|
895
|
+
if (!orchestrationActive) return;
|
|
896
|
+
// Allow completion even if phasePending was cleared by a duplicate event
|
|
897
|
+
if (!phasePending) {
|
|
898
|
+
// If queue is empty and orchestration is active, force completion
|
|
899
|
+
if (phaseQueue.length === 0) {
|
|
900
|
+
sendNextPhase(ctx);
|
|
901
|
+
}
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
879
904
|
|
|
880
|
-
//
|
|
881
|
-
//
|
|
882
|
-
//
|
|
905
|
+
// Build a structured summary of what happened in this phase
|
|
906
|
+
// Instead of raw LLM text, extract concrete actions: files created/modified,
|
|
907
|
+
// errors encountered, test results. This gives the next phase actionable context.
|
|
883
908
|
const messages = event.messages || [];
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
909
|
+
const filesWritten: string[] = [];
|
|
910
|
+
const filesEdited: string[] = [];
|
|
911
|
+
const errorsHit: string[] = [];
|
|
912
|
+
const testResults: string[] = [];
|
|
913
|
+
let toolCallCount = 0;
|
|
914
|
+
|
|
915
|
+
for (const msg of messages) {
|
|
916
|
+
// Pi uses role: "toolResult" instead of "tool"
|
|
917
|
+
if (msg.role === 'tool' || msg.role === 'function' || msg.role === 'toolResult') {
|
|
918
|
+
toolCallCount++;
|
|
919
|
+
const content = Array.isArray(msg.content)
|
|
920
|
+
? msg.content.map((c: any) => c.text || '').join('')
|
|
921
|
+
: String(msg.content || '');
|
|
922
|
+
const name = (msg as any).name || (msg as any).toolName || '';
|
|
923
|
+
// Track writes
|
|
924
|
+
if (name === 'write' && content.includes('Successfully wrote')) {
|
|
925
|
+
const match = content.match(/wrote \d+ bytes to (.+)/);
|
|
926
|
+
if (match) filesWritten.push(match[1]);
|
|
927
|
+
}
|
|
928
|
+
// Track edits
|
|
929
|
+
if (name === 'edit' && !content.includes('ERR')) {
|
|
930
|
+
const match = content.match(/edited (.+)/) || content.match(/in (.+)/);
|
|
931
|
+
if (match) filesEdited.push(match[1]);
|
|
932
|
+
}
|
|
933
|
+
// Track errors
|
|
934
|
+
if (content.includes('ERR:') || content.includes('Error:') || content.includes('FAIL')) {
|
|
935
|
+
const preview = content.slice(0, 150).replace(/\n/g, ' ');
|
|
936
|
+
errorsHit.push(`${name}: ${preview}`);
|
|
937
|
+
}
|
|
938
|
+
// Track test results
|
|
939
|
+
if (content.includes('PASS') || content.includes('โ
') || content.includes('โ') || content.includes('โ')) {
|
|
940
|
+
const lines = content.split('\n').filter(l => /PASS|FAIL|โ
|โ|โ/.test(l));
|
|
941
|
+
testResults.push(...lines.slice(0, 10));
|
|
942
|
+
}
|
|
896
943
|
}
|
|
897
944
|
}
|
|
898
|
-
const lastOutput = bestOutput.slice(0, 4000);
|
|
899
945
|
|
|
900
|
-
//
|
|
901
|
-
|
|
902
|
-
|
|
946
|
+
// Build the summary
|
|
947
|
+
const summaryParts: string[] = [];
|
|
948
|
+
summaryParts.push(`Tool calls: ${toolCallCount}`);
|
|
949
|
+
if (filesWritten.length > 0) summaryParts.push(`Files created/written: ${filesWritten.join(', ')}`);
|
|
950
|
+
if (filesEdited.length > 0) summaryParts.push(`Files edited: ${filesEdited.join(', ')}`);
|
|
951
|
+
if (testResults.length > 0) summaryParts.push(`Test results:\n${testResults.join('\n')}`);
|
|
952
|
+
if (errorsHit.length > 0) summaryParts.push(`Errors encountered: ${errorsHit.length}\n${errorsHit.slice(0, 5).join('\n')}`);
|
|
953
|
+
const phaseSummary = summaryParts.join('\n');
|
|
954
|
+
|
|
955
|
+
// Inject structured summary into next phase
|
|
956
|
+
if (phaseSummary && phaseQueue.length > 0) {
|
|
957
|
+
phaseQueue[0].instruction += `\n\n**Previous phase summary:**\n${phaseSummary}`;
|
|
903
958
|
}
|
|
904
959
|
|
|
905
960
|
// Phase complete โ chain to next
|
package/package.json
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
2
|
+
"name": "@phi-code-admin/phi-code",
|
|
3
|
+
"version": "0.72.0",
|
|
4
|
+
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"piConfig": {
|
|
7
|
+
"name": "phi",
|
|
8
|
+
"configDir": ".phi"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"phi": "dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./hooks": {
|
|
21
|
+
"types": "./dist/core/hooks/index.d.ts",
|
|
22
|
+
"import": "./dist/core/hooks/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"skills",
|
|
28
|
+
"agents",
|
|
29
|
+
"extensions",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"scripts"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "shx rm -rf dist",
|
|
37
|
+
"dev": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
38
|
+
"build": "tsgo -p tsconfig.build.json && shx chmod +x dist/cli.js && npm run copy-assets",
|
|
39
|
+
"build:binary": "npm --prefix ../tui run build && npm --prefix ../ai run build && npm --prefix ../agent run build && npm run build && bun build --compile ./dist/cli.js --outfile dist/pi && npm run copy-binary-assets",
|
|
40
|
+
"copy-assets": "./scripts/copy-assets.sh",
|
|
41
|
+
"copy-binary-assets": "shx cp package.json dist/ && shx cp README.md dist/ && shx cp CHANGELOG.md dist/ && shx mkdir -p dist/theme && shx cp src/modes/interactive/theme/*.json dist/theme/ && shx mkdir -p dist/export-html/vendor && shx cp src/core/export-html/template.html dist/export-html/ && shx cp src/core/export-html/vendor/*.js dist/export-html/vendor/ && shx cp -r docs dist/ && shx cp -r examples dist/ && shx cp ../../node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm dist/",
|
|
42
|
+
"test": "vitest --run",
|
|
43
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
44
|
+
"postinstall": "node scripts/postinstall.cjs"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@mariozechner/jiti": "^2.6.2",
|
|
48
|
+
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
49
|
+
"chalk": "^5.5.0",
|
|
50
|
+
"cli-highlight": "^2.1.11",
|
|
51
|
+
"diff": "^8.0.2",
|
|
52
|
+
"extract-zip": "^2.0.1",
|
|
53
|
+
"file-type": "^21.1.1",
|
|
54
|
+
"glob": "^13.0.1",
|
|
55
|
+
"hosted-git-info": "^9.0.2",
|
|
56
|
+
"ignore": "^7.0.5",
|
|
57
|
+
"marked": "^15.0.12",
|
|
58
|
+
"minimatch": "^10.2.3",
|
|
59
|
+
"phi-code-agent": "^0.56.3",
|
|
60
|
+
"phi-code-ai": "^0.56.3",
|
|
61
|
+
"phi-code-tui": "^0.56.3",
|
|
62
|
+
"proper-lockfile": "^4.1.2",
|
|
63
|
+
"sigma-agents": "^0.1.6",
|
|
64
|
+
"sigma-memory": "0.2.1",
|
|
65
|
+
"sigma-skills": "^0.1.2",
|
|
66
|
+
"strip-ansi": "^7.1.0",
|
|
67
|
+
"undici": "^7.19.1",
|
|
68
|
+
"yaml": "^2.8.2"
|
|
69
|
+
},
|
|
70
|
+
"overrides": {
|
|
71
|
+
"rimraf": "6.1.2",
|
|
72
|
+
"gaxios": {
|
|
73
|
+
"rimraf": "6.1.2"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"optionalDependencies": {
|
|
77
|
+
"@mariozechner/clipboard": "^0.3.2"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/diff": "^7.0.2",
|
|
81
|
+
"@types/hosted-git-info": "^3.0.5",
|
|
82
|
+
"@types/ms": "^2.1.0",
|
|
83
|
+
"@types/node": "^24.3.0",
|
|
84
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
85
|
+
"shx": "^0.4.0",
|
|
86
|
+
"typescript": "^5.7.3",
|
|
87
|
+
"vitest": "^3.2.4"
|
|
88
|
+
},
|
|
89
|
+
"keywords": [
|
|
90
|
+
"ai",
|
|
91
|
+
"coding-agent",
|
|
92
|
+
"cli",
|
|
93
|
+
"typescript",
|
|
94
|
+
"sub-agents",
|
|
95
|
+
"memory"
|
|
96
|
+
],
|
|
97
|
+
"author": "Mario Zechner",
|
|
98
|
+
"license": "MIT",
|
|
99
|
+
"repository": {
|
|
100
|
+
"type": "git",
|
|
101
|
+
"url": "https://github.com/uglyswap/phi-code.git"
|
|
102
|
+
},
|
|
103
|
+
"homepage": "https://github.com/uglyswap/phi-code",
|
|
104
|
+
"engines": {
|
|
105
|
+
"node": ">=20.6.0"
|
|
106
|
+
}
|
|
107
107
|
}
|