Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions plugin/scripts/notification.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { execSync } from "node:child_process";
import { basename } from "node:path";
import { basename, join } from "node:path";
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";

//#region src/hooks/_project.ts
function resolveProject(cwd) {
Expand All @@ -22,6 +24,46 @@ function resolveProject(cwd) {
return basename(dir);
}

//#endregion
//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/notification.ts
function isSdkChildContext(payload) {
Expand All @@ -30,7 +72,7 @@ function isSdkChildContext(payload) {
return payload.entrypoint === "sdk-ts";
}
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
function authHeaders() {
const h = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down
45 changes: 44 additions & 1 deletion plugin/scripts/post-commit.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
#!/usr/bin/env node
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";

//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/post-commit.ts
const exec = promisify(execFile);
function isSdkChildContext(payload) {
Expand All @@ -10,7 +53,7 @@ function isSdkChildContext(payload) {
return payload.entrypoint === "sdk-ts";
}
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
const TIMEOUT_MS = 1500;
function authHeaders() {
const h = { "Content-Type": "application/json" };
Expand Down
46 changes: 44 additions & 2 deletions plugin/scripts/post-tool-failure.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { execSync } from "node:child_process";
import { basename } from "node:path";
import { basename, join } from "node:path";
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";

//#region src/hooks/_project.ts
function resolveProject(cwd) {
Expand All @@ -22,6 +24,46 @@ function resolveProject(cwd) {
return basename(dir);
}

//#endregion
//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/post-tool-failure.ts
function isSdkChildContext(payload) {
Expand All @@ -30,7 +72,7 @@ function isSdkChildContext(payload) {
return payload.entrypoint === "sdk-ts";
}
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
function authHeaders() {
const h = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down
46 changes: 44 additions & 2 deletions plugin/scripts/post-tool-use.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { execSync } from "node:child_process";
import { basename } from "node:path";
import { basename, join } from "node:path";
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";

//#region src/hooks/_project.ts
function resolveProject(cwd) {
Expand All @@ -22,6 +24,46 @@ function resolveProject(cwd) {
return basename(dir);
}

//#endregion
//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/post-tool-use.ts
function isSdkChildContext(payload) {
Expand All @@ -30,7 +72,7 @@ function isSdkChildContext(payload) {
return payload.entrypoint === "sdk-ts";
}
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
function authHeaders() {
const h = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down
46 changes: 44 additions & 2 deletions plugin/scripts/pre-compact.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { execSync } from "node:child_process";
import { basename } from "node:path";
import { basename, join } from "node:path";
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";

//#region src/hooks/_project.ts
function resolveProject(cwd) {
Expand All @@ -22,6 +24,46 @@ function resolveProject(cwd) {
return basename(dir);
}

//#endregion
//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/pre-compact.ts
function isSdkChildContext(payload) {
Expand All @@ -30,7 +72,7 @@ function isSdkChildContext(payload) {
return payload.entrypoint === "sdk-ts";
}
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
function authHeaders() {
const h = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down
48 changes: 46 additions & 2 deletions plugin/scripts/pre-tool-use.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
#!/usr/bin/env node
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";

//#region src/hooks/env.ts
let cachedEnv = null;
function parseEnvFile(content) {
const vars = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith("#")) continue;
const eqIdx = line.indexOf("=");
if (eqIdx === -1) continue;
const key = line.slice(0, eqIdx).trim();
let value = line.slice(eqIdx + 1).trim();
const quote = value[0];
if (quote === "\"" || quote === "'") {
const closeIdx = value.indexOf(quote, 1);
if (closeIdx !== -1) value = value.slice(1, closeIdx);
} else {
const hashIdx = value.indexOf(" #");
if (hashIdx !== -1) value = value.slice(0, hashIdx).trim();
}
vars[key] = value;
}
return vars;
}
function readAgentmemoryEnvFile() {
const envPath = join(homedir(), ".agentmemory", ".env");
if (!existsSync(envPath)) return {};
try {
return parseEnvFile(readFileSync(envPath, "utf-8"));
} catch {
return {};
}
}
function agentmemoryEnv(key) {
const processValue = process.env[key];
if (processValue !== void 0) return processValue;
cachedEnv ??= readAgentmemoryEnvFile();
return cachedEnv[key] ?? "";
}

//#endregion
//#region src/hooks/pre-tool-use.ts
function isSdkChildContext(payload) {
if (process.env["AGENTMEMORY_SDK_CHILD"] === "1") return true;
if (!payload || typeof payload !== "object") return false;
return payload.entrypoint === "sdk-ts";
}
const INJECT_CONTEXT = process.env["AGENTMEMORY_INJECT_CONTEXT"] === "true";
const INJECT_CONTEXT = agentmemoryEnv("AGENTMEMORY_INJECT_CONTEXT") === "true";
const REST_URL = process.env["AGENTMEMORY_URL"] || "http://localhost:3111";
const SECRET = process.env["AGENTMEMORY_SECRET"] || "";
const SECRET = agentmemoryEnv("AGENTMEMORY_SECRET");
function authHeaders() {
const h = { "Content-Type": "application/json" };
if (SECRET) h["Authorization"] = `Bearer ${SECRET}`;
Expand Down
Loading