@gramatr/mcp 0.11.11 → 0.11.14
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/bin/gramatr-mcp.d.ts +3 -0
- package/dist/bin/gramatr-mcp.d.ts.map +1 -1
- package/dist/bin/gramatr-mcp.js +38 -0
- package/dist/bin/gramatr-mcp.js.map +1 -1
- package/dist/bin/login.d.ts.map +1 -1
- package/dist/bin/login.js +2 -0
- package/dist/bin/login.js.map +1 -1
- package/dist/config-runtime.d.ts +12 -0
- package/dist/config-runtime.d.ts.map +1 -1
- package/dist/config-runtime.js +18 -0
- package/dist/config-runtime.js.map +1 -1
- package/dist/daemon/db-path.d.ts +20 -0
- package/dist/daemon/db-path.d.ts.map +1 -0
- package/dist/daemon/db-path.js +28 -0
- package/dist/daemon/db-path.js.map +1 -0
- package/dist/daemon/http-server.d.ts +29 -0
- package/dist/daemon/http-server.d.ts.map +1 -0
- package/dist/daemon/http-server.js +70 -0
- package/dist/daemon/http-server.js.map +1 -0
- package/dist/daemon/index.d.ts +13 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +126 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/ipc-protocol.d.ts +56 -0
- package/dist/daemon/ipc-protocol.d.ts.map +1 -0
- package/dist/daemon/ipc-protocol.js +10 -0
- package/dist/daemon/ipc-protocol.js.map +1 -0
- package/dist/daemon/project-cache.d.ts +63 -0
- package/dist/daemon/project-cache.d.ts.map +1 -0
- package/dist/daemon/project-cache.js +139 -0
- package/dist/daemon/project-cache.js.map +1 -0
- package/dist/daemon/server.d.ts +22 -0
- package/dist/daemon/server.d.ts.map +1 -0
- package/dist/daemon/server.js +322 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/session-registry.d.ts +26 -0
- package/dist/daemon/session-registry.d.ts.map +1 -0
- package/dist/daemon/session-registry.js +42 -0
- package/dist/daemon/session-registry.js.map +1 -0
- package/dist/daemon/sqlite-owner.d.ts +55 -0
- package/dist/daemon/sqlite-owner.d.ts.map +1 -0
- package/dist/daemon/sqlite-owner.js +133 -0
- package/dist/daemon/sqlite-owner.js.map +1 -0
- package/dist/daemon/startup.d.ts +51 -0
- package/dist/daemon/startup.d.ts.map +1 -0
- package/dist/daemon/startup.js +182 -0
- package/dist/daemon/startup.js.map +1 -0
- package/dist/hooks/generated/hook-timeouts.d.ts +3 -1
- package/dist/hooks/generated/hook-timeouts.d.ts.map +1 -1
- package/dist/hooks/generated/hook-timeouts.js +3 -1
- package/dist/hooks/generated/hook-timeouts.js.map +1 -1
- package/dist/hooks/lib/hook-state.d.ts +36 -2
- package/dist/hooks/lib/hook-state.d.ts.map +1 -1
- package/dist/hooks/lib/hook-state.js +119 -5
- package/dist/hooks/lib/hook-state.js.map +1 -1
- package/dist/hooks/session-end.d.ts.map +1 -1
- package/dist/hooks/session-end.js +48 -21
- package/dist/hooks/session-end.js.map +1 -1
- package/dist/hooks/session-start.d.ts.map +1 -1
- package/dist/hooks/session-start.js +42 -23
- package/dist/hooks/session-start.js.map +1 -1
- package/dist/proxy/local-client.d.ts +30 -20
- package/dist/proxy/local-client.d.ts.map +1 -1
- package/dist/proxy/local-client.js +185 -50
- package/dist/proxy/local-client.js.map +1 -1
- package/dist/proxy/remote-client.d.ts.map +1 -1
- package/dist/proxy/remote-client.js +13 -4
- package/dist/proxy/remote-client.js.map +1 -1
- package/dist/server/auth.d.ts +13 -4
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +154 -20
- package/dist/server/auth.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +26 -0
- package/dist/server/server.js.map +1 -1
- package/dist/setup/generated/platform-hooks.d.ts +1 -1
- package/dist/setup/generated/platform-hooks.d.ts.map +1 -1
- package/dist/setup/generated/platform-hooks.js +1 -5
- package/dist/setup/generated/platform-hooks.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* daemon/index.ts — Entry point for `gramatr-mcp daemon start`.
|
|
3
|
+
*
|
|
4
|
+
* Starts the Unix socket IPC server, writes the PID file, removes the lock
|
|
5
|
+
* file (unblocking hook processes waiting on waitForSocket), registers
|
|
6
|
+
* graceful shutdown handlers, and emits a ready message to stderr.
|
|
7
|
+
*
|
|
8
|
+
* Sprint 2: sqliteOwner.open() / .close() for WAL checkpoint lifecycle,
|
|
9
|
+
* daemon.active sentinel for cross-process signaling.
|
|
10
|
+
* Sprint 3: projectCache.load() / .save() for in-process project identity.
|
|
11
|
+
*/
|
|
12
|
+
import { unlinkSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { createDaemonServer, dispatchRpcRequest } from './server.js';
|
|
15
|
+
import { startHttpFallback } from './http-server.js';
|
|
16
|
+
import { writePidFile, removePidFile, removeSocketFile, getDaemonSocketPath, getDaemonLockPath, writeHttpCredentials, removeHttpCredentials, } from './startup.js';
|
|
17
|
+
import { sessionRegistry } from './session-registry.js';
|
|
18
|
+
import { sqliteOwner } from './sqlite-owner.js';
|
|
19
|
+
import { closeDb } from '../hooks/lib/hook-state.js';
|
|
20
|
+
import { getGramatrDirFromEnv, getGramatrStateDatabaseFromEnv, getHomeDir } from '../config-runtime.js';
|
|
21
|
+
import { getStateDatabasePath } from './db-path.js';
|
|
22
|
+
import { projectCache, getProjectCachePath } from './project-cache.js';
|
|
23
|
+
function getGramatrDir() {
|
|
24
|
+
return getGramatrDirFromEnv() ?? join(getHomeDir(), '.gramatr');
|
|
25
|
+
}
|
|
26
|
+
function getSentinelPath() {
|
|
27
|
+
return join(getGramatrDir(), 'daemon.active');
|
|
28
|
+
}
|
|
29
|
+
function writeSentinel() {
|
|
30
|
+
// Skip when running in-memory (tests).
|
|
31
|
+
if (getStateDatabasePath() === ':memory:')
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
writeFileSync(getSentinelPath(), String(process.pid), 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Non-fatal — sentinel is a best-effort signal.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function removeSentinel() {
|
|
41
|
+
try {
|
|
42
|
+
unlinkSync(getSentinelPath());
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Already gone or never written.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let _httpServer = null;
|
|
49
|
+
export async function startDaemon() {
|
|
50
|
+
const sockPath = getDaemonSocketPath();
|
|
51
|
+
const server = createDaemonServer();
|
|
52
|
+
// Start listening on the Unix socket
|
|
53
|
+
await new Promise((resolve, reject) => {
|
|
54
|
+
server.listen(sockPath, () => resolve());
|
|
55
|
+
server.once('error', reject);
|
|
56
|
+
});
|
|
57
|
+
writePidFile();
|
|
58
|
+
// Open the daemon's owned SQLite connection and start the checkpoint cycle.
|
|
59
|
+
sqliteOwner.open();
|
|
60
|
+
// Restore project identity cache from disk (skip in :memory: test mode)
|
|
61
|
+
if (getGramatrStateDatabaseFromEnv() !== ':memory:') {
|
|
62
|
+
projectCache.load(getProjectCachePath());
|
|
63
|
+
}
|
|
64
|
+
// Remove the lock file now that the socket is ready.
|
|
65
|
+
// This unblocks any hook that is polling waitForSocket().
|
|
66
|
+
try {
|
|
67
|
+
unlinkSync(getDaemonLockPath());
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Already gone — another racer may have cleaned it up
|
|
71
|
+
}
|
|
72
|
+
// Start localhost HTTP fallback (Tier 2 IPC — works on all platforms including Windows)
|
|
73
|
+
try {
|
|
74
|
+
const { port, token, server: hs } = await startHttpFallback(dispatchRpcRequest);
|
|
75
|
+
_httpServer = hs;
|
|
76
|
+
writeHttpCredentials(port, token);
|
|
77
|
+
process.stderr.write(`[gramatr-daemon] HTTP fallback on 127.0.0.1:${port}\n`);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
// Non-fatal — hooks fall back to remote HTTP if localhost HTTP unavailable
|
|
81
|
+
process.stderr.write(`[gramatr-daemon] HTTP fallback unavailable: ${err.message}\n`);
|
|
82
|
+
}
|
|
83
|
+
// Write daemon.active sentinel so hook processes know the daemon owns the DB.
|
|
84
|
+
writeSentinel();
|
|
85
|
+
// Graceful shutdown when the last session releases (+ 30s grace)
|
|
86
|
+
sessionRegistry.setOnEmpty(() => {
|
|
87
|
+
gracefulShutdown(server, 'idle');
|
|
88
|
+
});
|
|
89
|
+
// Handle the internal daemon/shutdown method (emitted via setImmediate)
|
|
90
|
+
server.on('daemon-shutdown', () => {
|
|
91
|
+
gracefulShutdown(server, 'requested');
|
|
92
|
+
});
|
|
93
|
+
process.on('SIGTERM', () => gracefulShutdown(server, 'SIGTERM'));
|
|
94
|
+
process.on('SIGINT', () => gracefulShutdown(server, 'SIGINT'));
|
|
95
|
+
process.stderr.write(`[gramatr-daemon] listening on ${sockPath} (pid ${process.pid})\n`);
|
|
96
|
+
}
|
|
97
|
+
async function gracefulShutdown(server, reason) {
|
|
98
|
+
process.stderr.write(`[gramatr-daemon] shutting down (${reason})\n`);
|
|
99
|
+
server.close();
|
|
100
|
+
_httpServer?.close();
|
|
101
|
+
removeHttpCredentials();
|
|
102
|
+
// Persist project identity cache to disk (skip in :memory: test mode)
|
|
103
|
+
if (getGramatrStateDatabaseFromEnv() !== ':memory:') {
|
|
104
|
+
projectCache.save(getProjectCachePath());
|
|
105
|
+
}
|
|
106
|
+
// TRUNCATE checkpoint via daemon's owned connection — must run before closeDb().
|
|
107
|
+
try {
|
|
108
|
+
sqliteOwner.close();
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Non-fatal
|
|
112
|
+
}
|
|
113
|
+
// closeDb() handles any hook-state.ts DB connection that may be open in
|
|
114
|
+
// this process (e.g. from tools invoked directly in the daemon process).
|
|
115
|
+
try {
|
|
116
|
+
closeDb();
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Non-fatal
|
|
120
|
+
}
|
|
121
|
+
removeSentinel();
|
|
122
|
+
removePidFile();
|
|
123
|
+
removeSocketFile();
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/daemon/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAoB,MAAM,kBAAkB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,8BAA8B,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxG,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEvE,SAAS,aAAa;IACpB,OAAO,oBAAoB,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,UAAU,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,IAAI,CAAC,aAAa,EAAE,EAAE,eAAe,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,aAAa;IACpB,uCAAuC;IACvC,IAAI,oBAAoB,EAAE,KAAK,UA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;IACtE,IAAI,8BAA8B,EAAE,KAAK,UAAU,EAAE,CAAC;QACpD,YAAY,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,iFAAiF;IACjF,IAAI,CAAC;QACH,WAAW,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;IAED,wEAAwE;IACxE,yEAAyE;IACzE,IAAI,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;IAED,cAAc,EAAE,CAAC;IACjB,aAAa,EAAE,CAAC;IAChB,gBAAgB,EAAE,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ipc-protocol.ts — Types for the gramatr daemon IPC protocol.
|
|
3
|
+
*
|
|
4
|
+
* Newline-delimited JSON-RPC 2.0 over a Unix domain socket.
|
|
5
|
+
* One JSON object per line; no framing beyond the newline terminator.
|
|
6
|
+
*
|
|
7
|
+
* This file is types-only — no runtime code.
|
|
8
|
+
*/
|
|
9
|
+
export interface DaemonRequest {
|
|
10
|
+
jsonrpc: '2.0';
|
|
11
|
+
id: number | string;
|
|
12
|
+
method: DaemonMethod;
|
|
13
|
+
params: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface DaemonResponse {
|
|
16
|
+
jsonrpc: '2.0';
|
|
17
|
+
id: number | string;
|
|
18
|
+
result?: unknown;
|
|
19
|
+
error?: {
|
|
20
|
+
code: number;
|
|
21
|
+
message: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export type DaemonMethod = 'tool/call' | 'session/register' | 'session/release' | 'session/context/get' | 'session/context/set' | 'project/resolve' | 'project/cache-set' | 'db/query' | 'daemon/ping' | 'daemon/shutdown';
|
|
26
|
+
/**
|
|
27
|
+
* Parameters for the db/query IPC method.
|
|
28
|
+
*
|
|
29
|
+
* Forwards the three most-called read operations to the daemon's owned
|
|
30
|
+
* SQLite connection. Hook processes check for the daemon.active sentinel
|
|
31
|
+
* file before routing through IPC (Sprint 3 will wire the async call path).
|
|
32
|
+
*/
|
|
33
|
+
export interface DbQueryParams {
|
|
34
|
+
operation: 'getSessionContext' | 'getLastSessionForProject' | 'getLocalProjectByDirectory';
|
|
35
|
+
args: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export declare const DAEMON_UNAVAILABLE: unique symbol;
|
|
38
|
+
export type DaemonUnavailable = typeof DAEMON_UNAVAILABLE;
|
|
39
|
+
/** Parameters for the `project/resolve` IPC method. */
|
|
40
|
+
export interface ProjectResolveParams {
|
|
41
|
+
git_remote?: string;
|
|
42
|
+
directory?: string;
|
|
43
|
+
slug?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Response shape for a successful `project/resolve` hit. */
|
|
46
|
+
export interface ProjectResolveHit {
|
|
47
|
+
found: true;
|
|
48
|
+
project_id: string;
|
|
49
|
+
slug: string;
|
|
50
|
+
}
|
|
51
|
+
/** Response shape for a `project/resolve` miss. */
|
|
52
|
+
export interface ProjectResolveMiss {
|
|
53
|
+
found: false;
|
|
54
|
+
}
|
|
55
|
+
export type ProjectResolveResult = ProjectResolveHit | ProjectResolveMiss;
|
|
56
|
+
//# sourceMappingURL=ipc-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-protocol.d.ts","sourceRoot":"","sources":["../../src/daemon/ipc-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED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
4
|
+
* Newline-delimited JSON-RPC 2.0 over a Unix domain socket.
|
|
5
|
+
* One JSON object per line; no framing beyond the newline terminator.
|
|
6
|
+
*
|
|
7
|
+
* This file is types-only — no runtime code.
|
|
8
|
+
*/
|
|
9
|
+
export const DAEMON_UNAVAILABLE = Symbol('DAEMON_UNAVAILABLE');
|
|
10
|
+
//# sourceMappingURL=ipc-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-protocol.js","sourceRoot":"","sources":["../../src/daemon/ipc-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2CH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* project-cache.ts — In-process project identity cache for the gramatr daemon.
|
|
3
|
+
*
|
|
4
|
+
* The most expensive operation in session-start is resolving
|
|
5
|
+
* `git remote → project_id`. This module caches the result in the daemon
|
|
6
|
+
* process so repeated lookups are Map lookups (~0ms) rather than SQLite or
|
|
7
|
+
* remote server calls.
|
|
8
|
+
*
|
|
9
|
+
* The cache is keyed on three lookup axes simultaneously:
|
|
10
|
+
* - git remote URL (e.g. "git@github.com:org/repo.git")
|
|
11
|
+
* - working directory (e.g. "/home/user/work/myproject")
|
|
12
|
+
* - project slug (e.g. "org/repo")
|
|
13
|
+
*
|
|
14
|
+
* On daemon start: restored from ~/.gramatr/project-cache.json (warm start).
|
|
15
|
+
* On daemon shutdown: persisted to the same file.
|
|
16
|
+
* Skip load/save when GRAMATR_STATE_DB === ':memory:' (test mode).
|
|
17
|
+
*/
|
|
18
|
+
export interface ProjectEntry {
|
|
19
|
+
id: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
gitRemote: string | null;
|
|
22
|
+
directory: string | null;
|
|
23
|
+
cachedAt: number;
|
|
24
|
+
}
|
|
25
|
+
declare class ProjectCache {
|
|
26
|
+
private byRemote;
|
|
27
|
+
private byDirectory;
|
|
28
|
+
private bySlug;
|
|
29
|
+
/** Add or update a project entry in all applicable index maps. */
|
|
30
|
+
set(entry: ProjectEntry): void;
|
|
31
|
+
/** Look up by git remote URL. Returns null on cache miss or TTL expiry. */
|
|
32
|
+
getByRemote(remote: string): ProjectEntry | null;
|
|
33
|
+
/** Look up by working directory path. Returns null on cache miss or TTL expiry. */
|
|
34
|
+
getByDirectory(dir: string): ProjectEntry | null;
|
|
35
|
+
/** Look up by project slug. Returns null on cache miss or TTL expiry. */
|
|
36
|
+
getBySlug(slug: string): ProjectEntry | null;
|
|
37
|
+
/**
|
|
38
|
+
* Remove a project entry from all index maps by project ID.
|
|
39
|
+
* Scans all maps — O(n) but the cache is small and invalidation is rare.
|
|
40
|
+
*/
|
|
41
|
+
invalidate(id: string): void;
|
|
42
|
+
/** Total number of unique project entries (by slug). */
|
|
43
|
+
size(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Persist the cache to a JSON file on shutdown.
|
|
46
|
+
* Silently skips on write errors — the cache is advisory only.
|
|
47
|
+
*/
|
|
48
|
+
save(path: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Restore the cache from a JSON file on startup.
|
|
51
|
+
* Silently skips on read/parse errors — cache starts empty.
|
|
52
|
+
*/
|
|
53
|
+
load(path: string): void;
|
|
54
|
+
private _isExpired;
|
|
55
|
+
}
|
|
56
|
+
export declare const projectCache: ProjectCache;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the filesystem path for the project cache JSON file.
|
|
59
|
+
* Uses GRAMATR_DIR env override when available, otherwise ~/.gramatr/.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getProjectCachePath(): string;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=project-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-cache.d.ts","sourceRoot":"","sources":["../../src/daemon/project-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAOD,cAAM,YAAY;IAChB,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,MAAM,CAAmC;IAEjD,kEAAkE;IAClE,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAM9B,2EAA2E;IAC3E,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAKhD,mFAAmF;IACnF,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAKhD,yEAAyE;IACzE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAK5C;;;OAGG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAY5B,wDAAwD;IACxD,IAAI,IAAI,MAAM;IAId;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAaxB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAiBxB,OAAO,CAAC,UAAU;CAGnB;AAkBD,eAAO,MAAM,YAAY,cAAqB,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* project-cache.ts — In-process project identity cache for the gramatr daemon.
|
|
3
|
+
*
|
|
4
|
+
* The most expensive operation in session-start is resolving
|
|
5
|
+
* `git remote → project_id`. This module caches the result in the daemon
|
|
6
|
+
* process so repeated lookups are Map lookups (~0ms) rather than SQLite or
|
|
7
|
+
* remote server calls.
|
|
8
|
+
*
|
|
9
|
+
* The cache is keyed on three lookup axes simultaneously:
|
|
10
|
+
* - git remote URL (e.g. "git@github.com:org/repo.git")
|
|
11
|
+
* - working directory (e.g. "/home/user/work/myproject")
|
|
12
|
+
* - project slug (e.g. "org/repo")
|
|
13
|
+
*
|
|
14
|
+
* On daemon start: restored from ~/.gramatr/project-cache.json (warm start).
|
|
15
|
+
* On daemon shutdown: persisted to the same file.
|
|
16
|
+
* Skip load/save when GRAMATR_STATE_DB === ':memory:' (test mode).
|
|
17
|
+
*/
|
|
18
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
19
|
+
import { dirname, join } from 'node:path';
|
|
20
|
+
import { getGramatrDirFromEnv, getHomeDir } from '../config-runtime.js';
|
|
21
|
+
// 24-hour TTL — projects don't change identity frequently
|
|
22
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
23
|
+
// ── Cache class ───────────────────────────────────────────────────────────────
|
|
24
|
+
class ProjectCache {
|
|
25
|
+
byRemote = new Map();
|
|
26
|
+
byDirectory = new Map();
|
|
27
|
+
bySlug = new Map();
|
|
28
|
+
/** Add or update a project entry in all applicable index maps. */
|
|
29
|
+
set(entry) {
|
|
30
|
+
if (entry.gitRemote)
|
|
31
|
+
this.byRemote.set(entry.gitRemote, entry);
|
|
32
|
+
if (entry.directory)
|
|
33
|
+
this.byDirectory.set(entry.directory, entry);
|
|
34
|
+
this.bySlug.set(entry.slug, entry);
|
|
35
|
+
}
|
|
36
|
+
/** Look up by git remote URL. Returns null on cache miss or TTL expiry. */
|
|
37
|
+
getByRemote(remote) {
|
|
38
|
+
const entry = this.byRemote.get(remote);
|
|
39
|
+
return entry && !this._isExpired(entry) ? entry : null;
|
|
40
|
+
}
|
|
41
|
+
/** Look up by working directory path. Returns null on cache miss or TTL expiry. */
|
|
42
|
+
getByDirectory(dir) {
|
|
43
|
+
const entry = this.byDirectory.get(dir);
|
|
44
|
+
return entry && !this._isExpired(entry) ? entry : null;
|
|
45
|
+
}
|
|
46
|
+
/** Look up by project slug. Returns null on cache miss or TTL expiry. */
|
|
47
|
+
getBySlug(slug) {
|
|
48
|
+
const entry = this.bySlug.get(slug);
|
|
49
|
+
return entry && !this._isExpired(entry) ? entry : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Remove a project entry from all index maps by project ID.
|
|
53
|
+
* Scans all maps — O(n) but the cache is small and invalidation is rare.
|
|
54
|
+
*/
|
|
55
|
+
invalidate(id) {
|
|
56
|
+
for (const [key, entry] of this.byRemote) {
|
|
57
|
+
if (entry.id === id)
|
|
58
|
+
this.byRemote.delete(key);
|
|
59
|
+
}
|
|
60
|
+
for (const [key, entry] of this.byDirectory) {
|
|
61
|
+
if (entry.id === id)
|
|
62
|
+
this.byDirectory.delete(key);
|
|
63
|
+
}
|
|
64
|
+
for (const [key, entry] of this.bySlug) {
|
|
65
|
+
if (entry.id === id)
|
|
66
|
+
this.bySlug.delete(key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Total number of unique project entries (by slug). */
|
|
70
|
+
size() {
|
|
71
|
+
return this.bySlug.size;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Persist the cache to a JSON file on shutdown.
|
|
75
|
+
* Silently skips on write errors — the cache is advisory only.
|
|
76
|
+
*/
|
|
77
|
+
save(path) {
|
|
78
|
+
try {
|
|
79
|
+
const dir = dirname(path);
|
|
80
|
+
if (!existsSync(dir))
|
|
81
|
+
mkdirSync(dir, { recursive: true });
|
|
82
|
+
// De-duplicate: slug map is canonical (every entry is in bySlug)
|
|
83
|
+
const entries = [...this.bySlug.values()].filter((e) => !this._isExpired(e));
|
|
84
|
+
writeFileSync(path, JSON.stringify(entries, null, 2), 'utf8');
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Non-fatal — cache miss on next start is safe
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Restore the cache from a JSON file on startup.
|
|
92
|
+
* Silently skips on read/parse errors — cache starts empty.
|
|
93
|
+
*/
|
|
94
|
+
load(path) {
|
|
95
|
+
try {
|
|
96
|
+
if (!existsSync(path))
|
|
97
|
+
return;
|
|
98
|
+
const raw = readFileSync(path, 'utf8');
|
|
99
|
+
const entries = JSON.parse(raw);
|
|
100
|
+
if (!Array.isArray(entries))
|
|
101
|
+
return;
|
|
102
|
+
for (const item of entries) {
|
|
103
|
+
if (!isProjectEntry(item))
|
|
104
|
+
continue;
|
|
105
|
+
if (this._isExpired(item))
|
|
106
|
+
continue;
|
|
107
|
+
this.set(item);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Non-fatal — cache starts empty
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
_isExpired(entry) {
|
|
115
|
+
return Date.now() - entry.cachedAt > CACHE_TTL_MS;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// ── Type guard ────────────────────────────────────────────────────────────────
|
|
119
|
+
function isProjectEntry(v) {
|
|
120
|
+
if (v === null || typeof v !== 'object')
|
|
121
|
+
return false;
|
|
122
|
+
const o = v;
|
|
123
|
+
return (typeof o.id === 'string' &&
|
|
124
|
+
typeof o.slug === 'string' &&
|
|
125
|
+
typeof o.cachedAt === 'number' &&
|
|
126
|
+
(o.gitRemote === null || typeof o.gitRemote === 'string') &&
|
|
127
|
+
(o.directory === null || typeof o.directory === 'string'));
|
|
128
|
+
}
|
|
129
|
+
// ── Singleton ─────────────────────────────────────────────────────────────────
|
|
130
|
+
export const projectCache = new ProjectCache();
|
|
131
|
+
/**
|
|
132
|
+
* Returns the filesystem path for the project cache JSON file.
|
|
133
|
+
* Uses GRAMATR_DIR env override when available, otherwise ~/.gramatr/.
|
|
134
|
+
*/
|
|
135
|
+
export function getProjectCachePath() {
|
|
136
|
+
const dir = getGramatrDirFromEnv() ?? join(getHomeDir(), '.gramatr');
|
|
137
|
+
return join(dir, 'project-cache.json');
|
|
138
|
+
}
|
|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,UAAU,CAAC,KAAmB;QACpC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,GAAG,YAAY,CAAC;IACpD,CAAC;CACF;AAED,iFAAiF;AAEjF,SAAS,cAAc,CAAC,CAAU;IAChC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAG,CAA4B,CAAC;IACvC,OAAO,CACL,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ;QACxB,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;QAC1B,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ;QAC9B,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,CAAC;QACzD,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,iFAAiF;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,GAAG,GAAG,oBAAoB,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,UAAU,CAAC,CAAC;IACrE,OAAO,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* server.ts — Unix socket IPC server for the gramatr daemon.
|
|
3
|
+
*
|
|
4
|
+
* Accepts newline-delimited JSON-RPC 2.0 connections. Each connection
|
|
5
|
+
* can send one request and receives one response. Connections are
|
|
6
|
+
* short-lived (hook processes are short-lived); no multiplexing needed.
|
|
7
|
+
*
|
|
8
|
+
* Error codes:
|
|
9
|
+
* -32600 Invalid request
|
|
10
|
+
* -32601 Method not found
|
|
11
|
+
* -32603 Internal error
|
|
12
|
+
*/
|
|
13
|
+
import { type Server, type Socket } from 'node:net';
|
|
14
|
+
import type { DaemonRequest } from './ipc-protocol.js';
|
|
15
|
+
/**
|
|
16
|
+
* Route a JSON-RPC 2.0 request to the appropriate handler.
|
|
17
|
+
* Exported so the HTTP fallback server can share the same dispatch logic.
|
|
18
|
+
*/
|
|
19
|
+
export declare function dispatchRpcRequest(req: DaemonRequest): Promise<unknown>;
|
|
20
|
+
export declare function createDaemonServer(): Server;
|
|
21
|
+
export declare function getActiveSockets(): Set<Socket>;
|
|
22
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/daemon/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlE,OAAO,KAAK,EAAE,aAAa,EAAuD,MAAM,mBAAmB,CAAC;AA8F5G;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CA+J7E;AAgFD,wBAAgB,kBAAkB,IAAI,MAAM,CAS3C;AAED,wBAAgB,gBAAgB,IAAI,GAAG,CAAC,MAAM,CAAC,CAE9C"}
|