Integrated repository, worktree, git stacker, and project manager
0

Configure Feed

Select the types of activity you want to include in your feed.

emacs: scope the pm-serve sidebar to the launching Emacs instance

The daemon is shared across Emacs instances, and they all tag agents with
the same PM_META_SOURCE, so the sidebar's SOURCE-only filter showed every
instance's agents. Inject PM_META_EMACS (the Emacs pid, already the prefix
of the buffer id) on launch and filter the sidebar on SOURCE *and* EMACS,
so each Emacs sees only the sessions it launched.

Jordan Isaacs (Jun 22, 2026, 8:00 PM UTC) 2d4c5ffc 49345c8c

+20 -2
+14 -1
integrations/emacs/pm-agent.el
··· 103 103 (defvar pm-agent--buffer-seq 0 104 104 "Monotonic counter behind `pm-agent--new-buffer-id'.") 105 105 106 + (defun pm-agent--emacs-id () 107 + "Identifier for this Emacs instance, injected as `PM_META_EMACS'. 108 + The `pm-serve' sidebar filters on it so it shows only the sessions *this* 109 + Emacs launched — not those of other Emacs instances that share the daemon 110 + \(they all tag `PM_META_SOURCE' the same, so SOURCE alone can't tell them 111 + apart). The process id is unique per running Emacs, which is exactly the 112 + granularity we want." 113 + (number-to-string (emacs-pid))) 114 + 106 115 (defun pm-agent--new-buffer-id () 107 116 "Return a fresh agent-buffer id, unique within this Emacs process. 108 117 Generated *before* the buffer exists so it can be injected via 109 118 `process-environment' (no shell `export'); the same value is stamped 110 119 buffer-local as `pm-agent-buffer-id' for the reverse lookup." 111 - (format "%d-%d" (emacs-pid) (cl-incf pm-agent--buffer-seq))) 120 + (format "%s-%d" (pm-agent--emacs-id) (cl-incf pm-agent--buffer-seq))) 112 121 113 122 (defun pm-agent--seed-environment (buffer-id) 114 123 "Return `process-environment' with the PM_META_* launch seeds prepended. 115 124 The agent inherits these from its environment (no visible `export'), and 116 125 its hooks report them to `pm agent serve' as session metadata: 117 126 PM_META_SOURCE — `pm-agent-serve-source', a tag the sidebar filters on 127 + PM_META_EMACS — this Emacs instance, so the sidebar shows only its own 118 128 PM_META_BUF — BUFFER-ID, for mapping a session back to its buffer" 119 129 (append (list (format "PM_META_SOURCE=%s" pm-agent-serve-source) 130 + (format "PM_META_EMACS=%s" (pm-agent--emacs-id)) 120 131 (format "PM_META_BUF=%s" buffer-id)) 121 132 process-environment)) 122 133 ··· 134 145 buffer — so the `pm-serve' sidebar still sees it and can map it back to 135 146 its buffer: 136 147 PM_META_SOURCE — `pm-agent-serve-source', the tag the sidebar filters on 148 + PM_META_EMACS — this Emacs instance, so the sidebar shows only its own 137 149 PM_META_BUF — this buffer's stable `pm-agent-buffer-id' 138 150 The id is minted once and reused if the buffer ever respawns its shell, so 139 151 the buffer keeps a single identity across restarts." 140 152 (let ((buffer-id (or pm-agent-buffer-id (pm-agent--new-buffer-id)))) 141 153 (setq-local pm-agent-buffer-id buffer-id) 142 154 (setenv "PM_META_SOURCE" pm-agent-serve-source) 155 + (setenv "PM_META_EMACS" (pm-agent--emacs-id)) 143 156 (setenv "PM_META_BUF" buffer-id))) 144 157 145 158 ;;;###autoload
+6 -1
integrations/emacs/pm-serve.el
··· 201 201 202 202 ;; --- SSE plumbing ----------------------------------------------------------- 203 203 (defun pm-serve--filter-query () 204 - (format "meta.SOURCE=%s" pm-agent-serve-source)) 204 + ;; Scope to sessions THIS Emacs launched: SOURCE marks "from Emacs", 205 + ;; EMACS pins the specific instance (the daemon is shared, so filtering on 206 + ;; SOURCE alone would surface other Emacs instances' agents). The daemon 207 + ;; ANDs the params. 208 + (format "meta.SOURCE=%s&meta.EMACS=%s" 209 + pm-agent-serve-source (pm-agent--emacs-id))) 205 210 206 211 (defun pm-serve--handle (json) 207 212 (when (> (length json) 0)