Compare commits
3 Commits
v0.2.18-ma
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 13038989b8 | |||
| b55de8d75e | |||
| 8512ca615d |
@@ -704,6 +704,13 @@ pub async fn create_container(
|
|||||||
labels.insert("triple-c.timezone".to_string(), timezone.unwrap_or("").to_string());
|
labels.insert("triple-c.timezone".to_string(), timezone.unwrap_or("").to_string());
|
||||||
labels.insert("triple-c.mcp-fingerprint".to_string(), compute_mcp_fingerprint(mcp_servers));
|
labels.insert("triple-c.mcp-fingerprint".to_string(), compute_mcp_fingerprint(mcp_servers));
|
||||||
labels.insert("triple-c.mission-control".to_string(), project.mission_control_enabled.to_string());
|
labels.insert("triple-c.mission-control".to_string(), project.mission_control_enabled.to_string());
|
||||||
|
labels.insert("triple-c.custom-env-fingerprint".to_string(), custom_env_fingerprint.clone());
|
||||||
|
labels.insert("triple-c.instructions-fingerprint".to_string(),
|
||||||
|
combined_instructions.as_ref().map(|s| sha256_hex(s)).unwrap_or_default());
|
||||||
|
labels.insert("triple-c.git-user-name".to_string(), project.git_user_name.clone().unwrap_or_default());
|
||||||
|
labels.insert("triple-c.git-user-email".to_string(), project.git_user_email.clone().unwrap_or_default());
|
||||||
|
labels.insert("triple-c.git-token-hash".to_string(),
|
||||||
|
project.git_token.as_ref().map(|t| sha256_hex(t)).unwrap_or_default());
|
||||||
|
|
||||||
let host_config = HostConfig {
|
let host_config = HostConfig {
|
||||||
mounts: Some(mounts),
|
mounts: Some(mounts),
|
||||||
@@ -1000,41 +1007,32 @@ pub async fn container_needs_recreation(
|
|||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Git environment variables ────────────────────────────────────────
|
// ── Git settings (label-based to avoid stale snapshot env vars) ─────
|
||||||
let env_vars = info
|
let expected_git_name = project.git_user_name.clone().unwrap_or_default();
|
||||||
.config
|
let container_git_name = get_label("triple-c.git-user-name").unwrap_or_default();
|
||||||
.as_ref()
|
if container_git_name != expected_git_name {
|
||||||
.and_then(|c| c.env.as_ref());
|
log::info!("GIT_USER_NAME mismatch (container={:?}, project={:?})", container_git_name, expected_git_name);
|
||||||
|
|
||||||
let get_env = |name: &str| -> Option<String> {
|
|
||||||
env_vars.and_then(|vars| {
|
|
||||||
vars.iter()
|
|
||||||
.find(|v| v.starts_with(&format!("{}=", name)))
|
|
||||||
.map(|v| v[name.len() + 1..].to_string())
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let container_git_name = get_env("GIT_USER_NAME");
|
|
||||||
let container_git_email = get_env("GIT_USER_EMAIL");
|
|
||||||
let container_git_token = get_env("GIT_TOKEN");
|
|
||||||
|
|
||||||
if container_git_name.as_deref() != project.git_user_name.as_deref() {
|
|
||||||
log::info!("GIT_USER_NAME mismatch (container={:?}, project={:?})", container_git_name, project.git_user_name);
|
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
if container_git_email.as_deref() != project.git_user_email.as_deref() {
|
|
||||||
log::info!("GIT_USER_EMAIL mismatch (container={:?}, project={:?})", container_git_email, project.git_user_email);
|
let expected_git_email = project.git_user_email.clone().unwrap_or_default();
|
||||||
|
let container_git_email = get_label("triple-c.git-user-email").unwrap_or_default();
|
||||||
|
if container_git_email != expected_git_email {
|
||||||
|
log::info!("GIT_USER_EMAIL mismatch (container={:?}, project={:?})", container_git_email, expected_git_email);
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
if container_git_token.as_deref() != project.git_token.as_deref() {
|
|
||||||
|
let expected_git_token_hash = project.git_token.as_ref().map(|t| sha256_hex(t)).unwrap_or_default();
|
||||||
|
let container_git_token_hash = get_label("triple-c.git-token-hash").unwrap_or_default();
|
||||||
|
if container_git_token_hash != expected_git_token_hash {
|
||||||
log::info!("GIT_TOKEN mismatch");
|
log::info!("GIT_TOKEN mismatch");
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Custom environment variables ──────────────────────────────────────
|
// ── Custom environment variables (label-based fingerprint) ──────────
|
||||||
let merged_env = merge_custom_env_vars(global_custom_env_vars, &project.custom_env_vars);
|
let merged_env = merge_custom_env_vars(global_custom_env_vars, &project.custom_env_vars);
|
||||||
let expected_fingerprint = compute_env_fingerprint(&merged_env);
|
let expected_fingerprint = compute_env_fingerprint(&merged_env);
|
||||||
let container_fingerprint = get_env("TRIPLE_C_CUSTOM_ENV").unwrap_or_default();
|
let container_fingerprint = get_label("triple-c.custom-env-fingerprint").unwrap_or_default();
|
||||||
if container_fingerprint != expected_fingerprint {
|
if container_fingerprint != expected_fingerprint {
|
||||||
log::info!("Custom env vars mismatch (container={:?}, expected={:?})", container_fingerprint, expected_fingerprint);
|
log::info!("Custom env vars mismatch (container={:?}, expected={:?})", container_fingerprint, expected_fingerprint);
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
@@ -1048,15 +1046,16 @@ pub async fn container_needs_recreation(
|
|||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Claude instructions ───────────────────────────────────────────────
|
// ── Claude instructions (label-based fingerprint) ─────────────────────
|
||||||
let expected_instructions = build_claude_instructions(
|
let expected_instructions = build_claude_instructions(
|
||||||
global_claude_instructions,
|
global_claude_instructions,
|
||||||
project.claude_instructions.as_deref(),
|
project.claude_instructions.as_deref(),
|
||||||
&project.port_mappings,
|
&project.port_mappings,
|
||||||
project.mission_control_enabled,
|
project.mission_control_enabled,
|
||||||
);
|
);
|
||||||
let container_instructions = get_env("CLAUDE_INSTRUCTIONS");
|
let expected_instructions_fp = expected_instructions.as_ref().map(|s| sha256_hex(s)).unwrap_or_default();
|
||||||
if container_instructions.as_deref() != expected_instructions.as_deref() {
|
let container_instructions_fp = get_label("triple-c.instructions-fingerprint").unwrap_or_default();
|
||||||
|
if container_instructions_fp != expected_instructions_fp {
|
||||||
log::info!("CLAUDE_INSTRUCTIONS mismatch");
|
log::info!("CLAUDE_INSTRUCTIONS mismatch");
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
const [detectedUrl, setDetectedUrl] = useState<string | null>(null);
|
const [detectedUrl, setDetectedUrl] = useState<string | null>(null);
|
||||||
const [imagePasteMsg, setImagePasteMsg] = useState<string | null>(null);
|
const [imagePasteMsg, setImagePasteMsg] = useState<string | null>(null);
|
||||||
const [isAtBottom, setIsAtBottom] = useState(true);
|
const [isAtBottom, setIsAtBottom] = useState(true);
|
||||||
|
const [isAutoFollow, setIsAutoFollow] = useState(true);
|
||||||
const isAtBottomRef = useRef(true);
|
const isAtBottomRef = useRef(true);
|
||||||
// Tracks user intent to follow output — only set to false by explicit user
|
// Tracks user intent to follow output — only set to false by explicit user
|
||||||
// actions (mouse wheel up), not by xterm scroll events during writes.
|
// actions (mouse wheel up), not by xterm scroll events during writes.
|
||||||
const autoFollowRef = useRef(true);
|
const autoFollowRef = useRef(true);
|
||||||
|
const lastUserScrollTimeRef = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
@@ -138,8 +140,12 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
// Detect user-initiated scroll-up (mouse wheel) to pause auto-follow.
|
// Detect user-initiated scroll-up (mouse wheel) to pause auto-follow.
|
||||||
// Captured during capture phase so it fires before xterm's own handler.
|
// Captured during capture phase so it fires before xterm's own handler.
|
||||||
const handleWheel = (e: WheelEvent) => {
|
const handleWheel = (e: WheelEvent) => {
|
||||||
|
lastUserScrollTimeRef.current = Date.now();
|
||||||
if (e.deltaY < 0) {
|
if (e.deltaY < 0) {
|
||||||
autoFollowRef.current = false;
|
autoFollowRef.current = false;
|
||||||
|
setIsAutoFollow(false);
|
||||||
|
isAtBottomRef.current = false;
|
||||||
|
setIsAtBottom(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
containerRef.current.addEventListener("wheel", handleWheel, { capture: true, passive: true });
|
containerRef.current.addEventListener("wheel", handleWheel, { capture: true, passive: true });
|
||||||
@@ -151,10 +157,14 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
const buf = term.buffer.active;
|
const buf = term.buffer.active;
|
||||||
const atBottom = buf.viewportY >= buf.baseY;
|
const atBottom = buf.viewportY >= buf.baseY;
|
||||||
isAtBottomRef.current = atBottom;
|
isAtBottomRef.current = atBottom;
|
||||||
// Re-enable auto-follow when viewport reaches the bottom
|
|
||||||
if (atBottom) {
|
// Re-enable auto-follow only when USER scrolls to bottom (not write-triggered)
|
||||||
|
const isUserScroll = (Date.now() - lastUserScrollTimeRef.current) < 300;
|
||||||
|
if (atBottom && isUserScroll && !autoFollowRef.current) {
|
||||||
autoFollowRef.current = true;
|
autoFollowRef.current = true;
|
||||||
|
setIsAutoFollow(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollStateRafId === null) {
|
if (scrollStateRafId === null) {
|
||||||
scrollStateRafId = requestAnimationFrame(() => {
|
scrollStateRafId = requestAnimationFrame(() => {
|
||||||
scrollStateRafId = null;
|
scrollStateRafId = null;
|
||||||
@@ -214,14 +224,12 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
const outputPromise = onOutput(sessionId, (data) => {
|
const outputPromise = onOutput(sessionId, (data) => {
|
||||||
if (aborted) return;
|
if (aborted) return;
|
||||||
term.write(data, () => {
|
term.write(data, () => {
|
||||||
// Keep viewport pinned to bottom when user hasn't scrolled up.
|
|
||||||
// Uses autoFollowRef (user intent) rather than isAtBottomRef (viewport
|
|
||||||
// position) so that xterm desync during writes doesn't kill auto-follow,
|
|
||||||
// but an explicit user scroll-up does pause it.
|
|
||||||
if (autoFollowRef.current) {
|
if (autoFollowRef.current) {
|
||||||
term.scrollToBottom();
|
term.scrollToBottom();
|
||||||
isAtBottomRef.current = true;
|
if (!isAtBottomRef.current) {
|
||||||
setIsAtBottom(true);
|
isAtBottomRef.current = true;
|
||||||
|
setIsAtBottom(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
detector.feed(data);
|
detector.feed(data);
|
||||||
@@ -265,11 +273,9 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
resizeRafId = requestAnimationFrame(() => {
|
resizeRafId = requestAnimationFrame(() => {
|
||||||
resizeRafId = null;
|
resizeRafId = null;
|
||||||
if (!containerRef.current || containerRef.current.offsetWidth === 0) return;
|
if (!containerRef.current || containerRef.current.offsetWidth === 0) return;
|
||||||
const wasAtBottom = isAtBottomRef.current;
|
|
||||||
fitAddon.fit();
|
fitAddon.fit();
|
||||||
resize(sessionId, term.cols, term.rows);
|
resize(sessionId, term.cols, term.rows);
|
||||||
// Maintain scroll position after resize reflow
|
if (autoFollowRef.current) {
|
||||||
if (wasAtBottom) {
|
|
||||||
term.scrollToBottom();
|
term.scrollToBottom();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -323,6 +329,9 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fitRef.current?.fit();
|
fitRef.current?.fit();
|
||||||
|
if (autoFollowRef.current) {
|
||||||
|
term.scrollToBottom();
|
||||||
|
}
|
||||||
term.focus();
|
term.focus();
|
||||||
} else {
|
} else {
|
||||||
// Release WebGL context for inactive terminals
|
// Release WebGL context for inactive terminals
|
||||||
@@ -360,7 +369,7 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
const term = termRef.current;
|
const term = termRef.current;
|
||||||
if (term) {
|
if (term) {
|
||||||
autoFollowRef.current = true;
|
autoFollowRef.current = true;
|
||||||
// Re-fit first to fix viewport desync (same thing a resize does)
|
setIsAutoFollow(true);
|
||||||
fitRef.current?.fit();
|
fitRef.current?.fit();
|
||||||
term.scrollToBottom();
|
term.scrollToBottom();
|
||||||
isAtBottomRef.current = true;
|
isAtBottomRef.current = true;
|
||||||
@@ -368,6 +377,21 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleToggleAutoFollow = useCallback(() => {
|
||||||
|
const next = !autoFollowRef.current;
|
||||||
|
autoFollowRef.current = next;
|
||||||
|
setIsAutoFollow(next);
|
||||||
|
if (next) {
|
||||||
|
const term = termRef.current;
|
||||||
|
if (term) {
|
||||||
|
fitRef.current?.fit();
|
||||||
|
term.scrollToBottom();
|
||||||
|
isAtBottomRef.current = true;
|
||||||
|
setIsAtBottom(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={terminalContainerRef}
|
ref={terminalContainerRef}
|
||||||
@@ -388,6 +412,19 @@ export default function TerminalView({ sessionId, active }: Props) {
|
|||||||
{imagePasteMsg}
|
{imagePasteMsg}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{/* Auto-follow toggle - top right */}
|
||||||
|
<button
|
||||||
|
onClick={handleToggleAutoFollow}
|
||||||
|
className={`absolute top-2 right-4 z-50 px-2 py-1 rounded text-[10px] font-medium border shadow-sm transition-colors cursor-pointer ${
|
||||||
|
isAutoFollow
|
||||||
|
? "bg-[#1a2332] text-[#3fb950] border-[#238636] hover:bg-[#1f2d3d]"
|
||||||
|
: "bg-[#1f2937] text-[#8b949e] border-[#30363d] hover:bg-[#2d3748]"
|
||||||
|
}`}
|
||||||
|
title={isAutoFollow ? "Auto-scrolling to latest output (click to pause)" : "Auto-scroll paused (click to resume)"}
|
||||||
|
>
|
||||||
|
{isAutoFollow ? "▼ Following" : "▽ Paused"}
|
||||||
|
</button>
|
||||||
|
{/* Jump to Current - bottom right, when scrolled up */}
|
||||||
{!isAtBottom && (
|
{!isAtBottom && (
|
||||||
<button
|
<button
|
||||||
onClick={handleScrollToBottom}
|
onClick={handleScrollToBottom}
|
||||||
|
|||||||
Reference in New Issue
Block a user