openmsg 0.4.4 → 0.4.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +23 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmsg",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Messages between AI coding agents of different vendors, on one machine or between two people, sealed end to end.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.mjs CHANGED
@@ -97,8 +97,19 @@ function ago(ms) {
97
97
  return `${Math.floor(s / 86400)}d`;
98
98
  }
99
99
 
100
+ // Two records name one session when the vendor and the session id agree.
101
+ function sameSession(a, b) {
102
+ return Boolean(a && b && a.vendor === b.vendor && a.id === b.id);
103
+ }
104
+
100
105
  async function cmdList(args = []) {
101
- const all = notes.attach(await allAgents());
106
+ // Several sessions can run in one directory with names that look alike. The
107
+ // mark "(you)" shows the agent which row is its own, so that it does not send
108
+ // to itself. A command outside a session has no row, and it gets no mark.
109
+ const [all, me] = await Promise.all([
110
+ allAgents().then((a) => notes.attach(a)),
111
+ self().catch(() => null),
112
+ ]);
102
113
  const agents = args.includes("--all") ? all : all.filter((a) => !a.background);
103
114
  const hidden = all.length - agents.length;
104
115
  if (agents.length === 0) {
@@ -106,14 +117,15 @@ async function cmdList(args = []) {
106
117
  return;
107
118
  }
108
119
  if (args.includes("--json")) {
109
- console.log(JSON.stringify(agents.map(({ transport, ...a }) => a), null, 1));
120
+ console.log(JSON.stringify(agents.map(({ transport, ...a }) => ({ ...a, you: sameSession(a, me) })), null, 1));
110
121
  return;
111
122
  }
112
123
  const width = Math.max(...agents.map((a) => address(a).length));
113
124
  const tilde = (p) => (p && p.startsWith(os.homedir()) ? `~${p.slice(os.homedir().length)}` : p);
114
125
  for (const a of agents) {
115
126
  const times = [a.startedAt && `started ${ago(a.startedAt)} ago`, a.updatedAt && `active ${ago(a.updatedAt)} ago`];
116
- const head = [address(a).padEnd(width), a.status.padEnd(7), times.filter(Boolean).join(", ")];
127
+ const you = sameSession(a, me) ? "(you)" : "";
128
+ const head = [address(a).padEnd(width), a.status.padEnd(7), times.filter(Boolean).join(", "), you];
117
129
  console.log(head.join(" ").trimEnd());
118
130
  // The note of the agent comes first, because the agent wrote it about the
119
131
  // work of now. The title of the vendor comes next.
@@ -163,6 +175,12 @@ async function cmdSend(target, text, replyTo = null, args = []) {
163
175
  `Its name was ${address(answered.openmsg.from)}. Send a new message instead of a reply.`,
164
176
  );
165
177
  }
178
+ if (sameSession(to, from)) {
179
+ throw new Error(
180
+ `${address(to)} is this session. An agent does not send a message to itself. ` +
181
+ "Leave it out of the recipients.",
182
+ );
183
+ }
166
184
  if (pinned && to.id !== pinned) {
167
185
  throw new Error(
168
186
  `the session that sent ${replyTo} is gone. Its name now belongs to ${address(to)}. ` +
@@ -220,8 +238,9 @@ async function cmdSendProject(target, text, replyTo, args) {
220
238
 
221
239
  // Only the records of Claude Code, because they are files. The discovery of
222
240
  // Codex and OpenCode runs lsof, and that costs seconds.
241
+ // A session that sends to its own directory does not get its own message.
223
242
  const live = claudeAgents()
224
- .filter((a) => projectbox.sessionIsIn(a.cwd, dir))
243
+ .filter((a) => projectbox.sessionIsIn(a.cwd, dir) && !sameSession(a, from))
225
244
  .sort((a, b) => b.updatedAt - a.updatedAt);
226
245
  for (const agent of live) {
227
246
  const got = projectbox.takeMessage(dir, message);