@hienlh/ppm 0.8.92 → 0.8.94
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/.claude.bak/agent-memory/tester/MEMORY.md +3 -0
- package/.claude.bak/agent-memory/tester/project-ppm-test-conventions.md +32 -0
- package/CHANGELOG.md +3 -34
- package/dist/web/assets/api-settings-Dh4oFOpX.js +1 -0
- package/dist/web/assets/{browser-tab-CQojbRRg.js → browser-tab-DJLH0eDY.js} +1 -1
- package/dist/web/assets/chat-tab-C8HFXqGS.js +8 -0
- package/dist/web/assets/{code-editor-Dp3w7ZdH.js → code-editor-CaGdx-lS.js} +1 -1
- package/dist/web/assets/{database-viewer-DXEZ9XyO.js → database-viewer-i4Ddk6mO.js} +1 -1
- package/dist/web/assets/{diff-viewer-gjTmjJxA.js → diff-viewer-DQDS7yjv.js} +1 -1
- package/dist/web/assets/{git-graph-BPP0uvo6.js → git-graph-DUs-TN1u.js} +1 -1
- package/dist/web/assets/index-DhtLEnPD.css +2 -0
- package/dist/web/assets/{index-BiKAvKp1.js → index-Dm6RN1A1.js} +11 -11
- package/dist/web/assets/keybindings-store-qVLDZz97.js +1 -0
- package/dist/web/assets/{markdown-renderer-DJTeCvlY.js → markdown-renderer-L1NgC2Rw.js} +1 -1
- package/dist/web/assets/{postgres-viewer-D-_FH_ZH.js → postgres-viewer-_uDispGW.js} +1 -1
- package/dist/web/assets/{settings-tab-BQxPvO96.js → settings-tab-Bp4041i6.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DTZx5FY3.js → sqlite-viewer-GW-QCjHn.js} +1 -1
- package/dist/web/assets/{terminal-tab-BVllaZ_J.js → terminal-tab-E4cWujj4.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-FpL5fLOV.js → use-monaco-theme-zABXAAla.js} +1 -1
- package/dist/web/index.html +3 -3
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/providers/claude-agent-sdk.ts +9 -61
- package/src/providers/cli-provider-base.ts +0 -6
- package/src/server/routes/chat.ts +14 -33
- package/src/server/routes/settings.ts +0 -27
- package/src/server/ws/chat.ts +1 -7
- package/src/services/account.service.ts +2 -2
- package/src/services/claude-usage.service.ts +7 -2
- package/src/services/cloud-ws.service.ts +0 -1
- package/src/services/cloud.service.ts +0 -1
- package/src/services/db.service.ts +23 -11
- package/src/services/mcp-config.service.ts +6 -15
- package/src/services/supervisor.ts +2 -22
- package/src/types/api.ts +0 -1
- package/src/types/chat.ts +0 -2
- package/src/web/app.tsx +2 -3
- package/src/web/components/chat/chat-history-bar.tsx +7 -21
- package/src/web/components/chat/chat-tab.tsx +10 -15
- package/src/web/components/chat/message-list.tsx +3 -7
- package/src/web/components/chat/session-picker.tsx +0 -1
- package/src/web/components/chat/usage-badge.tsx +8 -58
- package/src/web/components/layout/upgrade-banner.tsx +5 -15
- package/src/web/components/settings/settings-tab.tsx +0 -4
- package/src/web/hooks/use-chat.ts +0 -17
- package/dist/web/assets/api-settings-Bid0NHuI.js +0 -1
- package/dist/web/assets/chat-tab-DLpVS21v.js +0 -8
- package/dist/web/assets/index-CqhIj4Ko.css +0 -2
- package/dist/web/assets/keybindings-store-CRWbpzzj.js +0 -1
- package/docs/streaming-input-guide.md +0 -267
- package/snapshot-state.md +0 -1526
- package/src/web/components/settings/change-password-section.tsx +0 -128
- package/test-session-ops.mjs +0 -444
- package/test-tokens.mjs +0 -212
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from "react";
|
|
2
|
-
import { KeyRound, Check, Eye, EyeOff } from "lucide-react";
|
|
3
|
-
import { Button } from "@/components/ui/button";
|
|
4
|
-
import { Input } from "@/components/ui/input";
|
|
5
|
-
import { api } from "@/lib/api-client";
|
|
6
|
-
import { setAuthToken } from "@/lib/api-client";
|
|
7
|
-
|
|
8
|
-
export function ChangePasswordSection() {
|
|
9
|
-
const [open, setOpen] = useState(false);
|
|
10
|
-
const [password, setPassword] = useState("");
|
|
11
|
-
const [confirm, setConfirm] = useState("");
|
|
12
|
-
const [showPw, setShowPw] = useState(false);
|
|
13
|
-
const [saving, setSaving] = useState(false);
|
|
14
|
-
const [saved, setSaved] = useState(false);
|
|
15
|
-
const [error, setError] = useState<string | null>(null);
|
|
16
|
-
|
|
17
|
-
const mismatch = confirm.length > 0 && password !== confirm;
|
|
18
|
-
const canSubmit = password.trim().length >= 4 && password === confirm && !saving;
|
|
19
|
-
|
|
20
|
-
const handleSubmit = useCallback(async () => {
|
|
21
|
-
if (!canSubmit) return;
|
|
22
|
-
setSaving(true);
|
|
23
|
-
setError(null);
|
|
24
|
-
try {
|
|
25
|
-
const { token } = await api.put<{ token: string }>("/api/settings/auth/password", {
|
|
26
|
-
password: password.trim(),
|
|
27
|
-
confirm: confirm.trim(),
|
|
28
|
-
});
|
|
29
|
-
// Update localStorage so current session stays authenticated
|
|
30
|
-
setAuthToken(token);
|
|
31
|
-
setSaved(true);
|
|
32
|
-
setPassword("");
|
|
33
|
-
setConfirm("");
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
setSaved(false);
|
|
36
|
-
setOpen(false);
|
|
37
|
-
}, 1500);
|
|
38
|
-
} catch (e) {
|
|
39
|
-
setError(e instanceof Error ? e.message : "Failed to change password");
|
|
40
|
-
} finally {
|
|
41
|
-
setSaving(false);
|
|
42
|
-
}
|
|
43
|
-
}, [canSubmit, password, confirm]);
|
|
44
|
-
|
|
45
|
-
if (!open) {
|
|
46
|
-
return (
|
|
47
|
-
<section className="space-y-2">
|
|
48
|
-
<h3 className="text-xs font-medium text-muted-foreground">Security</h3>
|
|
49
|
-
<Button
|
|
50
|
-
variant="outline"
|
|
51
|
-
size="sm"
|
|
52
|
-
className="h-8 text-xs gap-1.5 cursor-pointer"
|
|
53
|
-
onClick={() => setOpen(true)}
|
|
54
|
-
>
|
|
55
|
-
<KeyRound className="size-3.5" />
|
|
56
|
-
Change Password
|
|
57
|
-
</Button>
|
|
58
|
-
</section>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<section className="space-y-2">
|
|
64
|
-
<h3 className="text-xs font-medium text-muted-foreground">Change Password</h3>
|
|
65
|
-
<div className="space-y-2">
|
|
66
|
-
<div className="relative">
|
|
67
|
-
<Input
|
|
68
|
-
type={showPw ? "text" : "password"}
|
|
69
|
-
placeholder="New password"
|
|
70
|
-
value={password}
|
|
71
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
72
|
-
className="h-8 text-xs pr-8"
|
|
73
|
-
autoFocus
|
|
74
|
-
/>
|
|
75
|
-
<button
|
|
76
|
-
type="button"
|
|
77
|
-
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground cursor-pointer"
|
|
78
|
-
onClick={() => setShowPw(!showPw)}
|
|
79
|
-
tabIndex={-1}
|
|
80
|
-
>
|
|
81
|
-
{showPw ? <EyeOff className="size-3.5" /> : <Eye className="size-3.5" />}
|
|
82
|
-
</button>
|
|
83
|
-
</div>
|
|
84
|
-
<Input
|
|
85
|
-
type={showPw ? "text" : "password"}
|
|
86
|
-
placeholder="Confirm password"
|
|
87
|
-
value={confirm}
|
|
88
|
-
onChange={(e) => setConfirm(e.target.value)}
|
|
89
|
-
onKeyDown={(e) => { if (e.key === "Enter") handleSubmit(); }}
|
|
90
|
-
className="h-8 text-xs"
|
|
91
|
-
/>
|
|
92
|
-
{mismatch && (
|
|
93
|
-
<p className="text-[11px] text-destructive">Passwords do not match</p>
|
|
94
|
-
)}
|
|
95
|
-
{error && (
|
|
96
|
-
<p className="text-[11px] text-destructive">{error}</p>
|
|
97
|
-
)}
|
|
98
|
-
<div className="flex gap-1.5">
|
|
99
|
-
<Button
|
|
100
|
-
variant="outline"
|
|
101
|
-
size="sm"
|
|
102
|
-
className="h-8 text-xs flex-1 cursor-pointer"
|
|
103
|
-
onClick={() => {
|
|
104
|
-
setOpen(false);
|
|
105
|
-
setPassword("");
|
|
106
|
-
setConfirm("");
|
|
107
|
-
setError(null);
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
Cancel
|
|
111
|
-
</Button>
|
|
112
|
-
<Button
|
|
113
|
-
variant={saved ? "default" : "outline"}
|
|
114
|
-
size="sm"
|
|
115
|
-
className="h-8 text-xs flex-1 cursor-pointer"
|
|
116
|
-
disabled={!canSubmit}
|
|
117
|
-
onClick={handleSubmit}
|
|
118
|
-
>
|
|
119
|
-
{saving ? "..." : saved ? <Check className="size-3.5" /> : "Save"}
|
|
120
|
-
</Button>
|
|
121
|
-
</div>
|
|
122
|
-
<p className="text-[11px] text-muted-foreground">
|
|
123
|
-
Min 4 characters. You'll stay logged in on this device.
|
|
124
|
-
</p>
|
|
125
|
-
</div>
|
|
126
|
-
</section>
|
|
127
|
-
);
|
|
128
|
-
}
|
package/test-session-ops.mjs
DELETED
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test script: Advanced Session Operations
|
|
3
|
-
* Tests: listSessions, getSessionMessages, forkSession (mid-message), deleteSession, resumeSessionAt
|
|
4
|
-
*
|
|
5
|
-
* Usage: bun test-session-ops.mjs [test-name]
|
|
6
|
-
* Tests: list | messages | fork-mid | delete | resume-at | compact-summary | all
|
|
7
|
-
*/
|
|
8
|
-
import {
|
|
9
|
-
query,
|
|
10
|
-
listSessions,
|
|
11
|
-
getSessionMessages,
|
|
12
|
-
getSessionInfo,
|
|
13
|
-
forkSession,
|
|
14
|
-
renameSession,
|
|
15
|
-
tagSession,
|
|
16
|
-
} from "@anthropic-ai/claude-agent-sdk";
|
|
17
|
-
import { existsSync, unlinkSync, readdirSync } from "node:fs";
|
|
18
|
-
import { homedir } from "node:os";
|
|
19
|
-
import { resolve } from "node:path";
|
|
20
|
-
|
|
21
|
-
// Remove CLAUDECODE to avoid nested session error
|
|
22
|
-
delete process.env.CLAUDECODE;
|
|
23
|
-
|
|
24
|
-
const PROJECT_DIR = "/Users/hienlh/Projects/ppm";
|
|
25
|
-
const CLAUDE_PROJECTS_DIR = resolve(homedir(), ".claude/projects");
|
|
26
|
-
const testName = process.argv[2] || "all";
|
|
27
|
-
|
|
28
|
-
// Helpers
|
|
29
|
-
function log(label, data) {
|
|
30
|
-
console.log(`\n${"=".repeat(60)}`);
|
|
31
|
-
console.log(`[${label}]`);
|
|
32
|
-
console.log("=".repeat(60));
|
|
33
|
-
if (data !== undefined) console.log(typeof data === "string" ? data : JSON.stringify(data, null, 2));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function logOk(msg) { console.log(` ✅ ${msg}`); }
|
|
37
|
-
function logFail(msg) { console.log(` ❌ ${msg}`); }
|
|
38
|
-
function logInfo(msg) { console.log(` ℹ️ ${msg}`); }
|
|
39
|
-
|
|
40
|
-
// ─── Test 1: List Sessions ──────────────────────────────────────────────────
|
|
41
|
-
async function testListSessions() {
|
|
42
|
-
log("TEST: listSessions");
|
|
43
|
-
|
|
44
|
-
// List all sessions for PPM project
|
|
45
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 10 });
|
|
46
|
-
logInfo(`Found ${sessions.length} sessions for PPM project`);
|
|
47
|
-
|
|
48
|
-
for (const s of sessions.slice(0, 5)) {
|
|
49
|
-
console.log(` - ${s.sessionId.slice(0, 8)}... | "${s.summary?.slice(0, 50)}" | modified=${new Date(s.lastModified).toISOString().slice(0, 16)} | tag=${s.tag ?? "none"}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (sessions.length > 0) logOk("listSessions works");
|
|
53
|
-
else logFail("No sessions found");
|
|
54
|
-
|
|
55
|
-
return sessions;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ─── Test 2: Get Session Messages ───────────────────────────────────────────
|
|
59
|
-
async function testGetMessages(sessionId) {
|
|
60
|
-
log("TEST: getSessionMessages");
|
|
61
|
-
|
|
62
|
-
if (!sessionId) {
|
|
63
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 5 });
|
|
64
|
-
sessionId = sessions[0]?.sessionId;
|
|
65
|
-
if (!sessionId) { logFail("No session to test"); return; }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
logInfo(`Reading messages from session ${sessionId.slice(0, 8)}...`);
|
|
69
|
-
|
|
70
|
-
// Test with no limit
|
|
71
|
-
const allMsgs = await getSessionMessages(sessionId, { dir: PROJECT_DIR });
|
|
72
|
-
logInfo(`Total messages: ${allMsgs.length}`);
|
|
73
|
-
|
|
74
|
-
// Show first few messages with UUIDs (needed for fork-mid test)
|
|
75
|
-
for (const [i, msg] of allMsgs.slice(0, 6).entries()) {
|
|
76
|
-
const preview = typeof msg.message === "object"
|
|
77
|
-
? JSON.stringify(msg.message).slice(0, 80)
|
|
78
|
-
: String(msg.message).slice(0, 80);
|
|
79
|
-
console.log(` [${i}] type=${msg.type} uuid=${msg.uuid.slice(0, 8)}... | ${preview}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Test with limit/offset
|
|
83
|
-
const page1 = await getSessionMessages(sessionId, { dir: PROJECT_DIR, limit: 2 });
|
|
84
|
-
const page2 = await getSessionMessages(sessionId, { dir: PROJECT_DIR, limit: 2, offset: 2 });
|
|
85
|
-
logInfo(`Pagination: page1=${page1.length} msgs, page2=${page2.length} msgs`);
|
|
86
|
-
|
|
87
|
-
if (allMsgs.length > 0) logOk(`getSessionMessages works (${allMsgs.length} messages)`);
|
|
88
|
-
else logFail("No messages found");
|
|
89
|
-
|
|
90
|
-
return allMsgs;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// ─── Test 3: Fork at Mid-Message ────────────────────────────────────────────
|
|
94
|
-
async function testForkMid() {
|
|
95
|
-
log("TEST: forkSession with upToMessageId");
|
|
96
|
-
|
|
97
|
-
// Find a session with multiple messages
|
|
98
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 20 });
|
|
99
|
-
let sourceSession = null;
|
|
100
|
-
let sourceMessages = [];
|
|
101
|
-
|
|
102
|
-
for (const s of sessions) {
|
|
103
|
-
const msgs = await getSessionMessages(s.sessionId, { dir: PROJECT_DIR });
|
|
104
|
-
if (msgs.length >= 4) {
|
|
105
|
-
sourceSession = s;
|
|
106
|
-
sourceMessages = msgs;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (!sourceSession) {
|
|
112
|
-
logFail("No session with 4+ messages found");
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
logInfo(`Source: ${sourceSession.sessionId.slice(0, 8)}... (${sourceMessages.length} messages)`);
|
|
117
|
-
|
|
118
|
-
// Fork at the 2nd message (mid-conversation)
|
|
119
|
-
const forkAtMsg = sourceMessages[1]; // 2nd message
|
|
120
|
-
logInfo(`Forking at message[1]: uuid=${forkAtMsg.uuid.slice(0, 8)}... type=${forkAtMsg.type}`);
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const result = await forkSession(sourceSession.sessionId, {
|
|
124
|
-
dir: PROJECT_DIR,
|
|
125
|
-
upToMessageId: forkAtMsg.uuid,
|
|
126
|
-
title: `[TEST] Fork at msg[1] - ${new Date().toISOString().slice(11, 19)}`,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
logOk(`Fork created! New sessionId: ${result.sessionId}`);
|
|
130
|
-
|
|
131
|
-
// Verify forked session has fewer messages
|
|
132
|
-
const forkedMsgs = await getSessionMessages(result.sessionId, { dir: PROJECT_DIR });
|
|
133
|
-
logInfo(`Forked session has ${forkedMsgs.length} messages (source had ${sourceMessages.length})`);
|
|
134
|
-
|
|
135
|
-
if (forkedMsgs.length <= sourceMessages.length) {
|
|
136
|
-
logOk(`Mid-fork works: ${forkedMsgs.length} ≤ ${sourceMessages.length} messages`);
|
|
137
|
-
} else {
|
|
138
|
-
logFail(`Fork has more messages than source?!`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Get info about forked session
|
|
142
|
-
const info = await getSessionInfo(result.sessionId, { dir: PROJECT_DIR });
|
|
143
|
-
logInfo(`Fork info: title="${info?.summary}" created=${info?.createdAt ? new Date(info.createdAt).toISOString().slice(0, 16) : "?"}`);
|
|
144
|
-
|
|
145
|
-
return result.sessionId;
|
|
146
|
-
} catch (e) {
|
|
147
|
-
logFail(`forkSession failed: ${e.message}`);
|
|
148
|
-
console.error(e);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ─── Test 4: Delete Session (JSONL) ─────────────────────────────────────────
|
|
153
|
-
async function testDelete(sessionIdToDelete) {
|
|
154
|
-
log("TEST: deleteSession (JSONL unlink)");
|
|
155
|
-
|
|
156
|
-
// If no specific session, create a disposable one first via forkSession
|
|
157
|
-
if (!sessionIdToDelete) {
|
|
158
|
-
logInfo("Creating disposable session via fork for delete test...");
|
|
159
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 5 });
|
|
160
|
-
if (sessions.length === 0) { logFail("No sessions to fork from"); return; }
|
|
161
|
-
|
|
162
|
-
const result = await forkSession(sessions[0].sessionId, {
|
|
163
|
-
dir: PROJECT_DIR,
|
|
164
|
-
title: "[TEST] Disposable for delete test",
|
|
165
|
-
});
|
|
166
|
-
sessionIdToDelete = result.sessionId;
|
|
167
|
-
logInfo(`Created disposable: ${sessionIdToDelete}`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Find the JSONL file on disk
|
|
171
|
-
const projectDirs = readdirSync(CLAUDE_PROJECTS_DIR);
|
|
172
|
-
let jsonlPath = null;
|
|
173
|
-
|
|
174
|
-
for (const dir of projectDirs) {
|
|
175
|
-
const candidate = resolve(CLAUDE_PROJECTS_DIR, dir, `${sessionIdToDelete}.jsonl`);
|
|
176
|
-
if (existsSync(candidate)) {
|
|
177
|
-
jsonlPath = candidate;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!jsonlPath) {
|
|
183
|
-
logFail(`JSONL file not found for session ${sessionIdToDelete}`);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
logInfo(`Found JSONL: ${jsonlPath}`);
|
|
188
|
-
|
|
189
|
-
// Delete the file
|
|
190
|
-
unlinkSync(jsonlPath);
|
|
191
|
-
logInfo("JSONL deleted");
|
|
192
|
-
|
|
193
|
-
// Verify it's gone from listSessions
|
|
194
|
-
const afterSessions = await listSessions({ dir: PROJECT_DIR, limit: 100 });
|
|
195
|
-
const stillExists = afterSessions.some(s => s.sessionId === sessionIdToDelete);
|
|
196
|
-
|
|
197
|
-
if (!stillExists) {
|
|
198
|
-
logOk("Session deleted successfully — no longer in listSessions");
|
|
199
|
-
} else {
|
|
200
|
-
logFail("Session still appears in listSessions after JSONL deletion!");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// ─── Test 5: resumeSessionAt ────────────────────────────────────────────────
|
|
205
|
-
async function testResumeAt() {
|
|
206
|
-
log("TEST: resumeSessionAt (resume from specific message)");
|
|
207
|
-
|
|
208
|
-
// Find a session with enough messages
|
|
209
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 20 });
|
|
210
|
-
let sourceSession = null;
|
|
211
|
-
let sourceMessages = [];
|
|
212
|
-
|
|
213
|
-
for (const s of sessions) {
|
|
214
|
-
const msgs = await getSessionMessages(s.sessionId, { dir: PROJECT_DIR });
|
|
215
|
-
if (msgs.length >= 4) {
|
|
216
|
-
sourceSession = s;
|
|
217
|
-
sourceMessages = msgs;
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!sourceSession) {
|
|
223
|
-
logFail("No session with 4+ messages for resumeAt test");
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Pick middle message to resume from
|
|
228
|
-
const midIdx = Math.floor(sourceMessages.length / 2);
|
|
229
|
-
const resumeAtMsg = sourceMessages[midIdx];
|
|
230
|
-
logInfo(`Source: ${sourceSession.sessionId.slice(0, 8)}... (${sourceMessages.length} msgs)`);
|
|
231
|
-
logInfo(`Resuming at message[${midIdx}]: uuid=${resumeAtMsg.uuid.slice(0, 8)}... type=${resumeAtMsg.type}`);
|
|
232
|
-
|
|
233
|
-
try {
|
|
234
|
-
// Use query() with resume + resumeSessionAt + forkSession to test
|
|
235
|
-
const q = query({
|
|
236
|
-
prompt: "Just say 'RESUME_AT_TEST_OK' and nothing else.",
|
|
237
|
-
options: {
|
|
238
|
-
resume: sourceSession.sessionId,
|
|
239
|
-
resumeSessionAt: resumeAtMsg.uuid,
|
|
240
|
-
forkSession: true,
|
|
241
|
-
cwd: PROJECT_DIR,
|
|
242
|
-
maxTurns: 1,
|
|
243
|
-
allowedTools: [],
|
|
244
|
-
permissionMode: "bypassPermissions",
|
|
245
|
-
systemPrompt: { type: "custom", value: "You are a test assistant. Reply exactly as instructed." },
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
let resultSessionId = null;
|
|
250
|
-
let gotText = false;
|
|
251
|
-
|
|
252
|
-
for await (const msg of q) {
|
|
253
|
-
if (msg.type === "assistant") {
|
|
254
|
-
const textBlocks = (msg.message?.content || []).filter(b => b.type === "text");
|
|
255
|
-
if (textBlocks.length > 0) {
|
|
256
|
-
logInfo(`Assistant replied: "${textBlocks.map(b => b.text).join("").slice(0, 100)}"`);
|
|
257
|
-
gotText = true;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (msg.type === "result") {
|
|
261
|
-
resultSessionId = msg.session_id;
|
|
262
|
-
logInfo(`Result: subtype=${msg.subtype} session=${resultSessionId?.slice(0, 8)}... cost=$${msg.total_cost_usd?.toFixed(4)}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (gotText && resultSessionId) {
|
|
267
|
-
logOk(`resumeSessionAt works! Forked session: ${resultSessionId}`);
|
|
268
|
-
|
|
269
|
-
// Check the forked session has truncated history
|
|
270
|
-
const forkedMsgs = await getSessionMessages(resultSessionId, { dir: PROJECT_DIR });
|
|
271
|
-
logInfo(`Forked session messages: ${forkedMsgs.length} (original: ${sourceMessages.length})`);
|
|
272
|
-
|
|
273
|
-
// Cleanup: delete test session
|
|
274
|
-
return resultSessionId;
|
|
275
|
-
} else {
|
|
276
|
-
logFail("resumeSessionAt did not produce expected output");
|
|
277
|
-
}
|
|
278
|
-
} catch (e) {
|
|
279
|
-
logFail(`resumeSessionAt failed: ${e.message}`);
|
|
280
|
-
console.error(e);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// ─── Test 6: Compact/Summary for Merge ──────────────────────────────────────
|
|
285
|
-
async function testCompactSummary() {
|
|
286
|
-
log("TEST: Generate summary for merge (using query + compact approach)");
|
|
287
|
-
|
|
288
|
-
// Find a session with enough content
|
|
289
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 20 });
|
|
290
|
-
let sourceSession = null;
|
|
291
|
-
let sourceMessages = [];
|
|
292
|
-
|
|
293
|
-
for (const s of sessions) {
|
|
294
|
-
const msgs = await getSessionMessages(s.sessionId, { dir: PROJECT_DIR });
|
|
295
|
-
if (msgs.length >= 6) {
|
|
296
|
-
sourceSession = s;
|
|
297
|
-
sourceMessages = msgs;
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (!sourceSession) {
|
|
303
|
-
logFail("No session with 6+ messages for compact test");
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
logInfo(`Source: ${sourceSession.sessionId.slice(0, 8)}... (${sourceMessages.length} msgs)`);
|
|
308
|
-
|
|
309
|
-
// Extract conversation text for summary
|
|
310
|
-
const conversationText = sourceMessages.slice(0, 10).map((msg, i) => {
|
|
311
|
-
const content = msg.message?.content;
|
|
312
|
-
let text = "";
|
|
313
|
-
if (typeof content === "string") {
|
|
314
|
-
text = content;
|
|
315
|
-
} else if (Array.isArray(content)) {
|
|
316
|
-
text = content
|
|
317
|
-
.filter(b => b.type === "text")
|
|
318
|
-
.map(b => b.text)
|
|
319
|
-
.join("\n")
|
|
320
|
-
.slice(0, 500);
|
|
321
|
-
}
|
|
322
|
-
return `[${msg.type}] ${text.slice(0, 300)}`;
|
|
323
|
-
}).join("\n---\n");
|
|
324
|
-
|
|
325
|
-
logInfo(`Conversation excerpt (${conversationText.length} chars):\n${conversationText.slice(0, 500)}...`);
|
|
326
|
-
|
|
327
|
-
// Use a cheap query to generate summary
|
|
328
|
-
logInfo("Generating summary via Claude (short query)...");
|
|
329
|
-
try {
|
|
330
|
-
const summaryPrompt = `Summarize this conversation in 3-5 bullet points. Focus on: what was discussed, what decisions were made, what files were modified.
|
|
331
|
-
|
|
332
|
-
CONVERSATION:
|
|
333
|
-
${conversationText.slice(0, 3000)}
|
|
334
|
-
|
|
335
|
-
Reply with ONLY the bullet points, no preamble.`;
|
|
336
|
-
|
|
337
|
-
const q = query({
|
|
338
|
-
prompt: summaryPrompt,
|
|
339
|
-
options: {
|
|
340
|
-
cwd: PROJECT_DIR,
|
|
341
|
-
maxTurns: 1,
|
|
342
|
-
allowedTools: [],
|
|
343
|
-
permissionMode: "bypassPermissions",
|
|
344
|
-
model: "haiku",
|
|
345
|
-
systemPrompt: { type: "custom", value: "You are a concise conversation summarizer." },
|
|
346
|
-
persistSession: false, // Don't save this summary session
|
|
347
|
-
},
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
let summary = "";
|
|
351
|
-
for await (const msg of q) {
|
|
352
|
-
if (msg.type === "assistant") {
|
|
353
|
-
const textBlocks = (msg.message?.content || []).filter(b => b.type === "text");
|
|
354
|
-
summary += textBlocks.map(b => b.text).join("");
|
|
355
|
-
}
|
|
356
|
-
if (msg.type === "result") {
|
|
357
|
-
logInfo(`Summary cost: $${msg.total_cost_usd?.toFixed(4)}`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (summary) {
|
|
362
|
-
logOk("Summary generated successfully:");
|
|
363
|
-
console.log(`\n${summary}\n`);
|
|
364
|
-
logInfo("This summary could be injected into a merge session's system prompt");
|
|
365
|
-
} else {
|
|
366
|
-
logFail("No summary text produced");
|
|
367
|
-
}
|
|
368
|
-
} catch (e) {
|
|
369
|
-
logFail(`Summary generation failed: ${e.message}`);
|
|
370
|
-
console.error(e);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// ─── Test 7: Tag Session ────────────────────────────────────────────────────
|
|
375
|
-
async function testTagSession() {
|
|
376
|
-
log("TEST: tagSession");
|
|
377
|
-
|
|
378
|
-
const sessions = await listSessions({ dir: PROJECT_DIR, limit: 5 });
|
|
379
|
-
if (sessions.length === 0) { logFail("No sessions"); return; }
|
|
380
|
-
|
|
381
|
-
const target = sessions[0];
|
|
382
|
-
logInfo(`Tagging session ${target.sessionId.slice(0, 8)}... (current tag: ${target.tag ?? "none"})`);
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
await tagSession(target.sessionId, "test-tag", { dir: PROJECT_DIR });
|
|
386
|
-
const info = await getSessionInfo(target.sessionId, { dir: PROJECT_DIR });
|
|
387
|
-
logInfo(`After tag: tag="${info?.tag}"`);
|
|
388
|
-
|
|
389
|
-
if (info?.tag === "test-tag") {
|
|
390
|
-
logOk("tagSession works");
|
|
391
|
-
} else {
|
|
392
|
-
logFail(`Expected tag="test-tag", got "${info?.tag}"`);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Clear tag
|
|
396
|
-
await tagSession(target.sessionId, null, { dir: PROJECT_DIR });
|
|
397
|
-
logInfo("Tag cleared");
|
|
398
|
-
|
|
399
|
-
} catch (e) {
|
|
400
|
-
logFail(`tagSession failed: ${e.message}`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// ─── Runner ─────────────────────────────────────────────────────────────────
|
|
405
|
-
async function main() {
|
|
406
|
-
console.log(`\n🧪 Session Operations Test Suite`);
|
|
407
|
-
console.log(`Project: ${PROJECT_DIR}`);
|
|
408
|
-
console.log(`Test: ${testName}\n`);
|
|
409
|
-
|
|
410
|
-
const tests = {
|
|
411
|
-
list: testListSessions,
|
|
412
|
-
messages: testGetMessages,
|
|
413
|
-
"fork-mid": testForkMid,
|
|
414
|
-
delete: testDelete,
|
|
415
|
-
"resume-at": testResumeAt,
|
|
416
|
-
"compact-summary": testCompactSummary,
|
|
417
|
-
tag: testTagSession,
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
if (testName === "all") {
|
|
421
|
-
// Run non-destructive tests first
|
|
422
|
-
await testListSessions();
|
|
423
|
-
await testGetMessages();
|
|
424
|
-
await testTagSession();
|
|
425
|
-
await testForkMid();
|
|
426
|
-
// resume-at and compact-summary cost API tokens — ask first
|
|
427
|
-
console.log("\n⚠️ Remaining tests (resume-at, compact-summary) cost API tokens.");
|
|
428
|
-
console.log(" Run individually: bun test-session-ops.mjs resume-at");
|
|
429
|
-
console.log(" Run individually: bun test-session-ops.mjs compact-summary");
|
|
430
|
-
console.log(" Delete test: bun test-session-ops.mjs delete");
|
|
431
|
-
} else if (tests[testName]) {
|
|
432
|
-
await tests[testName]();
|
|
433
|
-
} else {
|
|
434
|
-
console.log(`Unknown test: ${testName}`);
|
|
435
|
-
console.log(`Available: ${Object.keys(tests).join(", ")}, all`);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
log("DONE", `Finished ${testName} test(s)`);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
main().catch(e => {
|
|
442
|
-
console.error("Fatal:", e);
|
|
443
|
-
process.exit(1);
|
|
444
|
-
});
|