@zzusp/ccsm 1.0.1 → 1.0.3

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.
Files changed (70) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +236 -236
  3. package/bin/cli.mjs +52 -52
  4. package/dist/assets/{DiskUsage-CKhggLs5.js → DiskUsage-BY6XwffG.js} +2 -2
  5. package/dist/assets/DiskUsage-BY6XwffG.js.map +1 -0
  6. package/dist/assets/{ImportPage-wge4VhZ-.js → ImportPage-Cwq5bx7G.js} +2 -2
  7. package/dist/assets/ImportPage-Cwq5bx7G.js.map +1 -0
  8. package/dist/assets/MarkdownContent-BFu7Nkk_.js +2 -0
  9. package/dist/assets/MarkdownContent-BFu7Nkk_.js.map +1 -0
  10. package/dist/assets/{ProjectMemory-Q4XX40j_.js → ProjectMemory-CcE3KbUK.js} +2 -2
  11. package/dist/assets/ProjectMemory-CcE3KbUK.js.map +1 -0
  12. package/dist/assets/index-CrWxV6sb.css +1 -0
  13. package/dist/assets/index-DTbWl1jb.js +11 -0
  14. package/dist/assets/index-DTbWl1jb.js.map +1 -0
  15. package/dist/assets/markdown-Bag5rX3T.js +30 -0
  16. package/dist/assets/markdown-Bag5rX3T.js.map +1 -0
  17. package/dist/index.html +26 -26
  18. package/package.json +81 -83
  19. package/server/index.ts +130 -130
  20. package/server/lib/active-sessions.test.ts +119 -119
  21. package/server/lib/active-sessions.ts +95 -95
  22. package/server/lib/bundle.test.ts +182 -182
  23. package/server/lib/bundle.ts +86 -86
  24. package/server/lib/claude-paths.test.ts +126 -126
  25. package/server/lib/claude-paths.ts +43 -43
  26. package/server/lib/cleanup-suggestions.ts +131 -131
  27. package/server/lib/constants.ts +8 -8
  28. package/server/lib/delete-project.ts +100 -100
  29. package/server/lib/delete.test.ts +244 -244
  30. package/server/lib/delete.ts +192 -192
  31. package/server/lib/disk-usage.ts +81 -81
  32. package/server/lib/encode-cwd.ts +24 -24
  33. package/server/lib/export-bundle.ts +236 -236
  34. package/server/lib/export-import-bundle.test.ts +337 -337
  35. package/server/lib/fs-size.ts +38 -38
  36. package/server/lib/import-bundle.ts +488 -488
  37. package/server/lib/load-memory.ts +120 -120
  38. package/server/lib/load-session.ts +209 -209
  39. package/server/lib/modified-files.test.ts +280 -280
  40. package/server/lib/modified-files.ts +228 -228
  41. package/server/lib/open-folder.ts +47 -47
  42. package/server/lib/parse-jsonl.ts +160 -139
  43. package/server/lib/port.ts +23 -23
  44. package/server/lib/safe-id.test.ts +41 -41
  45. package/server/lib/safe-id.ts +6 -6
  46. package/server/lib/safe-remove.test.ts +73 -73
  47. package/server/lib/safe-remove.ts +25 -25
  48. package/server/lib/scan.ts +289 -286
  49. package/server/lib/search-all.ts +130 -130
  50. package/server/lib/search-session.ts +203 -203
  51. package/server/lib/system-tags.ts +20 -20
  52. package/server/lib/update.ts +67 -67
  53. package/server/lib/version.test.ts +39 -39
  54. package/server/lib/version.ts +117 -117
  55. package/server/routes/disk-cleanup.ts +54 -54
  56. package/server/routes/disk.ts +9 -9
  57. package/server/routes/import.ts +87 -87
  58. package/server/routes/projects.ts +104 -104
  59. package/server/routes/search.ts +79 -79
  60. package/server/routes/sessions.ts +130 -130
  61. package/server/routes/version.ts +34 -34
  62. package/server/types.ts +1 -1
  63. package/shared/constants.ts +7 -7
  64. package/shared/types.ts +513 -511
  65. package/dist/assets/DiskUsage-CKhggLs5.js.map +0 -1
  66. package/dist/assets/ImportPage-wge4VhZ-.js.map +0 -1
  67. package/dist/assets/ProjectMemory-Q4XX40j_.js.map +0 -1
  68. package/dist/assets/index-7aMrnHJG.js +0 -7
  69. package/dist/assets/index-7aMrnHJG.js.map +0 -1
  70. package/dist/assets/index-BOeI_J4B.css +0 -1
@@ -1,130 +1,130 @@
1
- import { Hono } from 'hono';
2
- import { deleteSessions, type DeleteRequestItem } from '../lib/delete.ts';
3
- import { loadSessionDetail } from '../lib/load-session.ts';
4
- import { loadModifiedFiles } from '../lib/modified-files.ts';
5
- import { openFile } from '../lib/open-folder.ts';
6
- import { renameSession } from '../lib/rename-session.ts';
7
- import { isSafeId } from '../lib/safe-id.ts';
8
-
9
- export const sessionsRoute = new Hono();
10
-
11
- // 注意:放在 /:projectId/:sessionId 之前——Hono trie 对静态后缀的具体路由优先匹配,
12
- // 但显式按"更具体的路由先注册"是最稳的写法,避免日后引入其他通配段时被错位拦截。
13
- sessionsRoute.get('/:projectId/:sessionId/modified-files', async (c) => {
14
- const projectId = c.req.param('projectId');
15
- const sessionId = c.req.param('sessionId');
16
- if (!isSafeId(projectId) || !isSafeId(sessionId)) {
17
- return c.json({ error: 'invalid id' }, 400);
18
- }
19
- const result = await loadModifiedFiles(projectId, sessionId);
20
- if (!result) return c.json({ error: 'not found' }, 404);
21
- return c.json(result);
22
- });
23
-
24
- sessionsRoute.post('/:projectId/:sessionId/open-file', async (c) => {
25
- if (!isAcceptableOrigin(c.req.header('origin'))) {
26
- return c.json({ error: 'origin not allowed' }, 403);
27
- }
28
- const projectId = c.req.param('projectId');
29
- const sessionId = c.req.param('sessionId');
30
- if (!isSafeId(projectId) || !isSafeId(sessionId)) {
31
- return c.json({ error: 'invalid id' }, 400);
32
- }
33
- let body: { filePath?: unknown };
34
- try {
35
- body = (await c.req.json()) as { filePath?: unknown };
36
- } catch {
37
- return c.json({ error: 'invalid json body' }, 400);
38
- }
39
- if (typeof body.filePath !== 'string' || body.filePath === '') {
40
- return c.json({ error: 'filePath (string) required' }, 400);
41
- }
42
- // 只允许打开"本会话确实改过的文件"——从 jsonl 重新聚合校验成员资格,
43
- // 杜绝客户端传任意路径来打开系统中任意文件。
44
- const modified = await loadModifiedFiles(projectId, sessionId);
45
- if (!modified) return c.json({ error: 'session not found' }, 404);
46
- if (!modified.files.some((f) => f.filePath === body.filePath)) {
47
- return c.json({ error: 'file is not part of this session' }, 400);
48
- }
49
-
50
- const result = openFile(body.filePath);
51
- if (!result.ok) {
52
- const status = result.error === 'path not found' ? 404 : 500;
53
- return c.json({ error: result.error ?? 'failed to open file' }, status);
54
- }
55
- return c.json({ ok: true, path: body.filePath });
56
- });
57
-
58
- sessionsRoute.get('/:projectId/:sessionId', async (c) => {
59
- const projectId = c.req.param('projectId');
60
- const sessionId = c.req.param('sessionId');
61
- if (!isSafeId(projectId) || !isSafeId(sessionId)) {
62
- return c.json({ error: 'invalid id' }, 400);
63
- }
64
- const detail = await loadSessionDetail(projectId, sessionId);
65
- if (!detail) return c.json({ error: 'not found' }, 404);
66
- return c.json(detail);
67
- });
68
-
69
- sessionsRoute.patch('/:projectId/:sessionId', async (c) => {
70
- if (!isAcceptableOrigin(c.req.header('origin'))) {
71
- return c.json({ error: 'origin not allowed' }, 403);
72
- }
73
- const projectId = c.req.param('projectId');
74
- const sessionId = c.req.param('sessionId');
75
- let body: { customTitle?: unknown };
76
- try {
77
- body = (await c.req.json()) as { customTitle?: unknown };
78
- } catch {
79
- return c.json({ error: 'invalid json body' }, 400);
80
- }
81
- if (typeof body.customTitle !== 'string') {
82
- return c.json({ error: 'customTitle (string) required' }, 400);
83
- }
84
- const result = renameSession(projectId, sessionId, body.customTitle);
85
- if (!result.ok) {
86
- const status = result.reason.startsWith('live PID') ? 409 : 400;
87
- return c.json({ error: result.reason }, status);
88
- }
89
- return c.json({ customTitle: result.customTitle });
90
- });
91
-
92
- sessionsRoute.delete('/', async (c) => {
93
- if (!isAcceptableOrigin(c.req.header('origin'))) {
94
- return c.json({ error: 'origin not allowed' }, 403);
95
- }
96
- let body: { items?: unknown };
97
- try {
98
- body = (await c.req.json()) as { items?: unknown };
99
- } catch {
100
- return c.json({ error: 'invalid json body' }, 400);
101
- }
102
- if (!Array.isArray(body.items) || body.items.length === 0) {
103
- return c.json({ error: 'items[] required' }, 400);
104
- }
105
- const items: DeleteRequestItem[] = [];
106
- for (const raw of body.items) {
107
- if (
108
- !raw ||
109
- typeof raw !== 'object' ||
110
- typeof (raw as { projectId?: unknown }).projectId !== 'string' ||
111
- typeof (raw as { sessionId?: unknown }).sessionId !== 'string'
112
- ) {
113
- return c.json({ error: 'each item needs projectId and sessionId strings' }, 400);
114
- }
115
- items.push(raw as DeleteRequestItem);
116
- }
117
- const result = await deleteSessions(items);
118
- return c.json(result);
119
- });
120
-
121
- function isAcceptableOrigin(origin: string | undefined): boolean {
122
- if (!origin) return false;
123
- try {
124
- const url = new URL(origin);
125
- if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
126
- return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
127
- } catch {
128
- return false;
129
- }
130
- }
1
+ import { Hono } from 'hono';
2
+ import { deleteSessions, type DeleteRequestItem } from '../lib/delete.ts';
3
+ import { loadSessionDetail } from '../lib/load-session.ts';
4
+ import { loadModifiedFiles } from '../lib/modified-files.ts';
5
+ import { openFile } from '../lib/open-folder.ts';
6
+ import { renameSession } from '../lib/rename-session.ts';
7
+ import { isSafeId } from '../lib/safe-id.ts';
8
+
9
+ export const sessionsRoute = new Hono();
10
+
11
+ // 注意:放在 /:projectId/:sessionId 之前——Hono trie 对静态后缀的具体路由优先匹配,
12
+ // 但显式按"更具体的路由先注册"是最稳的写法,避免日后引入其他通配段时被错位拦截。
13
+ sessionsRoute.get('/:projectId/:sessionId/modified-files', async (c) => {
14
+ const projectId = c.req.param('projectId');
15
+ const sessionId = c.req.param('sessionId');
16
+ if (!isSafeId(projectId) || !isSafeId(sessionId)) {
17
+ return c.json({ error: 'invalid id' }, 400);
18
+ }
19
+ const result = await loadModifiedFiles(projectId, sessionId);
20
+ if (!result) return c.json({ error: 'not found' }, 404);
21
+ return c.json(result);
22
+ });
23
+
24
+ sessionsRoute.post('/:projectId/:sessionId/open-file', async (c) => {
25
+ if (!isAcceptableOrigin(c.req.header('origin'))) {
26
+ return c.json({ error: 'origin not allowed' }, 403);
27
+ }
28
+ const projectId = c.req.param('projectId');
29
+ const sessionId = c.req.param('sessionId');
30
+ if (!isSafeId(projectId) || !isSafeId(sessionId)) {
31
+ return c.json({ error: 'invalid id' }, 400);
32
+ }
33
+ let body: { filePath?: unknown };
34
+ try {
35
+ body = (await c.req.json()) as { filePath?: unknown };
36
+ } catch {
37
+ return c.json({ error: 'invalid json body' }, 400);
38
+ }
39
+ if (typeof body.filePath !== 'string' || body.filePath === '') {
40
+ return c.json({ error: 'filePath (string) required' }, 400);
41
+ }
42
+ // 只允许打开"本会话确实改过的文件"——从 jsonl 重新聚合校验成员资格,
43
+ // 杜绝客户端传任意路径来打开系统中任意文件。
44
+ const modified = await loadModifiedFiles(projectId, sessionId);
45
+ if (!modified) return c.json({ error: 'session not found' }, 404);
46
+ if (!modified.files.some((f) => f.filePath === body.filePath)) {
47
+ return c.json({ error: 'file is not part of this session' }, 400);
48
+ }
49
+
50
+ const result = openFile(body.filePath);
51
+ if (!result.ok) {
52
+ const status = result.error === 'path not found' ? 404 : 500;
53
+ return c.json({ error: result.error ?? 'failed to open file' }, status);
54
+ }
55
+ return c.json({ ok: true, path: body.filePath });
56
+ });
57
+
58
+ sessionsRoute.get('/:projectId/:sessionId', async (c) => {
59
+ const projectId = c.req.param('projectId');
60
+ const sessionId = c.req.param('sessionId');
61
+ if (!isSafeId(projectId) || !isSafeId(sessionId)) {
62
+ return c.json({ error: 'invalid id' }, 400);
63
+ }
64
+ const detail = await loadSessionDetail(projectId, sessionId);
65
+ if (!detail) return c.json({ error: 'not found' }, 404);
66
+ return c.json(detail);
67
+ });
68
+
69
+ sessionsRoute.patch('/:projectId/:sessionId', async (c) => {
70
+ if (!isAcceptableOrigin(c.req.header('origin'))) {
71
+ return c.json({ error: 'origin not allowed' }, 403);
72
+ }
73
+ const projectId = c.req.param('projectId');
74
+ const sessionId = c.req.param('sessionId');
75
+ let body: { customTitle?: unknown };
76
+ try {
77
+ body = (await c.req.json()) as { customTitle?: unknown };
78
+ } catch {
79
+ return c.json({ error: 'invalid json body' }, 400);
80
+ }
81
+ if (typeof body.customTitle !== 'string') {
82
+ return c.json({ error: 'customTitle (string) required' }, 400);
83
+ }
84
+ const result = renameSession(projectId, sessionId, body.customTitle);
85
+ if (!result.ok) {
86
+ const status = result.reason.startsWith('live PID') ? 409 : 400;
87
+ return c.json({ error: result.reason }, status);
88
+ }
89
+ return c.json({ customTitle: result.customTitle });
90
+ });
91
+
92
+ sessionsRoute.delete('/', async (c) => {
93
+ if (!isAcceptableOrigin(c.req.header('origin'))) {
94
+ return c.json({ error: 'origin not allowed' }, 403);
95
+ }
96
+ let body: { items?: unknown };
97
+ try {
98
+ body = (await c.req.json()) as { items?: unknown };
99
+ } catch {
100
+ return c.json({ error: 'invalid json body' }, 400);
101
+ }
102
+ if (!Array.isArray(body.items) || body.items.length === 0) {
103
+ return c.json({ error: 'items[] required' }, 400);
104
+ }
105
+ const items: DeleteRequestItem[] = [];
106
+ for (const raw of body.items) {
107
+ if (
108
+ !raw ||
109
+ typeof raw !== 'object' ||
110
+ typeof (raw as { projectId?: unknown }).projectId !== 'string' ||
111
+ typeof (raw as { sessionId?: unknown }).sessionId !== 'string'
112
+ ) {
113
+ return c.json({ error: 'each item needs projectId and sessionId strings' }, 400);
114
+ }
115
+ items.push(raw as DeleteRequestItem);
116
+ }
117
+ const result = await deleteSessions(items);
118
+ return c.json(result);
119
+ });
120
+
121
+ function isAcceptableOrigin(origin: string | undefined): boolean {
122
+ if (!origin) return false;
123
+ try {
124
+ const url = new URL(origin);
125
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
126
+ return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
127
+ } catch {
128
+ return false;
129
+ }
130
+ }
@@ -1,34 +1,34 @@
1
- import { Hono } from 'hono';
2
- import { runSelfUpdate } from '../lib/update.ts';
3
- import { getVersionInfo } from '../lib/version.ts';
4
-
5
- export const versionRoute = new Hono();
6
-
7
- versionRoute.get('/', async (c) => {
8
- const refresh = c.req.query('refresh') === '1';
9
- const info = await getVersionInfo(refresh);
10
- return c.json(info);
11
- });
12
-
13
- versionRoute.post('/update', async (c) => {
14
- if (!isAcceptableOrigin(c.req.header('origin'))) {
15
- return c.json({ error: 'origin not allowed' }, 403);
16
- }
17
- const info = await getVersionInfo();
18
- if (!info.hasUpdate) {
19
- return c.json({ error: 'already up to date' }, 400);
20
- }
21
- const result = await runSelfUpdate(info.latest);
22
- return c.json(result);
23
- });
24
-
25
- function isAcceptableOrigin(origin: string | undefined): boolean {
26
- if (!origin) return false;
27
- try {
28
- const url = new URL(origin);
29
- if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
30
- return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
31
- } catch {
32
- return false;
33
- }
34
- }
1
+ import { Hono } from 'hono';
2
+ import { runSelfUpdate } from '../lib/update.ts';
3
+ import { getVersionInfo } from '../lib/version.ts';
4
+
5
+ export const versionRoute = new Hono();
6
+
7
+ versionRoute.get('/', async (c) => {
8
+ const refresh = c.req.query('refresh') === '1';
9
+ const info = await getVersionInfo(refresh);
10
+ return c.json(info);
11
+ });
12
+
13
+ versionRoute.post('/update', async (c) => {
14
+ if (!isAcceptableOrigin(c.req.header('origin'))) {
15
+ return c.json({ error: 'origin not allowed' }, 403);
16
+ }
17
+ const info = await getVersionInfo();
18
+ if (!info.hasUpdate) {
19
+ return c.json({ error: 'already up to date' }, 400);
20
+ }
21
+ const result = await runSelfUpdate(info.latest);
22
+ return c.json(result);
23
+ });
24
+
25
+ function isAcceptableOrigin(origin: string | undefined): boolean {
26
+ if (!origin) return false;
27
+ try {
28
+ const url = new URL(origin);
29
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
30
+ return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
package/server/types.ts CHANGED
@@ -1 +1 @@
1
- export * from '../shared/types.ts';
1
+ export * from '../shared/types.ts';
@@ -1,7 +1,7 @@
1
- export const RECENT_ACTIVITY_WINDOW_MIN = 5;
2
- export const MAX_SESSION_MESSAGES = 5000;
3
-
4
- // Claude Code writes this synthetic `user` record when the operator aborts a turn
5
- // (Esc / Ctrl-C). It means the turn was *stopped*, not that Claude is still
6
- // working — so the "working" heuristic treats a trailing interrupt as idle.
7
- export const INTERRUPTED_MARKER_RE = /^\s*\[Request interrupted by user/;
1
+ export const RECENT_ACTIVITY_WINDOW_MIN = 5;
2
+ export const MAX_SESSION_MESSAGES = 5000;
3
+
4
+ // Claude Code writes this synthetic `user` record when the operator aborts a turn
5
+ // (Esc / Ctrl-C). It means the turn was *stopped*, not that Claude is still
6
+ // working — so the "working" heuristic treats a trailing interrupt as idle.
7
+ export const INTERRUPTED_MARKER_RE = /^\s*\[Request interrupted by user/;