@phi-code-admin/phi-code 0.71.1 โ†’ 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.
@@ -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. List all existing files and read key ones
541
- 2. Identify tech stack, patterns, and constraints
542
- 3. Create a STRUCTURED PROJECT BRIEF in \`.phi/plans/brief-${ts}.md\`:
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
- **Step 4:** Write your findings to \`.phi/plans/explore-${ts}.md\`
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 each file, verify it exists with \`ls\` before proceeding`,
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 on Windows, use: \`netstat -ano | findstr :PORT\` and \`taskkill /PID <pid> /F\`
714
- - For port conflicts on Linux/Mac, use: \`lsof -ti:PORT | xargs kill -9\`
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
- ctx.ui.notify(`\nโœ… **All 5 phases complete!**`, "info");
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,7 +892,15 @@ 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 || !phasePending) return;
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
905
  // Build a structured summary of what happened in this phase
881
906
  // Instead of raw LLM text, extract concrete actions: files created/modified,
@@ -888,12 +913,13 @@ Tag the note with relevant keywords for vector search.`,
888
913
  let toolCallCount = 0;
889
914
 
890
915
  for (const msg of messages) {
891
- if (msg.role === 'tool' || msg.role === 'function') {
916
+ // Pi uses role: "toolResult" instead of "tool"
917
+ if (msg.role === 'tool' || msg.role === 'function' || msg.role === 'toolResult') {
892
918
  toolCallCount++;
893
919
  const content = Array.isArray(msg.content)
894
920
  ? msg.content.map((c: any) => c.text || '').join('')
895
921
  : String(msg.content || '');
896
- const name = (msg as any).name || '';
922
+ const name = (msg as any).name || (msg as any).toolName || '';
897
923
  // Track writes
898
924
  if (name === 'write' && content.includes('Successfully wrote')) {
899
925
  const match = content.match(/wrote \d+ bytes to (.+)/);
package/package.json CHANGED
@@ -1,107 +1,107 @@
1
1
  {
2
- "name": "@phi-code-admin/phi-code",
3
- "version": "0.71.1",
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
- }
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
  }