@xfxstudio/claworld 2026.4.30-testing.2 → 2026.5.3-testing.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -202,7 +202,7 @@ function buildClaworldManagementStartupPrompt(options = {}) {
202
202
  '',
203
203
  '## Session Routing',
204
204
  '- Reports/approval requests: use explicit reportTargetSessionKey, else sessions/index.json main.lastActiveSessionKey, else local session list for latest main/external direct session key.',
205
- '- Conversation details: prefer sessions/index.json chatRequestId -> sessionArtifacts. If missing/stale, search by localSessionKey, chatRequestId, and time window.',
205
+ '- Conversation details: prefer sessions/index.json chatRequestId -> artifacts. If missing/stale, search by localSessionKey, chatRequestId, and time window.',
206
206
  '- If no safe Main route exists or session send fails, write a report artifact, journal the failure, and retry or surface it on the next Main route.',
207
207
  '',
208
208
  '## Write Rules',
@@ -846,8 +846,31 @@ function compactDirectoryObject(value = {}) {
846
846
  return cleanJournalObject(value);
847
847
  }
848
848
 
849
+ function compactSessionArtifact(artifact = {}) {
850
+ const sessionFile = firstText(artifact.sessionFile, artifact.transcriptPath);
851
+ const transcriptPath = firstText(
852
+ artifact.transcriptPath && artifact.transcriptPath !== sessionFile ? artifact.transcriptPath : null,
853
+ );
854
+ const deliveryId = firstText(artifact.deliveryId);
855
+ return compactDirectoryObject({
856
+ sessionId: firstText(artifact.sessionId),
857
+ sessionFile,
858
+ transcriptPath,
859
+ deliveryId,
860
+ sourceEventId: deliveryId ? null : firstText(artifact.sourceEventId, artifact.eventId),
861
+ seenAt: firstText(artifact.seenAt, artifact.lastSeenAt, artifact.firstSeenAt),
862
+ });
863
+ }
864
+
865
+ function normalizeSessionArtifacts(artifacts = []) {
866
+ if (!Array.isArray(artifacts)) return [];
867
+ return artifacts.reduce((nextArtifacts, artifact) => (
868
+ upsertSessionArtifact(nextArtifacts, artifact)
869
+ ), []);
870
+ }
871
+
849
872
  function upsertSessionArtifact(artifacts = [], artifact = {}) {
850
- const normalizedArtifact = compactDirectoryObject(artifact);
873
+ const normalizedArtifact = compactSessionArtifact(artifact);
851
874
  if (
852
875
  !normalizedArtifact.sessionId
853
876
  && !normalizedArtifact.sessionFile
@@ -870,8 +893,7 @@ function upsertSessionArtifact(artifacts = [], artifact = {}) {
870
893
  nextArtifacts[index] = compactDirectoryObject({
871
894
  ...nextArtifacts[index],
872
895
  ...normalizedArtifact,
873
- firstSeenAt: nextArtifacts[index].firstSeenAt || normalizedArtifact.firstSeenAt,
874
- lastSeenAt: normalizedArtifact.lastSeenAt || nextArtifacts[index].lastSeenAt,
896
+ seenAt: normalizedArtifact.seenAt || nextArtifacts[index].seenAt,
875
897
  });
876
898
  return nextArtifacts;
877
899
  }
@@ -879,24 +901,52 @@ function upsertSessionArtifact(artifacts = [], artifact = {}) {
879
901
  return nextArtifacts;
880
902
  }
881
903
 
882
- function applySessionArtifactHints(target = {}, relations = {}) {
883
- const nextTarget = { ...target };
884
- if (relations.sessionId) nextTarget.latestSessionId = relations.sessionId;
885
- if (relations.sessionFile) nextTarget.latestSessionFile = relations.sessionFile;
886
- if (relations.transcriptPath) nextTarget.latestTranscriptPath = relations.transcriptPath;
887
- return nextTarget;
904
+ function buildLatestSessionHint(source = {}, timestamp = null) {
905
+ const artifact = compactSessionArtifact({
906
+ sessionId: source.sessionId || source.latestSessionId,
907
+ sessionFile: source.sessionFile || source.latestSessionFile,
908
+ transcriptPath: source.transcriptPath || source.latestTranscriptPath,
909
+ seenAt: timestamp || source.seenAt || source.lastSeenAt || source.firstSeenAt,
910
+ });
911
+ if (!artifact.sessionId && !artifact.sessionFile && !artifact.transcriptPath) return null;
912
+ const latest = { ...artifact };
913
+ delete latest.deliveryId;
914
+ delete latest.sourceEventId;
915
+ return compactDirectoryObject(latest);
888
916
  }
889
917
 
890
- function buildSessionArtifact({ relations = {}, timestamp = null } = {}) {
918
+ function normalizeChatRequestDirectoryEntry(entry = {}) {
919
+ const current = isPlainObject(entry) ? entry : {};
920
+ const artifacts = normalizeSessionArtifacts(
921
+ Array.isArray(current.artifacts) ? current.artifacts : current.sessionArtifacts,
922
+ );
891
923
  return compactDirectoryObject({
924
+ firstSeenAt: current.firstSeenAt,
925
+ lastSeenAt: current.lastSeenAt,
926
+ artifacts,
927
+ });
928
+ }
929
+
930
+ function normalizeChatRequestsDirectory(chatRequests = {}) {
931
+ if (!isPlainObject(chatRequests)) return {};
932
+ const normalized = {};
933
+ for (const [chatRequestId, entry] of Object.entries(chatRequests)) {
934
+ const normalizedEntry = normalizeChatRequestDirectoryEntry(entry);
935
+ if (Object.keys(normalizedEntry).length > 0) {
936
+ normalized[chatRequestId] = normalizedEntry;
937
+ }
938
+ }
939
+ return normalized;
940
+ }
941
+
942
+ function buildSessionArtifact({ relations = {}, timestamp = null } = {}) {
943
+ return compactSessionArtifact({
892
944
  sessionId: relations.sessionId,
893
945
  sessionFile: relations.sessionFile,
894
- sessionStorePath: relations.sessionStorePath,
895
946
  transcriptPath: relations.transcriptPath,
896
947
  deliveryId: relations.deliveryId,
897
948
  eventId: relations.eventId,
898
- firstSeenAt: timestamp,
899
- lastSeenAt: timestamp,
949
+ seenAt: timestamp,
900
950
  });
901
951
  }
902
952
 
@@ -943,19 +993,20 @@ function applyClaworldSessionDirectoryUpdate(directory = {}, input = {}) {
943
993
  const currentSession = isPlainObject(conversationSessions[localSessionKey])
944
994
  ? conversationSessions[localSessionKey]
945
995
  : {};
946
- let nextSession = applySessionArtifactHints(
947
- compactDirectoryObject({
948
- ...currentSession,
949
- localSessionKey,
950
- relaySessionKey,
951
- conversationKey: firstText(currentSession.conversationKey, relations.conversationKey),
952
- worldId: firstText(currentSession.worldId, relations.worldId),
953
- localAgentId: firstText(currentSession.localAgentId, relations.localAgentId),
954
- firstSeenAt: currentSession.firstSeenAt || timestamp,
955
- lastSeenAt: timestamp,
956
- }),
957
- relations,
958
- );
996
+ const currentLatest = isPlainObject(currentSession.latest)
997
+ ? buildLatestSessionHint(currentSession.latest)
998
+ : buildLatestSessionHint(currentSession);
999
+ const nextLatest = buildLatestSessionHint(relations, timestamp) || currentLatest;
1000
+ let nextSession = compactDirectoryObject({
1001
+ relaySessionKey: firstText(relaySessionKey, currentSession.relaySessionKey),
1002
+ conversationKey: firstText(currentSession.conversationKey, relations.conversationKey),
1003
+ worldId: firstText(currentSession.worldId, relations.worldId),
1004
+ localAgentId: firstText(currentSession.localAgentId, relations.localAgentId),
1005
+ firstSeenAt: currentSession.firstSeenAt || timestamp,
1006
+ lastSeenAt: timestamp,
1007
+ latest: nextLatest,
1008
+ chatRequests: normalizeChatRequestsDirectory(currentSession.chatRequests),
1009
+ });
959
1010
 
960
1011
  const chatRequestId = normalizeChatRequestId(input, relations);
961
1012
  if (chatRequestId) {
@@ -966,16 +1017,14 @@ function applyClaworldSessionDirectoryUpdate(directory = {}, input = {}) {
966
1017
  ? chatRequests[chatRequestId]
967
1018
  : {};
968
1019
  const artifact = buildSessionArtifact({ relations, timestamp });
969
- const nextRequest = applySessionArtifactHints(
970
- compactDirectoryObject({
971
- ...currentRequest,
972
- chatRequestId,
973
- firstSeenAt: currentRequest.firstSeenAt || timestamp,
974
- lastSeenAt: timestamp,
975
- sessionArtifacts: upsertSessionArtifact(currentRequest.sessionArtifacts, artifact),
976
- }),
977
- relations,
978
- );
1020
+ const currentArtifacts = Array.isArray(currentRequest.artifacts)
1021
+ ? currentRequest.artifacts
1022
+ : currentRequest.sessionArtifacts;
1023
+ const nextRequest = compactDirectoryObject({
1024
+ firstSeenAt: currentRequest.firstSeenAt || timestamp,
1025
+ lastSeenAt: timestamp,
1026
+ artifacts: upsertSessionArtifact(currentArtifacts, artifact),
1027
+ });
979
1028
  chatRequests[chatRequestId] = nextRequest;
980
1029
  nextSession = compactDirectoryObject({
981
1030
  ...nextSession,