




















@@ -133,6 +133,33 @@ function resolveStoreScopedRequesterKey(params: {
133133return parsed.rest === params.mainKey ? params.mainKey : params.requesterKey;
134134}
135135136+function listImplicitDefaultDirectFallbackKeys(params: {
137+keyRaw: string;
138+mainKey: string;
139+}): string[] {
140+const parsed = parseAgentSessionKey(params.keyRaw.trim());
141+if (!parsed) {
142+return [];
143+}
144+const parts = parsed.rest.split(":");
145+if (parts.length < 4 || parts[1] !== "default" || parts[2] !== "direct") {
146+return [];
147+}
148+const [channel, , , ...peerParts] = parts;
149+if (!channel || peerParts.length === 0) {
150+return [];
151+}
152+const candidates = [
153+`agent:${parsed.agentId}:${channel}:direct:${peerParts.join(":")}`,
154+buildAgentMainSessionKey({
155+agentId: parsed.agentId,
156+mainKey: params.mainKey,
157+}),
158+params.mainKey,
159+];
160+return [...new Set(candidates)];
161+}
162+136163function formatSessionTaskLine(params: {
137164relatedSessionKey: string;
138165callerOwnerKey: string;
@@ -295,6 +322,7 @@ export function createSessionStatusTool(opts?: {
295322let requestedKeyRaw = requestedKeyParam ?? opts?.agentSessionKey;
296323const requestedKeyInput = requestedKeyRaw?.trim() ?? "";
297324let resolvedViaSessionId = false;
325+let resolvedViaImplicitCurrentFallback = false;
298326if (!requestedKeyRaw?.trim()) {
299327throw new Error("sessionKey required");
300328}
@@ -402,17 +430,39 @@ export function createSessionStatusTool(opts?: {
402430});
403431}
404432433+if (!resolved && requestedKeyParam === undefined) {
434+for (const fallbackKey of listImplicitDefaultDirectFallbackKeys({
435+keyRaw: requestedKeyRaw,
436+ mainKey,
437+})) {
438+resolved = resolveSessionEntry({
439+ store,
440+keyRaw: fallbackKey,
441+ alias,
442+ mainKey,
443+requesterInternalKey: storeScopedRequesterKey,
444+includeAliasFallback: true,
445+});
446+if (resolved) {
447+resolvedViaImplicitCurrentFallback = true;
448+break;
449+}
450+}
451+}
452+405453if (!resolved) {
406454const kind = shouldResolveSessionIdInput(requestedKeyRaw) ? "sessionId" : "sessionKey";
407455throw new Error(`Unknown ${kind}: ${requestedKeyRaw}`);
408456}
409457410458// Preserve caller-scoped raw-key/current lookups as "self" for visibility checks.
411-const visibilityTargetKey =
412-!resolvedViaSessionId &&
413-(requestedKeyInput === "current" || resolved.key === requestedKeyInput)
414- ? visibilityRequesterKey
415- : normalizeVisibilityTargetSessionKey(resolved.key, agentId);
459+const shouldTreatVisibilityTargetAsSelf =
460+resolvedViaImplicitCurrentFallback ||
461+(!resolvedViaSessionId &&
462+(requestedKeyInput === "current" || resolved.key === requestedKeyInput));
463+const visibilityTargetKey = shouldTreatVisibilityTargetAsSelf
464+ ? visibilityRequesterKey
465+ : normalizeVisibilityTargetSessionKey(resolved.key, agentId);
416466const access = visibilityGuard.check(visibilityTargetKey);
417467if (!access.allowed) {
418468throw new Error(access.error);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。