zcode-acp-server 0.80.0 → 0.81.0

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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/dist/backend/resolve.d.ts.map +1 -1
  3. package/dist/backend/resolve.js +11 -2
  4. package/dist/backend/resolve.js.map +1 -1
  5. package/dist/code-fingerprint.json +2 -2
  6. package/dist/handlers/background-tasks.d.ts +5 -1
  7. package/dist/handlers/background-tasks.d.ts.map +1 -1
  8. package/dist/handlers/background-tasks.js +49 -7
  9. package/dist/handlers/background-tasks.js.map +1 -1
  10. package/dist/handlers/session-titles.d.ts +38 -5
  11. package/dist/handlers/session-titles.d.ts.map +1 -1
  12. package/dist/handlers/session-titles.js +114 -7
  13. package/dist/handlers/session-titles.js.map +1 -1
  14. package/dist/handlers/session.d.ts.map +1 -1
  15. package/dist/handlers/session.js +72 -4
  16. package/dist/handlers/session.js.map +1 -1
  17. package/dist/handlers/slash.d.ts.map +1 -1
  18. package/dist/handlers/slash.js +12 -0
  19. package/dist/handlers/slash.js.map +1 -1
  20. package/dist/handlers/steering.d.ts +43 -0
  21. package/dist/handlers/steering.d.ts.map +1 -0
  22. package/dist/handlers/steering.js +148 -0
  23. package/dist/handlers/steering.js.map +1 -0
  24. package/dist/i18n.d.ts +3 -0
  25. package/dist/i18n.d.ts.map +1 -1
  26. package/dist/i18n.js +6 -0
  27. package/dist/i18n.js.map +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +5 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/remote/session-rename-endpoint.d.ts +5 -4
  32. package/dist/remote/session-rename-endpoint.d.ts.map +1 -1
  33. package/dist/remote/session-rename-endpoint.js +11 -33
  34. package/dist/remote/session-rename-endpoint.js.map +1 -1
  35. package/dist/server.d.ts +9 -0
  36. package/dist/server.d.ts.map +1 -1
  37. package/dist/server.js +16 -0
  38. package/dist/server.js.map +1 -1
  39. package/dist/settings/app-update.d.ts.map +1 -1
  40. package/dist/settings/app-update.js +34 -1
  41. package/dist/settings/app-update.js.map +1 -1
  42. package/dist/tasks-index.d.ts +18 -0
  43. package/dist/tasks-index.d.ts.map +1 -1
  44. package/dist/tasks-index.js +42 -4
  45. package/dist/tasks-index.js.map +1 -1
  46. package/dist/utils.d.ts +6 -0
  47. package/dist/utils.d.ts.map +1 -1
  48. package/dist/utils.js +5 -0
  49. package/dist/utils.js.map +1 -1
  50. package/docs/ARCHITECTURE.md +2 -1
  51. package/docs/BACKLOG.md +54 -4
  52. package/docs/PROTOCOL.md +67 -7
  53. package/docs/REMOTE-CLIENTS.md +18 -13
  54. package/package.json +1 -1
@@ -787,6 +787,17 @@ export async function ensureRealSession(server, acpSid, opts = {}) {
787
787
  title: session.title ?? "",
788
788
  traceId: session.traceId,
789
789
  });
790
+ // A rename made while this was still a placeholder (no backend id) could
791
+ // only pin in memory — re-run the shared core now that the session exists
792
+ // so the backend (v4 renameSession, titleSource=custom) and tasks-index
793
+ // catch up. Idempotent (same title, equality-guarded downstream).
794
+ if (server.titleUserSetBy.has(acpSid)) {
795
+ const placeholderTitle = server.sessionTitles.get(acpSid);
796
+ if (placeholderTitle) {
797
+ const { renameSessionCore } = await import("./session-titles.js");
798
+ void renameSessionCore(server, acpSid, placeholderTitle).catch(() => undefined);
799
+ }
800
+ }
790
801
  return sid;
791
802
  })();
792
803
  pending.creating = creating;
@@ -849,22 +860,79 @@ export async function listSessions(server, params) {
849
860
  catch {
850
861
  // tasks-index unavailable — show everything.
851
862
  }
863
+ // User renames are the title truth: the backend store can lag the v4
864
+ // renameSession command (an idle session cold-resumes first), so overlay
865
+ // the durable `title_overridden` titles — a rename must be visible in
866
+ // every read the moment it returns, or the client's next list pull flips
867
+ // the fresh title back to the stale one ("改名被弹回"). Own try (a partially
868
+ // mocked tasks-index must only skip the overlay, never fail the listing).
869
+ try {
870
+ const { overriddenTaskTitles } = await import("../tasks-index.js");
871
+ const renamed = await overriddenTaskTitles();
872
+ if (renamed.size > 0) {
873
+ sessions = sessions.map((s) => renamed.has(s.sessionId) ? { ...s, title: renamed.get(s.sessionId) } : s);
874
+ }
875
+ }
876
+ catch {
877
+ // overlay unavailable — backend titles as-is.
878
+ }
852
879
  log(`session/list → ${sessions.length} sessions`);
853
880
  return { sessions };
854
881
  }
855
882
  /**
856
- * Adopt the backend's stored title for a loaded/resumed session.
883
+ * Adopt a title for a loaded/resumed session, pin-first:
884
+ * 1. a sibling alias's already-known title (same conversation, another id
885
+ * spelling);
886
+ * 2. the durable user rename from the App's tasks-index
887
+ * (`title_overridden=1` — survives bridge restarts);
888
+ * 3. the backend's `session/list` stored title.
857
889
  *
858
890
  * The prompt loop's auto-title only fires for freshly created sessions
859
891
  * (`titleEligibleSessions`), so a session resumed across a bridge restart
860
892
  * would otherwise appear title-less in the hub's discovery API — remote
861
- * clients have no editor-side session storage to fall back on. The backend's
862
- * session/list is the only title source for sessions born in a previous
863
- * bridge lifetime. Best-effort: failures log and leave the session untitled.
893
+ * clients have no editor-side session storage to fall back on. Best-effort:
894
+ * failures log and leave the session untitled.
864
895
  */
865
896
  async function adoptStoredTitle(server, acpSid, zcodeSid) {
866
897
  if (server.sessionTitles.has(acpSid))
867
898
  return;
899
+ // Tier 1 — sibling alias: a rename or adoption under another spelling of
900
+ // the same conversation already knows the title. Copy it instead of asking
901
+ // the backend, whose store may lag a bridge-side rename (a rename through
902
+ // one alias used to be invisible here, so a load via a second alias reset
903
+ // the title).
904
+ const sibling = server
905
+ .sessionAliases(acpSid)
906
+ .map((sid) => server.sessionTitles.get(sid))
907
+ .find((t) => t !== undefined);
908
+ if (sibling !== undefined) {
909
+ server.sessionTitles.set(acpSid, sibling);
910
+ server.touchSessionSummary(acpSid, sibling);
911
+ refreshTerminalTabTitle(server, acpSid);
912
+ return;
913
+ }
914
+ // Tier 2 — durable user rename: `title_overridden=1` in the App's
915
+ // tasks-index survives bridge restarts (the in-memory pin does not). The
916
+ // backend store may never have been told (pre-v4 rename, command failure),
917
+ // so its session/list answer can be stale — the user's title wins.
918
+ try {
919
+ const { readTaskTitle } = await import("../tasks-index.js");
920
+ const task = await readTaskTitle(zcodeSid);
921
+ if (task?.overridden && task.title) {
922
+ server.sessionTitles.set(acpSid, task.title);
923
+ for (const sid of server.sessionAliases(acpSid))
924
+ server.titleUserSetBy.add(sid);
925
+ server.touchSessionSummary(acpSid, task.title);
926
+ refreshTerminalTabTitle(server, acpSid);
927
+ log(`adopted user-renamed title for ${acpSid.slice(0, 8)}: ${task.title}`);
928
+ return;
929
+ }
930
+ }
931
+ catch {
932
+ // Best-effort consult — fall through to the backend's stored title.
933
+ }
934
+ // Tier 3 — the backend's session/list: the only title source for sessions
935
+ // born in a previous bridge lifetime.
868
936
  try {
869
937
  const backend = await server.ensureBackend();
870
938
  const resp = await backend.request(server.nextId(), "session/list", {}, 15000);