@graphty/remote-logger 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -10
- package/dist/client/RemoteLogClient.d.ts +2 -0
- package/dist/client/RemoteLogClient.d.ts.map +1 -1
- package/dist/client/RemoteLogClient.js +35 -4
- package/dist/client/RemoteLogClient.js.map +1 -1
- package/dist/client/types.d.ts +13 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +9 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +32 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +270 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +14 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +14 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/logs-clear.d.ts +76 -0
- package/dist/mcp/tools/logs-clear.d.ts.map +1 -0
- package/dist/mcp/tools/logs-clear.js +58 -0
- package/dist/mcp/tools/logs-clear.js.map +1 -0
- package/dist/mcp/tools/logs-get-all.d.ts +60 -0
- package/dist/mcp/tools/logs-get-all.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-all.js +50 -0
- package/dist/mcp/tools/logs-get-all.js.map +1 -0
- package/dist/mcp/tools/logs-get-errors.d.ts +65 -0
- package/dist/mcp/tools/logs-get-errors.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-errors.js +46 -0
- package/dist/mcp/tools/logs-get-errors.js.map +1 -0
- package/dist/mcp/tools/logs-get-file-path.d.ts +75 -0
- package/dist/mcp/tools/logs-get-file-path.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-file-path.js +90 -0
- package/dist/mcp/tools/logs-get-file-path.js.map +1 -0
- package/dist/mcp/tools/logs-get-recent.d.ts +89 -0
- package/dist/mcp/tools/logs-get-recent.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-recent.js +74 -0
- package/dist/mcp/tools/logs-get-recent.js.map +1 -0
- package/dist/mcp/tools/logs-list-sessions.d.ts +64 -0
- package/dist/mcp/tools/logs-list-sessions.d.ts.map +1 -0
- package/dist/mcp/tools/logs-list-sessions.js +48 -0
- package/dist/mcp/tools/logs-list-sessions.js.map +1 -0
- package/dist/mcp/tools/logs-receive.d.ts +150 -0
- package/dist/mcp/tools/logs-receive.d.ts.map +1 -0
- package/dist/mcp/tools/logs-receive.js +68 -0
- package/dist/mcp/tools/logs-receive.js.map +1 -0
- package/dist/mcp/tools/logs-search.d.ts +91 -0
- package/dist/mcp/tools/logs-search.d.ts.map +1 -0
- package/dist/mcp/tools/logs-search.js +68 -0
- package/dist/mcp/tools/logs-search.js.map +1 -0
- package/dist/mcp/tools/logs-status.d.ts +45 -0
- package/dist/mcp/tools/logs-status.d.ts.map +1 -0
- package/dist/mcp/tools/logs-status.js +45 -0
- package/dist/mcp/tools/logs-status.js.map +1 -0
- package/dist/server/dual-server.d.ts +76 -0
- package/dist/server/dual-server.d.ts.map +1 -0
- package/dist/server/dual-server.js +214 -0
- package/dist/server/dual-server.js.map +1 -0
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +5 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/jsonl-writer.d.ts +93 -0
- package/dist/server/jsonl-writer.d.ts.map +1 -0
- package/dist/server/jsonl-writer.js +205 -0
- package/dist/server/jsonl-writer.js.map +1 -0
- package/dist/server/log-server.d.ts +62 -11
- package/dist/server/log-server.d.ts.map +1 -1
- package/dist/server/log-server.js +237 -101
- package/dist/server/log-server.js.map +1 -1
- package/dist/server/log-storage.d.ts +301 -0
- package/dist/server/log-storage.d.ts.map +1 -0
- package/dist/server/log-storage.js +408 -0
- package/dist/server/log-storage.js.map +1 -0
- package/dist/server/marker-utils.d.ts +69 -0
- package/dist/server/marker-utils.d.ts.map +1 -0
- package/dist/server/marker-utils.js +118 -0
- package/dist/server/marker-utils.js.map +1 -0
- package/dist/vite/index.d.ts +8 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +8 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/plugin.d.ts +42 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +46 -0
- package/dist/vite/plugin.js.map +1 -0
- package/package.json +12 -2
- package/src/client/RemoteLogClient.ts +52 -4
- package/src/client/types.ts +13 -0
- package/src/mcp/index.ts +25 -0
- package/src/mcp/mcp-server.ts +364 -0
- package/src/mcp/tools/index.ts +69 -0
- package/src/mcp/tools/logs-clear.ts +86 -0
- package/src/mcp/tools/logs-get-all.ts +78 -0
- package/src/mcp/tools/logs-get-errors.ts +71 -0
- package/src/mcp/tools/logs-get-file-path.ts +121 -0
- package/src/mcp/tools/logs-get-recent.ts +104 -0
- package/src/mcp/tools/logs-list-sessions.ts +71 -0
- package/src/mcp/tools/logs-receive.ts +96 -0
- package/src/mcp/tools/logs-search.ts +95 -0
- package/src/mcp/tools/logs-status.ts +69 -0
- package/src/server/dual-server.ts +308 -0
- package/src/server/index.ts +37 -0
- package/src/server/jsonl-writer.ts +277 -0
- package/src/server/log-server.ts +311 -119
- package/src/server/log-storage.ts +651 -0
- package/src/server/marker-utils.ts +144 -0
- package/src/vite/index.ts +8 -0
- package/src/vite/plugin.ts +59 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for extracting and resolving project markers.
|
|
3
|
+
*
|
|
4
|
+
* Project markers are used to identify which git worktree or project
|
|
5
|
+
* a log session belongs to, enabling filtering of logs by project.
|
|
6
|
+
* @module server/marker-utils
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Extract a project marker from a filesystem path.
|
|
12
|
+
*
|
|
13
|
+
* The function looks for `.worktrees` in the path and extracts the worktree name.
|
|
14
|
+
* If no worktree is found, it falls back to the directory basename.
|
|
15
|
+
* @param cwd - The filesystem path to extract a marker from
|
|
16
|
+
* @returns The extracted project marker, or "default" if extraction fails
|
|
17
|
+
* @example
|
|
18
|
+
* // Worktree paths
|
|
19
|
+
* extractMarkerFromPath("/home/user/.worktrees/remote-logging") // "remote-logging"
|
|
20
|
+
* extractMarkerFromPath("C:\\Users\\dev\\.worktrees\\feature-xyz") // "feature-xyz"
|
|
21
|
+
*
|
|
22
|
+
* // Regular paths (uses basename)
|
|
23
|
+
* extractMarkerFromPath("/home/user/my-project") // "my-project"
|
|
24
|
+
*/
|
|
25
|
+
export function extractMarkerFromPath(cwd: string): string {
|
|
26
|
+
if (!cwd || cwd === "/") {
|
|
27
|
+
return "default";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Normalize trailing slashes
|
|
31
|
+
const normalizedPath = cwd.replace(/[/\\]+$/, "");
|
|
32
|
+
|
|
33
|
+
if (!normalizedPath) {
|
|
34
|
+
return "default";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Check if in .worktrees directory (supports both Unix and Windows paths)
|
|
38
|
+
// Match: .worktrees/worktree-name or .worktrees\worktree-name
|
|
39
|
+
const worktreeMatch = normalizedPath.match(/\.worktrees[/\\]([^/\\]+)/);
|
|
40
|
+
if (worktreeMatch) {
|
|
41
|
+
return worktreeMatch[1];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Fall back to directory name
|
|
45
|
+
// Handle both Unix and Windows paths by splitting on both separators
|
|
46
|
+
const segments = normalizedPath.split(/[/\\]/);
|
|
47
|
+
const basename = segments.filter(Boolean).pop();
|
|
48
|
+
return basename || "default";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Extract a project marker from a session ID.
|
|
53
|
+
*
|
|
54
|
+
* Session IDs typically follow the format: {prefix}-{timestamp}-{random}
|
|
55
|
+
* This function extracts the prefix part as the project marker.
|
|
56
|
+
* @param sessionId - The session ID to extract a marker from
|
|
57
|
+
* @returns The extracted project marker, or "default" if extraction fails
|
|
58
|
+
* @example
|
|
59
|
+
* extractMarkerFromSessionId("graphty-element-1704067200000-abc123") // "graphty-element"
|
|
60
|
+
* extractMarkerFromSessionId("my-app-1704067200000-xyz") // "my-app"
|
|
61
|
+
* extractMarkerFromSessionId("simple") // "simple"
|
|
62
|
+
*/
|
|
63
|
+
export function extractMarkerFromSessionId(sessionId: string): string {
|
|
64
|
+
if (!sessionId) {
|
|
65
|
+
return "default";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Session IDs follow format: {prefix}-{timestamp}-{random}
|
|
69
|
+
// The timestamp is typically a 13-digit number (milliseconds since epoch)
|
|
70
|
+
// We want to extract everything before the timestamp
|
|
71
|
+
|
|
72
|
+
// Look for pattern: name-{13 digits}-{suffix}
|
|
73
|
+
const timestampMatch = sessionId.match(/^(.+?)-(\d{10,13})-[a-zA-Z0-9]+$/);
|
|
74
|
+
if (timestampMatch) {
|
|
75
|
+
return timestampMatch[1];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Fall back to first segment before hyphen
|
|
79
|
+
const firstHyphen = sessionId.indexOf("-");
|
|
80
|
+
if (firstHyphen > 0) {
|
|
81
|
+
return sessionId.substring(0, firstHyphen);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Return the whole session ID if no hyphen
|
|
85
|
+
return sessionId;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Options for resolving a project marker.
|
|
90
|
+
*/
|
|
91
|
+
export interface MarkerResolutionOptions {
|
|
92
|
+
/** Explicit project marker (highest priority) */
|
|
93
|
+
projectMarker?: string;
|
|
94
|
+
/** Working directory path to extract marker from */
|
|
95
|
+
workingDirectory?: string;
|
|
96
|
+
/** Session ID to extract marker from (lowest priority) */
|
|
97
|
+
sessionId?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resolve a project marker using a fallback chain.
|
|
102
|
+
*
|
|
103
|
+
* Priority order:
|
|
104
|
+
* 1. Explicit projectMarker parameter
|
|
105
|
+
* 2. Extracted from workingDirectory path
|
|
106
|
+
* 3. Extracted from sessionId
|
|
107
|
+
* 4. "default" as final fallback
|
|
108
|
+
* @param options - Resolution options with various marker sources
|
|
109
|
+
* @returns The resolved project marker
|
|
110
|
+
* @example
|
|
111
|
+
* resolveProjectMarker({
|
|
112
|
+
* projectMarker: "explicit",
|
|
113
|
+
* workingDirectory: "/path/to/.worktrees/from-path"
|
|
114
|
+
* }) // "explicit"
|
|
115
|
+
*
|
|
116
|
+
* resolveProjectMarker({
|
|
117
|
+
* workingDirectory: "/path/to/.worktrees/remote-logging"
|
|
118
|
+
* }) // "remote-logging"
|
|
119
|
+
*/
|
|
120
|
+
export function resolveProjectMarker(options: MarkerResolutionOptions): string {
|
|
121
|
+
// Priority 1: Explicit project marker
|
|
122
|
+
if (options.projectMarker) {
|
|
123
|
+
return options.projectMarker;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Priority 2: Extract from working directory
|
|
127
|
+
if (options.workingDirectory) {
|
|
128
|
+
const fromPath = extractMarkerFromPath(options.workingDirectory);
|
|
129
|
+
if (fromPath !== "default") {
|
|
130
|
+
return fromPath;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Priority 3: Extract from session ID
|
|
135
|
+
if (options.sessionId) {
|
|
136
|
+
const fromSession = extractMarkerFromSessionId(options.sessionId);
|
|
137
|
+
if (fromSession !== "default") {
|
|
138
|
+
return fromSession;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Final fallback
|
|
143
|
+
return "default";
|
|
144
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin for automatic project marker injection.
|
|
3
|
+
*
|
|
4
|
+
* This plugin injects global variables that the RemoteLogClient
|
|
5
|
+
* can use to automatically identify which project/worktree logs
|
|
6
|
+
* are coming from.
|
|
7
|
+
* @module vite/plugin
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { extractMarkerFromPath } from "../server/marker-utils.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Vite plugin configuration object.
|
|
14
|
+
* Matches Vite's Plugin type but without requiring the full vite dependency.
|
|
15
|
+
*/
|
|
16
|
+
interface VitePlugin {
|
|
17
|
+
name: string;
|
|
18
|
+
config: () => {
|
|
19
|
+
define: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a Vite plugin that injects project marker globals.
|
|
25
|
+
*
|
|
26
|
+
* The plugin detects the current working directory and:
|
|
27
|
+
* 1. Extracts a project marker (worktree name or directory basename)
|
|
28
|
+
* 2. Injects `__REMOTE_LOG_PROJECT_MARKER__` with the marker
|
|
29
|
+
* 3. Injects `__REMOTE_LOG_WORKTREE_PATH__` with the full path
|
|
30
|
+
*
|
|
31
|
+
* These globals are automatically read by RemoteLogClient when no
|
|
32
|
+
* explicit projectMarker/worktreePath options are provided.
|
|
33
|
+
* @returns A Vite plugin configuration object
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // vite.config.ts
|
|
37
|
+
* import { remoteLoggerPlugin } from "@graphty/remote-logger/vite";
|
|
38
|
+
*
|
|
39
|
+
* export default defineConfig({
|
|
40
|
+
* plugins: [remoteLoggerPlugin()]
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function remoteLoggerPlugin(): VitePlugin {
|
|
45
|
+
return {
|
|
46
|
+
name: "remote-logger",
|
|
47
|
+
config() {
|
|
48
|
+
const cwd = process.cwd();
|
|
49
|
+
const marker = extractMarkerFromPath(cwd);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
define: {
|
|
53
|
+
__REMOTE_LOG_PROJECT_MARKER__: JSON.stringify(marker),
|
|
54
|
+
__REMOTE_LOG_WORKTREE_PATH__: JSON.stringify(cwd),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|