源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s

This commit is contained in:
agent-radar committed 2026-09-01 20:17:27 +08:00
commit 2ed3415fb7
8018 files changed
+1936476

No files matched your search

@@ -0,0 +1,75 @@
import { renderHook } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import type { AgentActivityMessage } from "@tutti-os/agent-activity-core";
import { useAgentSessionControllerState } from "./useAgentSessionControllerState";
const ACTIVE_REF = {
agentSessionId: "session-1",
origin: "test",
workspaceId: "workspace-1"
};
function message(version: number): AgentActivityMessage {
return {
agentSessionId: "session-1",
kind: "text",
messageId: `message-${version}`,
occurredAtUnixMs: version,
payload: {},
role: "assistant",
turnId: "turn-1",
version
};
}
describe("useAgentSessionControllerState", () => {
it("does not infer older history from a streamed message version", () => {
const { result, rerender } = renderHook(
({ version }) =>
useAgentSessionControllerState(ACTIVE_REF, [message(version)]),
{ initialProps: { version: 1 } }
);
expect(result.current.activeSessionView).toMatchObject({
hasOlderMessages: false,
oldestLoadedVersion: 1
});
rerender({ version: 446 });
expect(result.current.activeSessionView).toMatchObject({
hasOlderMessages: false,
oldestLoadedVersion: 446
});
});
it("reads terminal older-page coverage from the canonical Engine window", () => {
const { result, rerender } = renderHook(
({ hasOlderMessages, messages, oldestLoadedVersion }) =>
useAgentSessionControllerState(ACTIVE_REF, messages, {
hasOlderMessages,
oldestLoadedVersion
}),
{
initialProps: {
hasOlderMessages: true,
messages: [message(446)],
oldestLoadedVersion: 446
}
}
);
expect(result.current.activeSessionView?.hasOlderMessages).toBe(true);
rerender({
hasOlderMessages: false,
messages: [message(1), message(446)],
oldestLoadedVersion: 1
});
expect(result.current.activeSessionView).toMatchObject({
hasOlderMessages: false,
oldestLoadedVersion: 1
});
});
});
@@ -0,0 +1,71 @@
import { useCallback } from "react";
import type {
AgentActivityMessage,
AgentActivitySessionMessageWindow
} from "@tutti-os/agent-activity-core";
import { type AgentSessionViewRef } from "./useAgentSessionPagingState";
import { useAgentSessionPagingState } from "./useAgentSessionPagingState";
export function useAgentSessionControllerState(
activeRef: AgentSessionViewRef,
canonicalMessages: readonly AgentActivityMessage[] = [],
canonicalWindow: AgentActivitySessionMessageWindow | null = null
) {
const paging = useAgentSessionPagingState();
const getAgentSessionView = useCallback(
(ref: AgentSessionViewRef) => {
const pagingEntry = paging.get(ref);
return pagingEntry
? {
...pagingEntry,
hasOlderMessages: false,
oldestLoadedVersion: null
}
: null;
},
[paging.get]
);
const deleteAgentSessionView = useCallback(
(ref: AgentSessionViewRef) => paging.remove(ref),
[paging.remove]
);
const setAgentSessionViewMessagesLoading = useCallback(
(ref: AgentSessionViewRef, value: boolean) =>
paging.flag("isLoadingMessages", ref, value),
[paging.flag]
);
const setAgentSessionViewOlderMessagesLoading = useCallback(
(ref: AgentSessionViewRef, value: boolean) =>
paging.flag("isLoadingOlderMessages", ref, value),
[paging.flag]
);
void paging.entries;
const storedActiveView = getAgentSessionView(activeRef);
const canonicalOldestVersion =
canonicalWindow?.oldestLoadedVersion ?? oldestVersion(canonicalMessages);
const activeSessionView =
storedActiveView === null && canonicalOldestVersion === null
? null
: {
...(storedActiveView ?? {
error: null,
isLoadingMessages: false,
isLoadingOlderMessages: false
}),
hasOlderMessages: canonicalWindow?.hasOlderMessages ?? false,
oldestLoadedVersion: canonicalOldestVersion
};
return {
activeSessionView,
deleteAgentSessionView,
getAgentSessionView,
setAgentSessionViewError: paging.setError,
setAgentSessionViewMessagesLoading,
setAgentSessionViewOlderMessagesLoading
};
}
function oldestVersion(messages: readonly AgentActivityMessage[]) {
const versions = messages.map((item) => item.version).filter(Number.isFinite);
return versions.length > 0 ? Math.min(...versions) : null;
}
@@ -0,0 +1,79 @@
import { useCallback, useRef, useState } from "react";
export interface AgentSessionViewRef {
workspaceId: string | null | undefined;
agentSessionId: string | null | undefined;
origin?: string | null;
}
export interface AgentSessionPagingEntry {
error: string | null;
isLoadingMessages: boolean;
isLoadingOlderMessages: boolean;
}
const EMPTY_ENTRY: AgentSessionPagingEntry = {
error: null,
isLoadingMessages: false,
isLoadingOlderMessages: false
};
export function useAgentSessionPagingState() {
const [entries, setEntries] = useState<
Record<string, AgentSessionPagingEntry>
>({});
const entriesRef = useRef(entries);
entriesRef.current = entries;
const update = useCallback(
(
ref: AgentSessionViewRef,
updater: (entry: AgentSessionPagingEntry) => AgentSessionPagingEntry
) => {
const key = sessionKey(ref);
if (!key) return;
setEntries((current) => {
const previous = current[key] ?? EMPTY_ENTRY;
const next = updater(previous);
return next === previous ? current : { ...current, [key]: next };
});
},
[]
);
const get = useCallback((ref: AgentSessionViewRef) => {
const key = sessionKey(ref);
return key ? (entriesRef.current[key] ?? null) : null;
}, []);
const remove = useCallback((ref: AgentSessionViewRef) => {
const key = sessionKey(ref);
if (!key) return;
setEntries((current) => {
if (!current[key]) return current;
const next = { ...current };
delete next[key];
return next;
});
}, []);
const flag = useCallback(
(
field: "isLoadingMessages" | "isLoadingOlderMessages",
ref: AgentSessionViewRef,
value: boolean
) => update(ref, (entry) => ({ ...entry, [field]: value })),
[update]
);
const setError = useCallback(
(ref: AgentSessionViewRef, error: string | null) =>
update(ref, (entry) => ({ ...entry, error })),
[update]
);
return { entries, flag, get, remove, setError };
}
function sessionKey(ref: AgentSessionViewRef): string | null {
const workspaceId = ref.workspaceId?.trim() ?? "";
const origin = ref.origin?.trim() ?? "";
const agentSessionId = ref.agentSessionId?.trim() ?? "";
return workspaceId && origin && agentSessionId
? `${workspaceId}::${origin}::${agentSessionId}`
: null;
}