@e9n/pi-personal-crm 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## [0.2.0] - 2026-02-17
9
+
10
+ ### Added
11
+
12
+ - Initial release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Espen Nilsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @e9n/pi-personal-crm
2
+
3
+ Personal CRM extension for [pi](https://github.com/mariozechner/pi-coding-agent). Manage contacts, companies, interactions, and reminders — all from the terminal or a web dashboard.
4
+
5
+ ## Features
6
+
7
+ - **Contacts** — full profiles with emails, phones, custom fields, and company association
8
+ - **Companies** — organization records with member contacts
9
+ - **Interactions** — timeline of calls, meetings, emails, notes, gifts, and messages
10
+ - **Relationships** — link contacts to each other with labeled relationships
11
+ - **Groups** — tag contacts into named groups
12
+ - **Reminders** — birthdays, anniversaries, and custom reminders with upcoming view
13
+ - **Fuzzy search** — typo-tolerant search across contacts and companies
14
+ - **Extension fields** — third-party extensions can attach read-only data to contacts/companies
15
+ - **CSV import/export** — bulk import with duplicate detection
16
+ - **Web dashboard** — 6-page UI (Contacts, Companies, Groups, Interactions, Reminders, Upcoming)
17
+
18
+ ## Setup
19
+
20
+ Add to `~/.pi/agent/settings.json` or `.pi/settings.json`:
21
+
22
+ ```json
23
+ {
24
+ "pi-personal-crm": {
25
+ "dbPath": "db/crm.db"
26
+ }
27
+ }
28
+ ```
29
+
30
+ | Key | Default | Description |
31
+ |-----|---------|-------------|
32
+ | `dbPath` | `"db/crm.db"` | SQLite file path (relative to agent dir, or absolute) |
33
+ | `useKysely` | `false` | Use shared pi-kysely DB instead of local SQLite |
34
+
35
+ ## Tool: `crm`
36
+
37
+ Manages all CRM entities. Pass `action` plus the relevant fields.
38
+
39
+ ### Actions
40
+
41
+ | Group | Actions |
42
+ |-------|---------|
43
+ | **Contacts** | `search`, `contact`, `add_contact`, `update_contact`, `delete_contact` |
44
+ | **Interactions** | `log_interaction` |
45
+ | **Reminders** | `add_reminder`, `upcoming` |
46
+ | **Relationships** | `add_relationship` |
47
+ | **Companies** | `list_companies`, `add_company` |
48
+ | **Groups** | `list_groups`, `add_to_group`, `remove_from_group` |
49
+ | **Import/Export** | `export_csv`, `import_csv` |
50
+
51
+ ### Key Parameters
52
+
53
+ | Parameter | Type | Description |
54
+ |-----------|------|-------------|
55
+ | `action` | string | Action to perform (required) |
56
+ | `query` | string | Search query (for `search`) |
57
+ | `contact_id` | number | Contact ID (for `contact`, `update_contact`, `log_interaction`, `add_reminder`) |
58
+ | `name` | string | Contact name — alternative to `contact_id` for `contact` action |
59
+ | `first_name` / `last_name` | string | Contact name fields |
60
+ | `email` / `phone` | string | Primary email / phone |
61
+ | `company_name` | string | Company association |
62
+ | `interaction_type` | string | `call`, `meeting`, `email`, `note`, `gift`, `message` |
63
+ | `summary` | string | Interaction summary (required for `log_interaction`) |
64
+ | `reminder_type` | string | `birthday`, `anniversary`, `custom` |
65
+ | `reminder_date` | string | ISO date for the reminder |
66
+
67
+ ## Commands
68
+
69
+ | Command | Description |
70
+ |---------|-------------|
71
+ | `/crm-web [port]` | Start standalone web UI (default port 4100) |
72
+ | `/crm-web stop` | Stop the standalone server |
73
+ | `/crm-web status` | Show whether CRM is running standalone or via pi-webserver |
74
+ | `/crm-export` | Export all contacts to `crm-contacts.csv` |
75
+ | `/crm-import <path>` | Import contacts from a CSV file |
76
+
77
+ ## Web UI
78
+
79
+ The dashboard (`crm.html`) auto-mounts at `/crm` when [pi-webserver](https://github.com/espennilsen/pi) is installed. Use `/crm-web` to start a standalone server on port 4100.
80
+
81
+ ## Install
82
+
83
+ ```bash
84
+ pi install npm:@e9n/pi-personal-crm
85
+ ```
86
+
87
+ ## License
88
+
89
+ MIT
package/crm.html ADDED
@@ -0,0 +1,377 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>CRM</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0a0a0f; --bg2: #12121a; --bg3: #1a1a25;
10
+ --fg: #e0e0e8; --fg2: #888898; --fg3: #555568;
11
+ --accent: #7c6ff0; --accent2: #9d8cf0;
12
+ --green: #4ade80; --red: #f87171; --yellow: #fbbf24; --blue: #60a5fa;
13
+ --border: #2a2a3a; --radius: 8px;
14
+ }
15
+ * { box-sizing: border-box; margin: 0; padding: 0; }
16
+ body { background: var(--bg); color: var(--fg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; font-size: 14px; line-height: 1.5; }
17
+
18
+
19
+
20
+ /* ── Layout ─────────────────────────────────────────── */
21
+ .container { max-width: 1600px; margin: 0 auto; padding: 20px; }
22
+ .split-view { display: grid; grid-template-columns: 400px 1fr; gap: 20px; }
23
+ @media (max-width: 1024px) { .split-view { grid-template-columns: 1fr; } }
24
+
25
+ /* ── Toolbar ────────────────────────────────────────── */
26
+ .toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
27
+ .toolbar h1 { font-size: 18px; font-weight: 700; }
28
+ .search-box { background: var(--bg3); border: 1px solid var(--border); color: var(--fg); padding: 6px 12px; border-radius: var(--radius); font-size: 13px; width: 300px; }
29
+ .search-box:focus { outline: none; border-color: var(--accent); }
30
+ .btn { background: var(--bg3); border: 1px solid var(--border); color: var(--fg); padding: 6px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px; transition: all 0.15s; }
31
+ .btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
32
+ .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
33
+ .btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
34
+ .btn-sm { padding: 4px 10px; font-size: 12px; }
35
+ .btn-danger { color: var(--red); }
36
+ .btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
37
+
38
+ /* ── Contact List ───────────────────────────────────── */
39
+ .contact-list-wrapper { display: flex; gap: 0; }
40
+ .letter-bar { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 2px; background: var(--bg2); border: 1px solid var(--border); border-right: none; border-radius: var(--radius) 0 0 var(--radius); overflow-y: auto; max-height: calc(100vh - 180px); }
41
+ .letter-jump { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; font-size: 10px; font-weight: 700; color: var(--fg3); cursor: pointer; border-radius: 3px; transition: all 0.15s; flex-shrink: 0; }
42
+ .letter-jump:hover:not(.disabled) { background: var(--accent); color: #fff; }
43
+ .letter-jump.disabled { opacity: 0.25; cursor: default; }
44
+ .letter-heading { position: sticky; top: 0; padding: 6px 16px; font-size: 12px; font-weight: 700; color: var(--accent); background: var(--bg1); border-bottom: 1px solid var(--border); letter-spacing: 0.5px; z-index: 1; }
45
+ .contact-list { flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; overflow: hidden; max-height: calc(100vh - 180px); overflow-y: auto; }
46
+ .contact-item { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; }
47
+ .contact-item:hover { background: var(--bg3); }
48
+ .contact-item.active { background: rgba(124,111,240,0.15); border-left: 3px solid var(--accent); }
49
+ .contact-item:last-child { border-bottom: none; }
50
+ .contact-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
51
+ .contact-meta { font-size: 12px; color: var(--fg2); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
52
+ .contact-company { color: var(--fg3); }
53
+ .contact-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
54
+ .tag { background: var(--bg3); border: 1px solid var(--border); padding: 2px 6px; border-radius: 4px; font-size: 10px; color: var(--fg2); }
55
+
56
+ /* ── Contact Detail ─────────────────────────────────── */
57
+ .detail-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; max-height: calc(100vh - 180px); overflow-y: auto; }
58
+ .detail-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
59
+ .detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
60
+ .contact-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--bg3); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; color: var(--accent); margin-bottom: 12px; }
61
+ .detail-name { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
62
+ .detail-company { font-size: 14px; color: var(--fg2); margin-bottom: 12px; }
63
+ .detail-field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
64
+ .detail-field-icon { color: var(--fg3); width: 20px; text-align: center; }
65
+ .section { margin-top: 24px; }
66
+ .section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--fg2); text-transform: uppercase; letter-spacing: 0.5px; }
67
+ .empty-state { text-align: center; padding: 40px 20px; color: var(--fg3); }
68
+
69
+ /* ── Timeline ───────────────────────────────────────── */
70
+ .timeline { border-left: 2px solid var(--border); padding-left: 0; }
71
+ .timeline-item { position: relative; padding-left: 32px; padding-bottom: 20px; }
72
+ .timeline-item:last-child { padding-bottom: 0; }
73
+ .timeline-dot { position: absolute; left: -9px; top: 0; width: 16px; height: 16px; border-radius: 50%; background: var(--bg3); border: 3px solid var(--border); }
74
+ .timeline-dot.call { border-color: var(--blue); }
75
+ .timeline-dot.meeting { border-color: var(--green); }
76
+ .timeline-dot.email { border-color: var(--yellow); }
77
+ .timeline-dot.note { border-color: var(--accent); }
78
+ .timeline-dot.gift { border-color: var(--red); }
79
+ .timeline-dot.message { border-color: var(--accent2); }
80
+ .timeline-date { font-size: 11px; color: var(--fg3); margin-bottom: 4px; }
81
+ .timeline-content { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
82
+ .timeline-type { display: inline-block; background: var(--bg); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; margin-bottom: 6px; text-transform: uppercase; }
83
+ .timeline-type.call { color: var(--blue); }
84
+ .timeline-type.meeting { color: var(--green); }
85
+ .timeline-type.email { color: var(--yellow); }
86
+ .timeline-type.note { color: var(--accent); }
87
+ .timeline-type.gift { color: var(--red); }
88
+ .timeline-type.message { color: var(--accent2); }
89
+ .timeline-summary { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
90
+ .timeline-notes { font-size: 12px; color: var(--fg2); }
91
+
92
+ /* ── Modal ──────────────────────────────────────────── */
93
+ .modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 1000; justify-content: center; align-items: center; }
94
+ .modal.show { display: flex; }
95
+ .modal-content { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto; }
96
+ .modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
97
+ .modal-title { font-size: 18px; font-weight: 700; }
98
+ .modal-close { background: none; border: none; color: var(--fg2); font-size: 24px; cursor: pointer; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius); }
99
+ .modal-close:hover { background: var(--bg3); color: var(--fg); }
100
+ .modal-body { padding: 20px; }
101
+ .form-group { margin-bottom: 16px; }
102
+ .form-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--fg2); }
103
+ .form-input, .form-textarea, .form-select { background: var(--bg3); border: 1px solid var(--border); color: var(--fg); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; width: 100%; }
104
+ .form-input:focus, .form-textarea:focus, .form-select:focus { outline: none; border-color: var(--accent); }
105
+ .form-textarea { resize: vertical; min-height: 80px; }
106
+ .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
107
+ @media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
108
+ .modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; }
109
+
110
+ /* ── Relationships & Reminders (contact detail) ─────── */
111
+ .rel-list, .rem-list { display: flex; flex-direction: column; gap: 8px; }
112
+ .rel-item, .rem-item { background: var(--bg3); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
113
+ .rel-type, .rem-type { font-size: 11px; color: var(--fg3); text-transform: uppercase; }
114
+ .rel-name { font-weight: 600; }
115
+ .rel-item > div[onclick]:hover .rel-name { color: var(--accent2); }
116
+ .delete-icon { background: none; border: none; color: var(--fg3); cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 4px; opacity: 0.5; transition: all 0.15s; }
117
+ .delete-icon:hover { opacity: 1; color: var(--red); background: rgba(248,113,113,0.1); }
118
+
119
+ /* ── Page visibility ────────────────────────────────── */
120
+ .page { animation: fadeIn 0.15s ease; }
121
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
122
+
123
+ /* ── Groups Page ────────────────────────────────────── */
124
+ .group-item { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; display: flex; justify-content: space-between; align-items: center; }
125
+ .group-item:hover { background: var(--bg3); }
126
+ .group-item.active { background: rgba(124,111,240,0.15); border-left: 3px solid var(--accent); }
127
+ .group-item:last-child { border-bottom: none; }
128
+ .group-name { font-weight: 600; font-size: 14px; }
129
+ .group-desc { font-size: 12px; color: var(--fg2); margin-top: 2px; }
130
+ .group-count { font-size: 11px; color: var(--fg3); background: var(--bg3); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
131
+
132
+ /* ── Interactions Page ──────────────────────────────── */
133
+ .interactions-grid { display: flex; flex-direction: column; gap: 8px; }
134
+ .interaction-row { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: flex-start; gap: 14px; transition: background 0.15s; }
135
+ .interaction-row:hover { background: var(--bg3); }
136
+ .interaction-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; background: var(--bg3); border: 2px solid var(--border); }
137
+ .interaction-icon.call { border-color: var(--blue); }
138
+ .interaction-icon.meeting { border-color: var(--green); }
139
+ .interaction-icon.email { border-color: var(--yellow); }
140
+ .interaction-icon.note { border-color: var(--accent); }
141
+ .interaction-icon.gift { border-color: var(--red); }
142
+ .interaction-icon.message { border-color: var(--accent2); }
143
+ .interaction-body { flex: 1; min-width: 0; }
144
+ .interaction-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
145
+ .interaction-contact { font-weight: 600; font-size: 13px; color: var(--accent2); cursor: pointer; }
146
+ .interaction-contact:hover { text-decoration: underline; }
147
+ .interaction-time { font-size: 11px; color: var(--fg3); margin-left: auto; white-space: nowrap; }
148
+ .interaction-summary { font-size: 13px; font-weight: 500; }
149
+ .interaction-notes-text { font-size: 12px; color: var(--fg2); margin-top: 4px; }
150
+
151
+ /* ── Reminders Page ─────────────────────────────────── */
152
+ .reminders-grid { display: flex; flex-direction: column; gap: 8px; }
153
+ .reminder-row { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: center; gap: 14px; transition: background 0.15s; }
154
+ .reminder-row:hover { background: var(--bg3); }
155
+ .reminder-row.overdue { border-left: 3px solid var(--red); }
156
+ .reminder-row.soon { border-left: 3px solid var(--yellow); }
157
+ .reminder-row.upcoming { border-left: 3px solid var(--green); }
158
+ .reminder-type-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; background: var(--bg3); border: 2px solid var(--border); }
159
+ .reminder-body { flex: 1; min-width: 0; }
160
+ .reminder-contact-name { font-weight: 600; font-size: 13px; color: var(--accent2); cursor: pointer; }
161
+ .reminder-contact-name:hover { text-decoration: underline; }
162
+ .reminder-date-text { font-size: 13px; font-weight: 500; }
163
+ .reminder-message-text { font-size: 12px; color: var(--fg2); margin-top: 2px; }
164
+ .reminder-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; text-transform: uppercase; white-space: nowrap; }
165
+ .reminder-badge.overdue { background: rgba(248,113,113,0.15); color: var(--red); }
166
+ .reminder-badge.soon { background: rgba(251,191,36,0.15); color: var(--yellow); }
167
+ .reminder-badge.upcoming { background: rgba(74,222,128,0.15); color: var(--green); }
168
+
169
+ /* ── Group member list ──────────────────────────────── */
170
+ .member-list { display: flex; flex-direction: column; gap: 6px; }
171
+ .member-item { background: var(--bg3); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
172
+ .member-item:hover { border-color: var(--accent); }
173
+ .member-name { font-weight: 600; cursor: pointer; }
174
+ .member-name:hover { color: var(--accent2); }
175
+ .member-meta { font-size: 12px; color: var(--fg2); }
176
+
177
+ /* ── Upcoming Cards ─────────────────────────────────── */
178
+ .upcoming-section { margin-bottom: 24px; }
179
+ .upcoming-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
180
+ .upcoming-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; align-items: center; gap: 14px; cursor: pointer; transition: all 0.15s; }
181
+ .upcoming-card:hover { background: var(--bg3); border-color: var(--accent); }
182
+ .upcoming-icon { font-size: 28px; }
183
+ .upcoming-name { font-weight: 600; font-size: 14px; }
184
+ .upcoming-date { font-size: 12px; color: var(--fg2); }
185
+ .upcoming-days { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px; margin-left: auto; white-space: nowrap; }
186
+ .upcoming-days.soon { background: rgba(251,191,36,0.15); color: var(--yellow); }
187
+ .upcoming-days.today { background: rgba(74,222,128,0.15); color: var(--green); }
188
+ .upcoming-days.later { background: rgba(124,111,240,0.1); color: var(--accent2); }
189
+
190
+ /* ── Import Result ────────────────────────────────────── */
191
+ .import-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
192
+ .import-stat { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
193
+ .import-stat-value { font-size: 24px; font-weight: 700; }
194
+ .import-stat-value.created { color: var(--green); }
195
+ .import-stat-value.skipped { color: var(--yellow); }
196
+ .import-stat-label { font-size: 11px; color: var(--fg2); text-transform: uppercase; margin-top: 4px; }
197
+ .import-section { margin-bottom: 16px; }
198
+ .import-section-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 10px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-weight: 600; user-select: none; }
199
+ .import-section-header:hover { background: var(--bg); }
200
+ .import-section-header .badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
201
+ .import-section-body { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); max-height: 200px; overflow-y: auto; }
202
+ .import-section-body.collapsed { display: none; }
203
+ .import-row { padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 12px; color: var(--fg2); }
204
+ .import-row:last-child { border-bottom: none; }
205
+ .import-row .match { color: var(--fg3); font-size: 11px; }
206
+
207
+ /* ── Navigation ─────────────────────────────────────── */
208
+ .crm-nav { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; align-items: center; gap: 0; position: sticky; top: 0; z-index: 900; }
209
+ .crm-nav .nav-brand { font-size: 16px; font-weight: 700; color: var(--accent); padding: 12px 16px 12px 0; margin-right: 8px; border-right: 1px solid var(--border); cursor: pointer; }
210
+ .crm-nav .nav-brand:hover { color: var(--accent2); }
211
+ .crm-nav a { color: var(--fg2); text-decoration: none; font-size: 13px; font-weight: 500; padding: 12px 14px; transition: all 0.15s; border-bottom: 2px solid transparent; cursor: pointer; user-select: none; }
212
+ .crm-nav a:hover { color: var(--fg); background: rgba(255,255,255,0.03); }
213
+ .crm-nav a.active { color: var(--accent2); border-bottom-color: var(--accent); }
214
+ .crm-nav .nav-spacer { flex: 1; }
215
+
216
+ /* ── Dashboard ──────────────────────────────────────── */
217
+ .dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
218
+ .stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 16px; text-align: center; cursor: pointer; transition: all 0.15s; }
219
+ .stat-card:hover { border-color: var(--accent); background: var(--bg3); }
220
+ .stat-icon { font-size: 24px; margin-bottom: 8px; }
221
+ .stat-value { font-size: 28px; font-weight: 700; color: var(--fg); }
222
+ .stat-label { font-size: 12px; color: var(--fg2); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
223
+
224
+ .dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
225
+ @media (max-width: 1024px) { .dash-grid { grid-template-columns: 1fr; } }
226
+
227
+ .dash-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
228
+ .dash-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
229
+ .dash-panel-header h2 { font-size: 15px; font-weight: 600; }
230
+
231
+ .dash-upcoming-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.03); cursor: pointer; transition: background 0.15s; }
232
+ .dash-upcoming-item:hover { background: var(--bg3); }
233
+ .dash-upcoming-item:last-child { border-bottom: none; }
234
+ .dash-upcoming-icon { font-size: 20px; flex-shrink: 0; }
235
+ .dash-upcoming-body { flex: 1; min-width: 0; }
236
+ .dash-upcoming-name { font-weight: 600; font-size: 13px; }
237
+ .dash-upcoming-meta { font-size: 11px; color: var(--fg3); }
238
+
239
+ .dash-activity-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.03); cursor: pointer; transition: background 0.15s; }
240
+ .dash-activity-item:hover { background: var(--bg3); }
241
+ .dash-activity-item:last-child { border-bottom: none; }
242
+ .dash-activity-icon { font-size: 16px; margin-top: 2px; flex-shrink: 0; }
243
+ .dash-activity-body { flex: 1; min-width: 0; }
244
+ .dash-activity-header { display: flex; align-items: center; gap: 8px; }
245
+ .dash-activity-name { font-weight: 600; font-size: 13px; }
246
+ .dash-activity-time { font-size: 11px; color: var(--fg3); margin-left: auto; white-space: nowrap; }
247
+ .dash-activity-summary { font-size: 12px; color: var(--fg2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
248
+
249
+ .dash-neglected-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0; }
250
+ .dash-neglected-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,0.03); cursor: pointer; transition: background 0.15s; }
251
+ .dash-neglected-item:hover { background: var(--bg3); }
252
+ .dash-neglected-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--bg3); border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
253
+ .dash-neglected-body { flex: 1; min-width: 0; }
254
+ .dash-neglected-name { font-weight: 600; font-size: 13px; }
255
+ .dash-neglected-meta { font-size: 11px; color: var(--fg3); }
256
+ </style>
257
+ </head>
258
+ <body>
259
+
260
+
261
+
262
+ <!-- Navigation -->
263
+ <nav class="crm-nav">
264
+ <span class="nav-brand" onclick="navigateTo('dashboard')">CRM</span>
265
+ <a onclick="navigateTo('dashboard')" data-page="dashboard">Dashboard</a>
266
+ <a onclick="navigateTo('contacts')" data-page="contacts">Contacts</a>
267
+ <a onclick="navigateTo('companies')" data-page="companies">Companies</a>
268
+ <a onclick="navigateTo('groups')" data-page="groups">Groups</a>
269
+ <a onclick="navigateTo('interactions')" data-page="interactions">Interactions</a>
270
+ <a onclick="navigateTo('reminders')" data-page="reminders">Reminders</a>
271
+ <a onclick="navigateTo('upcoming')" data-page="upcoming">Upcoming</a>
272
+ <span class="nav-spacer"></span>
273
+ </nav>
274
+
275
+ <!-- Shared globals & utilities — available to all page scripts -->
276
+ <script>
277
+ let currentPage = 'dashboard';
278
+ let currentContactId = null;
279
+ let allContacts = [];
280
+ let allGroups = [];
281
+
282
+ const typeIcons = { call: '📞', meeting: '🤝', email: '📧', note: '📝', gift: '🎁', message: '💬' };
283
+ const reminderIcons = { birthday: '🎂', anniversary: '💍', custom: '📌' };
284
+
285
+ function esc(str) {
286
+ if (str == null) return '';
287
+ return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
288
+ }
289
+
290
+ function showModal(id) {
291
+ document.getElementById(id).classList.add('show');
292
+ }
293
+
294
+ function closeModal(id) {
295
+ document.getElementById(id).classList.remove('show');
296
+ }
297
+
298
+ function navigateTo(page) {
299
+ currentPage = page;
300
+ document.querySelectorAll('.page').forEach(p => p.style.display = 'none');
301
+ const el = document.getElementById('page-' + page);
302
+ if (el) el.style.display = '';
303
+
304
+ // Update nav active state
305
+ document.querySelectorAll('.crm-nav a[data-page]').forEach(a => {
306
+ a.classList.toggle('active', a.dataset.page === page);
307
+ });
308
+
309
+ if (page === 'dashboard') loadDashboard();
310
+ if (page === 'contacts') { loadContacts(); loadCompanies(); }
311
+ if (page === 'companies') loadCompaniesPage();
312
+ if (page === 'groups') loadGroupsPage();
313
+ if (page === 'interactions') loadInteractionsPage();
314
+ if (page === 'reminders') loadRemindersPage();
315
+ if (page === 'upcoming') loadUpcomingPage();
316
+ }
317
+
318
+ /** Safe fetch: returns [] if the API errors or returns a non-array. */
319
+ async function safeFetchArray(url) {
320
+ try {
321
+ const res = await fetch(url);
322
+ if (!res.ok) return [];
323
+ const data = await res.json();
324
+ return Array.isArray(data) ? data : [];
325
+ } catch { return []; }
326
+ }
327
+
328
+ async function refreshContacts() {
329
+ allContacts = await safeFetchArray('/api/crm/contacts?limit=1000');
330
+ return allContacts;
331
+ }
332
+ </script>
333
+
334
+ <div class="container">
335
+ <!-- PAGES -->
336
+ </div>
337
+
338
+ <!-- Import Result Modal (global — used by contacts page) -->
339
+ <div class="modal" id="importResultModal">
340
+ <div class="modal-content" style="max-width: 520px;">
341
+ <div class="modal-header">
342
+ <h2 class="modal-title">📥 Import Results</h2>
343
+ <button class="modal-close" onclick="closeModal('importResultModal')">&times;</button>
344
+ </div>
345
+ <div class="modal-body" id="importResultBody"></div>
346
+ <div class="modal-footer">
347
+ <button class="btn btn-primary" onclick="closeModal('importResultModal')">Done</button>
348
+ </div>
349
+ </div>
350
+ </div>
351
+
352
+ <!-- Bootstrap — runs after all page scripts are loaded -->
353
+ <script>
354
+ document.addEventListener('keydown', (e) => {
355
+ if (e.key === 'Escape') {
356
+ document.querySelectorAll('.modal.show').forEach(m => m.classList.remove('show'));
357
+ }
358
+ });
359
+
360
+ document.querySelectorAll('.modal').forEach(modal => {
361
+ modal.addEventListener('click', (e) => {
362
+ if (e.target === modal) modal.classList.remove('show');
363
+ });
364
+ });
365
+
366
+ // Wire up contacts search
367
+ const searchEl = document.getElementById('search');
368
+ if (searchEl) searchEl.addEventListener('input', (e) => {
369
+ filterContacts(e.target.value.toLowerCase());
370
+ });
371
+
372
+ // Start on dashboard
373
+ navigateTo('dashboard');
374
+ </script>
375
+
376
+ </body>
377
+ </html>
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@e9n/pi-personal-crm",
3
+ "version": "0.2.0",
4
+ "description": "Personal CRM extension for pi coding agents",
5
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package"
8
+ ],
9
+ "pi": {
10
+ "extensions": [
11
+ "./src/index.ts"
12
+ ]
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit",
16
+ "test": "node --import tsx/esm test-db.ts"
17
+ },
18
+ "author": "Espen Nilsen <hi@e9n.dev>",
19
+ "license": "MIT",
20
+ "peerDependencies": {
21
+ "@mariozechner/pi-ai": "*",
22
+ "@mariozechner/pi-coding-agent": "*",
23
+ "@sinclair/typebox": "*"
24
+ },
25
+ "dependencies": {
26
+ "better-sqlite3": "^12.6.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/better-sqlite3": "^7.6.12",
30
+ "tsx": "^4.21.0",
31
+ "typescript": "^5.9.3"
32
+ },
33
+ "files": [
34
+ "CHANGELOG.md",
35
+ "README.md",
36
+ "crm.html",
37
+ "package.json",
38
+ "src"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/espennilsen/pi.git",
43
+ "directory": "extensions/pi-personal-crm"
44
+ }
45
+ }