chatshelf 0.2.0 → 0.3.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/README.md +28 -8
- package/bin/chatshelf.mjs +13 -9
- package/package.json +9 -2
- package/public/app.js +162 -7
- package/public/favicon.svg +8 -0
- package/public/index.html +71 -14
- package/public/logo-reversed.svg +8 -0
- package/public/logo.svg +8 -0
- package/public/style.css +87 -0
- package/server.mjs +148 -19
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
+
<img src="https://raw.githubusercontent.com/heyKhoaiz/chatshelf/main/docs/brand/logo.svg" width="88" height="88" alt="Chatshelf logo">
|
|
4
|
+
|
|
3
5
|
# Chatshelf
|
|
4
6
|
|
|
5
7
|
**One place for your AI coding chats.**
|
|
@@ -12,6 +14,7 @@ Browse, search and bookmark your history from Claude Code, Codex, Cursor and Git
|
|
|
12
14
|
[](LICENSE)
|
|
13
15
|

|
|
14
16
|

|
|
17
|
+
[](https://x.com/khoaizahmmed)
|
|
15
18
|
|
|
16
19
|

|
|
17
20
|
|
|
@@ -61,7 +64,7 @@ chatshelf
|
|
|
61
64
|
### Open it
|
|
62
65
|
|
|
63
66
|
- Run `chatshelf` (or `npx chatshelf`). It opens **http://chatshelf.localhost:4317** in your browser.
|
|
64
|
-
- Already running? Running `chatshelf` again just opens the browser to it.
|
|
67
|
+
- Already running? Running `chatshelf` again just opens the browser to it, even if it picked another port.
|
|
65
68
|
- Bookmark the address to get back in one click while it's running.
|
|
66
69
|
- Press **Ctrl+C** in the terminal to stop it. Run `chatshelf --help` to see every option.
|
|
67
70
|
- Just installed and your shell says `command not found`? Open a new terminal tab, or run `rehash` (zsh) or `hash -r` (bash).
|
|
@@ -87,14 +90,25 @@ The address works in Chrome, Edge, Firefox and Brave with no setup. If your brow
|
|
|
87
90
|
|
|
88
91
|
To look around without your own history, run `npm run demo`. It uses fake chats in a temporary folder.
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
### Choose the address
|
|
94
|
+
|
|
95
|
+
By default Chatshelf uses **http://chatshelf.localhost:4317**. If port 4317 is taken by another program, it moves to the next free port (4318, 4319…) by itself and prints the address.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
chatshelf --port 5000 # your own port (used as-is; you get a message if it's taken)
|
|
99
|
+
chatshelf --host work.localhost # your own name: http://work.localhost:4317
|
|
100
|
+
chatshelf --host notes.localhost --port 8080
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Names must end in `.localhost`. Browsers always send those to your own computer, which keeps Chatshelf safe from other websites. The same settings work as environment variables: `CHATSHELF_PORT=5000`, `CHATSHELF_HOST=work.localhost` (`PORT` also works).
|
|
104
|
+
|
|
105
|
+
Other options:
|
|
91
106
|
|
|
92
107
|
```bash
|
|
93
|
-
chatshelf --help
|
|
94
|
-
chatshelf --version
|
|
95
|
-
chatshelf --no-open
|
|
96
|
-
|
|
97
|
-
CHATSHELF_TERMINAL=kitty chatshelf # pick the terminal for "Open in terminal"
|
|
108
|
+
chatshelf --help # all options
|
|
109
|
+
chatshelf --version # installed version
|
|
110
|
+
chatshelf --no-open # don't open the browser
|
|
111
|
+
CHATSHELF_TERMINAL=kitty chatshelf # terminal for "Open in terminal"
|
|
98
112
|
```
|
|
99
113
|
|
|
100
114
|
## Supported tools
|
|
@@ -135,7 +149,7 @@ A move:
|
|
|
135
149
|
|
|
136
150
|
## Privacy and safety
|
|
137
151
|
|
|
138
|
-
- It listens on `127.0.0.1` only and accepts only
|
|
152
|
+
- It listens on `127.0.0.1` only and accepts only `127.0.0.1`, `localhost`, `chatshelf.localhost` and the `.localhost` name you choose, which blocks DNS rebinding.
|
|
139
153
|
- Every API call needs a random token that changes each time the server starts.
|
|
140
154
|
- It reads other tools' files but never changes them. The only writes outside its own folders are moving or restoring Claude Code sessions, and only when you click **Move** or **Restore**.
|
|
141
155
|
- One network request: the **Star on GitHub** button fetches the public star count from `api.github.com`, cached for 6 hours. Nothing about you or your chats is sent.
|
|
@@ -146,6 +160,12 @@ Contributions are very welcome, especially readers for more tools (Windsurf, Zed
|
|
|
146
160
|
|
|
147
161
|
If Chatshelf helped you find a lost chat, **[give it a ⭐ on GitHub](https://github.com/heyKhoaiz/chatshelf)**. It helps other people find it.
|
|
148
162
|
|
|
163
|
+
## Author
|
|
164
|
+
|
|
165
|
+
Made by **Shaikh khoaiz Ahmmed**: [khoaiz.com](https://khoaiz.com) · [X @khoaizahmmed](https://x.com/khoaizahmmed) · [GitHub @heyKhoaiz](https://github.com/heyKhoaiz)
|
|
166
|
+
|
|
167
|
+
Ideas, bugs or just saying hi: open an [issue](https://github.com/heyKhoaiz/chatshelf/issues) or find me on [X](https://x.com/khoaizahmmed).
|
|
168
|
+
|
|
149
169
|
## License
|
|
150
170
|
|
|
151
171
|
[MIT](LICENSE) © Shaikh khoaiz Ahmmed
|
package/bin/chatshelf.mjs
CHANGED
|
@@ -8,7 +8,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
9
9
|
const args = process.argv.slice(2);
|
|
10
10
|
const { version } = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
11
|
-
const port = process.env.PORT || '4317';
|
|
11
|
+
const port = process.env.CHATSHELF_PORT || process.env.PORT || '4317';
|
|
12
|
+
const host = process.env.CHATSHELF_HOST || 'chatshelf.localhost';
|
|
12
13
|
|
|
13
14
|
if (args.includes('--version') || args.includes('-v')) {
|
|
14
15
|
console.log(version);
|
|
@@ -18,15 +19,18 @@ if (args.includes('--help') || args.includes('-h')) {
|
|
|
18
19
|
console.log(`Chatshelf ${version}: one place for your AI coding chats
|
|
19
20
|
|
|
20
21
|
Usage
|
|
21
|
-
chatshelf
|
|
22
|
-
|
|
23
|
-
chatshelf --
|
|
24
|
-
chatshelf --
|
|
25
|
-
chatshelf --
|
|
22
|
+
chatshelf start and open http://${host}:${port}
|
|
23
|
+
(if it's already running, this just opens it)
|
|
24
|
+
chatshelf --port 5000 use this port (default: 4317, or the next free one)
|
|
25
|
+
chatshelf --host work.localhost use your own address (must end in .localhost)
|
|
26
|
+
chatshelf --no-open start without opening the browser
|
|
27
|
+
chatshelf --version print the version
|
|
28
|
+
chatshelf --help show this help
|
|
26
29
|
|
|
27
|
-
Settings (environment variables)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
Settings (environment variables, same as the flags)
|
|
31
|
+
CHATSHELF_PORT=5000 port
|
|
32
|
+
CHATSHELF_HOST=work.localhost address
|
|
33
|
+
CHATSHELF_TERMINAL=kitty terminal for "Open in terminal"
|
|
30
34
|
|
|
31
35
|
Stop it with Ctrl+C. If the address doesn't open in your browser, use http://127.0.0.1:${port}.
|
|
32
36
|
Docs: https://github.com/heyKhoaiz/chatshelf`);
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chatshelf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "One place for your AI coding chats: browse, search and bookmark Claude Code, Codex, Cursor and Copilot history, and fix Claude Code sessions after renaming a folder. Local, no dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"author":
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Shaikh khoaiz Ahmmed",
|
|
8
|
+
"url": "https://khoaiz.com"
|
|
9
|
+
},
|
|
10
|
+
"funding": {
|
|
11
|
+
"type": "individual",
|
|
12
|
+
"url": "https://khoaiz.com"
|
|
13
|
+
},
|
|
7
14
|
"homepage": "https://github.com/heyKhoaiz/chatshelf#readme",
|
|
8
15
|
"repository": {
|
|
9
16
|
"type": "git",
|
package/public/app.js
CHANGED
|
@@ -60,14 +60,15 @@ const ICON = {
|
|
|
60
60
|
reply: '<svg class="ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 14 4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 6 6v5"/></svg>',
|
|
61
61
|
};
|
|
62
62
|
let toastTimer;
|
|
63
|
-
function toast(msg) {
|
|
63
|
+
function toast(msg, action) {
|
|
64
64
|
const t = $('toast');
|
|
65
|
-
t.
|
|
65
|
+
t.innerHTML = esc(msg) + (action ? ` <a class="toast-act" href="${esc(action.href)}" target="_blank" rel="noopener noreferrer"${action.star ? ' data-star-click' : ''}>${esc(action.label)}</a>` : '');
|
|
66
|
+
t.classList.toggle('has-action', Boolean(action));
|
|
66
67
|
t.classList.remove('show');
|
|
67
68
|
void t.offsetWidth;
|
|
68
69
|
t.classList.add('show');
|
|
69
70
|
clearTimeout(toastTimer);
|
|
70
|
-
toastTimer = setTimeout(() => t.classList.remove('show'), 4500);
|
|
71
|
+
toastTimer = setTimeout(() => t.classList.remove('show'), action ? 8000 : 4500);
|
|
71
72
|
}
|
|
72
73
|
async function copy(text, btn) {
|
|
73
74
|
await navigator.clipboard.writeText(text);
|
|
@@ -89,7 +90,10 @@ const REPO_URL = `https://github.com/${REPO}`;
|
|
|
89
90
|
// Shows the star count next to "Star on GitHub". Uses GitHub's public API (no account, nothing about you is sent),
|
|
90
91
|
// cached for 6 hours, and stays hidden when offline.
|
|
91
92
|
async function loadStars() {
|
|
92
|
-
const show = (n) => {
|
|
93
|
+
const show = (n) => {
|
|
94
|
+
if (typeof n !== 'number' || n < 10) return;
|
|
95
|
+
document.querySelectorAll('[data-star-count]').forEach((el) => { el.textContent = n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n); el.hidden = false; });
|
|
96
|
+
};
|
|
93
97
|
try {
|
|
94
98
|
const c = JSON.parse(localStorage.getItem('chatshelf-stars') || 'null');
|
|
95
99
|
if (c && Date.now() - c.at < 6 * 36e5) { show(c.n); return; }
|
|
@@ -101,6 +105,27 @@ async function loadStars() {
|
|
|
101
105
|
} catch { /* offline: leave the plain button */ }
|
|
102
106
|
}
|
|
103
107
|
|
|
108
|
+
// Ask for a star at the right time: a quiet button at first, a small card from the 3rd visit,
|
|
109
|
+
// "Not now" waits 30 days, and after one click we never ask again.
|
|
110
|
+
const STAR_KEY = 'chatshelf-star';
|
|
111
|
+
const starState = () => { try { return JSON.parse(localStorage.getItem(STAR_KEY) || '{}'); } catch { return {}; } };
|
|
112
|
+
const saveStar = (st) => localStorage.setItem(STAR_KEY, JSON.stringify(st));
|
|
113
|
+
function renderStar() {
|
|
114
|
+
const st = starState();
|
|
115
|
+
const ask = !st.clicked && (st.visits || 0) >= 3 && (!st.laterUntil || Date.now() > st.laterUntil);
|
|
116
|
+
$('starCard').hidden = !ask;
|
|
117
|
+
$('ghStar').hidden = ask;
|
|
118
|
+
$('ghStar').classList.toggle('starred', Boolean(st.clicked));
|
|
119
|
+
}
|
|
120
|
+
function initStar() {
|
|
121
|
+
const st = starState();
|
|
122
|
+
st.visits = (st.visits || 0) + 1;
|
|
123
|
+
saveStar(st);
|
|
124
|
+
renderStar();
|
|
125
|
+
}
|
|
126
|
+
function starClicked() { const st = starState(); st.clicked = true; saveStar(st); setTimeout(renderStar, 300); }
|
|
127
|
+
function starLater() { const st = starState(); st.laterUntil = Date.now() + 30 * DAY; saveStar(st); renderStar(); }
|
|
128
|
+
|
|
104
129
|
// ---------- tools ----------
|
|
105
130
|
const TOOLS = {
|
|
106
131
|
claude: { label: 'Claude Code', short: 'Claude' },
|
|
@@ -1124,6 +1149,123 @@ function openBookmark(id) {
|
|
|
1124
1149
|
openDetail(s.uid, b.msgUuid);
|
|
1125
1150
|
}
|
|
1126
1151
|
|
|
1152
|
+
// ---------- handoff: continue a chat in another tool ----------
|
|
1153
|
+
const HO_OPTIONS = [
|
|
1154
|
+
{ id: 'codex', label: 'Codex', sub: 'Opens a terminal and starts codex', kind: 'terminal' },
|
|
1155
|
+
{ id: 'claude', label: 'Claude Code', sub: 'Starts a new Claude Code session', kind: 'terminal' },
|
|
1156
|
+
{ id: 'copy', label: 'Copy', sub: 'Paste into Cursor, ChatGPT, anything', kind: 'copy' },
|
|
1157
|
+
{ id: 'download', label: 'Download', sub: 'Save as a Markdown file', kind: 'download' },
|
|
1158
|
+
];
|
|
1159
|
+
const ho = { target: 'copy', targets: null };
|
|
1160
|
+
const cut = (t, n) => (t.length > n ? `${t.slice(0, n - 1)}…` : t);
|
|
1161
|
+
|
|
1162
|
+
function buildHandoff(s, msgs) {
|
|
1163
|
+
const p = s.project;
|
|
1164
|
+
const users = msgs.filter((m) => m.role === 'user' && m.text.trim()).map((m) => stripMd(m.text).replace(/\s+/g, ' ').trim()).filter(Boolean);
|
|
1165
|
+
const lastAnswer = [...msgs].reverse().find((m) => m.role === 'assistant' && m.text.trim());
|
|
1166
|
+
const touched = [];
|
|
1167
|
+
const seen = new Set();
|
|
1168
|
+
for (const m of msgs) {
|
|
1169
|
+
for (const t of m.tools || []) {
|
|
1170
|
+
const d = String(t.detail || '').trim();
|
|
1171
|
+
const k = `${t.name || t}${d ? ` ${d}` : ''}`;
|
|
1172
|
+
if (!d || seen.has(k)) continue;
|
|
1173
|
+
seen.add(k);
|
|
1174
|
+
touched.push(k);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const out = [`# Handoff: ${s.title}`, ''];
|
|
1178
|
+
out.push(`I'm continuing a conversation I had in ${toolLabel(s.source)} (last active ${date(s.mtime)}).`);
|
|
1179
|
+
if (p.cwd) out.push(`Project folder: ${p.cwd}${s.branch ? ` (git branch ${s.branch})` : ''}`);
|
|
1180
|
+
out.push('');
|
|
1181
|
+
if (users.length) {
|
|
1182
|
+
out.push('## What I asked, in order');
|
|
1183
|
+
const pick = users.length > 12 ? [...users.slice(0, 4), '…', ...users.slice(-7)] : users;
|
|
1184
|
+
for (const u of pick) out.push(u === '…' ? '- …' : `- ${cut(u, 240)}`);
|
|
1185
|
+
out.push('');
|
|
1186
|
+
}
|
|
1187
|
+
if (lastAnswer) out.push('## Where we left off', cut(lastAnswer.text.trim(), 1800), '');
|
|
1188
|
+
if (touched.length) {
|
|
1189
|
+
out.push('## Files and commands involved');
|
|
1190
|
+
for (const t of touched.slice(-15)) out.push(`- ${cut(t, 140)}`);
|
|
1191
|
+
out.push('');
|
|
1192
|
+
}
|
|
1193
|
+
out.push('## What I need from you', 'Check the current state of the files above, then continue from where we left off. Ask me if anything is unclear.');
|
|
1194
|
+
return out.join('\n');
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function renderHandoffTargets() {
|
|
1198
|
+
const p = state.detail.project;
|
|
1199
|
+
$('hoTargets').innerHTML = HO_OPTIONS.map((o) => {
|
|
1200
|
+
const t = ho.targets && ho.targets[o.id];
|
|
1201
|
+
const missing = o.kind === 'terminal' && t && !t.installed;
|
|
1202
|
+
return `<button type="button" class="ho-opt" role="radio" data-ho="${o.id}" aria-checked="${ho.target === o.id}" ${missing ? 'disabled' : ''}>
|
|
1203
|
+
${use(o.kind === 'copy' ? 'copy' : o.kind === 'download' ? 'download' : 'terminal')}
|
|
1204
|
+
<span><b>${esc(o.label)}</b><span class="small muted">${missing ? `Not installed (no "${o.id}" command)` : esc(o.sub)}</span></span>
|
|
1205
|
+
</button>`;
|
|
1206
|
+
}).join('');
|
|
1207
|
+
const opt = HO_OPTIONS.find((o) => o.id === ho.target);
|
|
1208
|
+
$('hoGoLabel').textContent = opt.kind === 'copy' ? 'Copy handoff' : opt.kind === 'download' ? 'Download .md' : `Open in ${opt.label}`;
|
|
1209
|
+
$('hoGo').querySelector('use').setAttribute('href', opt.kind === 'copy' ? '#i-copy' : opt.kind === 'download' ? '#i-download' : '#i-handoff');
|
|
1210
|
+
$('hoNote').textContent = opt.kind === 'terminal'
|
|
1211
|
+
? (p.exists ? `Starts in ${short(p.cwd)} with the handoff as your first message.` : 'This chat has no project folder on this computer, so it starts in your home folder.')
|
|
1212
|
+
: opt.kind === 'copy' ? 'Paste it as the first message in the other tool.' : 'Saves the handoff so you can attach or paste it later.';
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
async function openHandoff() {
|
|
1216
|
+
const s = state.detail;
|
|
1217
|
+
if (!s) return;
|
|
1218
|
+
if (!state.msgs.length) { toast('Wait for the chat to finish loading, then try again.'); return; }
|
|
1219
|
+
$('hoText').value = buildHandoff(s, state.msgs);
|
|
1220
|
+
$('hoError').textContent = '';
|
|
1221
|
+
updateHandoffCount();
|
|
1222
|
+
if (!ho.targets) { try { ho.targets = (await api('/api/handoff/targets')).targets; } catch { ho.targets = {}; } }
|
|
1223
|
+
// Default to "the other tool" when it's installed, otherwise Copy.
|
|
1224
|
+
const other = s.source === 'codex' ? 'claude' : 'codex';
|
|
1225
|
+
ho.target = ho.targets[other] && ho.targets[other].installed ? other : (ho.targets.claude && ho.targets.claude.installed && s.source !== 'claude' ? 'claude' : 'copy');
|
|
1226
|
+
renderHandoffTargets();
|
|
1227
|
+
$('handoff').showModal();
|
|
1228
|
+
$('hoText').scrollTop = 0;
|
|
1229
|
+
}
|
|
1230
|
+
function updateHandoffCount() {
|
|
1231
|
+
const n = $('hoText').value.length;
|
|
1232
|
+
$('hoCount').textContent = `${n.toLocaleString()} characters${n > 20000 ? ' (too long, 20,000 max)' : ''}`;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
async function goHandoff() {
|
|
1236
|
+
const s = state.detail;
|
|
1237
|
+
const text = $('hoText').value.trim();
|
|
1238
|
+
const opt = HO_OPTIONS.find((o) => o.id === ho.target);
|
|
1239
|
+
$('hoError').textContent = '';
|
|
1240
|
+
if (!text) { $('hoError').textContent = 'The handoff is empty.'; return; }
|
|
1241
|
+
if (opt.kind === 'copy') {
|
|
1242
|
+
await navigator.clipboard.writeText(text);
|
|
1243
|
+
$('handoff').close();
|
|
1244
|
+
toast('Handoff copied. Paste it as the first message in the other tool.');
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
if (opt.kind === 'download') {
|
|
1248
|
+
const a = document.createElement('a');
|
|
1249
|
+
a.href = URL.createObjectURL(new Blob([text], { type: 'text/markdown' }));
|
|
1250
|
+
a.download = `handoff-${s.title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'chat'}.md`;
|
|
1251
|
+
a.click();
|
|
1252
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
|
1253
|
+
$('handoff').close();
|
|
1254
|
+
toast('Handoff downloaded.');
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
$('hoGo').disabled = true;
|
|
1258
|
+
try {
|
|
1259
|
+
const r = await api('/api/handoff', { key: s.project.key, id: s.id, target: opt.id, text });
|
|
1260
|
+
$('handoff').close();
|
|
1261
|
+
toast(`Opened ${r.target} in ${r.terminal}, starting from your handoff.`);
|
|
1262
|
+
} catch (e) {
|
|
1263
|
+
$('hoError').textContent = e.message;
|
|
1264
|
+
} finally {
|
|
1265
|
+
$('hoGo').disabled = false;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1127
1269
|
// ---------- mover ----------
|
|
1128
1270
|
// groups: [{ key, ids|null }] (ids null = whole project, including memory)
|
|
1129
1271
|
async function openMover(groups) {
|
|
@@ -1228,7 +1370,11 @@ async function doMove(e) {
|
|
|
1228
1370
|
}
|
|
1229
1371
|
$('mover').close();
|
|
1230
1372
|
state.selected.clear();
|
|
1231
|
-
|
|
1373
|
+
const st = starState();
|
|
1374
|
+
const offer = !st.clicked && !st.offeredAfterFix;
|
|
1375
|
+
if (offer) { st.offeredAfterFix = true; saveStar(st); }
|
|
1376
|
+
toast(`Moved ${plural(moved, 'session')} to ${short(to)}.${skipped ? ` Skipped ${skipped} that already existed.` : ''}${offer ? ' Glad it helped?' : ''}`,
|
|
1377
|
+
offer ? { label: '★ Star on GitHub', href: REPO_URL, star: true } : undefined);
|
|
1232
1378
|
} catch (err) {
|
|
1233
1379
|
$('moverError').textContent = moved ? `Moved ${moved}, then stopped: ${err.message}` : err.message;
|
|
1234
1380
|
} finally {
|
|
@@ -1260,6 +1406,8 @@ function paletteItems(q) {
|
|
|
1260
1406
|
{ group: 'Go to', label: 'Backups', hint: 'g b', run: () => setView('backups'), icon: 'archive' },
|
|
1261
1407
|
{ group: 'Actions', label: 'Tools & import', run: () => openSources(), icon: 'plug' },
|
|
1262
1408
|
{ group: 'Chatshelf', label: 'Star Chatshelf on GitHub', run: () => window.open(REPO_URL, '_blank', 'noopener,noreferrer'), icon: 'star' },
|
|
1409
|
+
{ group: 'Chatshelf', label: 'About Chatshelf', run: () => $('shortcuts').showModal(), icon: 'star' },
|
|
1410
|
+
{ group: 'Chatshelf', label: 'Follow @khoaizahmmed on X', run: () => window.open('https://x.com/khoaizahmmed', '_blank', 'noopener,noreferrer'), icon: 'link' },
|
|
1263
1411
|
{ group: 'Chatshelf', label: 'Report a bug or suggest a feature', run: () => window.open(`${REPO_URL}/issues/new/choose`, '_blank', 'noopener,noreferrer'), icon: 'chat' },
|
|
1264
1412
|
{ group: 'Chatshelf', label: 'Contribute: add support for another tool', run: () => window.open(`${REPO_URL}/blob/main/CONTRIBUTING.md`, '_blank', 'noopener,noreferrer'), icon: 'plug' },
|
|
1265
1413
|
{ group: 'Actions', label: 'Import a ChatGPT or claude.ai export', run: () => openSources(), icon: 'upload' },
|
|
@@ -1329,7 +1477,7 @@ function applyTheme(pref, animate = true) {
|
|
|
1329
1477
|
if (animate && motionOn() && document.startViewTransition && root.dataset.theme !== (dark ? 'dark' : 'light')) document.startViewTransition(set);
|
|
1330
1478
|
else set();
|
|
1331
1479
|
}
|
|
1332
|
-
darkQuery.addEventListener('change', () => { if (
|
|
1480
|
+
darkQuery.addEventListener('change', () => { if (localStorage.getItem('csm-theme') === 'system') applyTheme('system'); });
|
|
1333
1481
|
|
|
1334
1482
|
// ---------- navigation ----------
|
|
1335
1483
|
const VIEWS = ['overview', 'sessions', 'bookmarks', 'projects', 'backups'];
|
|
@@ -1369,6 +1517,8 @@ const focusedUid = () => { const el = document.activeElement; return el && el.da
|
|
|
1369
1517
|
|
|
1370
1518
|
// ---------- events ----------
|
|
1371
1519
|
document.addEventListener('click', async (e) => {
|
|
1520
|
+
if (e.target.closest('[data-star-click]')) starClicked();
|
|
1521
|
+
if (e.target.closest('[data-star-later]')) { starLater(); return; }
|
|
1372
1522
|
const pi = e.target.closest('[data-pal]');
|
|
1373
1523
|
if (pi) { runPalette(Number(pi.dataset.pal)); return; }
|
|
1374
1524
|
const t = e.target.closest('button');
|
|
@@ -1380,6 +1530,7 @@ document.addEventListener('click', async (e) => {
|
|
|
1380
1530
|
else if ('sources' in d) openSources();
|
|
1381
1531
|
else if (d.src !== undefined) { state.src = d.src; state.shown = PAGE; renderTools(); renderSessions(); stagger($('list'), ':scope > .row, :scope > .date-head', 12); if (state.view !== 'sessions') setView('sessions'); }
|
|
1382
1532
|
else if (d.rmimport) removeImport(d.rmimport);
|
|
1533
|
+
else if (d.ho) { ho.target = d.ho; renderHandoffTargets(); }
|
|
1383
1534
|
else if ('reload' in d) { skeletons(); load(); }
|
|
1384
1535
|
else if ('clearFilters' in d) { $('q').value = ''; $('proj').value = ''; state.sessTab = 'all'; state.src = ''; renderTools(); setDateFilter(''); }
|
|
1385
1536
|
else if ('dateClear' in d) setDateFilter('');
|
|
@@ -1469,6 +1620,9 @@ $('bulkGo').addEventListener('click', () => openMover(bulkGroups()));
|
|
|
1469
1620
|
|
|
1470
1621
|
$('detailCopy').addEventListener('click', (e) => copy($('detailCmd').textContent, e.currentTarget));
|
|
1471
1622
|
$('detailOpen').addEventListener('click', openTerminal);
|
|
1623
|
+
$('detailHandoff').addEventListener('click', openHandoff);
|
|
1624
|
+
$('hoGo').addEventListener('click', goHandoff);
|
|
1625
|
+
$('hoText').addEventListener('input', updateHandoffCount);
|
|
1472
1626
|
$('detailPin').addEventListener('click', () => state.detail && togglePin(state.detail.uid));
|
|
1473
1627
|
$('detailMove').addEventListener('click', () => state.detail && openMover([{ key: state.detail.project.key, ids: [state.detail.id] }]));
|
|
1474
1628
|
$('detail').addEventListener('close', () => { state.detail = null; history.replaceState(null, '', `#${state.view}`); });
|
|
@@ -1529,8 +1683,9 @@ document.addEventListener('keydown', (e) => {
|
|
|
1529
1683
|
});
|
|
1530
1684
|
|
|
1531
1685
|
// ---------- start ----------
|
|
1532
|
-
applyTheme(localStorage.getItem('csm-theme') || '
|
|
1686
|
+
applyTheme(localStorage.getItem('csm-theme') || 'light', false);
|
|
1533
1687
|
skeletons();
|
|
1534
1688
|
loadStars();
|
|
1689
|
+
initStar();
|
|
1535
1690
|
setView(VIEWS.includes(location.hash.slice(1)) ? location.hash.slice(1) : deepLink ? 'sessions' : 'overview');
|
|
1536
1691
|
load();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="Chatshelf">
|
|
2
|
+
<rect width="32" height="32" rx="8" fill="#1C1917"/>
|
|
3
|
+
<path d="M10.5 17.75H22.5A2.5 2.5 0 0 1 25 20.25V20.75A2.5 2.5 0 0 1 22.5 23.25H13L9.5 25.75V23.05A2.5 2.5 0 0 1 8 20.75V20.25A2.5 2.5 0 0 1 10.5 17.75Z" fill="#78716C"/>
|
|
4
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="none" stroke="#1C1917" stroke-width="1.5" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="#D6D3D1"/>
|
|
6
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="none" stroke="#1C1917" stroke-width="1.5" stroke-linejoin="round"/>
|
|
7
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="#E8590C"/>
|
|
8
|
+
</svg>
|
package/public/index.html
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>Chatshelf</title>
|
|
7
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
+
<meta name="theme-color" content="#1C1917">
|
|
7
9
|
<link rel="stylesheet" href="/style.css">
|
|
8
10
|
<script>
|
|
9
11
|
window.CSM_TOKEN = "__TOKEN__";
|
|
10
12
|
(function () {
|
|
11
|
-
var pref = localStorage.getItem('csm-theme') || '
|
|
13
|
+
var pref = localStorage.getItem('csm-theme') || 'light';
|
|
12
14
|
var dark = pref === 'dark' || (pref === 'system' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
13
15
|
var root = document.documentElement;
|
|
14
16
|
root.dataset.theme = dark ? 'dark' : 'light';
|
|
@@ -44,19 +46,22 @@
|
|
|
44
46
|
<symbol id="i-plug" viewBox="0 0 24 24"><path d="M9 3v5M15 3v5M7 8h10v4a5 5 0 0 1-10 0Zm5 9v4"/></symbol>
|
|
45
47
|
<symbol id="i-link" viewBox="0 0 24 24"><path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></symbol>
|
|
46
48
|
<symbol id="i-star" viewBox="0 0 24 24"><path d="m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.5l6.1-.9Z"/></symbol>
|
|
49
|
+
<symbol id="i-handoff" viewBox="0 0 24 24"><path d="M14 4h6v6M20 4l-8 8M10 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-4"/></symbol>
|
|
50
|
+
<symbol id="i-download" viewBox="0 0 24 24"><path d="M12 4v11m-5-5 5 5 5-5M4 19h16"/></symbol>
|
|
47
51
|
<symbol id="i-key" viewBox="0 0 24 24"><rect x="2" y="6" width="20" height="12" rx="2"/><path d="M6 10h.01M10 10h.01M14 10h.01M18 10h.01M7 14h10"/></symbol>
|
|
48
52
|
</svg>
|
|
49
53
|
|
|
50
54
|
<div class="shell">
|
|
51
55
|
<aside class="side" aria-label="Main">
|
|
52
56
|
<div class="logo">
|
|
53
|
-
<
|
|
57
|
+
<img class="mark-img logo-on-light" src="/logo.svg" alt="" width="34" height="34">
|
|
58
|
+
<img class="mark-img logo-on-dark" src="/logo-reversed.svg" alt="" width="34" height="34">
|
|
54
59
|
<span class="logo-name">Chatshelf</span>
|
|
55
60
|
</div>
|
|
56
61
|
|
|
57
62
|
<button type="button" class="side-search" data-palette>
|
|
58
63
|
<svg class="ic"><use href="#i-search"/></svg>
|
|
59
|
-
<span>Search
|
|
64
|
+
<span>Search…</span>
|
|
60
65
|
<kbd>Ctrl K</kbd>
|
|
61
66
|
</button>
|
|
62
67
|
|
|
@@ -74,19 +79,37 @@
|
|
|
74
79
|
</div>
|
|
75
80
|
|
|
76
81
|
<div class="side-foot">
|
|
77
|
-
<div
|
|
78
|
-
<button type="button" data-
|
|
79
|
-
<
|
|
80
|
-
|
|
82
|
+
<div id="starCard" class="star-card" hidden>
|
|
83
|
+
<button type="button" class="star-x" data-star-later aria-label="Not now" title="Not now (ask again in 30 days)"><svg class="ic"><use href="#i-x"/></svg></button>
|
|
84
|
+
<div class="star-head">
|
|
85
|
+
<span class="star-badge" aria-hidden="true"><svg class="ic"><use href="#i-star"/></svg></span>
|
|
86
|
+
<p class="star-title">Is Chatshelf saving you time?</p>
|
|
87
|
+
</div>
|
|
88
|
+
<p class="star-text">A star on GitHub helps other developers find it.</p>
|
|
89
|
+
<a class="btn full star-go" href="https://github.com/heyKhoaiz/chatshelf" target="_blank" rel="noopener noreferrer" data-star-click>
|
|
90
|
+
<svg class="ic"><use href="#i-star"/></svg><span>Star on GitHub</span><span class="gh-count" data-star-count hidden></span>
|
|
91
|
+
</a>
|
|
81
92
|
</div>
|
|
93
|
+
<a class="btn ghost full gh-star" id="ghStar" href="https://github.com/heyKhoaiz/chatshelf" target="_blank" rel="noopener noreferrer" data-star-click>
|
|
94
|
+
<svg class="ic"><use href="#i-star"/></svg><span class="gh-label">Star on GitHub</span><span class="gh-count" data-star-count hidden></span>
|
|
95
|
+
</a>
|
|
82
96
|
<button type="button" class="btn ghost full side-tools" data-sources><svg class="ic"><use href="#i-plug"/></svg><span>Tools & import</span><span id="toolCount" class="nav-count"></span></button>
|
|
83
|
-
<div class="
|
|
84
|
-
<
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
<div class="foot-row">
|
|
98
|
+
<div class="theme icons" role="group" aria-label="Theme">
|
|
99
|
+
<button type="button" data-theme-set="light" aria-pressed="false" aria-label="Light theme" title="Light"><svg class="ic"><use href="#i-sun"/></svg></button>
|
|
100
|
+
<button type="button" data-theme-set="dark" aria-pressed="false" aria-label="Dark theme" title="Dark"><svg class="ic"><use href="#i-moon"/></svg></button>
|
|
101
|
+
<button type="button" data-theme-set="system" aria-pressed="false" aria-label="Match system theme" title="Auto (match system)"><svg class="ic"><use href="#i-monitor"/></svg></button>
|
|
102
|
+
</div>
|
|
103
|
+
<div class="foot-icons">
|
|
104
|
+
<button type="button" class="foot-btn" data-shortcuts aria-label="Keyboard shortcuts" title="Keyboard shortcuts (?)"><svg class="ic"><use href="#i-key"/></svg></button>
|
|
105
|
+
<a class="foot-btn" href="https://github.com/heyKhoaiz/chatshelf/issues/new/choose" target="_blank" rel="noopener noreferrer" aria-label="Send feedback or report a bug" title="Feedback"><svg class="ic"><use href="#i-chat"/></svg></a>
|
|
106
|
+
</div>
|
|
88
107
|
</div>
|
|
89
|
-
<
|
|
108
|
+
<p class="made-by">
|
|
109
|
+
Made by <a href="https://khoaiz.com" target="_blank" rel="noopener noreferrer" title="khoaiz.com">khoaiz</a>
|
|
110
|
+
<span aria-hidden="true">·</span>
|
|
111
|
+
<a href="https://x.com/khoaizahmmed" target="_blank" rel="noopener noreferrer" aria-label="Follow @khoaizahmmed on X" title="@khoaizahmmed on X" class="x-follow"><svg class="x-logo" viewBox="0 0 24 24" aria-hidden="true"><path d="M17.75 3h3.07l-6.7 7.66L22 21h-6.17l-4.83-6.32L5.47 21H2.4l7.17-8.2L2 3h6.32l4.37 5.78L17.75 3Zm-1.08 16.17h1.7L7.4 4.74H5.58l11.09 14.43Z"/></svg>Follow</a>
|
|
112
|
+
</p>
|
|
90
113
|
</div>
|
|
91
114
|
</aside>
|
|
92
115
|
|
|
@@ -268,6 +291,7 @@
|
|
|
268
291
|
<code id="detailCmd"></code>
|
|
269
292
|
<div class="resume-actions">
|
|
270
293
|
<button type="button" class="btn accent sm" id="detailOpen"><svg class="ic"><use href="#i-terminal"/></svg><span id="detailOpenLabel">Open in terminal</span></button>
|
|
294
|
+
<button type="button" class="btn ghost sm" id="detailHandoff" title="Carry this chat over to Codex, Claude Code or any other tool"><svg class="ic"><use href="#i-handoff"/></svg>Continue in…</button>
|
|
271
295
|
<button type="button" class="btn ghost sm" id="detailCopy"><svg class="ic"><use href="#i-copy"/></svg><span>Copy</span></button>
|
|
272
296
|
<p class="resume-note small muted" id="resumeNote" hidden></p>
|
|
273
297
|
<button type="button" class="btn ghost sm" id="detailMove"><svg class="ic"><use href="#i-move"/></svg>Move…</button>
|
|
@@ -319,6 +343,26 @@
|
|
|
319
343
|
</form>
|
|
320
344
|
</dialog>
|
|
321
345
|
|
|
346
|
+
<!-- Handoff -->
|
|
347
|
+
<dialog id="handoff" class="modal" aria-labelledby="hoTitle">
|
|
348
|
+
<div class="dlg-head">
|
|
349
|
+
<div>
|
|
350
|
+
<h2 id="hoTitle">Continue in another tool</h2>
|
|
351
|
+
<p class="small muted">Tools can't open each other's chats, so Chatshelf writes a short handoff for the next tool to pick up from. Edit it if you like.</p>
|
|
352
|
+
</div>
|
|
353
|
+
<button type="button" class="btn ghost icon" data-close aria-label="Close"><svg class="ic"><use href="#i-x"/></svg></button>
|
|
354
|
+
</div>
|
|
355
|
+
<div class="ho-targets" role="radiogroup" aria-label="Where to continue" id="hoTargets"></div>
|
|
356
|
+
<label class="ho-label" for="hoText"><span>Handoff</span><span class="muted small" id="hoCount"></span></label>
|
|
357
|
+
<textarea id="hoText" class="ho-text" spellcheck="false"></textarea>
|
|
358
|
+
<p class="small muted" id="hoNote"></p>
|
|
359
|
+
<p id="hoError" class="error" role="alert"></p>
|
|
360
|
+
<div class="actions">
|
|
361
|
+
<button type="button" class="btn ghost" data-close>Cancel</button>
|
|
362
|
+
<button type="button" class="btn accent" id="hoGo"><svg class="ic"><use href="#i-handoff"/></svg><span id="hoGoLabel">Continue</span></button>
|
|
363
|
+
</div>
|
|
364
|
+
</dialog>
|
|
365
|
+
|
|
322
366
|
<!-- Command palette -->
|
|
323
367
|
<dialog id="palette" class="palette" aria-label="Search or jump to">
|
|
324
368
|
<div class="pal-input">
|
|
@@ -350,7 +394,7 @@
|
|
|
350
394
|
<!-- Shortcuts -->
|
|
351
395
|
<dialog id="shortcuts" class="modal narrow" aria-labelledby="scTitle">
|
|
352
396
|
<div class="dlg-head">
|
|
353
|
-
<h2 id="scTitle">
|
|
397
|
+
<h2 id="scTitle">Shortcuts & about</h2>
|
|
354
398
|
<button type="button" class="btn ghost icon" data-close aria-label="Close"><svg class="ic"><use href="#i-x"/></svg></button>
|
|
355
399
|
</div>
|
|
356
400
|
<dl class="sc-list">
|
|
@@ -364,6 +408,19 @@
|
|
|
364
408
|
<div><dt><kbd>Esc</kbd></dt><dd>Close a panel or clear the selection</dd></div>
|
|
365
409
|
<div><dt><kbd>?</kbd></dt><dd>Show this list</dd></div>
|
|
366
410
|
</dl>
|
|
411
|
+
<div class="credits">
|
|
412
|
+
<img class="logo-on-light" src="/logo.svg" alt="" width="36" height="36">
|
|
413
|
+
<img class="logo-on-dark" src="/logo-reversed.svg" alt="" width="36" height="36">
|
|
414
|
+
<div class="min0">
|
|
415
|
+
<p class="credits-name">Chatshelf <span class="muted">v__VERSION__</span></p>
|
|
416
|
+
<p class="small muted">Made by Shaikh khoaiz Ahmmed</p>
|
|
417
|
+
</div>
|
|
418
|
+
<nav class="credits-links" aria-label="Author links">
|
|
419
|
+
<a href="https://khoaiz.com" target="_blank" rel="noopener noreferrer">khoaiz.com</a>
|
|
420
|
+
<a href="https://x.com/khoaizahmmed" target="_blank" rel="noopener noreferrer">X @khoaizahmmed</a>
|
|
421
|
+
<a href="https://github.com/heyKhoaiz/chatshelf" target="_blank" rel="noopener noreferrer">GitHub</a>
|
|
422
|
+
</nav>
|
|
423
|
+
</div>
|
|
367
424
|
</dialog>
|
|
368
425
|
|
|
369
426
|
<div id="toast" role="status" aria-live="polite"></div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="Chatshelf">
|
|
2
|
+
<rect width="32" height="32" rx="8" fill="#F5F5F4"/>
|
|
3
|
+
<path d="M10.5 17.75H22.5A2.5 2.5 0 0 1 25 20.25V20.75A2.5 2.5 0 0 1 22.5 23.25H13L9.5 25.75V23.05A2.5 2.5 0 0 1 8 20.75V20.25A2.5 2.5 0 0 1 10.5 17.75Z" fill="#A8A29E"/>
|
|
4
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="none" stroke="#F5F5F4" stroke-width="1.5" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="#57534E"/>
|
|
6
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="none" stroke="#F5F5F4" stroke-width="1.5" stroke-linejoin="round"/>
|
|
7
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="#E8590C"/>
|
|
8
|
+
</svg>
|
package/public/logo.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="Chatshelf">
|
|
2
|
+
<rect width="32" height="32" rx="8" fill="#1C1917"/>
|
|
3
|
+
<path d="M10.5 17.75H22.5A2.5 2.5 0 0 1 25 20.25V20.75A2.5 2.5 0 0 1 22.5 23.25H13L9.5 25.75V23.05A2.5 2.5 0 0 1 8 20.75V20.25A2.5 2.5 0 0 1 10.5 17.75Z" fill="#78716C"/>
|
|
4
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="none" stroke="#1C1917" stroke-width="1.5" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M9.5 12H21.5A2.5 2.5 0 0 1 24 14.5V15A2.5 2.5 0 0 1 21.5 17.5H12L8.5 20V17.3A2.5 2.5 0 0 1 7 15V14.5A2.5 2.5 0 0 1 9.5 12Z" fill="#D6D3D1"/>
|
|
6
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="none" stroke="#1C1917" stroke-width="1.5" stroke-linejoin="round"/>
|
|
7
|
+
<path d="M11 6.25H23A2.5 2.5 0 0 1 25.5 8.75V9.25A2.5 2.5 0 0 1 23 11.75H13.5L10 14.25V11.55A2.5 2.5 0 0 1 8.5 9.25V8.75A2.5 2.5 0 0 1 11 6.25Z" fill="#E8590C"/>
|
|
8
|
+
</svg>
|
package/public/style.css
CHANGED
|
@@ -608,3 +608,90 @@ dialog.palette { width: min(640px, calc(100vw - 32px)); padding: 0; margin: 12vh
|
|
|
608
608
|
.gh-count { margin-left: auto; font-size: 12px; font-weight: 600; background: var(--sunk); border: 1px solid var(--line-2); border-radius: 999px; padding: 0 8px; color: var(--ink-2); }
|
|
609
609
|
.gh-issue { text-decoration: none; }
|
|
610
610
|
a.btn { text-decoration: none; }
|
|
611
|
+
|
|
612
|
+
/* ---------- sidebar footer: star ask ---------- */
|
|
613
|
+
.side-foot { gap: 10px; }
|
|
614
|
+
.gh-star { justify-content: flex-start; gap: 10px; font-size: 14px; white-space: nowrap; min-width: 0; }
|
|
615
|
+
.gh-star .gh-label { overflow: hidden; text-overflow: ellipsis; }
|
|
616
|
+
.gh-star.starred .ic { fill: #FACC15; color: #CA8A04; }
|
|
617
|
+
.star-card { border: 1px solid #F6C9AA; background: linear-gradient(180deg, var(--accent-soft), var(--panel)); border-radius: 14px; padding: 14px; }
|
|
618
|
+
[data-theme="dark"] .star-card { border-color: #6B3514; }
|
|
619
|
+
.star-title { margin: 0; font-weight: 600; font-size: 14px; }
|
|
620
|
+
.star-text { margin: 4px 0 12px; font-size: 13px; color: var(--ink-2); }
|
|
621
|
+
.star-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
622
|
+
.star-go { background: var(--ink); color: var(--panel); border-color: var(--ink); white-space: nowrap; }
|
|
623
|
+
.star-go .ic { width: 15px; height: 15px; fill: #FACC15; color: #FACC15; }
|
|
624
|
+
.motion .star-card:not([hidden]) { animation: rise .5s var(--ease) both .3s; }
|
|
625
|
+
.side-links { display: flex; justify-content: space-between; gap: 8px; }
|
|
626
|
+
.side-links .link { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); min-height: 36px; }
|
|
627
|
+
.side-links .link:hover { color: var(--ink); }
|
|
628
|
+
#toast.has-action { pointer-events: auto; }
|
|
629
|
+
.toast-act { color: #FACC15; font-weight: 600; margin-left: 8px; white-space: nowrap; }
|
|
630
|
+
.star-actions .link { white-space: nowrap; min-height: 36px; padding: 0 2px; }
|
|
631
|
+
.star-go { padding: 0 12px; gap: 6px; }
|
|
632
|
+
|
|
633
|
+
/* ---------- sidebar footer v2 ---------- */
|
|
634
|
+
.side-foot { gap: 8px; }
|
|
635
|
+
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 4px; }
|
|
636
|
+
.theme.icons { display: inline-grid; grid-template-columns: repeat(3, 40px); padding: 3px; gap: 2px; }
|
|
637
|
+
.theme.icons button { min-height: 36px; padding: 0; }
|
|
638
|
+
.theme.icons button .ic { width: 17px; height: 17px; }
|
|
639
|
+
.foot-icons { display: flex; gap: 4px; }
|
|
640
|
+
.foot-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
|
|
641
|
+
transition: background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease); }
|
|
642
|
+
.foot-btn .ic { width: 18px; height: 18px; }
|
|
643
|
+
.foot-btn:hover { background: var(--panel); border-color: var(--line-2); color: var(--ink); }
|
|
644
|
+
.foot-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
645
|
+
|
|
646
|
+
.star-card { position: relative; padding: 14px 14px 12px; border-radius: 14px; }
|
|
647
|
+
.star-head { display: flex; align-items: center; gap: 10px; padding-right: 28px; }
|
|
648
|
+
.star-badge { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; background: #FEF3C7; color: #CA8A04; }
|
|
649
|
+
.star-badge .ic { width: 17px; height: 17px; fill: #FACC15; }
|
|
650
|
+
[data-theme="dark"] .star-badge { background: #3B2F0B; }
|
|
651
|
+
.star-title { font-size: 13.5px; line-height: 1.35; }
|
|
652
|
+
.star-text { margin: 8px 0 12px; font-size: 12.5px; line-height: 1.45; }
|
|
653
|
+
.star-go { justify-content: center; gap: 8px; min-height: 40px; font-size: 13.5px; text-decoration: none; }
|
|
654
|
+
.star-go .gh-count { background: rgba(255, 255, 255, .15); border-color: transparent; color: inherit; }
|
|
655
|
+
.star-x { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
|
|
656
|
+
.star-x .ic { width: 15px; height: 15px; }
|
|
657
|
+
.star-x:hover { background: rgba(28, 25, 23, .06); color: var(--ink); }
|
|
658
|
+
.star-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
659
|
+
|
|
660
|
+
/* logo */
|
|
661
|
+
.mark-img { display: block; width: 34px; height: 34px; border-radius: 9px; flex: none; }
|
|
662
|
+
/* the reversed logo is used on dark backgrounds instead of an outline */
|
|
663
|
+
.logo-on-dark { display: none !important; }
|
|
664
|
+
[data-theme="dark"] .logo-on-light { display: none !important; }
|
|
665
|
+
[data-theme="dark"] .logo-on-dark { display: block !important; }
|
|
666
|
+
|
|
667
|
+
/* ---------- handoff ---------- */
|
|
668
|
+
.ho-targets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
|
|
669
|
+
.ho-opt { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; text-align: left; padding: 12px; min-height: 64px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); color: var(--ink); font: inherit; cursor: pointer;
|
|
670
|
+
transition: border-color .18s var(--ease), background-color .18s var(--ease); }
|
|
671
|
+
.ho-opt > span { display: grid; gap: 2px; }
|
|
672
|
+
.ho-opt b { font-size: 14px; }
|
|
673
|
+
.ho-opt .ic { width: 18px; height: 18px; margin-top: 2px; color: var(--muted); }
|
|
674
|
+
.ho-opt:hover:not(:disabled) { border-color: var(--muted); }
|
|
675
|
+
.ho-opt[aria-checked="true"] { border: 2px solid var(--accent); background: var(--accent-soft); padding: 11px; }
|
|
676
|
+
.ho-opt[aria-checked="true"] .ic { color: var(--accent); }
|
|
677
|
+
.ho-opt:disabled { opacity: .55; cursor: not-allowed; }
|
|
678
|
+
.ho-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
|
|
679
|
+
.ho-text { width: 100%; min-height: 280px; max-height: 46vh; resize: vertical; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); background: var(--sunk); border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px; }
|
|
680
|
+
.ho-text:focus { outline: none; border-color: var(--accent); }
|
|
681
|
+
@media (max-width: 760px) { .ho-targets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
682
|
+
|
|
683
|
+
/* credits (Shortcuts & about) */
|
|
684
|
+
.credits { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 14px; background: var(--sunk); border: 1px solid var(--line); border-radius: 12px; flex-wrap: wrap; }
|
|
685
|
+
.credits img { border-radius: 9px; flex: none; }
|
|
686
|
+
.credits p { margin: 0; }
|
|
687
|
+
.credits-name { font-weight: 600; }
|
|
688
|
+
.credits-links { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
|
|
689
|
+
.credits-links a { font-size: 13px; color: var(--ink-2); text-decoration: none; border: 1px solid var(--line-2); border-radius: 999px; padding: 0 12px; min-height: 36px; display: inline-flex; align-items: center; background: var(--panel); }
|
|
690
|
+
.credits-links a:hover { border-color: var(--ink); color: var(--ink); }
|
|
691
|
+
|
|
692
|
+
/* always-visible author credit at the bottom of the sidebar */
|
|
693
|
+
.made-by { margin: 2px 0 0; display: flex; gap: 6px; align-items: center; justify-content: center; font-size: 12.5px; color: var(--muted); }
|
|
694
|
+
.made-by a { color: var(--ink-2); text-decoration: none; font-weight: 500; min-height: 32px; display: inline-flex; align-items: center; }
|
|
695
|
+
.made-by a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
|
|
696
|
+
.made-by .x-follow { gap: 5px; }
|
|
697
|
+
.x-logo { width: 12px; height: 12px; fill: currentColor; flex: none; }
|
package/server.mjs
CHANGED
|
@@ -24,8 +24,33 @@ const OLD_DATA_DIR = path.join(DATA_ROOT, 'claude-session-manager');
|
|
|
24
24
|
if (!fs.existsSync(DATA_DIR) && fs.existsSync(OLD_DATA_DIR)) { try { fs.renameSync(OLD_DATA_DIR, DATA_DIR); } catch { /* keep going with a fresh folder */ } }
|
|
25
25
|
const BOOKMARKS = path.join(DATA_DIR, 'bookmarks.json');
|
|
26
26
|
const CACHE_FILE = path.join(process.env.XDG_CACHE_HOME || path.join(HOME, '.cache'), 'chatshelf', 'index.json');
|
|
27
|
-
const PORT = Number(process.env.PORT || 4317);
|
|
28
27
|
const HOST = '127.0.0.1';
|
|
28
|
+
const VERSION = (() => { try { return JSON.parse(fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8')).version; } catch { return ''; } })();
|
|
29
|
+
|
|
30
|
+
// ---------- address: --port / --host flags, CHATSHELF_PORT / CHATSHELF_HOST (or PORT) settings ----------
|
|
31
|
+
function flag(name) {
|
|
32
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
33
|
+
if (i >= 0) return process.argv[i + 1];
|
|
34
|
+
const eq = process.argv.find((a) => a.startsWith(`--${name}=`));
|
|
35
|
+
return eq ? eq.slice(name.length + 3) : undefined;
|
|
36
|
+
}
|
|
37
|
+
const portSetting = flag('port') ?? process.env.CHATSHELF_PORT ?? process.env.PORT;
|
|
38
|
+
// A port the user chose is used as-is; otherwise start at 4317 and move up if it's taken.
|
|
39
|
+
const PORT_FIXED = portSetting !== undefined && portSetting !== '' && portSetting !== 'auto';
|
|
40
|
+
// CHATSHELF_FIRST_PORT only exists so the tests can check the automatic choice without touching 4317.
|
|
41
|
+
const DEFAULT_PORT = Number(process.env.CHATSHELF_FIRST_PORT || 4317);
|
|
42
|
+
let PORT = PORT_FIXED ? Number(portSetting) : DEFAULT_PORT;
|
|
43
|
+
if (!Number.isInteger(PORT) || PORT < 1 || PORT > 65535) {
|
|
44
|
+
console.error(`"${portSetting}" isn't a valid port. Use a number from 1 to 65535, e.g. --port 5000.`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
// The name must be localhost or end in .localhost: browsers always send those to this computer,
|
|
48
|
+
// which keeps the DNS-rebinding protection.
|
|
49
|
+
const NICE_HOST = String(flag('host') ?? process.env.CHATSHELF_HOST ?? 'chatshelf.localhost').toLowerCase().replace(/^https?:\/\//, '').replace(/[:/].*$/, '');
|
|
50
|
+
if (!/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)*localhost$/.test(NICE_HOST)) {
|
|
51
|
+
console.error(`"${NICE_HOST}" can't be used. Pick a name that ends in .localhost, e.g. --host work.localhost`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
29
54
|
const TOKEN = crypto.randomBytes(24).toString('hex');
|
|
30
55
|
const PUBLIC = path.join(path.dirname(fileURLToPath(import.meta.url)), 'public');
|
|
31
56
|
|
|
@@ -466,6 +491,37 @@ async function openTerminal({ key, id }) {
|
|
|
466
491
|
return { terminal: path.basename(cmd[0]) };
|
|
467
492
|
}
|
|
468
493
|
|
|
494
|
+
// ---------- handoff: continue a chat in another tool ----------
|
|
495
|
+
// The handoff text goes into a private temp file and the tool starts with it as its first message.
|
|
496
|
+
// Nothing is written into any tool's own history.
|
|
497
|
+
const HANDOFF_TARGETS = { codex: { bin: 'codex', label: 'Codex' }, claude: { bin: 'claude', label: 'Claude Code' } };
|
|
498
|
+
const noSpawn = () => Boolean(process.env.CHATSHELF_NO_SPAWN); // tests: build the command, don't run it
|
|
499
|
+
|
|
500
|
+
function handoffTargets() {
|
|
501
|
+
const out = {};
|
|
502
|
+
for (const [id, t] of Object.entries(HANDOFF_TARGETS)) out[id] = { label: t.label, installed: Boolean(which(t.bin)) };
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async function startHandoff({ key, id, target, text }) {
|
|
507
|
+
const p = await getProject(key);
|
|
508
|
+
if (!p.sessions.some((x) => x.id === id)) throw new HttpError(404, 'Unknown session.');
|
|
509
|
+
const t = HANDOFF_TARGETS[target];
|
|
510
|
+
if (!t) throw new HttpError(400, 'Pick Codex or Claude Code.');
|
|
511
|
+
if (typeof text !== 'string' || !text.trim()) throw new HttpError(400, 'The handoff is empty.');
|
|
512
|
+
if (text.length > 20000) throw new HttpError(400, 'The handoff is too long (20,000 characters max). Shorten it first.');
|
|
513
|
+
if (!which(t.bin) && !noSpawn()) throw new HttpError(501, `${t.label} isn't installed (no "${t.bin}" command). Use Copy instead.`);
|
|
514
|
+
const cwd = p.exists ? p.cwd : HOME;
|
|
515
|
+
const file = path.join(os.tmpdir(), `chatshelf-handoff-${crypto.randomBytes(6).toString('hex')}.md`);
|
|
516
|
+
fs.writeFileSync(file, text, { mode: 0o600 });
|
|
517
|
+
const command = `${t.bin} "$(cat ${shq(file)})"`;
|
|
518
|
+
if (noSpawn()) return { dryRun: true, command, file, cwd };
|
|
519
|
+
const cmd = terminalCommand(cwd, command);
|
|
520
|
+
if (!cmd) throw new HttpError(501, 'No supported terminal found. Use Copy instead, or set CHATSHELF_TERMINAL.');
|
|
521
|
+
spawn(cmd[0], cmd[1], { cwd, stdio: 'ignore', detached: true }).unref();
|
|
522
|
+
return { terminal: path.basename(cmd[0]), target: t.label, cwd };
|
|
523
|
+
}
|
|
524
|
+
|
|
469
525
|
// ---------- bookmarks (one JSON file, written atomically) ----------
|
|
470
526
|
function readBookmarks() {
|
|
471
527
|
try { const v = JSON.parse(fs.readFileSync(BOOKMARKS, 'utf8')); return Array.isArray(v) ? v : []; } catch { return []; }
|
|
@@ -657,6 +713,10 @@ async function api(req, res, url) {
|
|
|
657
713
|
return send(res, 200, saveBookmark(await readJson(req)));
|
|
658
714
|
case 'POST /api/bookmarks/delete':
|
|
659
715
|
return send(res, 200, deleteBookmark((await readJson(req)).id));
|
|
716
|
+
case 'GET /api/handoff/targets':
|
|
717
|
+
return send(res, 200, { targets: handoffTargets() });
|
|
718
|
+
case 'POST /api/handoff':
|
|
719
|
+
return send(res, 200, await startHandoff(await readJson(req)));
|
|
660
720
|
case 'GET /api/sources':
|
|
661
721
|
return send(res, 200, { sources: await sourceStatus() });
|
|
662
722
|
case 'POST /api/import': {
|
|
@@ -676,8 +736,8 @@ async function api(req, res, url) {
|
|
|
676
736
|
}
|
|
677
737
|
}
|
|
678
738
|
|
|
679
|
-
const STATIC = { '/': 'index.html', '/app.js': 'app.js', '/style.css': 'style.css' };
|
|
680
|
-
const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8' };
|
|
739
|
+
const STATIC = { '/': 'index.html', '/app.js': 'app.js', '/style.css': 'style.css', '/logo.svg': 'logo.svg', '/logo-reversed.svg': 'logo-reversed.svg', '/favicon.svg': 'favicon.svg', '/favicon.ico': 'favicon.svg' };
|
|
740
|
+
const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.svg': 'image/svg+xml' };
|
|
681
741
|
|
|
682
742
|
const server = http.createServer(async (req, res) => {
|
|
683
743
|
try {
|
|
@@ -691,7 +751,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
691
751
|
const file = STATIC[url.pathname];
|
|
692
752
|
if (!file || req.method !== 'GET') return send(res, 404, 'Not found', 'text/plain; charset=utf-8');
|
|
693
753
|
let body = await fsp.readFile(path.join(PUBLIC, file), 'utf8');
|
|
694
|
-
if (file === 'index.html') body = body.replace('__TOKEN__', TOKEN);
|
|
754
|
+
if (file === 'index.html') body = body.replace('__TOKEN__', TOKEN).replaceAll('__VERSION__', VERSION);
|
|
695
755
|
return send(res, 200, body, TYPES[path.extname(file)]);
|
|
696
756
|
} catch (e) {
|
|
697
757
|
if (!(e instanceof HttpError)) console.error(e);
|
|
@@ -702,31 +762,100 @@ const server = http.createServer(async (req, res) => {
|
|
|
702
762
|
// Browsers send any *.localhost name to this computer, so chatshelf.localhost needs no setup and,
|
|
703
763
|
// like 127.0.0.1, can never point anywhere else (which keeps the DNS-rebinding protection).
|
|
704
764
|
// Safari on macOS may not resolve *.localhost, so macOS opens 127.0.0.1; both always work.
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
765
|
+
let ALLOWED_HOSTS = new Set();
|
|
766
|
+
let niceUrl = '';
|
|
767
|
+
let ipUrl = '';
|
|
768
|
+
let appUrl = '';
|
|
769
|
+
function setAddress(port) {
|
|
770
|
+
PORT = port;
|
|
771
|
+
ALLOWED_HOSTS = new Set([`${HOST}:${port}`, `localhost:${port}`, `chatshelf.localhost:${port}`, `${NICE_HOST}:${port}`]);
|
|
772
|
+
niceUrl = `http://${NICE_HOST}:${port}/`;
|
|
773
|
+
ipUrl = `http://${HOST}:${port}/`;
|
|
774
|
+
appUrl = process.platform === 'darwin' ? ipUrl : niceUrl;
|
|
775
|
+
}
|
|
776
|
+
setAddress(PORT);
|
|
777
|
+
|
|
778
|
+
// Where the running copy writes its address, so `chatshelf` can find it again on any port.
|
|
779
|
+
const RUN_FILE = path.join(path.dirname(CACHE_FILE), 'running.json');
|
|
780
|
+
function readRunning() {
|
|
781
|
+
try { return JSON.parse(fs.readFileSync(RUN_FILE, 'utf8')); } catch { return null; }
|
|
782
|
+
}
|
|
783
|
+
// Is the server on this port a Chatshelf? (Asks with an allowed Host header.)
|
|
784
|
+
function isChatshelf(port) {
|
|
785
|
+
return new Promise((resolve) => {
|
|
786
|
+
const req = http.get({ host: HOST, port, path: '/', timeout: 1500, headers: { Host: `${HOST}:${port}` } }, (res) => {
|
|
787
|
+
let body = '';
|
|
788
|
+
res.on('data', (c) => { body += c; if (body.length > 4000) res.destroy(); });
|
|
789
|
+
res.on('end', () => resolve(body.includes('<title>Chatshelf')));
|
|
790
|
+
res.on('close', () => resolve(body.includes('<title>Chatshelf')));
|
|
791
|
+
});
|
|
792
|
+
req.on('error', () => resolve(false));
|
|
793
|
+
req.on('timeout', () => { req.destroy(); resolve(false); });
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
const open = (url = appUrl) => {
|
|
711
797
|
if (process.argv.includes('--no-open')) return;
|
|
712
798
|
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open';
|
|
713
|
-
spawn(cmd, [
|
|
799
|
+
spawn(cmd, [url], { stdio: 'ignore', detached: true }).unref();
|
|
714
800
|
};
|
|
715
801
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
802
|
+
function listen(port) {
|
|
803
|
+
return new Promise((resolve, reject) => {
|
|
804
|
+
const onError = (e) => { server.off('listening', onListening); reject(e); };
|
|
805
|
+
const onListening = () => { server.off('error', onError); resolve(); };
|
|
806
|
+
server.once('error', onError);
|
|
807
|
+
server.once('listening', onListening);
|
|
808
|
+
server.listen(port, HOST);
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
async function start() {
|
|
813
|
+
// Already running somewhere (maybe on an automatic port)? Open that one instead.
|
|
814
|
+
const running = readRunning();
|
|
815
|
+
if (running && running.port && (!PORT_FIXED || running.port === PORT) && await isChatshelf(running.port)) {
|
|
816
|
+
console.log(`Chatshelf is already running at ${running.url}`);
|
|
817
|
+
open(running.url);
|
|
720
818
|
process.exit(0);
|
|
721
819
|
}
|
|
722
|
-
|
|
723
|
-
|
|
820
|
+
const first = PORT;
|
|
821
|
+
for (let port = first; port < first + 20; port++) {
|
|
822
|
+
try {
|
|
823
|
+
await listen(port);
|
|
824
|
+
setAddress(port);
|
|
825
|
+
return;
|
|
826
|
+
} catch (e) {
|
|
827
|
+
if (e.code !== 'EADDRINUSE') throw e;
|
|
828
|
+
if (await isChatshelf(port)) {
|
|
829
|
+
setAddress(port);
|
|
830
|
+
console.log(`Chatshelf is already running at ${appUrl}`);
|
|
831
|
+
open();
|
|
832
|
+
process.exit(0);
|
|
833
|
+
}
|
|
834
|
+
if (PORT_FIXED) {
|
|
835
|
+
console.error(`Port ${port} is used by another program. Pick another one, e.g. --port ${port + 1}, or leave --port out to choose one automatically.`);
|
|
836
|
+
process.exit(1);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
console.error(`Ports ${first}-${first + 19} are all in use. Pick one with --port.`);
|
|
841
|
+
process.exit(1);
|
|
842
|
+
}
|
|
724
843
|
|
|
725
|
-
|
|
844
|
+
const cleanup = () => {
|
|
845
|
+
const r = readRunning();
|
|
846
|
+
if (r && r.pid === process.pid) { try { fs.unlinkSync(RUN_FILE); } catch { /* already gone */ } }
|
|
847
|
+
};
|
|
848
|
+
process.on('exit', cleanup);
|
|
849
|
+
for (const sig of ['SIGINT', 'SIGTERM']) process.on(sig, () => process.exit(0));
|
|
850
|
+
|
|
851
|
+
start().then(() => {
|
|
852
|
+
fs.mkdirSync(path.dirname(RUN_FILE), { recursive: true });
|
|
853
|
+
fs.writeFileSync(RUN_FILE, JSON.stringify({ url: appUrl, port: PORT, pid: process.pid }));
|
|
854
|
+
if (PORT !== DEFAULT_PORT && !PORT_FIXED) console.log(`Port ${DEFAULT_PORT} was busy, so Chatshelf picked ${PORT}.`);
|
|
726
855
|
console.log(`Chatshelf is running at ${appUrl}`);
|
|
727
856
|
console.log(` also at ${appUrl === niceUrl ? ipUrl : niceUrl} (Ctrl+C to stop)`);
|
|
728
857
|
console.log(`Reading sessions from ${ROOT}`);
|
|
729
858
|
const t = Date.now();
|
|
730
859
|
scan().then((p) => console.log(`Indexed ${p.reduce((n, x) => n + x.sessions.length, 0)} sessions in ${Date.now() - t} ms`));
|
|
731
860
|
open();
|
|
732
|
-
});
|
|
861
|
+
}).catch((e) => { console.error(e); process.exit(1); });
|