sandstream-kit 1.1.0 → 1.3.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 +101 -92
- package/dist/adapters/expo-eas.js +1 -1
- package/dist/adapters/expo-eas.js.map +1 -1
- package/dist/audit-logging-service.js +1 -1
- package/dist/audit-logging-service.js.map +1 -1
- package/dist/author-verification.js +1 -1
- package/dist/author-verification.js.map +1 -1
- package/dist/check-web-search.js +37 -6
- package/dist/check-web-search.js.map +1 -1
- package/dist/cli-shared.d.ts +4 -0
- package/dist/cli-shared.js +11 -0
- package/dist/cli-shared.js.map +1 -0
- package/dist/cli.js +175 -1189
- package/dist/cli.js.map +1 -1
- package/dist/commands/audit.d.ts +1 -0
- package/dist/commands/audit.js +99 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/auth.d.ts +1 -0
- package/dist/commands/auth.js +121 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/env.d.ts +1 -0
- package/dist/commands/env.js +149 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/hooks.d.ts +1 -0
- package/dist/commands/hooks.js +146 -0
- package/dist/commands/hooks.js.map +1 -0
- package/dist/commands/mcp.d.ts +1 -0
- package/dist/commands/mcp.js +120 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/memory.d.ts +1 -0
- package/dist/commands/memory.js +534 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +4 -0
- package/dist/config.js.map +1 -1
- package/dist/mcp-server.js +59 -6
- package/dist/mcp-server.js.map +1 -1
- package/dist/memory/amazonq.d.ts +5 -0
- package/dist/memory/amazonq.js +161 -0
- package/dist/memory/amazonq.js.map +1 -0
- package/dist/memory/cline.d.ts +5 -0
- package/dist/memory/cline.js +117 -0
- package/dist/memory/cline.js.map +1 -0
- package/dist/memory/codex.d.ts +5 -0
- package/dist/memory/codex.js +150 -0
- package/dist/memory/codex.js.map +1 -0
- package/dist/memory/continue.d.ts +5 -0
- package/dist/memory/continue.js +116 -0
- package/dist/memory/continue.js.map +1 -0
- package/dist/memory/cursor.d.ts +4 -0
- package/dist/memory/cursor.js +116 -0
- package/dist/memory/cursor.js.map +1 -0
- package/dist/memory/db.d.ts +12 -1
- package/dist/memory/db.js +43 -1
- package/dist/memory/db.js.map +1 -1
- package/dist/memory/gemini.d.ts +5 -0
- package/dist/memory/gemini.js +176 -0
- package/dist/memory/gemini.js.map +1 -0
- package/dist/memory/hook.d.ts +9 -0
- package/dist/memory/hook.js +34 -1
- package/dist/memory/hook.js.map +1 -1
- package/dist/memory/install.js +1 -0
- package/dist/memory/install.js.map +1 -1
- package/dist/memory/merge.d.ts +18 -0
- package/dist/memory/merge.js +109 -0
- package/dist/memory/merge.js.map +1 -0
- package/dist/memory/parser.d.ts +9 -0
- package/dist/memory/parser.js +40 -3
- package/dist/memory/parser.js.map +1 -1
- package/dist/memory/suggest.d.ts +21 -0
- package/dist/memory/suggest.js +36 -0
- package/dist/memory/suggest.js.map +1 -0
- package/dist/onepassword.js +1 -1
- package/dist/onepassword.js.map +1 -1
- package/dist/open.js +8 -2
- package/dist/open.js.map +1 -1
- package/dist/run.js +1 -1
- package/dist/run.js.map +1 -1
- package/dist/service-auth.d.ts +31 -0
- package/dist/service-auth.js +47 -0
- package/dist/service-auth.js.map +1 -0
- package/dist/stack-detector.js +53 -76
- package/dist/stack-detector.js.map +1 -1
- package/dist/status.d.ts +9 -0
- package/dist/status.js +119 -0
- package/dist/status.js.map +1 -0
- package/package.json +9 -4
- package/dist/memory/backup 2.d.ts +0 -6
- package/dist/memory/backup 2.js +0 -80
- package/dist/memory/backup 2.js.map +0 -1
- package/dist/memory/db 2.d.ts +0 -40
- package/dist/memory/db 2.js +0 -233
- package/dist/memory/db 2.js.map +0 -1
- package/dist/memory/hook 2.d.ts +0 -6
- package/dist/memory/hook 2.js +0 -51
- package/dist/memory/hook 2.js.map +0 -1
- package/dist/memory/hook.test 2.d.ts +0 -1
- package/dist/memory/hook.test 2.js +0 -35
- package/dist/memory/hook.test 2.js.map +0 -1
- package/dist/memory/install 2.d.ts +0 -8
- package/dist/memory/install 2.js +0 -72
- package/dist/memory/install 2.js.map +0 -1
- package/dist/memory/install.test 2.d.ts +0 -1
- package/dist/memory/install.test 2.js +0 -59
- package/dist/memory/install.test 2.js.map +0 -1
- package/dist/memory/pal 2.d.ts +0 -47
- package/dist/memory/pal 2.js +0 -154
- package/dist/memory/pal 2.js.map +0 -1
- package/dist/memory/project 2.d.ts +0 -1
- package/dist/memory/project 2.js +0 -24
- package/dist/memory/project 2.js.map +0 -1
- package/dist/memory/scan 2.d.ts +0 -15
- package/dist/memory/scan 2.js +0 -94
- package/dist/memory/scan 2.js.map +0 -1
- package/dist/memory/scan.test 2.d.ts +0 -1
- package/dist/memory/scan.test 2.js +0 -55
- package/dist/memory/scan.test 2.js.map +0 -1
- package/dist/memory/shared 2.d.ts +0 -33
- package/dist/memory/shared 2.js +0 -120
- package/dist/memory/shared 2.js.map +0 -1
- package/dist/memory/threads 2.d.ts +0 -37
- package/dist/memory/threads 2.js +0 -50
- package/dist/memory/threads 2.js.map +0 -1
- package/dist/memory/threads.test 2.d.ts +0 -1
- package/dist/memory/threads.test 2.js +0 -66
- package/dist/memory/threads.test 2.js.map +0 -1
- package/dist/memory/types 2.d.ts +0 -52
- package/dist/memory/types 2.js +0 -5
- package/dist/memory/types 2.js.map +0 -1
package/dist/memory/backup 2.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kit memory — encrypted backup / restore.
|
|
3
|
-
*
|
|
4
|
-
* The personal store is local-only (0600) — a stolen laptop loses it. This makes
|
|
5
|
-
* an ENCRYPTED, portable backup so you can restore your whole brain on a new
|
|
6
|
-
* machine. AES-256-GCM with a scrypt-derived key from a passphrase the operator
|
|
7
|
-
* supplies (and which is NEVER stored). Zero dependencies (node:crypto). The
|
|
8
|
-
* encrypted blob can live anywhere — Turso, object storage, a USB stick — and is
|
|
9
|
-
* the transport for the future opt-in live sync.
|
|
10
|
-
*
|
|
11
|
-
* Blob layout: MAGIC(8) | salt(16) | iv(12) | authTag(16) | ciphertext
|
|
12
|
-
*/
|
|
13
|
-
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";
|
|
14
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
|
-
import { openMemoryDb, getMemoryDbPath } from "./db.js";
|
|
16
|
-
const MAGIC = Buffer.from("KITMEM01");
|
|
17
|
-
const SALT_LEN = 16;
|
|
18
|
-
const IV_LEN = 12;
|
|
19
|
-
const TAG_LEN = 16;
|
|
20
|
-
function deriveKey(passphrase, salt) {
|
|
21
|
-
return scryptSync(passphrase, salt, 32);
|
|
22
|
-
}
|
|
23
|
-
const MIN_PASSPHRASE_LEN = 12;
|
|
24
|
-
// Substrings that mark an obviously guessable / placeholder passphrase. A long
|
|
25
|
-
// phrase is worthless if it is predictable — the passphrase is the ONLY thing
|
|
26
|
-
// protecting an encrypted backup that may sit on a USB stick or in the cloud.
|
|
27
|
-
const WEAK_MARKERS = [
|
|
28
|
-
"passphrase",
|
|
29
|
-
"password",
|
|
30
|
-
"changeme",
|
|
31
|
-
"example",
|
|
32
|
-
"valfri",
|
|
33
|
-
"correct horse",
|
|
34
|
-
"testpass",
|
|
35
|
-
"123456",
|
|
36
|
-
];
|
|
37
|
-
/** Reject a too-short or obviously-weak backup passphrase (fail before encrypting). */
|
|
38
|
-
export function validatePassphrase(passphrase) {
|
|
39
|
-
if (passphrase.length < MIN_PASSPHRASE_LEN) {
|
|
40
|
-
throw new Error(`passphrase too weak: use at least ${MIN_PASSPHRASE_LEN} characters — it is the only thing protecting your encrypted backup`);
|
|
41
|
-
}
|
|
42
|
-
const low = passphrase.toLowerCase();
|
|
43
|
-
if (WEAK_MARKERS.some((m) => low.includes(m))) {
|
|
44
|
-
throw new Error("passphrase too weak: it looks like an example/placeholder — choose a long, non-obvious phrase");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/** Encrypt the memory DB file into `outPath`. WAL is checkpointed first so the file is complete. */
|
|
48
|
-
export function backupEncrypted(passphrase, srcPath = getMemoryDbPath(), outPath) {
|
|
49
|
-
if (!outPath)
|
|
50
|
-
throw new Error("backupEncrypted requires an output path");
|
|
51
|
-
validatePassphrase(passphrase);
|
|
52
|
-
// Flush WAL into the main file so reading the .db captures everything.
|
|
53
|
-
const db = openMemoryDb(srcPath);
|
|
54
|
-
db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
55
|
-
db.close();
|
|
56
|
-
const data = readFileSync(srcPath);
|
|
57
|
-
const salt = randomBytes(SALT_LEN);
|
|
58
|
-
const iv = randomBytes(IV_LEN);
|
|
59
|
-
const cipher = createCipheriv("aes-256-gcm", deriveKey(passphrase, salt), iv);
|
|
60
|
-
const ciphertext = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
61
|
-
const tag = cipher.getAuthTag();
|
|
62
|
-
writeFileSync(outPath, Buffer.concat([MAGIC, salt, iv, tag, ciphertext]));
|
|
63
|
-
}
|
|
64
|
-
/** Decrypt a backup blob into `destPath`. Throws on a wrong passphrase or tampered blob (GCM auth). */
|
|
65
|
-
export function restoreEncrypted(passphrase, inPath, destPath) {
|
|
66
|
-
const blob = readFileSync(inPath);
|
|
67
|
-
if (!blob.subarray(0, MAGIC.length).equals(MAGIC)) {
|
|
68
|
-
throw new Error("not a kit memory backup (bad magic)");
|
|
69
|
-
}
|
|
70
|
-
let off = MAGIC.length;
|
|
71
|
-
const salt = blob.subarray(off, (off += SALT_LEN));
|
|
72
|
-
const iv = blob.subarray(off, (off += IV_LEN));
|
|
73
|
-
const tag = blob.subarray(off, (off += TAG_LEN));
|
|
74
|
-
const ciphertext = blob.subarray(off);
|
|
75
|
-
const decipher = createDecipheriv("aes-256-gcm", deriveKey(passphrase, salt), iv);
|
|
76
|
-
decipher.setAuthTag(tag);
|
|
77
|
-
const data = Buffer.concat([decipher.update(ciphertext), decipher.final()]); // throws if wrong key
|
|
78
|
-
writeFileSync(destPath, data);
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=backup%202.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backup 2.js","sourceRoot":"","sources":["../../src/memory/backup 2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,OAAO,GAAG,EAAE,CAAC;AAEnB,SAAS,SAAS,CAAC,UAAkB,EAAE,IAAY;IACjD,OAAO,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,+EAA+E;AAC/E,8EAA8E;AAC9E,8EAA8E;AAC9E,MAAM,YAAY,GAAG;IACnB,YAAY;IACZ,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,eAAe;IACf,UAAU;IACV,QAAQ;CACT,CAAC;AAEF,uFAAuF;AACvF,MAAM,UAAU,kBAAkB,CAAC,UAAkB;IACnD,IAAI,UAAU,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,qCAAqC,kBAAkB,qEAAqE,CAC7H,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC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AAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC;IACnD,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,sBAAsB;IACnG,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/memory/db 2.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kit memory — local SQLite store (node:sqlite + FTS5).
|
|
3
|
-
*
|
|
4
|
-
* Schema is derived from cloudctx (MIT — github.com/chadptk1238/cloudctx): we reuse
|
|
5
|
-
* its proven table layout, PRAGMAs and FTS5 design. Differences: kit is a Node/TS
|
|
6
|
-
* project, so we use the built-in `node:sqlite` driver instead of `bun:sqlite`; we
|
|
7
|
-
* add a `harness` column (kit is harness-agnostic) and a `pending_actions` table
|
|
8
|
-
* (PAL — the structured, actionable layer on top of raw conversation memory).
|
|
9
|
-
*
|
|
10
|
-
* Memory is RAW and append-only: one row per message, no summarisation. Retrieval
|
|
11
|
-
* (FTS5) happens at time of work — store everything raw, search on demand. This DB
|
|
12
|
-
* is secret-dense (it indexes private transcripts): it lives only under ~/.kit/ with
|
|
13
|
-
* 0600 perms and is never committed. Redaction / encryption is stage B7.
|
|
14
|
-
*/
|
|
15
|
-
import { DatabaseSync } from "node:sqlite";
|
|
16
|
-
import type { MemoryStats, MessageInput, SearchHit, SessionInput, ToolUseInput } from "./types.js";
|
|
17
|
-
export declare const SCHEMA_VERSION = 2;
|
|
18
|
-
export declare function getMemoryDir(): string;
|
|
19
|
-
export declare function getMemoryDbPath(): string;
|
|
20
|
-
/**
|
|
21
|
-
* Open (creating + migrating if needed) the memory database. Pass ":memory:" for
|
|
22
|
-
* an ephemeral in-process DB (tests). Otherwise defaults to ~/.kit/memory.db.
|
|
23
|
-
*/
|
|
24
|
-
export declare function openMemoryDb(path?: string): DatabaseSync;
|
|
25
|
-
export declare function upsertSession(db: DatabaseSync, s: SessionInput): void;
|
|
26
|
-
/** Insert a message idempotently (by uuid). Returns true if a new row was added. */
|
|
27
|
-
export declare function insertMessage(db: DatabaseSync, m: MessageInput): boolean;
|
|
28
|
-
export declare function insertToolUse(db: DatabaseSync, t: ToolUseInput): void;
|
|
29
|
-
export interface SearchOptions {
|
|
30
|
-
limit?: number;
|
|
31
|
-
/** Restrict to messages whose cwd is this repo root (or a subdirectory). */
|
|
32
|
-
projectPath?: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Full-text search over raw message content (FTS5 MATCH, ranked by `rank`).
|
|
36
|
-
* Pass opts.projectPath to scope to one repo (relevance + blast-radius); omit it
|
|
37
|
-
* for cross-project ("--global") recall over the personal store.
|
|
38
|
-
*/
|
|
39
|
-
export declare function searchMessages(db: DatabaseSync, query: string, opts?: SearchOptions): SearchHit[];
|
|
40
|
-
export declare function getStats(db: DatabaseSync): MemoryStats;
|
package/dist/memory/db 2.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kit memory — local SQLite store (node:sqlite + FTS5).
|
|
3
|
-
*
|
|
4
|
-
* Schema is derived from cloudctx (MIT — github.com/chadptk1238/cloudctx): we reuse
|
|
5
|
-
* its proven table layout, PRAGMAs and FTS5 design. Differences: kit is a Node/TS
|
|
6
|
-
* project, so we use the built-in `node:sqlite` driver instead of `bun:sqlite`; we
|
|
7
|
-
* add a `harness` column (kit is harness-agnostic) and a `pending_actions` table
|
|
8
|
-
* (PAL — the structured, actionable layer on top of raw conversation memory).
|
|
9
|
-
*
|
|
10
|
-
* Memory is RAW and append-only: one row per message, no summarisation. Retrieval
|
|
11
|
-
* (FTS5) happens at time of work — store everything raw, search on demand. This DB
|
|
12
|
-
* is secret-dense (it indexes private transcripts): it lives only under ~/.kit/ with
|
|
13
|
-
* 0600 perms and is never committed. Redaction / encryption is stage B7.
|
|
14
|
-
*/
|
|
15
|
-
import { DatabaseSync } from "node:sqlite";
|
|
16
|
-
import { homedir } from "node:os";
|
|
17
|
-
import { join } from "node:path";
|
|
18
|
-
import { existsSync, mkdirSync, chmodSync, statSync } from "node:fs";
|
|
19
|
-
export const SCHEMA_VERSION = 2;
|
|
20
|
-
export function getMemoryDir() {
|
|
21
|
-
return process.env.KIT_MEMORY_DIR ?? join(homedir(), ".kit");
|
|
22
|
-
}
|
|
23
|
-
export function getMemoryDbPath() {
|
|
24
|
-
return process.env.KIT_MEMORY_DB ?? join(getMemoryDir(), "memory.db");
|
|
25
|
-
}
|
|
26
|
-
function ensureMemoryDir() {
|
|
27
|
-
const dir = getMemoryDir();
|
|
28
|
-
if (!existsSync(dir))
|
|
29
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
30
|
-
}
|
|
31
|
-
const SCHEMA_SQL = `
|
|
32
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
33
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
34
|
-
session_id TEXT UNIQUE NOT NULL,
|
|
35
|
-
harness TEXT NOT NULL DEFAULT 'claude-code',
|
|
36
|
-
project TEXT,
|
|
37
|
-
first_message_at TEXT,
|
|
38
|
-
last_message_at TEXT,
|
|
39
|
-
message_count INTEGER DEFAULT 0,
|
|
40
|
-
is_agent_sidechain INTEGER DEFAULT 0
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
CREATE TABLE IF NOT EXISTS messages (
|
|
44
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
45
|
-
uuid TEXT UNIQUE,
|
|
46
|
-
session_id TEXT NOT NULL,
|
|
47
|
-
parent_uuid TEXT,
|
|
48
|
-
type TEXT NOT NULL,
|
|
49
|
-
role TEXT,
|
|
50
|
-
content TEXT,
|
|
51
|
-
model TEXT,
|
|
52
|
-
input_tokens INTEGER,
|
|
53
|
-
output_tokens INTEGER,
|
|
54
|
-
timestamp TEXT,
|
|
55
|
-
cwd TEXT,
|
|
56
|
-
git_branch TEXT,
|
|
57
|
-
version TEXT
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
CREATE TABLE IF NOT EXISTS tool_uses (
|
|
61
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
|
-
message_uuid TEXT,
|
|
63
|
-
session_id TEXT,
|
|
64
|
-
tool_name TEXT,
|
|
65
|
-
tool_input TEXT,
|
|
66
|
-
timestamp TEXT
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
CREATE TABLE IF NOT EXISTS saved_threads (
|
|
70
|
-
name TEXT PRIMARY KEY,
|
|
71
|
-
session_id TEXT NOT NULL,
|
|
72
|
-
summary TEXT,
|
|
73
|
-
project_path TEXT,
|
|
74
|
-
saved_at TEXT DEFAULT CURRENT_TIMESTAMP
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
CREATE TABLE IF NOT EXISTS pending_actions (
|
|
78
|
-
id TEXT PRIMARY KEY,
|
|
79
|
-
status TEXT NOT NULL DEFAULT 'open',
|
|
80
|
-
title TEXT NOT NULL,
|
|
81
|
-
detail TEXT,
|
|
82
|
-
scope TEXT,
|
|
83
|
-
kind TEXT NOT NULL DEFAULT 'manual',
|
|
84
|
-
verify_cmd TEXT,
|
|
85
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
86
|
-
next_check TEXT,
|
|
87
|
-
snooze_until TEXT,
|
|
88
|
-
closed_at TEXT,
|
|
89
|
-
verify_passes INTEGER NOT NULL DEFAULT 0
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);
|
|
93
|
-
CREATE INDEX IF NOT EXISTS idx_messages_type ON messages(type);
|
|
94
|
-
CREATE INDEX IF NOT EXISTS idx_messages_timestamp ON messages(timestamp);
|
|
95
|
-
CREATE INDEX IF NOT EXISTS idx_tool_uses_tool ON tool_uses(tool_name);
|
|
96
|
-
CREATE INDEX IF NOT EXISTS idx_pending_status ON pending_actions(status);
|
|
97
|
-
|
|
98
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(
|
|
99
|
-
content,
|
|
100
|
-
content=messages,
|
|
101
|
-
content_rowid=id
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
CREATE TRIGGER IF NOT EXISTS messages_ai AFTER INSERT ON messages BEGIN
|
|
105
|
-
INSERT INTO messages_fts(rowid, content) VALUES (new.id, new.content);
|
|
106
|
-
END;
|
|
107
|
-
CREATE TRIGGER IF NOT EXISTS messages_ad AFTER DELETE ON messages BEGIN
|
|
108
|
-
INSERT INTO messages_fts(messages_fts, rowid, content) VALUES ('delete', old.id, old.content);
|
|
109
|
-
END;
|
|
110
|
-
CREATE TRIGGER IF NOT EXISTS messages_au AFTER UPDATE ON messages BEGIN
|
|
111
|
-
INSERT INTO messages_fts(messages_fts, rowid, content) VALUES ('delete', old.id, old.content);
|
|
112
|
-
INSERT INTO messages_fts(rowid, content) VALUES (new.id, new.content);
|
|
113
|
-
END;
|
|
114
|
-
`;
|
|
115
|
-
function ensureColumn(db, table, column, decl) {
|
|
116
|
-
const cols = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
117
|
-
if (!cols.some((col) => col.name === column)) {
|
|
118
|
-
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${decl}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function migrate(db) {
|
|
122
|
-
db.exec("CREATE TABLE IF NOT EXISTS schema_meta (version INTEGER NOT NULL)");
|
|
123
|
-
db.exec(SCHEMA_SQL);
|
|
124
|
-
// v2: pending_actions.verify_passes (N=2 auto-verify confirmation). Add to
|
|
125
|
-
// tables created before this column existed.
|
|
126
|
-
ensureColumn(db, "pending_actions", "verify_passes", "INTEGER NOT NULL DEFAULT 0");
|
|
127
|
-
const row = db.prepare("SELECT version FROM schema_meta LIMIT 1").get();
|
|
128
|
-
if (!row) {
|
|
129
|
-
db.prepare("INSERT INTO schema_meta(version) VALUES (?)").run(SCHEMA_VERSION);
|
|
130
|
-
}
|
|
131
|
-
else if (row.version < SCHEMA_VERSION) {
|
|
132
|
-
db.prepare("UPDATE schema_meta SET version = ?").run(SCHEMA_VERSION);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Open (creating + migrating if needed) the memory database. Pass ":memory:" for
|
|
137
|
-
* an ephemeral in-process DB (tests). Otherwise defaults to ~/.kit/memory.db.
|
|
138
|
-
*/
|
|
139
|
-
export function openMemoryDb(path) {
|
|
140
|
-
const dbPath = path ?? getMemoryDbPath();
|
|
141
|
-
if (dbPath !== ":memory:")
|
|
142
|
-
ensureMemoryDir();
|
|
143
|
-
const db = new DatabaseSync(dbPath);
|
|
144
|
-
db.exec("PRAGMA journal_mode = WAL");
|
|
145
|
-
db.exec("PRAGMA busy_timeout = 5000");
|
|
146
|
-
db.exec("PRAGMA foreign_keys = OFF");
|
|
147
|
-
migrate(db);
|
|
148
|
-
if (dbPath !== ":memory:" && existsSync(dbPath)) {
|
|
149
|
-
try {
|
|
150
|
-
chmodSync(dbPath, 0o600);
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
// best-effort: non-POSIX filesystems may not support chmod
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return db;
|
|
157
|
-
}
|
|
158
|
-
export function upsertSession(db, s) {
|
|
159
|
-
db.prepare(`INSERT INTO sessions (session_id, harness, project, first_message_at, last_message_at, is_agent_sidechain)
|
|
160
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
161
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
162
|
-
last_message_at = COALESCE(excluded.last_message_at, sessions.last_message_at),
|
|
163
|
-
first_message_at = COALESCE(sessions.first_message_at, excluded.first_message_at),
|
|
164
|
-
project = COALESCE(excluded.project, sessions.project),
|
|
165
|
-
harness = excluded.harness,
|
|
166
|
-
is_agent_sidechain = MAX(sessions.is_agent_sidechain, excluded.is_agent_sidechain)`).run(s.sessionId, s.harness, s.project ?? null, s.firstMessageAt ?? null, s.lastMessageAt ?? null, s.isAgentSidechain ? 1 : 0);
|
|
167
|
-
}
|
|
168
|
-
/** Insert a message idempotently (by uuid). Returns true if a new row was added. */
|
|
169
|
-
export function insertMessage(db, m) {
|
|
170
|
-
const res = db
|
|
171
|
-
.prepare(`INSERT OR IGNORE INTO messages
|
|
172
|
-
(uuid, session_id, parent_uuid, type, role, content, model, input_tokens, output_tokens, timestamp, cwd, git_branch, version)
|
|
173
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
174
|
-
.run(m.uuid, m.sessionId, m.parentUuid ?? null, m.type, m.role ?? null, m.content ?? null, m.model ?? null, m.inputTokens ?? null, m.outputTokens ?? null, m.timestamp ?? null, m.cwd ?? null, m.gitBranch ?? null, m.version ?? null);
|
|
175
|
-
if (Number(res.changes) > 0) {
|
|
176
|
-
db.prepare("UPDATE sessions SET message_count = message_count + 1 WHERE session_id = ?").run(m.sessionId);
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
export function insertToolUse(db, t) {
|
|
182
|
-
db.prepare(`INSERT INTO tool_uses (message_uuid, session_id, tool_name, tool_input, timestamp)
|
|
183
|
-
VALUES (?, ?, ?, ?, ?)`).run(t.messageUuid ?? null, t.sessionId ?? null, t.toolName, t.toolInput ?? null, t.timestamp ?? null);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Full-text search over raw message content (FTS5 MATCH, ranked by `rank`).
|
|
187
|
-
* Pass opts.projectPath to scope to one repo (relevance + blast-radius); omit it
|
|
188
|
-
* for cross-project ("--global") recall over the personal store.
|
|
189
|
-
*/
|
|
190
|
-
export function searchMessages(db, query, opts = {}) {
|
|
191
|
-
const limit = opts.limit ?? 20;
|
|
192
|
-
const params = [query];
|
|
193
|
-
let where = "messages_fts MATCH ?";
|
|
194
|
-
if (opts.projectPath) {
|
|
195
|
-
where += " AND (m.cwd = ? OR m.cwd LIKE ?)";
|
|
196
|
-
params.push(opts.projectPath, `${opts.projectPath}/%`);
|
|
197
|
-
}
|
|
198
|
-
params.push(limit);
|
|
199
|
-
return db
|
|
200
|
-
.prepare(`SELECT m.id AS id, m.uuid AS uuid, m.session_id AS sessionId, m.role AS role,
|
|
201
|
-
m.content AS content, m.timestamp AS timestamp
|
|
202
|
-
FROM messages_fts f
|
|
203
|
-
JOIN messages m ON m.id = f.rowid
|
|
204
|
-
WHERE ${where}
|
|
205
|
-
ORDER BY rank
|
|
206
|
-
LIMIT ?`)
|
|
207
|
-
.all(...params);
|
|
208
|
-
}
|
|
209
|
-
export function getStats(db) {
|
|
210
|
-
const count = (sql) => {
|
|
211
|
-
const r = db.prepare(sql).get();
|
|
212
|
-
return r ? Number(r.n) : 0;
|
|
213
|
-
};
|
|
214
|
-
const dbPath = getMemoryDbPath();
|
|
215
|
-
let sizeBytes = 0;
|
|
216
|
-
if (dbPath !== ":memory:" && existsSync(dbPath)) {
|
|
217
|
-
try {
|
|
218
|
-
sizeBytes = statSync(dbPath).size;
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
// best-effort: size is informational only
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
sessions: count("SELECT COUNT(*) AS n FROM sessions"),
|
|
226
|
-
messages: count("SELECT COUNT(*) AS n FROM messages"),
|
|
227
|
-
toolUses: count("SELECT COUNT(*) AS n FROM tool_uses"),
|
|
228
|
-
pendingOpen: count("SELECT COUNT(*) AS n FROM pending_actions WHERE status = 'open'"),
|
|
229
|
-
dbPath,
|
|
230
|
-
sizeBytes,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
//# sourceMappingURL=db%202.js.map
|
package/dist/memory/db 2.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db 2.js","sourceRoot":"","sources":["../../src/memory/db 2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AASrE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU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iEAAiE,CAClE;QACD,MAAM;QACN,SAAS;KACV,CAAC;AACJ,CAAC"}
|
package/dist/memory/hook 2.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** Reminder injected before every prompt. Empty string on any error (fail-open). */
|
|
2
|
-
export declare function userPromptSubmitReminder(): string;
|
|
3
|
-
/** Index the just-ended session. Returns count of newly indexed messages (fail-open). */
|
|
4
|
-
export declare function runSessionEndIndex(): {
|
|
5
|
-
messages: number;
|
|
6
|
-
};
|
package/dist/memory/hook 2.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kit memory — Claude Code hook entry points (the "whole system is two hooks").
|
|
3
|
-
*
|
|
4
|
-
* - UserPromptSubmit → a short reminder that searchable memory exists. The agent
|
|
5
|
-
* pulls on demand (`kit memory search`) instead of pre-loading everything.
|
|
6
|
-
* - SessionEnd → index the just-ended session into the store (incremental sync).
|
|
7
|
-
*
|
|
8
|
-
* Both are FAIL-OPEN: any error yields an empty/no-op result so a hook can never
|
|
9
|
-
* block a prompt or break a session. Deterministic, zero model calls.
|
|
10
|
-
*/
|
|
11
|
-
import { basename } from "node:path";
|
|
12
|
-
import { openMemoryDb, getStats } from "./db.js";
|
|
13
|
-
import { indexClaudeTranscripts } from "./parser.js";
|
|
14
|
-
import { palList } from "./pal.js";
|
|
15
|
-
import { getCurrentProjectRoot } from "./project.js";
|
|
16
|
-
/** Reminder injected before every prompt. Empty string on any error (fail-open). */
|
|
17
|
-
export function userPromptSubmitReminder() {
|
|
18
|
-
try {
|
|
19
|
-
const db = openMemoryDb();
|
|
20
|
-
const s = getStats(db);
|
|
21
|
-
// Only surface THIS project's open items (plus globally-scoped) — no cross-project noise.
|
|
22
|
-
const openItems = palList(db, { scope: basename(getCurrentProjectRoot()) });
|
|
23
|
-
db.close();
|
|
24
|
-
let pending = "";
|
|
25
|
-
if (openItems.length > 0) {
|
|
26
|
-
const shown = openItems.slice(0, 3);
|
|
27
|
-
const titles = shown.map((p) => `${p.id} ${p.title}`).join("; ");
|
|
28
|
-
const more = openItems.length > shown.length ? " …" : "";
|
|
29
|
-
pending = ` ${openItems.length} open action item(s) blocked on you: ${titles}${more}.`;
|
|
30
|
-
}
|
|
31
|
-
return (`You have local conversation memory: ${s.messages} messages indexed. ` +
|
|
32
|
-
"Before answering anything project-specific, run `kit memory search <terms>` " +
|
|
33
|
-
`to retrieve what was actually said instead of reconstructing it.${pending}`);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return ""; // fail-open: never block a prompt
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** Index the just-ended session. Returns count of newly indexed messages (fail-open). */
|
|
40
|
-
export function runSessionEndIndex() {
|
|
41
|
-
try {
|
|
42
|
-
const db = openMemoryDb();
|
|
43
|
-
const res = indexClaudeTranscripts(db);
|
|
44
|
-
db.close();
|
|
45
|
-
return { messages: res.messages };
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return { messages: 0 }; // fail-open
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=hook%202.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hook 2.js","sourceRoot":"","sources":["../../src/memory/hook 2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,oFAAoF;AACpF,MAAM,UAAU,wBAAwB;IACtC,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,CA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E,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,YAAY;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { describe, it, before, after } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { openMemoryDb, upsertSession, insertMessage } from "./db.js";
|
|
7
|
-
import { userPromptSubmitReminder } from "./hook.js";
|
|
8
|
-
describe("memory hook — UserPromptSubmit reminder", () => {
|
|
9
|
-
let tmp;
|
|
10
|
-
const prev = process.env.KIT_MEMORY_DB;
|
|
11
|
-
before(() => {
|
|
12
|
-
tmp = mkdtempSync(join(tmpdir(), "kit-hook-"));
|
|
13
|
-
process.env.KIT_MEMORY_DB = join(tmp, "memory.db");
|
|
14
|
-
const db = openMemoryDb();
|
|
15
|
-
upsertSession(db, { sessionId: "s1", harness: "claude-code" });
|
|
16
|
-
insertMessage(db, { uuid: "u1", sessionId: "s1", type: "user", content: "hi" });
|
|
17
|
-
db.close();
|
|
18
|
-
});
|
|
19
|
-
after(() => {
|
|
20
|
-
if (prev === undefined)
|
|
21
|
-
delete process.env.KIT_MEMORY_DB;
|
|
22
|
-
else
|
|
23
|
-
process.env.KIT_MEMORY_DB = prev;
|
|
24
|
-
rmSync(tmp, { recursive: true, force: true });
|
|
25
|
-
});
|
|
26
|
-
it("nudges the agent to search and reports the message count", () => {
|
|
27
|
-
const text = userPromptSubmitReminder();
|
|
28
|
-
assert.match(text, /kit memory search/);
|
|
29
|
-
assert.match(text, /1 messages/);
|
|
30
|
-
});
|
|
31
|
-
it("never throws (fail-open)", () => {
|
|
32
|
-
assert.doesNotThrow(() => userPromptSubmitReminder());
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
//# sourceMappingURL=hook.test%202.js.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AAI,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;;YACpD,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;QACtC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,IAAI,GAAG,wBAAwB,EAAE,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/memory/install 2.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kit memory — install/remove the two Claude Code hooks in ~/.claude/settings.json.
|
|
3
|
-
*
|
|
4
|
-
* Idempotent and non-destructive: merges our hook entries into the existing
|
|
5
|
-
* settings without touching the user's other hooks. Re-running adds nothing.
|
|
6
|
-
* Honors KIT_CLAUDE_SETTINGS for tests.
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
9
|
-
import { homedir } from "node:os";
|
|
10
|
-
import { join, dirname } from "node:path";
|
|
11
|
-
const MEMORY_HOOKS = [
|
|
12
|
-
{ event: "UserPromptSubmit", command: "kit memory hook user-prompt-submit" },
|
|
13
|
-
{ event: "SessionEnd", command: "kit memory hook session-end" },
|
|
14
|
-
];
|
|
15
|
-
export function getClaudeSettingsPath() {
|
|
16
|
-
return process.env.KIT_CLAUDE_SETTINGS ?? join(homedir(), ".claude", "settings.json");
|
|
17
|
-
}
|
|
18
|
-
function readSettings(path) {
|
|
19
|
-
if (!existsSync(path))
|
|
20
|
-
return {};
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return {}; // corrupt/unreadable → start fresh rather than crash
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function writeSettings(path, s) {
|
|
29
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
30
|
-
writeFileSync(path, JSON.stringify(s, null, 2) + "\n");
|
|
31
|
-
}
|
|
32
|
-
function groupsHaveCommand(groups, command) {
|
|
33
|
-
return groups.some((g) => g.hooks?.some((h) => h.command === command));
|
|
34
|
-
}
|
|
35
|
-
export function installMemoryHooks(path = getClaudeSettingsPath()) {
|
|
36
|
-
const s = readSettings(path);
|
|
37
|
-
const hooks = (s.hooks ??= {});
|
|
38
|
-
const added = [];
|
|
39
|
-
const alreadyPresent = [];
|
|
40
|
-
for (const { event, command } of MEMORY_HOOKS) {
|
|
41
|
-
const groups = (hooks[event] ??= []);
|
|
42
|
-
if (groupsHaveCommand(groups, command)) {
|
|
43
|
-
alreadyPresent.push(event);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
groups.push({ hooks: [{ type: "command", command }] });
|
|
47
|
-
added.push(event);
|
|
48
|
-
}
|
|
49
|
-
if (added.length)
|
|
50
|
-
writeSettings(path, s);
|
|
51
|
-
return { added, alreadyPresent };
|
|
52
|
-
}
|
|
53
|
-
export function uninstallMemoryHooks(path = getClaudeSettingsPath()) {
|
|
54
|
-
const s = readSettings(path);
|
|
55
|
-
if (!s.hooks)
|
|
56
|
-
return { removed: [] };
|
|
57
|
-
const removed = [];
|
|
58
|
-
for (const { event, command } of MEMORY_HOOKS) {
|
|
59
|
-
const groups = s.hooks[event];
|
|
60
|
-
if (!Array.isArray(groups))
|
|
61
|
-
continue;
|
|
62
|
-
const filtered = groups.filter((g) => !g.hooks?.some((h) => h.command === command));
|
|
63
|
-
if (filtered.length !== groups.length) {
|
|
64
|
-
s.hooks[event] = filtered;
|
|
65
|
-
removed.push(event);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (removed.length)
|
|
69
|
-
writeSettings(path, s);
|
|
70
|
-
return { removed };
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=install%202.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"install 2.js","sourceRoot":"","sources":["../../src/memory/install 2.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,YAAY,GAAyC;IACzD,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,oCAAoC,EAAE;IAC5E,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,6BAA6B,EAAE;CAChE,CAAC;AAEF,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;AACxF,CAAC;AAeD,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAa,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,qDAAqD;IAClE,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE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IAAI,EAAE,CAAC,CAAC,CAAC;IACzC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAe,qBAAqB,EAAE;IAEtC,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACrC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,SAAS;QACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC;QACpF,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;YACtC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,MAAM;QAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, it, before, after, beforeEach } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync, readFileSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { installMemoryHooks, uninstallMemoryHooks } from "./install.js";
|
|
7
|
-
describe("memory hook installer", () => {
|
|
8
|
-
let tmp;
|
|
9
|
-
let settingsPath;
|
|
10
|
-
const prev = process.env.KIT_CLAUDE_SETTINGS;
|
|
11
|
-
before(() => {
|
|
12
|
-
tmp = mkdtempSync(join(tmpdir(), "kit-install-"));
|
|
13
|
-
settingsPath = join(tmp, "settings.json");
|
|
14
|
-
process.env.KIT_CLAUDE_SETTINGS = settingsPath;
|
|
15
|
-
});
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
// Start each test from a settings file with an unrelated, pre-existing hook.
|
|
18
|
-
writeFileSync(settingsPath, JSON.stringify({
|
|
19
|
-
hooks: {
|
|
20
|
-
UserPromptSubmit: [{ hooks: [{ type: "command", command: "some-other-tool" }] }],
|
|
21
|
-
},
|
|
22
|
-
}));
|
|
23
|
-
});
|
|
24
|
-
after(() => {
|
|
25
|
-
if (prev === undefined)
|
|
26
|
-
delete process.env.KIT_CLAUDE_SETTINGS;
|
|
27
|
-
else
|
|
28
|
-
process.env.KIT_CLAUDE_SETTINGS = prev;
|
|
29
|
-
rmSync(tmp, { recursive: true, force: true });
|
|
30
|
-
});
|
|
31
|
-
it("installs both hooks without clobbering existing ones", () => {
|
|
32
|
-
const res = installMemoryHooks();
|
|
33
|
-
assert.deepEqual(res.added.sort(), ["SessionEnd", "UserPromptSubmit"]);
|
|
34
|
-
const s = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
35
|
-
const ups = s.hooks.UserPromptSubmit.flatMap((g) => g.hooks.map((h) => h.command));
|
|
36
|
-
assert.ok(ups.includes("some-other-tool"), "preserves the pre-existing hook");
|
|
37
|
-
assert.ok(ups.includes("kit memory hook user-prompt-submit"));
|
|
38
|
-
assert.ok(s.hooks.SessionEnd.some((g) => g.hooks.some((h) => h.command === "kit memory hook session-end")));
|
|
39
|
-
});
|
|
40
|
-
it("is idempotent — re-install adds nothing and creates no duplicates", () => {
|
|
41
|
-
installMemoryHooks();
|
|
42
|
-
const res2 = installMemoryHooks();
|
|
43
|
-
assert.deepEqual(res2.added, []);
|
|
44
|
-
assert.deepEqual(res2.alreadyPresent.sort(), ["SessionEnd", "UserPromptSubmit"]);
|
|
45
|
-
const s = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
46
|
-
const ours = s.hooks.UserPromptSubmit.filter((g) => g.hooks.some((h) => h.command === "kit memory hook user-prompt-submit"));
|
|
47
|
-
assert.equal(ours.length, 1);
|
|
48
|
-
});
|
|
49
|
-
it("uninstall removes only our hooks, leaving others intact", () => {
|
|
50
|
-
installMemoryHooks();
|
|
51
|
-
const res = uninstallMemoryHooks();
|
|
52
|
-
assert.deepEqual(res.removed.sort(), ["SessionEnd", "UserPromptSubmit"]);
|
|
53
|
-
const s = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
54
|
-
const ups = s.hooks.UserPromptSubmit.flatMap((g) => g.hooks.map((h) => h.command));
|
|
55
|
-
assert.ok(ups.includes("some-other-tool"), "unrelated hook survives uninstall");
|
|
56
|
-
assert.ok(!ups.includes("kit memory hook user-prompt-submit"));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=install.test%202.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"install.test 2.js","sourceRoot":"","sources":["../../src/memory/install.test 2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IA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