Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test(workstream): add Copilot CLI managed acceptance legs (#1040)
Jean Vetorello7216f7cbff8c
diff --git a/scripts/managed-workstream-acceptance.sh b/scripts/managed-workstream-acceptance.shindex c17f6fab..3f635ef6 100755--- a/scripts/managed-workstream-acceptance.sh+++ b/scripts/managed-workstream-acceptance.sh@@ -8,7 +8,7 @@ ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)BIN=${AI_MEMORY_ACCEPTANCE_BIN:-"$ROOT/target/debug/ai-memory"}KEEP=${AI_MEMORY_ACCEPTANCE_KEEP:-0}DETERMINISTIC_ONLY=${AI_MEMORY_ACCEPTANCE_DETERMINISTIC_ONLY:-0}-HARNESS_WORDS=${AI_MEMORY_ACCEPTANCE_HARNESSES:-"claude codex opencode pi crush omp kimi command-code kiro grok antigravity"}+HARNESS_WORDS=${AI_MEMORY_ACCEPTANCE_HARNESSES:-"claude codex opencode pi crush omp kimi command-code kiro grok antigravity copilot"}TMP=$(mktemp -d "${TMPDIR:-/tmp}/ai-memory-workstream-acceptance.XXXXXX")DATA="$TMP/data"REPO="$TMP/repo"@@ -418,6 +418,48 @@ case "${AI_MEMORY_ACCEPTANCE_FAKE_MODE:-argv}" in"$AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_HOOK" \>"$AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_HOOK_LOG";;+ copilot)+ printf '%s\n' "$@" >"$AI_MEMORY_ACCEPTANCE_ARGV_LOG"+ # Honor the wrapper-owned `--session-id <id>` (fresh) and `--resume=<id>`+ # (returning) selectors the way the real CLI does.+ session_id=""+ previous_arg=""+ for arg in "$@"; do+ case "$arg" in+ --resume=*) session_id=${arg#--resume=} ;;+ esac+ if [ "$previous_arg" = --session-id ]; then+ session_id=$arg+ fi+ previous_arg=$arg+ done+ [ -n "$session_id" ] || {+ printf 'copilot fake mode requires a wrapper session selector\n' >&2+ exit 1+ }+ session_dir="${COPILOT_HOME:?copilot fake mode requires COPILOT_HOME}/session-state/$session_id"+ mkdir -p "$session_dir"+ events="$session_dir/events.jsonl"+ if [ ! -f "$events" ]; then+ jq -nc --arg id "$session_id" --arg cwd "$PWD" \+ '{type:"session.start",data:{sessionId:$id,version:1,producer:"copilot-agent",context:{cwd:$cwd}},id:"start"}' \+ >"$events"+ printf '{"type":"system.message","data":{"role":"system","content":"PRIVATE fake copilot system prompt"},"id":"system"}\n' >>"$events"+ fi+ # The real SessionStart hook links the native session and returns any+ # pending workstream context as top-level additionalContext.+ jq -nc --arg id "$session_id" --arg cwd "$PWD" \+ '{session_id:$id, cwd:$cwd, hook_event_name:"SessionStart", source:"startup"}' | \+ AI_MEMORY_HOOK_URL="${AI_MEMORY_SERVER_URL:?}" \+ "$AI_MEMORY_ACCEPTANCE_COPILOT_HOOK" \+ >"$AI_MEMORY_ACCEPTANCE_COPILOT_HOOK_LOG"+ sentinel=${AI_MEMORY_ACCEPTANCE_SENTINEL:-AMWS-FAKE-COPILOT}+ round=$(wc -l <"$events" | tr -d ' ')+ jq -nc --arg text "$sentinel" --arg id "user-$round" \+ '{type:"user.message",data:{content:$text},id:$id}' >>"$events"+ jq -nc --arg text "$sentinel reply" --arg id "assistant-$round" \+ '{type:"assistant.message",data:{content:$text,reasoningText:"PRIVATE reasoning",toolRequests:[]},id:$id}' >>"$events"+ ;;esacEOFchmod +x "$FAKE"@@ -1113,6 +1155,117 @@ assert_managed_leg "$kimi_ws_hex" grok "$grok_cross_before" \"$grok_cross_delivery" 1 \"$LOGS/edge-grok-cross.log" >/dev/null+# Copilot fake-mode fixture: the fake copilot honors the wrapper's+# `--session-id`/`--resume=` selectors, writes the real+# $COPILOT_HOME/session-state/<id>/events.jsonl layout, and pipes its startup+# payload through the real SessionStart hook, which links the native session+# and returns pending context as top-level additionalContext.+COPILOT_FAKE_HOME="$CONFIG/copilot-fake"+COPILOT_HOOK="$ROOT/hooks/copilot-cli/session-start.sh"+mkdir -p "$COPILOT_FAKE_HOME"+(+ cd "$REPO"+ COPILOT_HOME="$COPILOT_FAKE_HOME" \+ AI_MEMORY_ACCEPTANCE_FAKE_MODE=copilot \+ AI_MEMORY_ACCEPTANCE_ARGV_LOG="$TMP/copilot-first-argv.log" \+ AI_MEMORY_ACCEPTANCE_SENTINEL="AMWS-FAKE-COPILOT-ONE" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK="$COPILOT_HOOK" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK_LOG="$TMP/copilot-first-hook.json" \+ "$BIN" --data-dir "$DATA" run --new edge-copilot --executable "$FAKE" \+ --yolo copilot >"$LOGS/edge-copilot-first.log" 2>&1+)+grep -qx -- '--yolo' "$TMP/copilot-first-argv.log" &&+ grep -qx -- '--session-id' "$TMP/copilot-first-argv.log" || {+ printf 'fresh copilot launch did not receive --yolo and a wrapper session id\n' >&2+ cat "$TMP/copilot-first-argv.log" >&2+ exit 1+}+copilot_session_id=$(grep -A1 -x -- '--session-id' "$TMP/copilot-first-argv.log" | tail -1)+copilot_ws_hex=$(workstream_hex edge-copilot)+[ "${#copilot_ws_hex}" -eq 32 ] || {+ printf 'could not resolve the edge-copilot workstream id\n' >&2+ exit 1+}+copilot_native=$(assert_managed_leg "$copilot_ws_hex" copilot-cli 0 0 0 \+ "$LOGS/edge-copilot-first.log")+[ "$copilot_native" = "$copilot_session_id" ] || {+ printf 'Copilot linked native session %s, expected %s\n' \+ "$copilot_native" "$copilot_session_id" >&2+ exit 1+}+copilot_ws_id="${copilot_ws_hex:0:8}-${copilot_ws_hex:8:4}-${copilot_ws_hex:12:4}-${copilot_ws_hex:16:4}-${copilot_ws_hex:20:12}"+private_hits=$("$BIN" --data-dir "$DATA" workstream-search \+ --workstream-id "$copilot_ws_id" --limit 100 --json "PRIVATE")+jq -e 'length == 0' <<<"$private_hits" >/dev/null || {+ printf 'Copilot system prompt or reasoning leaked into the workstream ledger\n' >&2+ exit 1+}++# Returning to the same copilot session must resume it with `--resume=<id>`+# and import only the new round.+copilot_second_before=$(latest_workstream_sequence "$copilot_ws_hex")+copilot_second_delivery=$(current_delivery_cursor "$copilot_ws_hex" copilot-cli)+(+ cd "$REPO"+ COPILOT_HOME="$COPILOT_FAKE_HOME" \+ AI_MEMORY_ACCEPTANCE_FAKE_MODE=copilot \+ AI_MEMORY_ACCEPTANCE_ARGV_LOG="$TMP/copilot-second-argv.log" \+ AI_MEMORY_ACCEPTANCE_SENTINEL="AMWS-FAKE-COPILOT-TWO" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK="$COPILOT_HOOK" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK_LOG="$TMP/copilot-second-hook.json" \+ "$BIN" --data-dir "$DATA" run --workstream edge-copilot --executable "$FAKE" \+ copilot-cli >"$LOGS/edge-copilot-second.log" 2>&1+)+diff -u <(printf '%s\n' "--resume=$copilot_session_id") \+ "$TMP/copilot-second-argv.log"+returned_copilot=$(assert_managed_leg "$copilot_ws_hex" copilot-cli \+ "$copilot_second_before" "$copilot_second_delivery" 0 \+ "$LOGS/edge-copilot-second.log")+[ "$returned_copilot" = "$copilot_session_id" ] || {+ printf 'returning Copilot launch did not resume %s\n' "$copilot_session_id" >&2+ exit 1+}+copilot_second_hits=$("$BIN" --data-dir "$DATA" workstream-search \+ --workstream-id "$copilot_ws_id" --limit 100 --json "AMWS-FAKE-COPILOT")+jq -e \+ '([.[] | select(.role == "assistant" and (.content | contains("AMWS-FAKE-COPILOT-ONE")))] | length == 1)+ and ([.[] | select(.role == "assistant" and (.content | contains("AMWS-FAKE-COPILOT-TWO")))] | length == 1)' \+ <<<"$copilot_second_hits" >/dev/null || {+ printf 'copilot incremental import duplicated or missed a round sentinel\n' >&2+ tail -80 "$LOGS/edge-copilot-second.log" >&2+ exit 1+}++# A fresh copilot session joining the established edge-kimi workstream must+# start a new native session and receive the prior visible ledger through the+# real hook's additionalContext output.+copilot_cross_before=$(latest_workstream_sequence "$kimi_ws_hex")+copilot_cross_delivery=$(current_delivery_cursor "$kimi_ws_hex" copilot-cli)+(+ cd "$REPO"+ COPILOT_HOME="$COPILOT_FAKE_HOME" \+ AI_MEMORY_ACCEPTANCE_FAKE_MODE=copilot \+ AI_MEMORY_ACCEPTANCE_ARGV_LOG="$TMP/copilot-cross-argv.log" \+ AI_MEMORY_ACCEPTANCE_SENTINEL="AMWS-FAKE-COPILOT-CROSS" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK="$COPILOT_HOOK" \+ AI_MEMORY_ACCEPTANCE_COPILOT_HOOK_LOG="$TMP/copilot-cross-hook.json" \+ "$BIN" --data-dir "$DATA" run --workstream edge-kimi --executable "$FAKE" \+ copilot >"$LOGS/edge-copilot-cross.log" 2>&1+)+grep -qx -- '--session-id' "$TMP/copilot-cross-argv.log" || {+ printf 'copilot joining an established workstream did not start a fresh session\n' >&2+ cat "$TMP/copilot-cross-argv.log" >&2+ exit 1+}+jq -e '.additionalContext | contains("AMWS-FAKE-KIMI")' \+ "$TMP/copilot-cross-hook.json" >/dev/null || {+ printf 'Copilot hook did not receive the prior Kimi workstream history\n' >&2+ cat "$TMP/copilot-cross-hook.json" >&2+ exit 1+}+assert_managed_leg "$kimi_ws_hex" copilot-cli "$copilot_cross_before" \+ "$copilot_cross_delivery" 1 "$LOGS/edge-copilot-cross.log" >/dev/null+# A blank first launch remains eligible for one-time native-session adoption.# Use a pseudo-terminal because redirected/scripted launches deliberately skip# the chooser.@@ -1344,6 +1497,7 @@ for requested_harness in "${requested_harnesses[@]}"; do;;grok-build) harness=grok ;;antigravity-cli | agy) harness=antigravity ;;+ copilot-cli) harness=copilot ;;*) harness=$requested_harness ;;esacharness_command=$harness@@ -1377,6 +1531,9 @@ COMMAND_CODE_SETTINGS="$COMMAND_CODE_ACCEPTANCE_HOME/.commandcode/settings.json"GROK_ACCEPTANCE_HOME="$CONFIG/grok-home"ANTIGRAVITY_ACCEPTANCE_HOME="$CONFIG/antigravity-home"ANTIGRAVITY_HOOKS="$ANTIGRAVITY_ACCEPTANCE_HOME/.gemini/config/hooks.json"+COPILOT_ACCEPTANCE_HOME="$CONFIG/copilot-home"+COPILOT_HOOKS="$COPILOT_ACCEPTANCE_HOME/hooks/ai-memory.json"+mkdir -p "$(dirname "$COPILOT_HOOKS")"mkdir -p "$(dirname "$CLAUDE_SETTINGS")" "$(dirname "$CODEX_HOOKS")" \"$(dirname "$OPENCODE_PLUGIN")" "$(dirname "$PI_EXTENSION")" \"$(dirname "$OMP_EXTENSION")" "$OMP_AGENT_DIR" "$OPENCODE_DATA_HOME/opencode" \@@ -1493,6 +1650,15 @@ if [ -f "$HOME/.gemini/config/config.json" ]; then"$ANTIGRAVITY_ACCEPTANCE_HOME/.gemini/config/config.json"fi+# Copilot CLI resolves config, login state, hooks, and session-state below+# $COPILOT_HOME. Copy only config.json (login and model preferences, verified+# sufficient on Copilot CLI 1.0.92); the operator's hooks, MCP servers, and+# sessions stay out of the fixture.+COPILOT_SOURCE_HOME=${COPILOT_HOME:-$HOME/.copilot}+if [ -f "$COPILOT_SOURCE_HOME/config.json" ]; then+ cp "$COPILOT_SOURCE_HOME/config.json" "$COPILOT_ACCEPTANCE_HOME/config.json"+fi+install_hook() {local agent=$1local target=$2@@ -1502,7 +1668,7 @@ install_hook() {--config-file "$target")case "$agent" in- claude-code | codex | kimi-code | antigravity-cli)+ claude-code | codex | kimi-code | antigravity-cli | copilot-cli)command+=(--hooks-dir "$ROOT/hooks");;esac@@ -1519,6 +1685,7 @@ install_hook omp "$OMP_EXTENSION"install_hook kimi-code "$KIMI_ACCEPTANCE_HOME/config.toml"install_hook command-code "$COMMAND_CODE_SETTINGS"install_hook antigravity-cli "$ANTIGRAVITY_HOOKS"+install_hook copilot-cli "$COPILOT_HOOKS"agent_wire_name() {case "$1" in@@ -1528,6 +1695,7 @@ agent_wire_name() {kimi) printf 'kimi-code\n' ;;command-code) printf 'command-code\n' ;;antigravity) printf 'antigravity-cli\n' ;;+ copilot) printf 'copilot-cli\n' ;;*) printf '%s\n' "$1" ;;esac}@@ -1608,6 +1776,10 @@ run_harness() {native_args=(-p --print-timeout "${AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_TIMEOUT:-5m}" "$prompt")[ -z "${AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_MODEL:-}" ] || native_args=(-p --print-timeout "${AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_TIMEOUT:-5m}" --model "$AI_MEMORY_ACCEPTANCE_ANTIGRAVITY_MODEL" "$prompt");;+ copilot)+ native_args=(-p "$prompt")+ [ -z "${AI_MEMORY_ACCEPTANCE_COPILOT_MODEL:-}" ] || native_args=(-p --model "$AI_MEMORY_ACCEPTANCE_COPILOT_MODEL" "$prompt")+ ;;*)printf 'unsupported acceptance harness: %s\n' "$harness" >&2return 1@@ -1649,6 +1821,10 @@ run_harness() {(cd "$REPO" && HOME="$ANTIGRAVITY_ACCEPTANCE_HOME" \"$BIN" --data-dir "$DATA" run "${wrapper_args[@]}" "$harness" "${native_args[@]}") \>"$log" 2>&1+ elif [ "$harness" = copilot ]; then+ (cd "$REPO" && COPILOT_HOME="$COPILOT_ACCEPTANCE_HOME" \+ "$BIN" --data-dir "$DATA" run "${wrapper_args[@]}" "$harness" "${native_args[@]}") \+ >"$log" 2>&1else(cd "$REPO" && "$BIN" --data-dir "$DATA" run \"${wrapper_args[@]}" "$harness" "${native_args[@]}") >"$log" 2>&1