opencode-subagent-magazine 1.1.2 → 1.1.3

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.
@@ -1 +1 @@
1
- export declare const PLUGIN_VERSION = "1.1.2";
1
+ export declare const PLUGIN_VERSION = "1.1.3";
package/dist/_version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // auto-generated
2
- export const PLUGIN_VERSION = "1.1.2";
2
+ export const PLUGIN_VERSION = "1.1.3";
package/dist/index.js CHANGED
@@ -198,8 +198,7 @@ function safeErrorMsg(err) {
198
198
  // ===================================================================
199
199
  // Sidebar component
200
200
  // ===================================================================
201
- // 模块级缓存:保留各 session 的最新 entryMap,不随组件内 session 切换而丢失。
202
- // 当用户在子 session 内部时,handleSessionEnd 可通过此缓存找到父 session 的 entries。
201
+ // 模块级缓存:各 session entry 状态独立存储,不随当前视图切换而清除。
203
202
  const globalEntryCache = new Map();
204
203
  function SubAgentPanel(props) {
205
204
  const t = (key) => I18N[props.lang()][key] ?? key;
@@ -283,8 +282,8 @@ function SubAgentPanel(props) {
283
282
  const setEntryMap = (arg) => {
284
283
  setEntryMapRaw((prev) => {
285
284
  const next = typeof arg === "function" ? arg(prev) : arg;
286
- // 检测是否有 entry 从 running 变为 done/error 立即写 KV
287
- // 避免 session 切换时 KV 仍是旧状态,导致 scan 用 Date.now() 覆盖正确的 endedAt
285
+ // entry 状态落定(done/error)时立即持久化到 KV,跳过常规 debounce,
286
+ // 确保跨视图的状态一致性。
288
287
  let needsImmediateFlush = false;
289
288
  for (const [id, entry] of next) {
290
289
  const prevEntry = prev.get(id);
@@ -305,7 +304,7 @@ function SubAgentPanel(props) {
305
304
  else {
306
305
  persistEntries(props.sessionId, next);
307
306
  }
308
- // 同步到全局缓存,确保跨 session 查找时数据可用
307
+ // 同步到模块级缓存,供其他视图读取当前 session 的最新状态
309
308
  globalEntryCache.set(props.sessionId, new Map(next));
310
309
  return next;
311
310
  });
@@ -678,21 +677,20 @@ function SubAgentPanel(props) {
678
677
  }
679
678
  return changed ? next : prev;
680
679
  });
681
- // session 完成事件:用户正在查看子 session 内部时,其他子代理 done。
682
- // 上面的 setEntryMap 在子 session 的 entries 中找不到父 session 的 entry
683
- // 通过全局缓存(切换前保留的父 session entries)查找并更新,再同步回 KV。
680
+ // 当子代理所属的父 session 与当前视图不同时,通过模块级缓存定位
681
+ // 并更新父 session 的 entry 状态,随后写回 KV
684
682
  try {
685
683
  const sessionObj = props.api.state.session.get(sid);
686
684
  const parentSid = sessionObj?.parentID;
687
685
  if (parentSid && parentSid !== props.sessionId) {
688
- // 优先全局缓存——切换 session 时不会被替换,始终保留父 session 的最新 entries
686
+ // 优先从模块级缓存获取父 session entries,不受当前视图切换影响
689
687
  const parentCache = globalEntryCache.get(parentSid);
690
688
  const nowTs = Date.now();
691
689
  let found = false;
692
690
  if (parentCache) {
693
691
  found = tryMatchAndUpdate(parentCache, sid, status, nowTs);
694
692
  }
695
- // 缓存未命中时回退到 KV(极端情况:session 切换前缓存未建立)
693
+ // 缓存未命中时回退到 KV 读取
696
694
  if (!found) {
697
695
  const data = loadSessionData();
698
696
  const rec = data[parentSid];
@@ -700,14 +698,14 @@ function SubAgentPanel(props) {
700
698
  const fallbackMap = new Map(rec.entries.map((e) => [e.id, e]));
701
699
  found = tryMatchAndUpdate(fallbackMap, sid, status, nowTs);
702
700
  if (found) {
703
- // 回退命中了也要写回 KV,并回填缓存
701
+ // 回退命中后写入 KV 并回填缓存
704
702
  data[parentSid] = { ...rec, ts: nowTs, entries: [...fallbackMap.values()] };
705
703
  saveSessionData(data);
706
704
  globalEntryCache.set(parentSid, fallbackMap);
707
705
  }
708
706
  }
709
707
  }
710
- // KV 同步:以全局缓存(最新的内存状态)为准写回 KV
708
+ // 将模块级缓存中的最新状态同步到 KV
711
709
  if (found && parentCache) {
712
710
  const data = loadSessionData();
713
711
  data[parentSid] = { ...data[parentSid], ts: nowTs, entries: [...parentCache.values()] };
@@ -838,7 +836,7 @@ function SubAgentPanel(props) {
838
836
  // scan uses setEntryMapRaw — ephemeral data, not persisted to kv.
839
837
  // Only event-driven changes (handlePartUpdated, handleSessionEnd) persist.
840
838
  setEntryMapRaw((prev) => {
841
- // 优先全局缓存——handleSessionEnd 修复2 已同步更新,无 KV 读写延迟
839
+ // 优先从模块级缓存加载,KV 仅作缓存未命中时的回退
842
840
  const next = switched
843
841
  ? new Map(globalEntryCache.get(sid) ?? loadEntries(sid))
844
842
  : new Map(prev);