@phi-code-admin/phi-code 0.68.0 → 0.69.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/agents/code.md CHANGED
@@ -39,3 +39,10 @@ Use this context to understand the project scope and build on previous work. Do
39
39
  2. **What was done**: Concise implementation summary
40
40
  3. **Verification**: What you checked (compilation, tests, edge cases)
41
41
  4. **Concerns**: Any TODOs, limitations, or risks
42
+
43
+ ## Constraints
44
+ - Write ONE file per tool call — never combine multiple files in a single response
45
+ - Keep each file under 500 lines — split into modules if needed
46
+ - Files containing JSX/TSX syntax MUST use .tsx extension, not .ts
47
+ - Pure TypeScript files use .ts extension
48
+ - When using React/Ink components, ALWAYS use .tsx
package/agents/explore.md CHANGED
@@ -31,6 +31,13 @@ Use the project context to focus your analysis on what matters. Avoid duplicatin
31
31
  - **Read-only**: You NEVER modify files
32
32
  - **Time-efficient**: Focus on what the task asks. Don't analyze the entire codebase if only one module matters
33
33
 
34
+ ## Ontology Rules
35
+ - After adding entities, ALWAYS create relations between them
36
+ - Relation types: "uses", "contains", "depends_on", "implements", "extends"
37
+ - Example: Project "finance-tracker" --uses--> Library "ink"
38
+ - A knowledge graph without relations is just a flat list — useless
39
+ - Create at minimum: project→uses→each library, project→contains→each module
40
+
34
41
  ## Output Format
35
42
 
36
43
  Structure your findings for maximum utility to downstream agents:
@@ -254,15 +254,38 @@ export default function memoryExtension(pi: ExtensionAPI) {
254
254
  if (!p.from || !p.to || !p.relationType) {
255
255
  return { content: [{ type: "text", text: "Relation requires 'from', 'to', and 'relationType'" }], isError: true };
256
256
  }
257
+
258
+ // Try finding source entity by ID first, then by name
259
+ let sourceEntity = sigmaMemory.ontology.findEntity({ id: p.from })[0];
260
+ if (!sourceEntity) {
261
+ // Try finding by name (case-insensitive)
262
+ const allEntities = sigmaMemory.ontology.findEntity({});
263
+ sourceEntity = allEntities.find(e => e.name.toLowerCase() === p.from.toLowerCase());
264
+ if (!sourceEntity) {
265
+ return { content: [{ type: "text", text: `Source entity not found: ${p.from}` }], isError: true };
266
+ }
267
+ }
268
+
269
+ // Try finding target entity by ID first, then by name
270
+ let targetEntity = sigmaMemory.ontology.findEntity({ id: p.to })[0];
271
+ if (!targetEntity) {
272
+ // Try finding by name (case-insensitive)
273
+ const allEntities = sigmaMemory.ontology.findEntity({});
274
+ targetEntity = allEntities.find(e => e.name.toLowerCase() === p.to.toLowerCase());
275
+ if (!targetEntity) {
276
+ return { content: [{ type: "text", text: `Target entity not found: ${p.to}` }], isError: true };
277
+ }
278
+ }
279
+
257
280
  const id = sigmaMemory.ontology.addRelation({
258
- from: p.from,
259
- to: p.to,
281
+ from: sourceEntity.id,
282
+ to: targetEntity.id,
260
283
  type: p.relationType,
261
284
  properties: p.properties || {},
262
285
  });
263
286
  return {
264
- content: [{ type: "text", text: `Relation added: \`${p.from}\` → **${p.relationType}** → \`${p.to}\` — ID: \`${id}\`` }],
265
- details: { id, from: p.from, to: p.to, type: p.relationType },
287
+ content: [{ type: "text", text: `Relation added: \`${sourceEntity.name}\` → **${p.relationType}** → \`${targetEntity.name}\` — ID: \`${id}\`` }],
288
+ details: { id, from: sourceEntity.id, to: targetEntity.id, type: p.relationType },
266
289
  };
267
290
  }
268
291
  return { content: [{ type: "text", text: "Type must be 'entity' or 'relation'" }], isError: true };
@@ -548,7 +548,12 @@ export default function orchestratorExtension(pi: ExtensionAPI) {
548
548
 
549
549
  **Step 4:** Write your findings to \`.phi/plans/explore-${ts}.md\`
550
550
 
551
- After your analysis, use \`ontology_add\` to save key project entities (files, modules, dependencies) to the knowledge graph.
551
+ **Knowledge Graph:**
552
+ After your analysis, use \`ontology_add\` to save key project entities AND their relations:
553
+ - Add entities for: the project, each major library, each module/directory
554
+ - Add relations between them: "uses", "contains", "depends_on", "implements"
555
+ - Example: entity "finance-tracker" (type: Project) → relation "uses" → entity "ink" (type: Library)
556
+ - ALWAYS create relations — entities without relations are useless
552
557
 
553
558
  **Format for the project brief:**
554
559
  \`\`\`markdown
@@ -578,6 +583,11 @@ After your analysis, use \`ontology_add\` to save key project entities (files, m
578
583
  agent: loadAgentDef("plan"),
579
584
  instruction: `You are the PLAN agent. Design the architecture and create a detailed task list.
580
585
 
586
+ **Context Retrieval:**
587
+ 1. Use \`ontology_query\` to retrieve all entities and relations from Phase 1
588
+ 2. Use \`memory_search\` with project-relevant keywords to find existing notes
589
+ 3. Use this knowledge to inform your plan
590
+
581
591
  **Project Request:** ${description}
582
592
 
583
593
  **Step 1:** Read \`.phi/plans/brief-*.md\` (created by the explore phase)
@@ -604,13 +614,20 @@ After your analysis, use \`ontology_add\` to save key project entities (files, m
604
614
  ## Task 2: [Task Title] [agent-type]
605
615
  - [ ] Implementation details
606
616
  - Dependencies: Task 1
607
- \`\`\``,
617
+ \`\`\`
618
+
619
+ Before finishing, use \`memory_write\` to save your plan summary with relevant tags for future reference.`,
608
620
  },
609
621
  {
610
622
  key: "code", label: "💻 Phase 3 — CODE", model: code.preferred, fallback: code.fallback,
611
623
  agent: loadAgentDef("code"),
612
624
  instruction: `You are the CODE agent. Implement the complete project.
613
625
 
626
+ **Context Retrieval:**
627
+ 1. Use \`memory_search\` with project keywords to find notes from previous phases
628
+ 2. Use \`ontology_query\` to understand the project structure and dependencies
629
+ 3. Use this context to guide implementation
630
+
614
631
  **Project Request:** ${description}
615
632
 
616
633
  **Step 1:** Read \`.phi/plans/brief-*.md\` for project context
@@ -639,13 +656,25 @@ After your analysis, use \`ontology_add\` to save key project entities (files, m
639
656
 
640
657
  ## Implementation Notes
641
658
  [Any important decisions or changes made]
642
- \`\`\``,
659
+ \`\`\`
660
+
661
+ After implementation, use \`memory_write\` to save a summary of what was built, patterns used, and any issues encountered.
662
+
663
+ **CRITICAL RULES:**
664
+ - Write ONE file per tool call — NEVER combine multiple files in a single response
665
+ - Keep each file under 500 lines. If longer, split into modules
666
+ - After writing each file, verify it exists with \`ls\` before proceeding`,
643
667
  },
644
668
  {
645
669
  key: "test", label: "🧪 Phase 4 — TEST", model: test.preferred, fallback: test.fallback,
646
670
  agent: loadAgentDef("test"),
647
671
  instruction: `You are the TEST agent. Verify the implementation.
648
672
 
673
+ **Context Retrieval:**
674
+ 1. Use \`memory_search\` to find implementation notes from the CODE phase
675
+ 2. Use \`ontology_query\` to understand the project architecture
676
+ 3. Use this context to focus your testing
677
+
649
678
  **Project Request:** ${description}
650
679
 
651
680
  **Step 1:** Read \`.phi/plans/todo-*.md\` to know what was planned
@@ -677,13 +706,20 @@ After your analysis, use \`ontology_add\` to save key project entities (files, m
677
706
  **CRITICAL RULES:**
678
707
  - NEVER run a server with \`&\` without cleanup. Always use: \`timeout 15 bash -c 'node src/index.js & PID=$!; sleep 2; curl ...; kill $PID'\`
679
708
  - ALWAYS kill background processes after testing
680
- - If a test hangs, use \`timeout\` to prevent deadlock`,
709
+ - If a test hangs, use \`timeout\` to prevent deadlock
710
+
711
+ After testing, use \`memory_write\` to save test results, bugs found, and lessons learned.`,
681
712
  },
682
713
  {
683
714
  key: "review", label: "🔍 Phase 5 — REVIEW", model: review.preferred, fallback: review.fallback,
684
715
  agent: loadAgentDef("review"),
685
716
  instruction: `You are the REVIEW agent. Final quality review.
686
717
 
718
+ **Context Retrieval:**
719
+ 1. Use \`memory_search\` to find all notes from previous phases (explore, plan, code, test)
720
+ 2. Use \`ontology_query\` to understand the full project architecture
721
+ 3. Review all \`.phi/plans/*.md\` files for complete context
722
+
687
723
  **Project Request:** ${description}
688
724
 
689
725
  **Step 1:** Read all \`.phi/plans/*.md\` files
@@ -723,7 +759,11 @@ After your analysis, use \`ontology_add\` to save key project entities (files, m
723
759
  ✅ Project ready for production / ❌ Issues need resolution
724
760
  \`\`\`
725
761
 
726
- After your review, use \`memory_write\` to save key lessons learned, patterns found, and important decisions for future reference.`,
762
+ After your review, use \`memory_write\` to save:
763
+ - Key lessons learned about this project type
764
+ - Patterns that worked well
765
+ - Common mistakes to avoid in future projects
766
+ Tag the note with relevant keywords for vector search.`,
727
767
  },
728
768
  ];
729
769
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {