@diggerhq/anyware 0.7.36 → 0.7.40
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/dist/api/session.d.ts +1 -7
- package/dist/api/session.d.ts.map +1 -1
- package/dist/api/session.js +2 -11
- package/dist/api/session.js.map +1 -1
- package/dist/api/wsClient.d.ts +9 -0
- package/dist/api/wsClient.d.ts.map +1 -1
- package/dist/api/wsClient.js +34 -9
- package/dist/api/wsClient.js.map +1 -1
- package/dist/claude/terminalRenderer.d.ts +1 -1
- package/dist/claude/terminalRenderer.d.ts.map +1 -1
- package/dist/claude/terminalRenderer.js +50 -33
- package/dist/claude/terminalRenderer.js.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +54 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/sessionManager.d.ts +3 -1
- package/dist/server/sessionManager.d.ts.map +1 -1
- package/dist/server/sessionManager.js +213 -25
- package/dist/server/sessionManager.js.map +1 -1
- package/package.json +3 -2
- package/dist/claude/sdk/query.d.ts +0 -71
- package/dist/claude/sdk/query.d.ts.map +0 -1
- package/dist/claude/sdk/query.js +0 -379
- package/dist/claude/sdk/query.js.map +0 -1
- package/dist/claude/sdk/stream.d.ts +0 -28
- package/dist/claude/sdk/stream.d.ts.map +0 -1
- package/dist/claude/sdk/stream.js +0 -91
- package/dist/claude/sdk/stream.js.map +0 -1
- package/dist/claude/sdk/types.d.ts +0 -179
- package/dist/claude/sdk/types.d.ts.map +0 -1
- package/dist/claude/sdk/types.js +0 -13
- package/dist/claude/sdk/types.js.map +0 -1
- package/dist/utils/claudeHistory.d.ts +0 -33
- package/dist/utils/claudeHistory.d.ts.map +0 -1
- package/dist/utils/claudeHistory.js +0 -170
- package/dist/utils/claudeHistory.js.map +0 -1
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for Claude Code SDK integration
|
|
3
|
-
*/
|
|
4
|
-
export interface SDKMessage {
|
|
5
|
-
type: string;
|
|
6
|
-
[key: string]: unknown;
|
|
7
|
-
}
|
|
8
|
-
export interface SDKImageContent {
|
|
9
|
-
type: 'image';
|
|
10
|
-
source: {
|
|
11
|
-
type: 'base64';
|
|
12
|
-
media_type: string;
|
|
13
|
-
data: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface SDKTextContent {
|
|
17
|
-
type: 'text';
|
|
18
|
-
text: string;
|
|
19
|
-
}
|
|
20
|
-
export type SDKContentBlock = SDKTextContent | SDKImageContent | {
|
|
21
|
-
type: string;
|
|
22
|
-
text?: string;
|
|
23
|
-
tool_use_id?: string;
|
|
24
|
-
content?: unknown;
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
};
|
|
27
|
-
export interface SDKUserMessage extends SDKMessage {
|
|
28
|
-
type: 'user';
|
|
29
|
-
parent_tool_use_id?: string;
|
|
30
|
-
message: {
|
|
31
|
-
role: 'user';
|
|
32
|
-
content: string | SDKContentBlock[];
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export interface SDKAssistantMessage extends SDKMessage {
|
|
36
|
-
type: 'assistant';
|
|
37
|
-
parent_tool_use_id?: string;
|
|
38
|
-
message: {
|
|
39
|
-
role: 'assistant';
|
|
40
|
-
content: Array<{
|
|
41
|
-
type: string;
|
|
42
|
-
text?: string;
|
|
43
|
-
id?: string;
|
|
44
|
-
name?: string;
|
|
45
|
-
input?: unknown;
|
|
46
|
-
[key: string]: unknown;
|
|
47
|
-
}>;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export interface SDKSystemMessage extends SDKMessage {
|
|
51
|
-
type: 'system';
|
|
52
|
-
subtype: string;
|
|
53
|
-
session_id?: string;
|
|
54
|
-
model?: string;
|
|
55
|
-
cwd?: string;
|
|
56
|
-
tools?: string[];
|
|
57
|
-
slash_commands?: string[];
|
|
58
|
-
}
|
|
59
|
-
export interface SDKResultMessage extends SDKMessage {
|
|
60
|
-
type: 'result';
|
|
61
|
-
subtype: 'success' | 'error_max_turns' | 'error_during_execution';
|
|
62
|
-
result?: string;
|
|
63
|
-
num_turns: number;
|
|
64
|
-
usage?: {
|
|
65
|
-
input_tokens: number;
|
|
66
|
-
output_tokens: number;
|
|
67
|
-
cache_read_input_tokens?: number;
|
|
68
|
-
cache_creation_input_tokens?: number;
|
|
69
|
-
};
|
|
70
|
-
total_cost_usd: number;
|
|
71
|
-
duration_ms: number;
|
|
72
|
-
duration_api_ms: number;
|
|
73
|
-
is_error: boolean;
|
|
74
|
-
session_id: string;
|
|
75
|
-
}
|
|
76
|
-
export interface SDKControlResponse extends SDKMessage {
|
|
77
|
-
type: 'control_response';
|
|
78
|
-
response: {
|
|
79
|
-
request_id: string;
|
|
80
|
-
subtype: 'success' | 'error';
|
|
81
|
-
error?: string;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
export interface SDKLog extends SDKMessage {
|
|
85
|
-
type: 'log';
|
|
86
|
-
log: {
|
|
87
|
-
level: 'debug' | 'info' | 'warn' | 'error';
|
|
88
|
-
message: string;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Control request types
|
|
93
|
-
*/
|
|
94
|
-
export interface ControlRequest {
|
|
95
|
-
subtype: string;
|
|
96
|
-
}
|
|
97
|
-
export interface InterruptRequest extends ControlRequest {
|
|
98
|
-
subtype: 'interrupt';
|
|
99
|
-
}
|
|
100
|
-
export interface CanUseToolRequest extends ControlRequest {
|
|
101
|
-
subtype: 'can_use_tool';
|
|
102
|
-
tool_name: string;
|
|
103
|
-
input: unknown;
|
|
104
|
-
}
|
|
105
|
-
export interface CanUseToolControlRequest {
|
|
106
|
-
type: 'control_request';
|
|
107
|
-
request_id: string;
|
|
108
|
-
request: CanUseToolRequest;
|
|
109
|
-
}
|
|
110
|
-
export interface CanUseToolControlResponse {
|
|
111
|
-
type: 'control_response';
|
|
112
|
-
response: {
|
|
113
|
-
subtype: 'success' | 'error';
|
|
114
|
-
request_id: string;
|
|
115
|
-
response?: PermissionResult;
|
|
116
|
-
error?: string;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
export interface ControlCancelRequest {
|
|
120
|
-
type: 'control_cancel_request';
|
|
121
|
-
request_id: string;
|
|
122
|
-
}
|
|
123
|
-
export interface SDKControlRequest {
|
|
124
|
-
request_id: string;
|
|
125
|
-
type: 'control_request';
|
|
126
|
-
request: ControlRequest;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Permission result type for tool calls
|
|
130
|
-
*/
|
|
131
|
-
export type PermissionResult = {
|
|
132
|
-
behavior: 'allow';
|
|
133
|
-
updatedInput: Record<string, unknown>;
|
|
134
|
-
} | {
|
|
135
|
-
behavior: 'deny';
|
|
136
|
-
message: string;
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Callback function for tool permission checks
|
|
140
|
-
*/
|
|
141
|
-
export interface CanCallToolCallback {
|
|
142
|
-
(toolName: string, input: unknown, options: {
|
|
143
|
-
signal: AbortSignal;
|
|
144
|
-
}): Promise<PermissionResult>;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Query options
|
|
148
|
-
*/
|
|
149
|
-
export interface QueryOptions {
|
|
150
|
-
abort?: AbortSignal;
|
|
151
|
-
allowedTools?: string[];
|
|
152
|
-
appendSystemPrompt?: string;
|
|
153
|
-
customSystemPrompt?: string;
|
|
154
|
-
cwd?: string;
|
|
155
|
-
disallowedTools?: string[];
|
|
156
|
-
maxTurns?: number;
|
|
157
|
-
mcpServers?: Record<string, unknown>;
|
|
158
|
-
permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
|
|
159
|
-
continue?: boolean;
|
|
160
|
-
resume?: string;
|
|
161
|
-
model?: string;
|
|
162
|
-
fallbackModel?: string;
|
|
163
|
-
canCallTool?: CanCallToolCallback;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Query prompt types
|
|
167
|
-
*/
|
|
168
|
-
export type QueryPrompt = string | AsyncIterable<SDKMessage>;
|
|
169
|
-
/**
|
|
170
|
-
* Control response handlers
|
|
171
|
-
*/
|
|
172
|
-
export type ControlResponseHandler = (response: SDKControlResponse['response']) => void;
|
|
173
|
-
/**
|
|
174
|
-
* Error types
|
|
175
|
-
*/
|
|
176
|
-
export declare class AbortError extends Error {
|
|
177
|
-
constructor(message: string);
|
|
178
|
-
}
|
|
179
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/claude/sdk/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAGD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAGD,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,GAAG,eAAe,EAAE,CAAC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;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AAExF;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/claude/sdk/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/claude/sdk/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAoMH;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read Claude Code's local session history for a given project path.
|
|
3
|
-
*
|
|
4
|
-
* Claude stores sessions in ~/.claude/projects/{encoded-path}/*.jsonl
|
|
5
|
-
* where {encoded-path} is the full path with / replaced by -
|
|
6
|
-
*/
|
|
7
|
-
export interface HistoricalEvent {
|
|
8
|
-
type: 'user' | 'assistant' | 'tool_use' | 'tool_result';
|
|
9
|
-
timestamp: number;
|
|
10
|
-
content?: string;
|
|
11
|
-
message?: {
|
|
12
|
-
role: string;
|
|
13
|
-
content: unknown;
|
|
14
|
-
};
|
|
15
|
-
toolName?: string;
|
|
16
|
-
toolInput?: unknown;
|
|
17
|
-
toolResult?: unknown;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Read Claude's local session history for a project path
|
|
21
|
-
* Returns the most recent N events from the latest session, or null if none found
|
|
22
|
-
* @param projectPath - The project directory path
|
|
23
|
-
* @param limit - Maximum number of messages to return (default 100)
|
|
24
|
-
*/
|
|
25
|
-
export declare function readClaudeLocalHistory(projectPath: string, limit?: number): HistoricalEvent[] | null;
|
|
26
|
-
/**
|
|
27
|
-
* Get info about previous sessions in a project folder
|
|
28
|
-
*/
|
|
29
|
-
export declare function getSessionsInfo(projectPath: string): {
|
|
30
|
-
count: number;
|
|
31
|
-
latestTimestamp: number | null;
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=claudeHistory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claudeHistory.d.ts","sourceRoot":"","sources":["../../src/utils/claudeHistory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA2HD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,MAAY,GAAG,eAAe,EAAE,GAAG,IAAI,CA4BzG;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAwBtG"}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read Claude Code's local session history for a given project path.
|
|
3
|
-
*
|
|
4
|
-
* Claude stores sessions in ~/.claude/projects/{encoded-path}/*.jsonl
|
|
5
|
-
* where {encoded-path} is the full path with / replaced by -
|
|
6
|
-
*/
|
|
7
|
-
import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs';
|
|
8
|
-
import { join } from 'node:path';
|
|
9
|
-
import { homedir } from 'node:os';
|
|
10
|
-
/**
|
|
11
|
-
* Encode a path the same way Claude does for project folders
|
|
12
|
-
* /Users/brian/myproject -> -Users-brian-myproject
|
|
13
|
-
*/
|
|
14
|
-
function encodeProjectPath(path) {
|
|
15
|
-
return path.replace(/\//g, '-');
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Get the Claude projects directory
|
|
19
|
-
*/
|
|
20
|
-
function getClaudeProjectsDir() {
|
|
21
|
-
return join(homedir(), '.claude', 'projects');
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Find the most recent MAIN session file for a project (not sub-agent sessions)
|
|
25
|
-
* Main session files have UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.jsonl
|
|
26
|
-
* Sub-agent files have format: agent-xxxxxxx.jsonl
|
|
27
|
-
*/
|
|
28
|
-
function findLatestSessionFile(projectDir) {
|
|
29
|
-
if (!existsSync(projectDir)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
// UUID pattern for main session files
|
|
33
|
-
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.jsonl$/i;
|
|
34
|
-
const files = readdirSync(projectDir)
|
|
35
|
-
.filter(f => f.endsWith('.jsonl'))
|
|
36
|
-
// Only include main session files (UUID format), not sub-agent files
|
|
37
|
-
.filter(f => uuidPattern.test(f))
|
|
38
|
-
.map(f => ({
|
|
39
|
-
name: f,
|
|
40
|
-
path: join(projectDir, f),
|
|
41
|
-
mtime: statSync(join(projectDir, f)).mtime.getTime(),
|
|
42
|
-
size: statSync(join(projectDir, f)).size,
|
|
43
|
-
}))
|
|
44
|
-
// Filter out empty files
|
|
45
|
-
.filter(f => f.size > 0)
|
|
46
|
-
// Sort by modification time, newest first
|
|
47
|
-
.sort((a, b) => b.mtime - a.mtime);
|
|
48
|
-
if (files.length === 0) {
|
|
49
|
-
console.log('[history] No main session files found (agent sessions excluded)');
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
console.log(`[history] Found ${files.length} main session files, using: ${files[0].name} (${files[0].size} bytes)`);
|
|
53
|
-
return files[0].path;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Parse a JSONL file into events
|
|
57
|
-
*/
|
|
58
|
-
function parseSessionFile(filePath) {
|
|
59
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
60
|
-
const lines = content.trim().split('\n');
|
|
61
|
-
const events = [];
|
|
62
|
-
for (const line of lines) {
|
|
63
|
-
if (!line.trim())
|
|
64
|
-
continue;
|
|
65
|
-
try {
|
|
66
|
-
const parsed = JSON.parse(line);
|
|
67
|
-
events.push(parsed);
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
// Skip malformed lines
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return events;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Convert Claude's local events to our API format
|
|
77
|
-
*/
|
|
78
|
-
function convertToHistoricalEvents(events) {
|
|
79
|
-
const result = [];
|
|
80
|
-
let userCount = 0;
|
|
81
|
-
let assistantCount = 0;
|
|
82
|
-
let skippedCount = 0;
|
|
83
|
-
for (const event of events) {
|
|
84
|
-
// Skip internal events
|
|
85
|
-
if (event.type === 'queue-operation' || event.type === 'change' || event.type === 'file-history-snapshot') {
|
|
86
|
-
skippedCount++;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const timestamp = event.timestamp ? new Date(event.timestamp).getTime() : Date.now();
|
|
90
|
-
if (event.type === 'user' && event.message) {
|
|
91
|
-
userCount++;
|
|
92
|
-
// Extract content for logging
|
|
93
|
-
const content = event.message.content;
|
|
94
|
-
const preview = typeof content === 'string'
|
|
95
|
-
? content.slice(0, 50)
|
|
96
|
-
: Array.isArray(content)
|
|
97
|
-
? (content[0]?.text?.slice(0, 50) || '[complex content]')
|
|
98
|
-
: '[unknown format]';
|
|
99
|
-
console.log(`[history] User message: "${preview}..."`);
|
|
100
|
-
result.push({
|
|
101
|
-
type: 'user',
|
|
102
|
-
timestamp,
|
|
103
|
-
message: event.message,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else if (event.type === 'assistant' && event.message) {
|
|
107
|
-
assistantCount++;
|
|
108
|
-
result.push({
|
|
109
|
-
type: 'assistant',
|
|
110
|
-
timestamp,
|
|
111
|
-
message: event.message,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
console.log(`[history] Conversion stats: ${userCount} user, ${assistantCount} assistant, ${skippedCount} skipped`);
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Read Claude's local session history for a project path
|
|
120
|
-
* Returns the most recent N events from the latest session, or null if none found
|
|
121
|
-
* @param projectPath - The project directory path
|
|
122
|
-
* @param limit - Maximum number of messages to return (default 100)
|
|
123
|
-
*/
|
|
124
|
-
export function readClaudeLocalHistory(projectPath, limit = 250) {
|
|
125
|
-
const projectsDir = getClaudeProjectsDir();
|
|
126
|
-
const encodedPath = encodeProjectPath(projectPath);
|
|
127
|
-
const projectDir = join(projectsDir, encodedPath);
|
|
128
|
-
console.log(`[history] Looking for Claude history in: ${projectDir}`);
|
|
129
|
-
const latestSession = findLatestSessionFile(projectDir);
|
|
130
|
-
if (!latestSession) {
|
|
131
|
-
console.log('[history] No Claude session history found');
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
console.log(`[history] Found session file: ${latestSession}`);
|
|
135
|
-
const events = parseSessionFile(latestSession);
|
|
136
|
-
console.log(`[history] Parsed ${events.length} raw events`);
|
|
137
|
-
const historicalEvents = convertToHistoricalEvents(events);
|
|
138
|
-
console.log(`[history] Converted to ${historicalEvents.length} historical events`);
|
|
139
|
-
// Return only the most recent N messages
|
|
140
|
-
if (historicalEvents.length > limit) {
|
|
141
|
-
console.log(`[history] Limiting to most recent ${limit} messages (had ${historicalEvents.length})`);
|
|
142
|
-
return historicalEvents.slice(-limit);
|
|
143
|
-
}
|
|
144
|
-
return historicalEvents;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Get info about previous sessions in a project folder
|
|
148
|
-
*/
|
|
149
|
-
export function getSessionsInfo(projectPath) {
|
|
150
|
-
const projectsDir = getClaudeProjectsDir();
|
|
151
|
-
const encodedPath = encodeProjectPath(projectPath);
|
|
152
|
-
const projectDir = join(projectsDir, encodedPath);
|
|
153
|
-
if (!existsSync(projectDir)) {
|
|
154
|
-
return { count: 0, latestTimestamp: null };
|
|
155
|
-
}
|
|
156
|
-
const files = readdirSync(projectDir)
|
|
157
|
-
.filter(f => f.endsWith('.jsonl'))
|
|
158
|
-
.map(f => ({
|
|
159
|
-
path: join(projectDir, f),
|
|
160
|
-
mtime: statSync(join(projectDir, f)).mtime.getTime(),
|
|
161
|
-
size: statSync(join(projectDir, f)).size,
|
|
162
|
-
}))
|
|
163
|
-
.filter(f => f.size > 0);
|
|
164
|
-
if (files.length === 0) {
|
|
165
|
-
return { count: 0, latestTimestamp: null };
|
|
166
|
-
}
|
|
167
|
-
const latestTimestamp = Math.max(...files.map(f => f.mtime));
|
|
168
|
-
return { count: files.length, latestTimestamp };
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=claudeHistory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claudeHistory.js","sourceRoot":"","sources":["../../src/utils/claudeHistory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA+BlC;;;GAGG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;A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