mirror of
https://github.com/akitaonrails/ai-memory.git
synced 2026-10-02 03:24:46 +08:00
fix(hooks): finish marker integration
This commit is contained in:
+3
-3
@@ -10,9 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `.ai-memory.toml` marker file lets a directory tree declare its
|
||||
`workspace` (required) and `project` (optional) without depending on
|
||||
`basename($cwd)`. Lifecycle hook scripts walk up from `cwd` to find
|
||||
the closest marker and forward the declared names as
|
||||
`&workspace=X&project=Y` query params on `POST /hook` and
|
||||
`GET /handoff`. Server accepts the new params as optional overrides;
|
||||
the closest marker and forward `cwd` plus the declared names as
|
||||
query params on `POST /hook` and `GET /handoff`. Server accepts the
|
||||
new params as optional overrides;
|
||||
absent marker means the previous behaviour (`workspace = "default"`,
|
||||
`project = basename(cwd)`) — fully backward compatible. See
|
||||
[`docs/marker-file.md`](docs/marker-file.md).
|
||||
|
||||
@@ -946,8 +946,17 @@ fn render_agent(
|
||||
/// Errors propagate when source is missing, the staging dir
|
||||
/// can't be created, or any file copy fails.
|
||||
fn stage_hook_scripts(source_dir: &Path, agent_label: &str) -> Result<PathBuf> {
|
||||
let dest_root = dirs::data_local_dir()
|
||||
.context("could not locate the user data-local directory (e.g. ~/.local/share)")?
|
||||
let data_dir = dirs::data_local_dir()
|
||||
.context("could not locate the user data-local directory (e.g. ~/.local/share)")?;
|
||||
stage_hook_scripts_in(source_dir, agent_label, &data_dir)
|
||||
}
|
||||
|
||||
fn stage_hook_scripts_in(
|
||||
source_dir: &Path,
|
||||
agent_label: &str,
|
||||
data_local_dir: &Path,
|
||||
) -> Result<PathBuf> {
|
||||
let dest_root = data_local_dir
|
||||
.join("ai-memory")
|
||||
.join("hooks")
|
||||
.join(agent_label);
|
||||
@@ -1301,7 +1310,8 @@ mod tests {
|
||||
fs::write(bundle.join("_lib.sh"), "# shared helper\n").unwrap();
|
||||
stub_scripts(&agent_src, &["session-start.sh", "post-tool-use.sh"]);
|
||||
|
||||
let staged = stage_hook_scripts(&agent_src, "stage-shared-lib").unwrap();
|
||||
let data_dir = tmp.path().join("data");
|
||||
let staged = stage_hook_scripts_in(&agent_src, "stage-shared-lib", &data_dir).unwrap();
|
||||
assert!(staged.join("session-start.sh").exists());
|
||||
assert!(staged.join("post-tool-use.sh").exists());
|
||||
assert!(
|
||||
@@ -1327,7 +1337,8 @@ mod tests {
|
||||
// Note: no _lib.sh in `bundle`.
|
||||
stub_scripts(&agent_src, &["session-start.sh"]);
|
||||
|
||||
let staged = stage_hook_scripts(&agent_src, "stage-no-lib").unwrap();
|
||||
let data_dir = tmp.path().join("data");
|
||||
let staged = stage_hook_scripts_in(&agent_src, "stage-no-lib", &data_dir).unwrap();
|
||||
assert!(staged.join("session-start.sh").exists());
|
||||
assert!(!staged.join("_lib.sh").exists());
|
||||
}
|
||||
|
||||
@@ -706,6 +706,7 @@ mod tests {
|
||||
Query(HookQuery {
|
||||
event: "session-start".into(),
|
||||
agent: Some("claude-code".into()),
|
||||
..Default::default()
|
||||
}),
|
||||
Json(serde_json::json!({})),
|
||||
)
|
||||
@@ -887,6 +888,50 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn handoff_with_workspace_marker_and_cwd_uses_basename_project() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let state = make_state(&tmp).await;
|
||||
let cwd = "/home/u/repo";
|
||||
|
||||
let (ws, proj) = resolve_project_ids(&state, Some(cwd), Some("acme"), None)
|
||||
.await
|
||||
.unwrap();
|
||||
state
|
||||
.writer
|
||||
.insert_handoff(NewHandoff {
|
||||
workspace_id: ws,
|
||||
project_id: proj,
|
||||
from_session_id: None,
|
||||
from_agent: AgentKind::ClaudeCode,
|
||||
to_agent: None,
|
||||
cwd: Some(std::path::PathBuf::from(cwd)),
|
||||
summary: "handoff summary".to_string(),
|
||||
open_questions: Vec::new(),
|
||||
next_steps: vec!["continue".to_string()],
|
||||
files_touched: Vec::new(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let rendered = fetch_and_accept_handoff(
|
||||
&state,
|
||||
HandoffQuery {
|
||||
agent: Some("codex".into()),
|
||||
cwd: Some(cwd.into()),
|
||||
workspace: Some("acme".into()),
|
||||
project: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
rendered.as_deref().is_some_and(|s| s.contains("continue")),
|
||||
"workspace-only marker handoff lookup must resolve workspace + basename(cwd)"
|
||||
);
|
||||
}
|
||||
|
||||
/// A marker file with `project = "pe-portais"` replaces the
|
||||
/// basename-derived project name for every descendant `cwd`.
|
||||
#[tokio::test]
|
||||
|
||||
+4
-1
@@ -25,7 +25,10 @@ ai-memory or running CLI commands per directory.
|
||||
|
||||
`.ai-memory.toml` in **any ancestor** of your `cwd`. Lifecycle hooks
|
||||
walk up from `cwd` toward `$HOME` (or `/` if `$HOME` is unset) and
|
||||
use the **first** marker found. Closer markers override outer ones.
|
||||
use the **first** marker found. Closer markers override outer ones. When
|
||||
a marker is found, hook scripts also forward the current `cwd` so
|
||||
workspace-only markers can still resolve `project = basename(cwd)` for
|
||||
handoff lookups.
|
||||
|
||||
## Schema
|
||||
|
||||
|
||||
+5
-4
@@ -54,9 +54,10 @@ ai_memory_url_encode() {
|
||||
| sed 's/%/%25/g; s/&/%26/g; s/=/%3D/g; s/?/%3F/g; s/#/%23/g; s/ /%20/g'
|
||||
}
|
||||
|
||||
# Build a `&workspace=X&project=Y` suffix from the marker file walked up
|
||||
# from "$1". Returns the suffix (with the leading `&`) or nothing. The
|
||||
# server tolerates either key being absent.
|
||||
# Build a query-string suffix from the marker file walked up from "$1".
|
||||
# Returns the suffix (with the leading `&`) or nothing. `cwd` is included
|
||||
# whenever a marker exists so `GET /handoff` can resolve workspace-only
|
||||
# markers by combining `workspace` with basename(cwd).
|
||||
ai_memory_marker_qs() {
|
||||
cwd="$1"
|
||||
[ -z "$cwd" ] && return 0
|
||||
@@ -64,7 +65,7 @@ ai_memory_marker_qs() {
|
||||
[ -z "$marker" ] && return 0
|
||||
ws=$(ai_memory_parse_toml_key "$marker" workspace)
|
||||
pr=$(ai_memory_parse_toml_key "$marker" project)
|
||||
qs=""
|
||||
qs="&cwd=$(ai_memory_url_encode "$cwd")"
|
||||
[ -n "$ws" ] && qs="${qs}&workspace=$(ai_memory_url_encode "$ws")"
|
||||
[ -n "$pr" ] && qs="${qs}&project=$(ai_memory_url_encode "$pr")"
|
||||
printf '%s' "$qs"
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex post-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=post-tool-use&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=post-tool-use&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex pre-compact hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-compact&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-compact&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex pre-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-tool-use&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-tool-use&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex session-end hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=session-end&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-end&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
#!/bin/sh
|
||||
# codex SessionStart hook.
|
||||
#
|
||||
# 1. Forwards the event JSON to the ai-memory server (fire-and-forget).
|
||||
# 2. Synchronously fetches any pending cross-agent handoff and prints
|
||||
# it to stdout — agent CLIs prepend session-start hook stdout to
|
||||
# the next session, so the resuming agent sees prior context with
|
||||
# no human in the loop.
|
||||
#
|
||||
# Both calls carry an Authorization: Bearer header when
|
||||
# AI_MEMORY_AUTH_TOKEN is set in this hook's environment.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
|
||||
get_handoff() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 1.0 "$1" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN"
|
||||
else
|
||||
curl -s --max-time 1.0 "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "$PAYLOAD" | post_hook "$SERVER/hook?event=session-start&agent=codex" >/dev/null 2>&1 || true
|
||||
get_handoff "$SERVER/handoff?agent=codex" 2>/dev/null || true
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-start&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
ai_memory_get_handoff "$SERVER/handoff?agent=codex${QS}" 2>/dev/null || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex stop hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=stop&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=stop&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# codex user-prompt hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=user-prompt&agent=codex" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=user-prompt&agent=codex${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor post-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=post-tool-use&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=post-tool-use&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor pre-compact hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-compact&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-compact&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor pre-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-tool-use&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-tool-use&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor session-end hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=session-end&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-end&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
#!/bin/sh
|
||||
# cursor SessionStart hook.
|
||||
#
|
||||
# 1. Forwards the event JSON to the ai-memory server (fire-and-forget).
|
||||
# 2. Synchronously fetches any pending cross-agent handoff and prints
|
||||
# it to stdout — agent CLIs prepend session-start hook stdout to
|
||||
# the next session, so the resuming agent sees prior context with
|
||||
# no human in the loop.
|
||||
#
|
||||
# Both calls carry an Authorization: Bearer header when
|
||||
# AI_MEMORY_AUTH_TOKEN is set in this hook's environment.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
|
||||
get_handoff() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 1.0 "$1" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN"
|
||||
else
|
||||
curl -s --max-time 1.0 "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "$PAYLOAD" | post_hook "$SERVER/hook?event=session-start&agent=cursor" >/dev/null 2>&1 || true
|
||||
get_handoff "$SERVER/handoff?agent=cursor" 2>/dev/null || true
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-start&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
ai_memory_get_handoff "$SERVER/handoff?agent=cursor${QS}" 2>/dev/null || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor stop hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=stop&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=stop&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# cursor user-prompt hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=user-prompt&agent=cursor" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=user-prompt&agent=cursor${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli post-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=post-tool-use&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=post-tool-use&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli pre-compact hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-compact&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-compact&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli pre-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-tool-use&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-tool-use&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli session-end hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=session-end&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-end&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli SessionStart hook.
|
||||
#
|
||||
# 1. Forwards the event JSON to the ai-memory server (fire-and-forget).
|
||||
# 2. Synchronously fetches any pending cross-agent handoff and prints
|
||||
# it to stdout — agent CLIs prepend session-start hook stdout to
|
||||
# the next session, so the resuming agent sees prior context with
|
||||
# no human in the loop.
|
||||
#
|
||||
# Both calls carry an Authorization: Bearer header when
|
||||
# AI_MEMORY_AUTH_TOKEN is set in this hook's environment.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
|
||||
get_handoff() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 1.0 "$1" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN"
|
||||
else
|
||||
curl -s --max-time 1.0 "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "$PAYLOAD" | post_hook "$SERVER/hook?event=session-start&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
get_handoff "$SERVER/handoff?agent=gemini-cli" 2>/dev/null || true
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-start&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
ai_memory_get_handoff "$SERVER/handoff?agent=gemini-cli${QS}" 2>/dev/null || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli stop hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=stop&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=stop&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# gemini-cli user-prompt hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=user-prompt&agent=gemini-cli" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=user-prompt&agent=gemini-cli${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -36,7 +36,7 @@ function Get-AiMemoryMarkerQuery {
|
||||
param([string] $Cwd)
|
||||
$marker = Get-AiMemoryMarkerToml -Cwd $Cwd
|
||||
if (-not $marker) { return "" }
|
||||
$qs = ""
|
||||
$qs = "&cwd=$([uri]::EscapeDataString($Cwd))"
|
||||
$ws = Get-AiMemoryTomlKey -File $marker -Key "workspace"
|
||||
if ($ws) { $qs += "&workspace=$([uri]::EscapeDataString($ws))" }
|
||||
$proj = Get-AiMemoryTomlKey -File $marker -Key "project"
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode post-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=post-tool-use&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=post-tool-use&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode pre-compact hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-compact&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-compact&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode pre-tool-use hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=pre-tool-use&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=pre-tool-use&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode session-end hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=session-end&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-end&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
#!/bin/sh
|
||||
# opencode SessionStart hook.
|
||||
#
|
||||
# 1. Forwards the event JSON to the ai-memory server (fire-and-forget).
|
||||
# 2. Synchronously fetches any pending cross-agent handoff and prints
|
||||
# it to stdout — agent CLIs prepend session-start hook stdout to
|
||||
# the next session, so the resuming agent sees prior context with
|
||||
# no human in the loop.
|
||||
#
|
||||
# Both calls carry an Authorization: Bearer header when
|
||||
# AI_MEMORY_AUTH_TOKEN is set in this hook's environment.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
|
||||
get_handoff() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 1.0 "$1" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN"
|
||||
else
|
||||
curl -s --max-time 1.0 "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "$PAYLOAD" | post_hook "$SERVER/hook?event=session-start&agent=open-code" >/dev/null 2>&1 || true
|
||||
get_handoff "$SERVER/handoff?agent=open-code" 2>/dev/null || true
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=session-start&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
ai_memory_get_handoff "$SERVER/handoff?agent=open-code${QS}" 2>/dev/null || true
|
||||
exit 0
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode stop hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=stop&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=stop&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#!/bin/sh
|
||||
# opencode user-prompt hook.
|
||||
# Forwards the event JSON to the ai-memory server. Adds an
|
||||
# Authorization: Bearer header when AI_MEMORY_AUTH_TOKEN is set in
|
||||
# this hook's environment (set it via install-hooks --auth-token).
|
||||
# Forwards the event JSON to the ai-memory server, fire-and-forget.
|
||||
_lib_dir="$(dirname "$0")"
|
||||
[ -f "$_lib_dir/_lib.sh" ] || _lib_dir="$_lib_dir/.."
|
||||
. "$_lib_dir/_lib.sh"
|
||||
|
||||
SERVER="${AI_MEMORY_HOOK_URL:-http://127.0.0.1:49374}"
|
||||
post_hook() {
|
||||
if [ -n "${AI_MEMORY_AUTH_TOKEN:-}" ]; then
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AI_MEMORY_AUTH_TOKEN" \
|
||||
--data-binary @-
|
||||
else
|
||||
curl -s --max-time 0.5 -X POST "$1" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
fi
|
||||
}
|
||||
post_hook "$SERVER/hook?event=user-prompt&agent=open-code" >/dev/null 2>&1 || true
|
||||
PAYLOAD=$(cat)
|
||||
CWD=$(ai_memory_extract_cwd "$PAYLOAD")
|
||||
QS=$(ai_memory_marker_qs "$CWD")
|
||||
|
||||
printf '%s' "$PAYLOAD" \
|
||||
| ai_memory_post_hook "$SERVER/hook?event=user-prompt&agent=open-code${QS}" >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
|
||||
@@ -59,11 +59,11 @@ assert_eq "extract cwd from empty json" "" "$(ai_memory_extract_cwd
|
||||
|
||||
# --- marker_qs --------------------------------------------------------
|
||||
QS=$(ai_memory_marker_qs "$TMP/a/b/c")
|
||||
assert_eq "marker_qs single key" "&workspace=deep" "$QS"
|
||||
assert_eq "marker_qs single key" "&cwd=$TMP/a/b/c&workspace=deep" "$QS"
|
||||
|
||||
printf 'workspace = "ws1"\nproject = "p1"\n' >"$TMP/a/b/.ai-memory.toml"
|
||||
QS2=$(ai_memory_marker_qs "$TMP/a/b/c")
|
||||
assert_eq "closer marker wins" "&workspace=ws1&project=p1" "$QS2"
|
||||
assert_eq "closer marker wins" "&cwd=$TMP/a/b/c&workspace=ws1&project=p1" "$QS2"
|
||||
|
||||
QS3=$(ai_memory_marker_qs "$TMP/nonexistent")
|
||||
assert_eq "no marker -> empty qs" "" "$QS3"
|
||||
|
||||
Reference in New Issue
Block a user