stratagate-dsh 0.3.54 → 0.3.55
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.
- package/CHANGELOG.md +5 -0
- package/dist/client.js +1 -1
- package/dist/plugin.js +77 -72
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/client.js
CHANGED
|
@@ -322,7 +322,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
322
322
|
\r
|
|
323
323
|
`,STAR_REPOSITORY_URL="https://github.com/diqierjia/StrataGate-AgentMemory",ISSUE_URL=STAR_REPOSITORY_URL+"/issues/new",DISCUSSION_URL=STAR_REPOSITORY_URL+"/discussions/categories/q-a",FEEDBACK_AI_PROMPT="\u8BF7\u6839\u636E\u5F53\u524D\u4F1A\u8BDD\u4E2D StrataGate \u63D2\u4EF6\u7684\u6545\u969C\u3001\u4F7F\u7528\u7591\u95EE\u6216\u6539\u8FDB\u5EFA\u8BAE\u6574\u7406\u53CD\u9988\u3002\u53EA\u7528\u5DF2\u77E5\u4E8B\u5B9E\uFF0C\u4E0D\u8981\u731C\u6D4B\uFF0C\u672A\u77E5\u7559\u7A7A\uFF0C\u53BB\u9664\u51ED\u636E\u3002\u8C03\u7528 feedback_prepare \u4FDD\u5B58\u672C\u5730\u8349\u7A3F\uFF1B\u65B0\u95EE\u9898\u4F20 new_draft=true\u3002\u8BCA\u65AD\u7531\u7A0B\u5E8F\u81EA\u52A8\u8865\u5145\u3002\u7ED9\u6211\u201C\u6253\u5F00\u53CD\u9988\u8349\u7A3F\u201D\u7684\u94FE\u63A5\uFF0C\u6211\u4F1A\u68C0\u67E5\u540E\u624B\u52A8\u53D1\u90AE\u4EF6\u3002",FEEDBACK_SETTINGS_ID="stratagate-memory",FEEDBACK_VIEW_ID="feedback",MEMORY_PANEL_ID="stratagate-memory",SIDEBAR_PROMPT_STORAGE_KEY="stratagate-dsh.sidebar-prompt.v1",SIDEBAR_PROMPT_STYLES=".sg-sidebar-panel-icon{display:block;flex-shrink:0}.sg-sidebar-placement-prompt{display:inline-flex;align-items:center;gap:8px;flex-wrap:wrap;max-width:100%;font-size:11px;line-height:1.5;color:var(--sg-muted)}.sg-sidebar-placement-text{min-width:0}.sg-memory .sg-sidebar-placement-action{padding:0;border:0;background:transparent;color:var(--sg-accent);font-size:11px;line-height:1.5;cursor:pointer;white-space:nowrap}.sg-sidebar-placement-action:hover{text-decoration:underline}.sg-memory .sg-sidebar-placement-close{display:inline-grid;place-items:center;width:20px;height:20px;flex:none;padding:0;border:0;border-radius:4px;background:transparent;color:var(--sg-muted);font-size:15px;line-height:1;cursor:pointer}.sg-sidebar-placement-close:hover{background:var(--sg-soft);color:var(--sg-text)}",pendingFeedbackNavigation=null,feedbackNavigationListeners=new Set;function setFeedbackNavigation(state){pendingFeedbackNavigation=state;for(let listener of feedbackNavigationListeners)listener(state);feedbackNavigationListeners.size&&(pendingFeedbackNavigation=null)}function FeedbackSettingsPage(props){let[navigationState,setNavigationState]=React.useState(()=>pendingFeedbackNavigation);return React.useEffect(()=>(feedbackNavigationListeners.add(setNavigationState),pendingFeedbackNavigation&&setNavigationState(pendingFeedbackNavigation),pendingFeedbackNavigation=null,()=>feedbackNavigationListeners.delete(setNavigationState)),[]),h(MemoryPage,{...props,navigationState:navigationState||props.navigationState})}let ISSUE_BODY_HINT=`> \u8BF7\u5728\u4E0B\u65B9\u7C98\u8D34 StrataGate \u53CD\u9988\u62A5\u544A\uFF08Ctrl+V / \u2318V\uFF09\uFF0C\u68C0\u67E5\u540E\u63D0\u4EA4\u3002\u82E5\u65E0\u6CD5\u7C98\u8D34\uFF0C\u8BF7\u8FD4\u56DE StrataGate \u624B\u52A8\u590D\u5236\u62A5\u544A\u3002
|
|
324
324
|
|
|
325
|
-
`,STRATAGATE_CLIENT_VERSION="0.3.54",MEMORY_CITATIONS_KIND="stratagate-memory-citations",MEMORY_RETRIEVAL_TOOLS=new Set(["memory_search_events","memory_search_graph","memory_expand_graph_node","memory_search_elements","memory_search_raw","memory_get_blocks","memory_expand_block","memory_expand_event","memory_expand_element"]);function readFeedbackDeepLink(locationRef=window.location){let params=new URLSearchParams(String(locationRef?.search||""));if(params.get("settings")!==FEEDBACK_SETTINGS_ID||params.get("stratagateView")!==FEEDBACK_VIEW_ID)return null;let namespace=String(params.get("namespace")||"").trim();return namespace?{namespace}:null}function readFeedbackNavigationState(state){if(!state||state.view!==FEEDBACK_VIEW_ID)return null;let namespace=String(state.namespace||"").trim();return namespace?{namespace}:null}function readNewFeedbackNavigationState(previousState,state){return state===previousState?null:readFeedbackNavigationState(state)}function readGraphNodeNavigationState(state){if(!state||state.view!=="graph-node")return null;let namespace=String(state.namespace||"").trim(),nodeId=String(state.nodeId||"").trim();return namespace&&nodeId?{namespace,nodeId}:null}function readGraphNodeDeepLink(locationRef=window.location){let params=new URLSearchParams(String(locationRef?.search||""));if(params.get("settings")!==FEEDBACK_SETTINGS_ID||params.get("stratagateView")!=="graph-node")return null;let namespace=String(params.get("namespace")||"").trim(),nodeId=String(params.get("nodeId")||"").trim();return namespace&&nodeId?{namespace,nodeId}:null}function consumeFeedbackDeepLink(locationRef=window.location,historyRef=window.history){let params=new URLSearchParams(String(locationRef?.search||""));params.delete("settings"),params.delete("stratagateView"),params.delete("namespace");let search=params.toString(),next2=String(locationRef?.pathname||"/")+(search?"?"+search:"")+String(locationRef?.hash||"");return historyRef?.replaceState?.(historyRef.state,"",next2),next2}function consumeGraphNodeDeepLink(locationRef=window.location,historyRef=window.history){let params=new URLSearchParams(String(locationRef?.search||""));params.delete("settings"),params.delete("stratagateView"),params.delete("namespace"),params.delete("nodeId");let search=params.toString(),next2=String(locationRef?.pathname||"/")+(search?"?"+search:"")+String(locationRef?.hash||"");return historyRef?.replaceState?.(historyRef.state,"",next2),next2}function isDesktopFeedbackSurface(locationRef){try{let url=new URL(String(locationRef?.href||""));return url.protocol==="dsh-app:"&&url.hostname==="app"}catch{return!1}}function desktopFeedbackOrigin(value){try{let url=new URL(String(value||""));return url.protocol==="http:"&&["127.0.0.1","localhost","[::1]"].includes(url.hostname)&&!url.username&&!url.password&&url.pathname==="/"&&!url.search&&!url.hash?url.origin:""}catch{return""}}function feedbackAnchorTarget(target,locationRef){let anchor=target?.closest?.("a[href]")||target?.parentElement?.closest?.("a[href]");if(!anchor)return null;let url;try{url=new URL(String(anchor.getAttribute?.("href")||""),String(locationRef?.href||""))}catch{return null}return!readFeedbackDeepLink(url)||url.pathname!=="/"||url.username||url.password?null:{anchor,url}}function feedbackLinkTarget(target,locationRef=window.location,desktopHostOrigin=""){let match2=feedbackAnchorTarget(target,locationRef);return match2&&(match2.url.origin===String(locationRef?.origin||"")||isDesktopFeedbackSurface(locationRef)&&desktopFeedbackOrigin(desktopHostOrigin)===match2.url.origin)?match2:null}function navigateToFeedback(ctx,targetUrl,locationRef=window.location,allowHttpFallback=!0){let feedback=readFeedbackDeepLink(targetUrl);if(!feedback)return"ignored";let navigation=ctx?.get?.("settingsNavigation");if(typeof navigation?.openSection=="function")return navigation.openSection(FEEDBACK_SETTINGS_ID,{view:FEEDBACK_VIEW_ID,namespace:feedback.namespace}),"host";let shell=ctx?.get?.("slots")?.entries?.("sidebar.settings")?.find(entry=>typeof entry.store?.create=="function")?.store.create();return typeof shell?.actions?.openSection=="function"?(setFeedbackNavigation({view:FEEDBACK_VIEW_ID,namespace:feedback.namespace}),shell.actions.openSection(FEEDBACK_SETTINGS_ID),"host"):(allowHttpFallback&&locationRef.assign(targetUrl.href),"http")}function navigateToGraphNode(ctx,namespace,nodeId,locationRef=window.location,allowHttpFallback=!0){let targetNamespace=String(namespace||"").trim(),targetNodeId=String(nodeId||"").trim();if(!targetNamespace||!targetNodeId)return Promise.resolve(!1);let navigation=ctx?.get?.("settingsNavigation");if(typeof navigation?.openSection!="function"){if(!allowHttpFallback||typeof locationRef?.assign!="function")return Promise.resolve(!1);try{let targetUrl=new URL(String(locationRef.href||""));return targetUrl.searchParams.set("settings",FEEDBACK_SETTINGS_ID),targetUrl.searchParams.set("stratagateView","graph-node"),targetUrl.searchParams.set("namespace",targetNamespace),targetUrl.searchParams.set("nodeId",targetNodeId),locationRef.assign(targetUrl.href),Promise.resolve(!0)}catch{return Promise.resolve(!1)}}try{return Promise.resolve(navigation.openSection(FEEDBACK_SETTINGS_ID,{view:"graph-node",namespace:targetNamespace,nodeId:targetNodeId})).then(result=>result!==!1,()=>!1)}catch{return Promise.resolve(!1)}}function installFeedbackLinkNavigation(ctx,documentRef=document,locationRef=window.location){let desktop=isDesktopFeedbackSurface(locationRef),active=!0,desktopHostOrigin="",bootPending=desktop&&typeof window.dshDesktopBoot?.ready=="function",replayingAnchor=null,bootReady=bootPending?Promise.resolve().then(()=>window.dshDesktopBoot.ready()).then(boot=>{active&&(desktopHostOrigin=desktopFeedbackOrigin(boot?.streamBaseUrl))}).catch(()=>{}).finally(()=>{bootPending=!1}):Promise.resolve(),takeClick=event3=>{event3.preventDefault(),event3.stopPropagation()},onClick=event3=>{if(event3.defaultPrevented||typeof event3.button=="number"&&event3.button!==0||event3.metaKey||event3.ctrlKey||event3.shiftKey||event3.altKey)return;let candidate=feedbackAnchorTarget(event3.target,locationRef);if(!candidate||candidate.anchor===replayingAnchor)return;let match2=feedbackLinkTarget(event3.target,locationRef,desktopHostOrigin);match2?(takeClick(event3),navigateToFeedback(ctx,match2.url,locationRef,!desktop)):bootPending&&desktopFeedbackOrigin(candidate.url.origin)&&(takeClick(event3),bootReady.then(()=>{if(active)if(candidate.url.origin===desktopHostOrigin)navigateToFeedback(ctx,candidate.url,locationRef,!1);else{replayingAnchor=candidate.anchor;try{candidate.anchor.click()}finally{replayingAnchor=null}}}))};return documentRef.addEventListener("click",onClick,!0),()=>{active=!1,documentRef.removeEventListener("click",onClick,!0)}}function exactInteractiveControl(labels,documentRef){let selector='button,[role="button"],[role="tab"],a',matches33=element3=>{let values=[element3.getAttribute?.("aria-label"),element3.getAttribute?.("title"),element3.textContent].map(value=>String(value||"").trim());return labels.some(label=>values.includes(label))},visible=element3=>!element3.hidden&&element3.getAttribute?.("aria-hidden")!=="true"&&(typeof element3.getClientRects!="function"||element3.getClientRects().length>0),direct=Array.from(documentRef.querySelectorAll(selector)).find(element3=>visible(element3)&&matches33(element3));if(direct)return direct;for(let element3 of Array.from(documentRef.querySelectorAll("*"))){if(String(element3.textContent||"").trim()!==labels[0])continue;let control=element3.closest?.(selector)||element3;if(visible(control)&&typeof control.click=="function")return control}return null}function openLegacyFeedbackDeepLink(documentRef=document){let observer=null,timer=null,settingsClicked=!1,sectionClicked=!1,cleanup=()=>{observer?.disconnect?.(),timer!==null&&window.clearTimeout(timer)},attempt=()=>{if(documentRef.querySelector('[data-testid="stratagate-memory-ui"]')){cleanup();return}if(!sectionClicked){let section=exactInteractiveControl(["StrataGate-AgentMemory"],documentRef);if(section){sectionClicked=!0,section.click();return}}if(!settingsClicked){let settings=exactInteractiveControl(["\u8BBE\u7F6E","Settings"],documentRef);settings&&(settingsClicked=!0,settings.click())}},Observer=window.MutationObserver||globalThis.MutationObserver;return typeof Observer=="function"&&(observer=new Observer(attempt),observer.observe(documentRef.documentElement||documentRef.body,{childList:!0,subtree:!0})),timer=window.setTimeout(cleanup,12e3),attempt(),cleanup}function openFeedbackDeepLink(ctx,documentRef=document,locationRef=window.location,historyRef=window.history){if(!readFeedbackDeepLink(locationRef))return()=>{};if(navigateToFeedback(ctx,locationRef,locationRef,!1)==="host")return consumeFeedbackDeepLink(locationRef,historyRef),()=>{};let legacyCleanup=()=>{},timer=window.setTimeout(()=>{legacyCleanup=openLegacyFeedbackDeepLink(documentRef)},250);return ctx?.inject?.(["settingsNavigation"],scope=>{navigateToFeedback(scope,locationRef,locationRef,!1)==="host"&&(window.clearTimeout(timer),legacyCleanup(),consumeFeedbackDeepLink(locationRef,historyRef))}),()=>{window.clearTimeout(timer),legacyCleanup()}}function openGraphNodeDeepLink(ctx,documentRef=document,locationRef=window.location,historyRef=window.history){let graphLink=readGraphNodeDeepLink(locationRef);if(!graphLink)return()=>{};if(typeof ctx?.get?.("settingsNavigation")?.openSection=="function")return navigateToGraphNode(ctx,graphLink.namespace,graphLink.nodeId,locationRef,!1).then(opened=>{opened&&consumeGraphNodeDeepLink(locationRef,historyRef)}),()=>{};let legacyCleanup=()=>{},timer=window.setTimeout(()=>{legacyCleanup=openLegacyFeedbackDeepLink(documentRef)},250);return ctx?.inject?.(["settingsNavigation"],scope=>{navigateToGraphNode(scope,graphLink.namespace,graphLink.nodeId,locationRef,!1).then(opened=>{opened&&(window.clearTimeout(timer),legacyCleanup(),consumeGraphNodeDeepLink(locationRef,historyRef))})}),()=>{window.clearTimeout(timer),legacyCleanup()}}let eventDetailCss=`
|
|
325
|
+
`,STRATAGATE_CLIENT_VERSION="0.3.55",MEMORY_CITATIONS_KIND="stratagate-memory-citations",MEMORY_RETRIEVAL_TOOLS=new Set(["memory_search_events","memory_search_graph","memory_expand_graph_node","memory_search_elements","memory_search_raw","memory_get_blocks","memory_expand_block","memory_expand_event","memory_expand_element"]);function readFeedbackDeepLink(locationRef=window.location){let params=new URLSearchParams(String(locationRef?.search||""));if(params.get("settings")!==FEEDBACK_SETTINGS_ID||params.get("stratagateView")!==FEEDBACK_VIEW_ID)return null;let namespace=String(params.get("namespace")||"").trim();return namespace?{namespace}:null}function readFeedbackNavigationState(state){if(!state||state.view!==FEEDBACK_VIEW_ID)return null;let namespace=String(state.namespace||"").trim();return namespace?{namespace}:null}function readNewFeedbackNavigationState(previousState,state){return state===previousState?null:readFeedbackNavigationState(state)}function readGraphNodeNavigationState(state){if(!state||state.view!=="graph-node")return null;let namespace=String(state.namespace||"").trim(),nodeId=String(state.nodeId||"").trim();return namespace&&nodeId?{namespace,nodeId}:null}function readGraphNodeDeepLink(locationRef=window.location){let params=new URLSearchParams(String(locationRef?.search||""));if(params.get("settings")!==FEEDBACK_SETTINGS_ID||params.get("stratagateView")!=="graph-node")return null;let namespace=String(params.get("namespace")||"").trim(),nodeId=String(params.get("nodeId")||"").trim();return namespace&&nodeId?{namespace,nodeId}:null}function consumeFeedbackDeepLink(locationRef=window.location,historyRef=window.history){let params=new URLSearchParams(String(locationRef?.search||""));params.delete("settings"),params.delete("stratagateView"),params.delete("namespace");let search=params.toString(),next2=String(locationRef?.pathname||"/")+(search?"?"+search:"")+String(locationRef?.hash||"");return historyRef?.replaceState?.(historyRef.state,"",next2),next2}function consumeGraphNodeDeepLink(locationRef=window.location,historyRef=window.history){let params=new URLSearchParams(String(locationRef?.search||""));params.delete("settings"),params.delete("stratagateView"),params.delete("namespace"),params.delete("nodeId");let search=params.toString(),next2=String(locationRef?.pathname||"/")+(search?"?"+search:"")+String(locationRef?.hash||"");return historyRef?.replaceState?.(historyRef.state,"",next2),next2}function isDesktopFeedbackSurface(locationRef){try{let url=new URL(String(locationRef?.href||""));return url.protocol==="dsh-app:"&&url.hostname==="app"}catch{return!1}}function desktopFeedbackOrigin(value){try{let url=new URL(String(value||""));return url.protocol==="http:"&&["127.0.0.1","localhost","[::1]"].includes(url.hostname)&&!url.username&&!url.password&&url.pathname==="/"&&!url.search&&!url.hash?url.origin:""}catch{return""}}function feedbackAnchorTarget(target,locationRef){let anchor=target?.closest?.("a[href]")||target?.parentElement?.closest?.("a[href]");if(!anchor)return null;let url;try{url=new URL(String(anchor.getAttribute?.("href")||""),String(locationRef?.href||""))}catch{return null}return!readFeedbackDeepLink(url)||url.pathname!=="/"||url.username||url.password?null:{anchor,url}}function feedbackLinkTarget(target,locationRef=window.location,desktopHostOrigin=""){let match2=feedbackAnchorTarget(target,locationRef);return match2&&(match2.url.origin===String(locationRef?.origin||"")||isDesktopFeedbackSurface(locationRef)&&desktopFeedbackOrigin(desktopHostOrigin)===match2.url.origin)?match2:null}function navigateToFeedback(ctx,targetUrl,locationRef=window.location,allowHttpFallback=!0){let feedback=readFeedbackDeepLink(targetUrl);if(!feedback)return"ignored";let navigation=ctx?.get?.("settingsNavigation");if(typeof navigation?.openSection=="function")return navigation.openSection(FEEDBACK_SETTINGS_ID,{view:FEEDBACK_VIEW_ID,namespace:feedback.namespace}),"host";let shell=ctx?.get?.("slots")?.entries?.("sidebar.settings")?.find(entry=>typeof entry.store?.create=="function")?.store.create();return typeof shell?.actions?.openSection=="function"?(setFeedbackNavigation({view:FEEDBACK_VIEW_ID,namespace:feedback.namespace}),shell.actions.openSection(FEEDBACK_SETTINGS_ID),"host"):(allowHttpFallback&&locationRef.assign(targetUrl.href),"http")}function navigateToGraphNode(ctx,namespace,nodeId,locationRef=window.location,allowHttpFallback=!0){let targetNamespace=String(namespace||"").trim(),targetNodeId=String(nodeId||"").trim();if(!targetNamespace||!targetNodeId)return Promise.resolve(!1);let navigation=ctx?.get?.("settingsNavigation");if(typeof navigation?.openSection!="function"){if(!allowHttpFallback||typeof locationRef?.assign!="function")return Promise.resolve(!1);try{let targetUrl=new URL(String(locationRef.href||""));return targetUrl.searchParams.set("settings",FEEDBACK_SETTINGS_ID),targetUrl.searchParams.set("stratagateView","graph-node"),targetUrl.searchParams.set("namespace",targetNamespace),targetUrl.searchParams.set("nodeId",targetNodeId),locationRef.assign(targetUrl.href),Promise.resolve(!0)}catch{return Promise.resolve(!1)}}try{return Promise.resolve(navigation.openSection(FEEDBACK_SETTINGS_ID,{view:"graph-node",namespace:targetNamespace,nodeId:targetNodeId})).then(result=>result!==!1,()=>!1)}catch{return Promise.resolve(!1)}}function installFeedbackLinkNavigation(ctx,documentRef=document,locationRef=window.location){let desktop=isDesktopFeedbackSurface(locationRef),active=!0,desktopHostOrigin="",bootPending=desktop&&typeof window.dshDesktopBoot?.ready=="function",replayingAnchor=null,bootReady=bootPending?Promise.resolve().then(()=>window.dshDesktopBoot.ready()).then(boot=>{active&&(desktopHostOrigin=desktopFeedbackOrigin(boot?.streamBaseUrl))}).catch(()=>{}).finally(()=>{bootPending=!1}):Promise.resolve(),takeClick=event3=>{event3.preventDefault(),event3.stopPropagation()},onClick=event3=>{if(event3.defaultPrevented||typeof event3.button=="number"&&event3.button!==0||event3.metaKey||event3.ctrlKey||event3.shiftKey||event3.altKey)return;let candidate=feedbackAnchorTarget(event3.target,locationRef);if(!candidate||candidate.anchor===replayingAnchor)return;let match2=feedbackLinkTarget(event3.target,locationRef,desktopHostOrigin);match2?(takeClick(event3),navigateToFeedback(ctx,match2.url,locationRef,!desktop)):bootPending&&desktopFeedbackOrigin(candidate.url.origin)&&(takeClick(event3),bootReady.then(()=>{if(active)if(candidate.url.origin===desktopHostOrigin)navigateToFeedback(ctx,candidate.url,locationRef,!1);else{replayingAnchor=candidate.anchor;try{candidate.anchor.click()}finally{replayingAnchor=null}}}))};return documentRef.addEventListener("click",onClick,!0),()=>{active=!1,documentRef.removeEventListener("click",onClick,!0)}}function exactInteractiveControl(labels,documentRef){let selector='button,[role="button"],[role="tab"],a',matches33=element3=>{let values=[element3.getAttribute?.("aria-label"),element3.getAttribute?.("title"),element3.textContent].map(value=>String(value||"").trim());return labels.some(label=>values.includes(label))},visible=element3=>!element3.hidden&&element3.getAttribute?.("aria-hidden")!=="true"&&(typeof element3.getClientRects!="function"||element3.getClientRects().length>0),direct=Array.from(documentRef.querySelectorAll(selector)).find(element3=>visible(element3)&&matches33(element3));if(direct)return direct;for(let element3 of Array.from(documentRef.querySelectorAll("*"))){if(String(element3.textContent||"").trim()!==labels[0])continue;let control=element3.closest?.(selector)||element3;if(visible(control)&&typeof control.click=="function")return control}return null}function openLegacyFeedbackDeepLink(documentRef=document){let observer=null,timer=null,settingsClicked=!1,sectionClicked=!1,cleanup=()=>{observer?.disconnect?.(),timer!==null&&window.clearTimeout(timer)},attempt=()=>{if(documentRef.querySelector('[data-testid="stratagate-memory-ui"]')){cleanup();return}if(!sectionClicked){let section=exactInteractiveControl(["StrataGate-AgentMemory"],documentRef);if(section){sectionClicked=!0,section.click();return}}if(!settingsClicked){let settings=exactInteractiveControl(["\u8BBE\u7F6E","Settings"],documentRef);settings&&(settingsClicked=!0,settings.click())}},Observer=window.MutationObserver||globalThis.MutationObserver;return typeof Observer=="function"&&(observer=new Observer(attempt),observer.observe(documentRef.documentElement||documentRef.body,{childList:!0,subtree:!0})),timer=window.setTimeout(cleanup,12e3),attempt(),cleanup}function openFeedbackDeepLink(ctx,documentRef=document,locationRef=window.location,historyRef=window.history){if(!readFeedbackDeepLink(locationRef))return()=>{};if(navigateToFeedback(ctx,locationRef,locationRef,!1)==="host")return consumeFeedbackDeepLink(locationRef,historyRef),()=>{};let legacyCleanup=()=>{},timer=window.setTimeout(()=>{legacyCleanup=openLegacyFeedbackDeepLink(documentRef)},250);return ctx?.inject?.(["settingsNavigation"],scope=>{navigateToFeedback(scope,locationRef,locationRef,!1)==="host"&&(window.clearTimeout(timer),legacyCleanup(),consumeFeedbackDeepLink(locationRef,historyRef))}),()=>{window.clearTimeout(timer),legacyCleanup()}}function openGraphNodeDeepLink(ctx,documentRef=document,locationRef=window.location,historyRef=window.history){let graphLink=readGraphNodeDeepLink(locationRef);if(!graphLink)return()=>{};if(typeof ctx?.get?.("settingsNavigation")?.openSection=="function")return navigateToGraphNode(ctx,graphLink.namespace,graphLink.nodeId,locationRef,!1).then(opened=>{opened&&consumeGraphNodeDeepLink(locationRef,historyRef)}),()=>{};let legacyCleanup=()=>{},timer=window.setTimeout(()=>{legacyCleanup=openLegacyFeedbackDeepLink(documentRef)},250);return ctx?.inject?.(["settingsNavigation"],scope=>{navigateToGraphNode(scope,graphLink.namespace,graphLink.nodeId,locationRef,!1).then(opened=>{opened&&(window.clearTimeout(timer),legacyCleanup(),consumeGraphNodeDeepLink(locationRef,historyRef))})}),()=>{window.clearTimeout(timer),legacyCleanup()}}let eventDetailCss=`
|
|
326
326
|
.sg-event-metadata{display:flex;align-items:center;gap:7px 16px;flex-wrap:wrap;margin-top:8px;color:var(--sg-muted);font-size:12px;line-height:1.45}.sg-event-metadata-item{display:inline-flex;align-items:center;gap:5px;min-width:0}.sg-event-metadata b{color:var(--sg-muted);font-weight:620}.sg-event-participants{display:inline-flex;align-items:center;gap:5px;flex-wrap:wrap}.sg-event-metadata .sg-entity-pill{padding:2px 7px}.sg-entity-pill-static{cursor:default;opacity:.82}.sg-entity-pill-static:hover{transform:none!important;background:transparent!important}.sg-event-section{display:grid;gap:9px;padding:17px 0;border-bottom:1px solid var(--sg-border)}.sg-event-section-title{margin:0;color:var(--sg-text);font-size:14px;font-weight:730}.sg-event-memory-copy{max-width:65ch;margin:0;color:var(--sg-text);font-size:14px;line-height:1.72;white-space:pre-wrap;overflow-wrap:anywhere;text-wrap:pretty}.sg-event-weight-section{gap:0}
|
|
327
327
|
.sg-weight-header{display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin-bottom:9px}.sg-weight-header .sg-section-title,.sg-long-detail .sg-weight-header h3{margin:0}.sg-weight-metrics{display:grid!important;grid-template-columns:1fr!important;gap:0!important;margin:0 0 13px!important}.sg-weight-metric{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:14px;min-width:0;padding:7px 2px!important;border-bottom:1px solid color-mix(in srgb,var(--sg-border) 72%,transparent);border-radius:0!important;background:transparent!important}.sg-weight-metric:last-child{border-bottom:0}.sg-weight-metric>span:first-child{color:var(--sg-muted);font-size:12px}.sg-weight-metric strong{margin:0!important;color:var(--sg-text);font-size:15px!important;font-weight:740;font-variant-numeric:tabular-nums;white-space:nowrap}.sg-weight-value{display:inline-flex!important;align-items:center;justify-content:flex-end;gap:6px;color:var(--sg-text)!important}
|
|
328
328
|
.sg-info-disclosure{position:relative;display:inline-flex}.sg-info-trigger{display:grid;place-items:center;width:19px;height:19px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--sg-muted);font-size:13px;line-height:1;cursor:pointer}.sg-info-trigger:hover,.sg-info-trigger[aria-expanded="true"]{background:var(--sg-soft);color:var(--sg-text)}.sg-info-popover{position:absolute;right:0;top:calc(100% + 7px);z-index:20;width:min(320px,calc(100vw - 40px));padding:13px 14px;border:1px solid color-mix(in srgb,var(--sg-accent) 20%,var(--sg-border));border-radius:9px;background:var(--sg-page);color:var(--sg-text);box-shadow:0 14px 36px color-mix(in srgb,var(--sg-text) 18%,transparent);font-size:12px;line-height:1.58;text-align:left}.sg-info-title{display:block;margin-bottom:7px;font-size:13px}.sg-info-popover p{margin:0;color:var(--sg-muted)}.sg-info-popover p+p{margin-top:7px}.sg-adoption-history{display:grid;gap:10px;margin:0;padding:0;list-style:none;counter-reset:history}.sg-adoption-history li{display:grid;gap:1px;padding-bottom:9px;border-bottom:1px solid var(--sg-border)}.sg-adoption-history li:last-child{padding-bottom:0;border-bottom:0}.sg-adoption-history time,.sg-adoption-history span{color:var(--sg-muted)}.sg-floor-table{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:4px 14px;margin:10px 0 0;padding-top:9px;border-top:1px solid var(--sg-border)}.sg-floor-table dt,.sg-floor-table dd{margin:0;color:var(--sg-muted)}.sg-floor-table .current{color:var(--sg-accent);font-weight:720}
|
package/dist/plugin.js
CHANGED
|
@@ -2445,6 +2445,7 @@ import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
|
2445
2445
|
|
|
2446
2446
|
// packages/core/src/topic-diagnostics.ts
|
|
2447
2447
|
var TOPIC_OVERVIEW_MAX_CHARACTERS = 1e3;
|
|
2448
|
+
var LEGACY_TOPIC_OVERVIEW_SECTION_ERROR = "New topic overview must match a final topic section.";
|
|
2448
2449
|
var categories = [
|
|
2449
2450
|
"max-tokens",
|
|
2450
2451
|
"schema-invalid",
|
|
@@ -2468,7 +2469,7 @@ var TOPIC_SAFE_REASONS = /* @__PURE__ */ new Set([
|
|
|
2468
2469
|
"Invalid topic section source events.",
|
|
2469
2470
|
"Invalid topic sections.",
|
|
2470
2471
|
"Invalid topic title or description.",
|
|
2471
|
-
|
|
2472
|
+
LEGACY_TOPIC_OVERVIEW_SECTION_ERROR,
|
|
2472
2473
|
"Old overview evidence must be preserved verbatim; new sections need batch events.",
|
|
2473
2474
|
"Old section membership must be preserved; reassignment needs batch events.",
|
|
2474
2475
|
"Overview references must belong to returned topic membership.",
|
|
@@ -2600,7 +2601,7 @@ var MEMORY_TOPIC_PROJECTOR_VERSION = 3;
|
|
|
2600
2601
|
var TOPIC_BATCH_LIMIT = 12;
|
|
2601
2602
|
var TOPIC_CANDIDATE_LIMIT = 12;
|
|
2602
2603
|
var TOPIC_MAX_ATTEMPTS = 3;
|
|
2603
|
-
var TOPIC_RECOVERY_VERSION =
|
|
2604
|
+
var TOPIC_RECOVERY_VERSION = 3;
|
|
2604
2605
|
var TOPIC_LEASE_MS = 5 * 6e4;
|
|
2605
2606
|
function canonical(value) {
|
|
2606
2607
|
if (Array.isArray(value)) return value.map(canonical);
|
|
@@ -2632,31 +2633,32 @@ var SECTION_TITLES = {
|
|
|
2632
2633
|
function memoryTopicSectionTitle(part) {
|
|
2633
2634
|
return part.title?.trim() || SECTION_TITLES[part.kind] || "\u4E3B\u9898\u6982\u89C8";
|
|
2634
2635
|
}
|
|
2635
|
-
var
|
|
2636
|
+
var normalizeMemoryTopicLabel = (value) => value.normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
2636
2637
|
function memoryTopicOverviewMatchesSection(part, titles) {
|
|
2637
|
-
const display =
|
|
2638
|
-
return titles.some((title) =>
|
|
2638
|
+
const display = normalizeMemoryTopicLabel(memoryTopicSectionTitle(part));
|
|
2639
|
+
return titles.some((title) => normalizeMemoryTopicLabel(title) === display);
|
|
2639
2640
|
}
|
|
2640
2641
|
function memoryTopicMembershipSections(topic) {
|
|
2641
2642
|
if (topic.sections !== void 0) return structuredClone(topic.sections);
|
|
2642
2643
|
const sections = /* @__PURE__ */ new Map();
|
|
2643
2644
|
for (const part of topic.overview) {
|
|
2644
2645
|
const title = memoryTopicSectionTitle(part);
|
|
2645
|
-
const key =
|
|
2646
|
+
const key = normalizeMemoryTopicLabel(title);
|
|
2646
2647
|
const section = sections.get(key) ?? { title, sourceEventIds: [] };
|
|
2647
2648
|
section.sourceEventIds = unique2([...section.sourceEventIds, ...part.sourceEventIds]);
|
|
2648
2649
|
sections.set(key, section);
|
|
2649
2650
|
}
|
|
2650
2651
|
return [...sections.values()];
|
|
2651
2652
|
}
|
|
2652
|
-
function
|
|
2653
|
-
const
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2653
|
+
function memoryTopicSectionContent(topic) {
|
|
2654
|
+
const members = new Set(topic.sourceEventIds);
|
|
2655
|
+
const sections = memoryTopicMembershipSections(topic).map((section) => ({
|
|
2656
|
+
...section,
|
|
2657
|
+
sourceEventIds: section.sourceEventIds.filter((id) => members.has(id))
|
|
2658
|
+
})).filter((section) => section.sourceEventIds.length > 0);
|
|
2659
|
+
const labels = new Set(sections.map((section) => normalizeMemoryTopicLabel(section.title)));
|
|
2660
|
+
const overview2 = topic.overview.filter((part) => labels.has(normalizeMemoryTopicLabel(memoryTopicSectionTitle(part))));
|
|
2661
|
+
return { sections, overview: overview2 };
|
|
2660
2662
|
}
|
|
2661
2663
|
function sourceVersions(sources2) {
|
|
2662
2664
|
return new Map([...sources2].map(([id, event]) => [id, memoryTopicEventFingerprint(event)]));
|
|
@@ -2672,15 +2674,15 @@ function topicView(topic, events, versions) {
|
|
|
2672
2674
|
const ids2 = topic.sourceEventIds.filter((id) => events.has(id));
|
|
2673
2675
|
if (ids2.length === 0) return null;
|
|
2674
2676
|
const valid = !topic.invalidated && topic.projectorVersion === MEMORY_TOPIC_PROJECTOR_VERSION && ids2.length === topic.sourceEventIds.length && Object.entries(topic.dependencyVersions ?? topic.sourceVersions).every(([id, version]) => versions.get(id) === version);
|
|
2675
|
-
const overview2 = valid ?
|
|
2677
|
+
const { sections, overview: overview2 } = valid ? memoryTopicSectionContent(topic) : { sections: [], overview: [] };
|
|
2676
2678
|
const summarized = new Set(overview2.flatMap((part) => part.sourceEventIds));
|
|
2677
2679
|
return {
|
|
2678
2680
|
id: topic.id,
|
|
2679
2681
|
title: valid ? topic.title : "\u5F85\u66F4\u65B0\u8BB0\u5FC6\u4E3B\u9898",
|
|
2680
2682
|
description: valid ? topic.description : "\u6982\u89C8\u7B49\u5F85\u91CD\u65B0\u6574\u7406\uFF0C\u8BF7\u67E5\u770B\u5173\u8054\u4E8B\u4EF6\u3002",
|
|
2681
2683
|
sourceEventIds: ids2,
|
|
2682
|
-
overview: overview2,
|
|
2683
|
-
sections
|
|
2684
|
+
overview: structuredClone(overview2),
|
|
2685
|
+
sections,
|
|
2684
2686
|
...valid && topic.sectionAliases ? { sectionAliases: structuredClone(topic.sectionAliases) } : {},
|
|
2685
2687
|
createdAt: topic.createdAt,
|
|
2686
2688
|
updatedAt: topic.updatedAt,
|
|
@@ -2727,6 +2729,7 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
2727
2729
|
for (const id of retained(part.sourceEventIds)) needsOverview.add(id);
|
|
2728
2730
|
return false;
|
|
2729
2731
|
});
|
|
2732
|
+
Object.assign(topic, memoryTopicSectionContent(topic));
|
|
2730
2733
|
topic.sourceVersions = Object.fromEntries(topic.sourceEventIds.map((id) => [id, versions.get(id)]));
|
|
2731
2734
|
topic.dependencyVersions = Object.fromEntries(retained(Object.keys(topic.dependencyVersions ?? {})).map((id) => [id, versions.get(id)]));
|
|
2732
2735
|
topic.updatedAt = now;
|
|
@@ -2815,14 +2818,16 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
2815
2818
|
this.synchronize(events, now);
|
|
2816
2819
|
}
|
|
2817
2820
|
recoverFailures(events, now) {
|
|
2818
|
-
|
|
2821
|
+
const previousVersion = this.state.recoveryVersion ?? 0;
|
|
2822
|
+
if (previousVersion >= TOPIC_RECOVERY_VERSION) return;
|
|
2819
2823
|
this.state.recoveryVersion = TOPIC_RECOVERY_VERSION;
|
|
2820
2824
|
const versions = sourceVersions(new Map(events.filter(visible).map((event) => [event.id, event])));
|
|
2821
2825
|
for (const previous of [...this.state.jobs]) {
|
|
2822
2826
|
if (previous.superseded || previous.status !== "failed" || previous.attempts < TOPIC_MAX_ATTEMPTS || previous.nextRetryAt !== null || !jobInputsCurrent(previous, versions)) continue;
|
|
2823
2827
|
const diagnostic = safeTopicDiagnostics(previous.diagnostics);
|
|
2824
|
-
const
|
|
2825
|
-
|
|
2828
|
+
const legacyOverviewFailure = previousVersion < 2 && (!!previous.overviewRepairRequirements?.length || diagnostic?.category === "provider-failed" || (diagnostic?.category === "validation-failed" || diagnostic?.category === "schema-invalid") && (diagnostic.reason.startsWith("overview.text ") || diagnostic.reason === "Topic retry must replace invalid overview without removing entries.") || previous.lastError === "invalid-output" || /^(?:validation-failed|schema-invalid): (?:overview\.text |Topic retry must replace invalid overview)/.test(previous.lastError ?? ""));
|
|
2829
|
+
const removedSectionFailure = diagnostic?.category === "validation-failed" && diagnostic.reason === LEGACY_TOPIC_OVERVIEW_SECTION_ERROR || previous.lastError === `validation-failed: ${LEGACY_TOPIC_OVERVIEW_SECTION_ERROR}`;
|
|
2830
|
+
if (!legacyOverviewFailure && !removedSectionFailure) continue;
|
|
2826
2831
|
const work = memoryTopicUnfinishedJobEventIds(previous, this.state, versions);
|
|
2827
2832
|
if (!work.length) continue;
|
|
2828
2833
|
const ids2 = work.filter((id) => !this.state.jobs.some((job) => job.id !== previous.id && !job.superseded && jobInputsCurrent(job, versions) && job.sectionBackfillTopicId === previous.sectionBackfillTopicId && job.sourceVersions[id] === versions.get(id) && (job.status === "pending" || job.status === "running" || job.status === "failed" && job.attempts < TOPIC_MAX_ATTEMPTS && job.nextRetryAt !== null)));
|
|
@@ -3061,7 +3066,7 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
3061
3066
|
const lexicalScores = new Map(bm25Rank(eligibleTopics, query, (topic) => weightedSearchTokens([
|
|
3062
3067
|
[topic.title, 8],
|
|
3063
3068
|
[topic.description, 2],
|
|
3064
|
-
[
|
|
3069
|
+
[topic.sections?.map((section) => section.title).join(" ") ?? "", 6],
|
|
3065
3070
|
// Route broad chapters by bounded member hints as well. These hints
|
|
3066
3071
|
// select candidates locally; they are never new factual model evidence.
|
|
3067
3072
|
[topic.sourceEventIds.slice(0, 3).concat(topic.sourceEventIds.slice(-3)).flatMap((id) => {
|
|
@@ -3079,7 +3084,7 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
3079
3084
|
...overview2.flatMap((part) => part.sourceEventIds),
|
|
3080
3085
|
...topic.sourceEventIds.filter((id) => batchIds.has(id))
|
|
3081
3086
|
]);
|
|
3082
|
-
const allTitles =
|
|
3087
|
+
const allTitles = topic.sections?.map((section) => section.title) ?? [];
|
|
3083
3088
|
let titleBudget = 4e3;
|
|
3084
3089
|
const shownTitles = job.sectionBackfillTopicId ? allTitles.filter((title, index) => {
|
|
3085
3090
|
const cost2 = JSON.stringify(title).length;
|
|
@@ -3168,7 +3173,7 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
3168
3173
|
const ids2 = checkIds(proposal.sourceEventIds, "membership");
|
|
3169
3174
|
const matching = this.state.topics.filter((topic) => candidates.has(topic.id) && topic.sourceEventIds.some((eventId) => ids2.includes(eventId)));
|
|
3170
3175
|
const inferred = matching.length === 1 && result.topics.filter((other) => Array.isArray(other.sourceEventIds) && matching[0].sourceEventIds.some((eventId) => other.sourceEventIds.includes(eventId))).length === 1 ? matching[0] : void 0;
|
|
3171
|
-
const label2 =
|
|
3176
|
+
const label2 = normalizeMemoryTopicLabel;
|
|
3172
3177
|
const sameLabel = typeof proposal.title === "string" ? this.state.topics.filter((topic) => !topic.invalidated && label2(topic.title) === label2(proposal.title)) : [];
|
|
3173
3178
|
if (sameLabel.some((topic) => !candidates.has(topic.id))) {
|
|
3174
3179
|
throw new TopicProjectionError("validation-failed", "Invalid duplicate chapter label matches an unexposed existing topic.");
|
|
@@ -3224,16 +3229,8 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
3224
3229
|
if (section) section.sourceEventIds = unique2([...section.sourceEventIds, ...incoming]);
|
|
3225
3230
|
else sections.push({ title: assignment.title.trim(), sourceEventIds: [...incoming] });
|
|
3226
3231
|
}
|
|
3227
|
-
const finalSections = sections.filter((section) => section.sourceEventIds.length > 0);
|
|
3228
|
-
const titles = finalSections.map((section) => section.title);
|
|
3229
3232
|
const inherited = existing && !existing.invalidated ? existing.overview : [];
|
|
3230
|
-
|
|
3231
|
-
if (!inherited.some((old) => digest(old) === digest(part)) && !memoryTopicOverviewMatchesSection(part, titles)) {
|
|
3232
|
-
throw new TopicProjectionError("validation-failed", "New topic overview must match a final topic section.");
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
const overview2 = uniqueTopicOverviewEntries(proposal.overview.filter((part) => memoryTopicOverviewMatchesSection(part, titles))).map((part) => structuredClone(part));
|
|
3236
|
-
for (const part of inherited) if (memoryTopicOverviewMatchesSection(part, titles) && !overview2.some((current) => digest(current) === digest(part))) overview2.push(structuredClone(part));
|
|
3233
|
+
const content = memoryTopicSectionContent({ sourceEventIds: membership, sections, overview: [...proposal.overview, ...inherited] });
|
|
3237
3234
|
proposals.push({
|
|
3238
3235
|
id: topicId,
|
|
3239
3236
|
title: job.sectionBackfillTopicId || existing?.dreamingManaged ? existing.title : proposal.title.trim(),
|
|
@@ -3241,8 +3238,8 @@ var MemoryTopicDirectory = class _MemoryTopicDirectory {
|
|
|
3241
3238
|
...existing?.sectionAliases ? { sectionAliases: structuredClone(existing.sectionAliases) } : {},
|
|
3242
3239
|
description: job.sectionBackfillTopicId || existing?.dreamingManaged ? existing.description : proposal.description.trim(),
|
|
3243
3240
|
sourceEventIds: membership,
|
|
3244
|
-
|
|
3245
|
-
|
|
3241
|
+
sections: content.sections,
|
|
3242
|
+
overview: structuredClone(uniqueTopicOverviewEntries(content.overview)),
|
|
3246
3243
|
sourceVersions: Object.fromEntries(membership.map((eventId) => [eventId, versions.get(eventId)])),
|
|
3247
3244
|
dependencyVersions: { ...!existing?.invalidated ? existing?.dependencyVersions ?? {} : {}, ...job.dependencyVersions },
|
|
3248
3245
|
projectorVersion: MEMORY_TOPIC_PROJECTOR_VERSION,
|
|
@@ -3507,7 +3504,7 @@ function label(value, maximum = 80) {
|
|
|
3507
3504
|
return value.trim();
|
|
3508
3505
|
}
|
|
3509
3506
|
function memoryTopicSectionIdentity(title) {
|
|
3510
|
-
return "section:" + createHash3("sha256").update(title
|
|
3507
|
+
return "section:" + createHash3("sha256").update(normalizeMemoryTopicLabel(title)).digest("hex");
|
|
3511
3508
|
}
|
|
3512
3509
|
function live(event) {
|
|
3513
3510
|
return event.status !== "forgotten" && event.status !== "archived";
|
|
@@ -3825,7 +3822,9 @@ function updateDreaming(state, events, command, now) {
|
|
|
3825
3822
|
const readTopic = state.topics.find((t) => t.id === command.trace.args.id && !t.invalidated && t.sourceEventIds.every((id) => sources2.has(id) && run.sourceVersions[id] === memoryTopicEventFingerprint(sources2.get(id))));
|
|
3826
3823
|
const result = command.trace.result;
|
|
3827
3824
|
if (readTopic && result?.id === readTopic.id) {
|
|
3828
|
-
|
|
3825
|
+
const content = memoryTopicSectionContent(readTopic);
|
|
3826
|
+
for (const field of ["sections", "overview"]) {
|
|
3827
|
+
const items2 = content[field];
|
|
3829
3828
|
const page2 = result[field];
|
|
3830
3829
|
if (!page2 || !Number.isSafeInteger(page2.offset) || page2.offset < 0 || !Array.isArray(page2.items) || !page2.items.length || page2.total !== items2.length || page2.offset + page2.items.length > items2.length || page2.contentVersion !== dreamingTopicVersion(items2) || JSON.stringify(page2.items) !== JSON.stringify(items2.slice(page2.offset, page2.offset + page2.items.length)) || page2.nextOffset !== (page2.offset + page2.items.length < items2.length ? page2.offset + page2.items.length : null)) continue;
|
|
3831
3830
|
const key = JSON.stringify([readTopic.id, field]);
|
|
@@ -3868,6 +3867,7 @@ function updateDreaming(state, events, command, now) {
|
|
|
3868
3867
|
const updated = structuredClone(topic);
|
|
3869
3868
|
const sections = updated.sections = memoryTopicMembershipSections(updated);
|
|
3870
3869
|
for (const section of sections) section.id ??= memoryTopicSectionIdentity(section.title);
|
|
3870
|
+
const findSection = (title) => sections.find((section) => normalizeMemoryTopicLabel(section.title) === normalizeMemoryTopicLabel(title));
|
|
3871
3871
|
const members = new Set(updated.sourceEventIds);
|
|
3872
3872
|
if (!Array.isArray(command.operations) || !command.operations.length) throw new Error("Directory operations are required");
|
|
3873
3873
|
for (const op of command.operations) {
|
|
@@ -3880,23 +3880,27 @@ function updateDreaming(state, events, command, now) {
|
|
|
3880
3880
|
updated.description = op.description;
|
|
3881
3881
|
}
|
|
3882
3882
|
} else if (op.kind === "rename-section") {
|
|
3883
|
-
const section =
|
|
3883
|
+
const section = typeof op.from === "string" ? findSection(op.from) : void 0;
|
|
3884
3884
|
if (!section) throw new Error("Unknown section");
|
|
3885
3885
|
const title = label(op.title);
|
|
3886
|
-
|
|
3886
|
+
const target = findSection(title);
|
|
3887
|
+
if (target && target !== section) throw new Error("Duplicate section");
|
|
3887
3888
|
section.title = title;
|
|
3888
3889
|
for (const part of updated.overview) if (memoryTopicOverviewMatchesSection(part, [op.from])) part.title = title;
|
|
3889
3890
|
} else if (op.kind === "merge-sections") {
|
|
3890
|
-
if (!Array.isArray(op.from) || op.from.length < 2
|
|
3891
|
+
if (!Array.isArray(op.from) || op.from.length < 2) throw new Error("Invalid merge sources");
|
|
3892
|
+
const selected = new Set(op.from.map((name2) => typeof name2 === "string" ? findSection(name2) : void 0));
|
|
3893
|
+
if (selected.has(void 0) || selected.size !== op.from.length) throw new Error("Invalid merge sources");
|
|
3894
|
+
const merged = sections.filter((section) => selected.has(section));
|
|
3891
3895
|
const title = label(op.title);
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
const
|
|
3896
|
+
const target = findSection(title);
|
|
3897
|
+
if (target && !selected.has(target)) throw new Error("Duplicate section");
|
|
3898
|
+
const ids2 = [...new Set(merged.flatMap((section) => section.sourceEventIds))];
|
|
3895
3899
|
const stableId = merged[0].id;
|
|
3896
3900
|
updated.sectionAliases ??= {};
|
|
3897
3901
|
for (const section of merged) if (section.id !== stableId) updated.sectionAliases[section.id] = stableId;
|
|
3898
|
-
for (const [old,
|
|
3899
|
-
for (let i = sections.length - 1; i >= 0; i--) if (
|
|
3902
|
+
for (const [old, target2] of Object.entries(updated.sectionAliases)) if (merged.some((section) => section.id === target2)) updated.sectionAliases[old] = stableId;
|
|
3903
|
+
for (let i = sections.length - 1; i >= 0; i--) if (selected.has(sections[i])) sections.splice(i, 1);
|
|
3900
3904
|
sections.push({ id: stableId, title, sourceEventIds: ids2 });
|
|
3901
3905
|
for (const part of updated.overview) if (memoryTopicOverviewMatchesSection(part, op.from)) part.title = title;
|
|
3902
3906
|
} else if (op.kind === "move-events") {
|
|
@@ -3913,7 +3917,7 @@ function updateDreaming(state, events, command, now) {
|
|
|
3913
3917
|
(updated.dependencyVersions ??= {})[id] = version;
|
|
3914
3918
|
}
|
|
3915
3919
|
}
|
|
3916
|
-
let target =
|
|
3920
|
+
let target = findSection(title);
|
|
3917
3921
|
if (!target) {
|
|
3918
3922
|
target = { id: `section:${randomUUID2()}`, title, sourceEventIds: [] };
|
|
3919
3923
|
sections.push(target);
|
|
@@ -3921,9 +3925,17 @@ function updateDreaming(state, events, command, now) {
|
|
|
3921
3925
|
for (const section of sections) section.sourceEventIds = section.sourceEventIds.filter((id) => !op.eventIds.includes(id));
|
|
3922
3926
|
target.sourceEventIds.push(...new Set(op.eventIds));
|
|
3923
3927
|
} else if (op.kind === "set-overview" || op.kind === "append-overview" || op.kind === "rewrite-overview") {
|
|
3924
|
-
const
|
|
3925
|
-
if (!Array.isArray(
|
|
3926
|
-
|
|
3928
|
+
const requested = op.kind === "rewrite-overview" ? op.titles : [op.title];
|
|
3929
|
+
if (!Array.isArray(requested) || !requested.length || requested.some((title) => label(title) !== title)) {
|
|
3930
|
+
throw new Error("overview-sections-invalid: titles must be distinct existing section names");
|
|
3931
|
+
}
|
|
3932
|
+
const titles = requested.map((title) => {
|
|
3933
|
+
const section = findSection(title);
|
|
3934
|
+
if (!section) throw new Error(`overview-section-unknown: ${JSON.stringify(title)}; create it with move-events before writing its overview`);
|
|
3935
|
+
return section.title;
|
|
3936
|
+
});
|
|
3937
|
+
const titlesByLabel = new Map(titles.map((title) => [normalizeMemoryTopicLabel(title), title]));
|
|
3938
|
+
if (titlesByLabel.size !== titles.length) throw new Error("overview-sections-invalid: titles must be distinct existing section names");
|
|
3927
3939
|
if (!Array.isArray(op.entries)) throw new Error("overview-entries-invalid: entries must be an array");
|
|
3928
3940
|
const requireEvidence = (id) => {
|
|
3929
3941
|
if (typeof id !== "string" || !sources2.has(id)) throw new Error(`overview-source-unavailable: Event ${JSON.stringify(id)} is unknown, changed or outside the frozen run; use an available current-chapter Event`);
|
|
@@ -3936,8 +3948,8 @@ function updateDreaming(state, events, command, now) {
|
|
|
3936
3948
|
for (const id of part.sourceEventIds) if (!members.has(id)) requireEvidence(id);
|
|
3937
3949
|
for (const id of part.sourceEventIds) requireEvidence(id);
|
|
3938
3950
|
validateTopicOverviewText(part.text, `entries[${index}].text`);
|
|
3939
|
-
const title = op.kind
|
|
3940
|
-
if (
|
|
3951
|
+
const title = typeof part.title === "string" ? titlesByLabel.get(normalizeMemoryTopicLabel(part.title)) : op.kind !== "rewrite-overview" && part.title === void 0 ? titles[0] : void 0;
|
|
3952
|
+
if (!title) throw new Error(`overview-entry-section-invalid: entries[${index}].title must name one of ${JSON.stringify(titles)}; set-overview affects only its named section`);
|
|
3941
3953
|
return { ...part, title };
|
|
3942
3954
|
});
|
|
3943
3955
|
const replaced = op.kind === "append-overview" ? [] : updated.overview.filter((part) => memoryTopicOverviewMatchesSection(part, titles));
|
|
@@ -3952,6 +3964,7 @@ function updateDreaming(state, events, command, now) {
|
|
|
3952
3964
|
updated.overview.push(...additions);
|
|
3953
3965
|
} else throw new Error("Unsupported directory operation");
|
|
3954
3966
|
}
|
|
3967
|
+
Object.assign(updated, memoryTopicSectionContent(updated));
|
|
3955
3968
|
const contentVersion = directoryContent(updated);
|
|
3956
3969
|
if (contentVersion === directoryContent(topic) || run.scope === "directory" && run.contentVersions?.includes(contentVersion)) throw new Error("Directory operation repeats an unchanged or previous state");
|
|
3957
3970
|
run.contentVersions = [...run.contentVersions ?? [], contentVersion].slice(-128);
|
|
@@ -10992,22 +11005,20 @@ function memoryTopicSections(topic) {
|
|
|
10992
11005
|
topic.sourceEventIds.forEach((id, index) => {
|
|
10993
11006
|
if (!memberPositions.has(id)) memberPositions.set(id, index);
|
|
10994
11007
|
});
|
|
11008
|
+
const content = memoryTopicSectionContent(topic);
|
|
10995
11009
|
const sections = /* @__PURE__ */ new Map();
|
|
10996
|
-
|
|
11010
|
+
const keyByLabel = /* @__PURE__ */ new Map();
|
|
11011
|
+
for (const membership of content.sections) {
|
|
10997
11012
|
const key = membership.id ?? memoryTopicSectionKey(membership.title);
|
|
10998
11013
|
const section = sections.get(key) ?? { key, title: membership.title, paragraphs: [], sourceEventIds: [] };
|
|
10999
|
-
section.sourceEventIds.push(...membership.sourceEventIds
|
|
11014
|
+
section.sourceEventIds.push(...membership.sourceEventIds);
|
|
11000
11015
|
sections.set(key, section);
|
|
11016
|
+
const label2 = normalizeMemoryTopicLabel(membership.title);
|
|
11017
|
+
if (!keyByLabel.has(label2)) keyByLabel.set(label2, key);
|
|
11001
11018
|
}
|
|
11002
|
-
for (const part of
|
|
11003
|
-
const
|
|
11004
|
-
|
|
11005
|
-
let section = sections.get(identity);
|
|
11006
|
-
if (!section) {
|
|
11007
|
-
section = { key: identity, title, paragraphs: [], sourceEventIds: [] };
|
|
11008
|
-
sections.set(identity, section);
|
|
11009
|
-
}
|
|
11010
|
-
section.paragraphs.push(part);
|
|
11019
|
+
for (const part of content.overview) {
|
|
11020
|
+
const label2 = normalizeMemoryTopicLabel(memoryTopicSectionTitle(part));
|
|
11021
|
+
sections.get(keyByLabel.get(label2)).paragraphs.push(part);
|
|
11011
11022
|
}
|
|
11012
11023
|
return [...sections.values()].map((section) => ({
|
|
11013
11024
|
section: {
|
|
@@ -11184,7 +11195,7 @@ function boundedTopic(topic, envelope = {}) {
|
|
|
11184
11195
|
}
|
|
11185
11196
|
|
|
11186
11197
|
// src/dreaming.ts
|
|
11187
|
-
var DREAMING_DIRECTORY_GUIDANCE = `set-overview {title,entries} replaces ONLY the named section's entire overview, not the chapter. append-overview {title,entries} adds genuinely new facts only. move-events changes Event membership
|
|
11198
|
+
var DREAMING_DIRECTORY_GUIDANCE = `set-overview {title,entries} replaces ONLY the named section's entire overview, not the chapter. append-overview {title,entries} adds genuinely new facts only. move-events changes Event membership. After all operations, sections with no Events and their remaining overview prose are removed. Use rewrite-overview in the same operations array to retain supported facts when emptying a section.
|
|
11188
11199
|
To relocate or consolidate overview facts across sections, use rewrite-overview {titles:[all affected source and destination section names],entries:[{title,kind,text,sourceEventIds}]}. It atomically replaces ALL overview entries in the named sections; include every unique supported fact to retain, including existing destination content. Entries must name one of those sections; other sections remain untouched. Sections must already exist (move-events can create a destination first in the same operations array). For a pure move, keep the original text and citations and change its title; do not leave a duplicate or a cross-reference solely to satisfy source preservation.
|
|
11189
11200
|
Before any replacement, retrieve all existing cited Events not already supplied in full. Preserve the union of their sourceEventIds across the replacement, even when a fact moves to another selected section. When newer evidence corrects old prose, update or consolidate that prose with both old and new citations, retaining its timeline, scope, uncertainty and any still-valid details; do not keep an obsolete claim as a current fact and append another correction. Conflicting evidence is not settled merely because it is newer. Use set-overview for corrections within one section and rewrite-overview across sections. Each overview text is at most 1000 Unicode characters. On rejection, use the named Event and reason: retrieve an unread source; a foreign-chapter source cannot be authorized by reading it. Failed operations save nothing.`;
|
|
11190
11201
|
var LIMIT = DREAMING_SOURCE_PAGE_CHARACTERS;
|
|
@@ -12354,7 +12365,7 @@ Topic \u662F\u957F\u671F\u7684\u5927\u7AE0\u8282\uFF0C\u6309\u9879\u76EE\u3001\u
|
|
|
12354
12365
|
title \u662F\u53EF\u8BC6\u522B\u7684\u4E3B\u9898\u540D\u79F0\uFF1Bdescription \u7528\u4E00\u53E5\u8BDD\u8BF4\u660E\u8FD9\u91CC\u5B58\u6709\u54EA\u4E9B\u8D44\u6599\uFF0C\u4F8B\u5982\u201C\u5305\u542B\u90E8\u7F72\u9009\u578B\u3001\u8FC1\u79FB\u7ECF\u8FC7\u548C\u9057\u7559\u95EE\u9898\u201D\uFF0C\u4E0D\u8981\u628A\u5386\u53F2\u7ED3\u8BBA\u5199\u6210\u5F53\u524D\u4E8B\u5B9E\u3002\u65B0\u6982\u8981\u6309\u9700\u751F\u6210\uFF0C\u901A\u5E38 0\uFF5E2 \u6BB5\uFF1B\u6CA1\u6709\u5FC5\u8981\u65F6\u5141\u8BB8 overview: []\u3002\u5C1A\u672A\u4FDD\u5B58\u7684\u4E0D\u5408\u683C\u8349\u7A3F\u53EF\u4EE5\u820D\u5F03\uFF0C\u4F46\u5FC5\u987B\u5B8C\u6574\u4FDD\u7559\u672C\u6279 Event \u7684\u5F52\u7C7B\uFF0C\u4E0D\u80FD\u4F2A\u9020\u6765\u6E90\u6216\u5220\u9664\u5DF2\u6301\u4E45\u5316\u7684\u6709\u6548\u8BB0\u5FC6\u3002
|
|
12355
12366
|
overview \u7684 kind \u4EC5\u5141\u8BB8 scope\uFF08\u80CC\u666F\u6216\u8986\u76D6\u8303\u56F4\uFF09\u3001history\uFF08\u5386\u53F2\u8FDB\u5C55\uFF09\u3001decision\uFF08\u5F53\u65F6\u7684\u51B3\u5B9A\uFF09\u3001change\uFF08\u6709\u4F9D\u636E\u7684\u53D8\u5316\uFF09\u3001open-question\uFF08\u5F85\u786E\u8BA4\u4E8B\u9879\uFF09\u3002\u4FDD\u7559\u660E\u786E\u65F6\u70B9\u3001\u8FC7\u53BB\u5F0F\u3001\u8BA1\u5212\u3001\u53D6\u6D88\u3001\u4E89\u8BAE\u548C\u4E0D\u786E\u5B9A\u6027\uFF1B\u6CA1\u6709\u65B0\u7684\u652F\u6301\u4E0D\u80FD\u628A\u65E7\u4E8B\u5B9E\u5347\u683C\u4E3A\u5F53\u524D\u7ED3\u8BBA\uFF0C\u4E0D\u80FD\u628A\u8BA1\u5212\u5199\u6210\u5DF2\u5B8C\u6210\u3001\u5EFA\u8BAE\u5199\u6210\u5DF2\u51B3\u5B9A\u3001\u63A8\u6D4B\u5199\u6210\u539F\u56E0\u3002\u51B3\u5B9A\u66FE\u7ECF\u6210\u7ACB\u4E0D\u7B49\u4E8E\u73B0\u5728\u4ECD\u6709\u6548\u3002\u76F8\u5173\u4E8B\u4EF6\u77DB\u76FE\u65F6\u4FDD\u7559\u77DB\u76FE\u548C\u5F85\u786E\u8BA4\u72B6\u6001\u3002
|
|
12356
12367
|
|
|
12357
|
-
sections \
|
|
12368
|
+
sections \u4FDD\u5B58\u4E8B\u4EF6\u7684\u5C0F\u8282\u5F52\u5C5E\u3002\u6BCF\u4E2A\u5F52\u5165\u672C\u7AE0\u7684\u672C\u6279\u4E8B\u4EF6\u5FC5\u987B\u81F3\u5C11\u5206\u914D\u5230\u4E00\u4E2A sections \u5C0F\u8282\u3002sections \u53EA\u5199\u672C\u6279\u4E8B\u4EF6\u7F16\u53F7\uFF0C\u65E7\u5F52\u5C5E\u7531\u5B58\u50A8\u5C42\u7EE7\u627F\u3002\u4F18\u5148\u9010\u5B57\u590D\u7528 existingTopics.sectionTitles \u4E2D\u9002\u5408\u7684\u6807\u9898\u3002\u65B0\u589E overview \u4F18\u5148\u4F7F\u7528\u672C\u8F6E sections.title\uFF1B\u5B58\u50A8\u5C42\u53EA\u4FDD\u7559\u80FD\u6302\u5728\u6700\u7EC8\u975E\u7A7A\u5C0F\u8282\u4E0A\u7684\u6982\u8981\u3002overview.title \u53EA\u51B3\u5B9A\u6587\u5B57\u663E\u793A\u5728\u54EA\u4E00\u8282\u3002\u65E0\u9700\u4E3A\u6BCF\u6761\u4E8B\u4EF6\u5199\u6982\u8981\u3002
|
|
12358
12369
|
\u82E5\u8F93\u5165\u542B sectionBackfillTopicId\uFF0C\u8FD9\u662F\u5347\u7EA7\u540E\u7684\u65E7\u4E8B\u4EF6\u8865\u5F52\u7C7B\uFF1A\u53EA\u8FD4\u56DE\u8BE5 topicId \u7684\u4E00\u4E2A\u7AE0\u8282\uFF0C\u4FDD\u7559\u539F\u7AE0\u540D\u548C\u63CF\u8FF0\uFF0C\u4E3A\u5168\u90E8\u672C\u6279\u4E8B\u4EF6\u5199\u5165\u9002\u5F53\u7684\u5C0F\u8282\uFF1B\u4E0D\u5F97\u6362\u7AE0\u6216\u65B0\u5EFA\u7AE0\u3002\u5DF2\u6709\u5C0F\u8282\u6807\u9898\u53EF\u80FD\u53EA\u5C55\u793A\u524D 120 \u4E2A\uFF0C\u4F18\u5148\u590D\u7528\u9002\u5408\u7684\u5DF2\u6709\u6807\u9898\u3002\u6B64\u4EFB\u52A1\u65E0\u9700\u91CD\u5199\u603B\u89C8\uFF0Coverview \u53EF\u4EE5\u4E3A\u7A7A\uFF0C\u5B58\u50A8\u5C42\u4FDD\u7559\u6709\u6548\u65E7\u603B\u89C8\u3002
|
|
12359
12370
|
|
|
12360
12371
|
outputTokenBudget \u662F\u6574\u4E2A\u54CD\u5E94\u7684\u8F93\u51FA\u9884\u7B97\u3002\u4F18\u5148\u5B8C\u6574\u5206\u914D\u672C\u6279\u6240\u6709\u4E8B\u4EF6\u5230\u7AE0\u8282\u548C\u5C0F\u8282\uFF0C\u518D\u5199\u5FC5\u8981\u7684\u7B80\u77ED\u540D\u79F0\u3001\u8303\u56F4\u8BF4\u660E\u548C\u65B0\u589E\u6BB5\u3002\u5B58\u50A8\u5C42\u4F1A\u5728\u6700\u7EC8\u5C0F\u8282\u4ECD\u5B58\u5728\u65F6\u81EA\u52A8\u7EE7\u627F\u6709\u6548\u65E7\u6982\u8981\uFF0C\u65E0\u9700\u8F93\u51FA\u590D\u8FF0\uFF1B\u901A\u5E38\u53EA\u9700 0-2 \u6BB5\u65B0\u589E\u6982\u8981\uFF0C\u9884\u7B97\u4E0D\u8DB3\u65F6 overview \u53EF\u4E3A\u7A7A\uFF0Csections \u4ECD\u5FC5\u987B\u5B8C\u6574\u5F52\u7C7B\u672C\u6279\u4E8B\u4EF6\uFF0C\u4E0D\u622A\u65AD JSON \u6216\u9057\u6F0F\u4E8B\u4EF6\u3002
|
|
@@ -12593,7 +12604,7 @@ function parseTopicProjection(value, context) {
|
|
|
12593
12604
|
const topics = rawTopics.map((candidate, topicIndex) => {
|
|
12594
12605
|
const item = object(candidate);
|
|
12595
12606
|
const title = boundedText(item.title, "topic.title", 120);
|
|
12596
|
-
const label2 = title
|
|
12607
|
+
const label2 = normalizeMemoryTopicLabel(title);
|
|
12597
12608
|
if (usedLabels.has(label2)) fail("duplicate chapter label; combine its batch assignments");
|
|
12598
12609
|
usedLabels.add(label2);
|
|
12599
12610
|
if (Object.keys(item).some((key) => !["topicId", "title", "description", "sourceEventIds", "overview", "sections"].includes(key))) fail("unexpected topic field");
|
|
@@ -12614,7 +12625,7 @@ function parseTopicProjection(value, context) {
|
|
|
12614
12625
|
const section = object(candidateSection);
|
|
12615
12626
|
if (Object.keys(section).some((key2) => !["title", "sourceEventIds"].includes(key2))) fail("unexpected section field");
|
|
12616
12627
|
const title2 = boundedText(section.title, "section.title", 80);
|
|
12617
|
-
const key = title2
|
|
12628
|
+
const key = normalizeMemoryTopicLabel(title2);
|
|
12618
12629
|
if (sectionLabels.has(key)) fail("duplicate section title");
|
|
12619
12630
|
sectionLabels.add(key);
|
|
12620
12631
|
return { title: title2, sourceEventIds: sourceIds(section.sourceEventIds, "section.sourceEventIds", new Set(sources2.filter((id) => eventIds.has(id)))) };
|
|
@@ -12622,10 +12633,6 @@ function parseTopicProjection(value, context) {
|
|
|
12622
12633
|
const assigned = new Set(sections.flatMap((section) => section.sourceEventIds));
|
|
12623
12634
|
if (sources2.some((id) => eventIds.has(id) && !assigned.has(id))) fail("every topic batch Event must be assigned to a section");
|
|
12624
12635
|
if (!Array.isArray(item.overview) || item.overview.length > 8) fail("overview must contain 0-8 source-grounded entries");
|
|
12625
|
-
const overviewTitles = [
|
|
12626
|
-
...sections.map((section) => section.title),
|
|
12627
|
-
...existing?.sectionTitles ?? memoryTopicMembershipSections(existing ?? { overview: [] }).map((section) => section.title)
|
|
12628
|
-
];
|
|
12629
12636
|
const overview2 = item.overview.map((candidateEntry, overviewIndex) => {
|
|
12630
12637
|
const entry = object(candidateEntry);
|
|
12631
12638
|
if (Object.keys(entry).some((key) => !["kind", "title", "text", "sourceEventIds"].includes(key))) fail("unexpected overview field");
|
|
@@ -12639,9 +12646,7 @@ function parseTopicProjection(value, context) {
|
|
|
12639
12646
|
if (paragraphSources.some((id) => !eventIds.has(id)) && !preserved) {
|
|
12640
12647
|
fail("old overview evidence may only be preserved verbatim; rewritten entries must cite batch Events only");
|
|
12641
12648
|
}
|
|
12642
|
-
|
|
12643
|
-
if (!preserved && !memoryTopicOverviewMatchesSection(part, overviewTitles)) fail("new overview must match a declared or inherited section");
|
|
12644
|
-
return part;
|
|
12649
|
+
return { kind: entry.kind, ...sectionTitle === void 0 ? {} : { title: sectionTitle }, text: paragraph, sourceEventIds: paragraphSources };
|
|
12645
12650
|
});
|
|
12646
12651
|
return {
|
|
12647
12652
|
...topicId === void 0 ? {} : { topicId },
|