@phi-code-admin/phi-code 0.59.4 → 0.59.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.59.4",
3
+ "version": "0.59.5",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -29,7 +29,8 @@
29
29
  "extensions",
30
30
  "README.md",
31
31
  "LICENSE",
32
- "CHANGELOG.md"
32
+ "CHANGELOG.md",
33
+ "scripts"
33
34
  ],
34
35
  "scripts": {
35
36
  "clean": "shx rm -rf dist",
@@ -39,7 +40,8 @@
39
40
  "copy-assets": "shx mkdir -p dist/modes/interactive/theme && shx cp src/modes/interactive/theme/*.json dist/modes/interactive/theme/ && shx mkdir -p dist/core/export-html/vendor && shx cp src/core/export-html/template.html src/core/export-html/template.css src/core/export-html/template.js dist/core/export-html/ && shx cp src/core/export-html/vendor/*.js dist/core/export-html/vendor/",
40
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/",
41
42
  "test": "vitest --run",
42
- "prepublishOnly": "npm run clean && npm run build"
43
+ "prepublishOnly": "npm run clean && npm run build",
44
+ "postinstall": "node scripts/postinstall.cjs"
43
45
  },
44
46
  "dependencies": {
45
47
  "@mariozechner/jiti": "^2.6.2",
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Migrate sessions from ~/.pi/agent/*.jsonl to proper session directories.
4
+ # This fixes sessions created by the bug in v0.30.0 where sessions were
5
+ # saved to ~/.pi/agent/ instead of ~/.pi/agent/sessions/<encoded-cwd>/.
6
+ #
7
+ # Usage: ./migrate-sessions.sh [--dry-run]
8
+ #
9
+
10
+ set -e
11
+
12
+ AGENT_DIR="${PI_AGENT_DIR:-$HOME/.pi/agent}"
13
+ DRY_RUN=false
14
+
15
+ if [[ "$1" == "--dry-run" ]]; then
16
+ DRY_RUN=true
17
+ echo "Dry run mode - no files will be moved"
18
+ echo
19
+ fi
20
+
21
+ # Find all .jsonl files directly in agent dir (not in subdirectories)
22
+ shopt -s nullglob
23
+ files=("$AGENT_DIR"/*.jsonl)
24
+ shopt -u nullglob
25
+
26
+ if [[ ${#files[@]} -eq 0 ]]; then
27
+ echo "No session files found in $AGENT_DIR"
28
+ exit 0
29
+ fi
30
+
31
+ echo "Found ${#files[@]} session file(s) to migrate"
32
+ echo
33
+
34
+ migrated=0
35
+ failed=0
36
+
37
+ for file in "${files[@]}"; do
38
+ filename=$(basename "$file")
39
+
40
+ # Read first line and extract cwd using jq
41
+ if ! first_line=$(head -1 "$file" 2>/dev/null); then
42
+ echo "SKIP: $filename - cannot read file"
43
+ ((failed++))
44
+ continue
45
+ fi
46
+
47
+ # Parse JSON and extract cwd
48
+ if ! cwd=$(echo "$first_line" | jq -r '.cwd // empty' 2>/dev/null); then
49
+ echo "SKIP: $filename - invalid JSON"
50
+ ((failed++))
51
+ continue
52
+ fi
53
+
54
+ if [[ -z "$cwd" ]]; then
55
+ echo "SKIP: $filename - no cwd in session header"
56
+ ((failed++))
57
+ continue
58
+ fi
59
+
60
+ # Encode cwd: remove leading slash, replace slashes with dashes, wrap with --
61
+ encoded=$(echo "$cwd" | sed 's|^/||' | sed 's|[/:\\]|-|g')
62
+ encoded="--${encoded}--"
63
+
64
+ target_dir="$AGENT_DIR/sessions/$encoded"
65
+ target_file="$target_dir/$filename"
66
+
67
+ if [[ -e "$target_file" ]]; then
68
+ echo "SKIP: $filename - target already exists"
69
+ ((failed++))
70
+ continue
71
+ fi
72
+
73
+ echo "MIGRATE: $filename"
74
+ echo " cwd: $cwd"
75
+ echo " to: $target_dir/"
76
+
77
+ if [[ "$DRY_RUN" == false ]]; then
78
+ mkdir -p "$target_dir"
79
+ mv "$file" "$target_file"
80
+ fi
81
+
82
+ ((migrated++))
83
+ echo
84
+ done
85
+
86
+ echo "---"
87
+ echo "Migrated: $migrated"
88
+ echo "Skipped: $failed"
89
+
90
+ if [[ "$DRY_RUN" == true && $migrated -gt 0 ]]; then
91
+ echo
92
+ echo "Run without --dry-run to perform the migration"
93
+ fi
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-install script: copies bundled extensions, agents, and skills
4
+ * to ~/.phi/agent/ so Pi discovers them automatically.
5
+ */
6
+ const { existsSync, mkdirSync, cpSync, readdirSync } = require("fs");
7
+ const { join } = require("path");
8
+ const { homedir } = require("os");
9
+
10
+ const agentDir = join(homedir(), ".phi", "agent");
11
+ const packageDir = __dirname.replace(/[/\\]scripts$/, "");
12
+
13
+ const copies = [
14
+ { src: "extensions/phi", dest: join(agentDir, "extensions"), label: "extensions" },
15
+ { src: "agents", dest: join(agentDir, "agents"), label: "agents" },
16
+ { src: "skills", dest: join(agentDir, "skills"), label: "skills" },
17
+ ];
18
+
19
+ for (const { src, dest, label } of copies) {
20
+ const srcDir = join(packageDir, src);
21
+ if (!existsSync(srcDir)) continue;
22
+
23
+ mkdirSync(dest, { recursive: true });
24
+
25
+ const files = readdirSync(srcDir);
26
+ let copied = 0;
27
+ for (const file of files) {
28
+ const srcPath = join(srcDir, file);
29
+ const destPath = join(dest, file);
30
+ try {
31
+ cpSync(srcPath, destPath, { recursive: true, force: true });
32
+ copied++;
33
+ } catch (e) {
34
+ // Skip files that can't be copied (permissions, etc.)
35
+ }
36
+ }
37
+ if (copied > 0) {
38
+ console.log(` Φ Installed ${copied} ${label} to ${dest}`);
39
+ }
40
+ }