@shoppingjaws/peer 0.1.0 → 0.1.1

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/dist/index.js +51 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,10 +31,15 @@ function initDb() {
31
31
  from_pane_id TEXT NOT NULL,
32
32
  to_pane_id TEXT NOT NULL,
33
33
  relation TEXT NOT NULL CHECK(relation IN ('parent', 'child')),
34
+ description TEXT DEFAULT NULL,
34
35
  created_at TEXT NOT NULL DEFAULT (datetime('now')),
35
36
  PRIMARY KEY (session_id, from_pane_id, to_pane_id)
36
37
  )
37
38
  `);
39
+ const columns = db.prepare("PRAGMA table_info(peer_edges)").all();
40
+ if (!columns.some((c) => c.name === "description")) {
41
+ db.run("ALTER TABLE peer_edges ADD COLUMN description TEXT DEFAULT NULL");
42
+ }
38
43
  return db;
39
44
  }
40
45
 
@@ -82,11 +87,11 @@ function getPeerGroupPaneIds(db) {
82
87
  const rows = db.prepare("SELECT DISTINCT to_pane_id FROM peer_edges WHERE session_id = ? AND from_pane_id = ?").all(sessionId, myPaneId);
83
88
  return new Set(rows.map((r) => r.to_pane_id));
84
89
  }
85
- function registerPeerEdge(db, fromPaneId, toPaneId, relation) {
90
+ function registerPeerEdge(db, fromPaneId, toPaneId, relation, description) {
86
91
  const sessionId = getSessionId();
87
92
  const reverseRelation = relation === "child" ? "parent" : "child";
88
- db.prepare("INSERT OR IGNORE INTO peer_edges (session_id, from_pane_id, to_pane_id, relation) VALUES (?, ?, ?, ?)").run(sessionId, fromPaneId, toPaneId, relation);
89
- db.prepare("INSERT OR IGNORE INTO peer_edges (session_id, from_pane_id, to_pane_id, relation) VALUES (?, ?, ?, ?)").run(sessionId, toPaneId, fromPaneId, reverseRelation);
93
+ db.prepare("INSERT OR IGNORE INTO peer_edges (session_id, from_pane_id, to_pane_id, relation, description) VALUES (?, ?, ?, ?, ?)").run(sessionId, fromPaneId, toPaneId, relation, description ?? null);
94
+ db.prepare("INSERT OR IGNORE INTO peer_edges (session_id, from_pane_id, to_pane_id, relation, description) VALUES (?, ?, ?, ?, ?)").run(sessionId, toPaneId, fromPaneId, reverseRelation, description ?? null);
90
95
  }
91
96
  function getPeerRelation(db, paneId) {
92
97
  const sessionId = getSessionId();
@@ -94,6 +99,12 @@ function getPeerRelation(db, paneId) {
94
99
  const row = db.prepare("SELECT relation FROM peer_edges WHERE session_id = ? AND from_pane_id = ? AND to_pane_id = ?").get(sessionId, myPaneId, paneId);
95
100
  return row?.relation ?? null;
96
101
  }
102
+ function getPeerDescription(db, paneId) {
103
+ const sessionId = getSessionId();
104
+ const myPaneId = getMyPaneId();
105
+ const row = db.prepare("SELECT description FROM peer_edges WHERE session_id = ? AND from_pane_id = ? AND to_pane_id = ?").get(sessionId, myPaneId, paneId);
106
+ return row?.description ?? null;
107
+ }
97
108
 
98
109
  // commands/clean.ts
99
110
  function cmdClean() {
@@ -146,10 +157,12 @@ async function cmdList() {
146
157
  const peerPaneIds = getPeerGroupPaneIds(db);
147
158
  const sameTabIds = new Set(panes.filter((p) => p.tab_id === myPane.tab_id).map((p) => p.pane_id));
148
159
  const visiblePanes = panes.filter((p) => sameTabIds.has(p.pane_id) || peerPaneIds.has(String(p.pane_id)));
149
- console.log("WINID\tTABID\tPANEID\tRELATION\tWORKSPACE\tSIZE\tTITLE");
160
+ console.log("WINID\tTABID\tPANEID\tRELATION\tDESCRIPTION\tWORKSPACE\tSIZE\tTITLE");
150
161
  for (const p of visiblePanes) {
151
- const relation = p.pane_id === Number(myPaneId) ? "self" : getPeerRelation(db, String(p.pane_id)) ?? "none";
152
- console.log(`${p.window_id} ${p.tab_id} ${p.pane_id} ${relation} ${p.workspace} ${p.size} ${p.title}`);
162
+ const isSelf = p.pane_id === Number(myPaneId);
163
+ const relation = isSelf ? "self" : getPeerRelation(db, String(p.pane_id)) ?? "none";
164
+ const description = isSelf ? "" : getPeerDescription(db, String(p.pane_id)) ?? "";
165
+ console.log(`${p.window_id} ${p.tab_id} ${p.pane_id} ${relation} ${description} ${p.workspace} ${p.size} ${p.title}`);
153
166
  }
154
167
  db.close();
155
168
  }
@@ -160,12 +173,22 @@ async function cmdNewPane(args) {
160
173
  const myPaneId = getMyPaneId();
161
174
  const splitArgs = [];
162
175
  let commandArgs = [];
163
- const separatorIndex = args.indexOf("--");
176
+ let description;
177
+ const filteredArgs = [];
178
+ for (let i = 0;i < args.length; i++) {
179
+ if (args[i] === "--description" && i + 1 < args.length) {
180
+ description = args[i + 1];
181
+ i++;
182
+ } else {
183
+ filteredArgs.push(args[i]);
184
+ }
185
+ }
186
+ const separatorIndex = filteredArgs.indexOf("--");
164
187
  if (separatorIndex >= 0) {
165
- splitArgs.push(...args.slice(0, separatorIndex));
166
- commandArgs = args.slice(separatorIndex + 1);
188
+ splitArgs.push(...filteredArgs.slice(0, separatorIndex));
189
+ commandArgs = filteredArgs.slice(separatorIndex + 1);
167
190
  } else {
168
- splitArgs.push(...args);
191
+ splitArgs.push(...filteredArgs);
169
192
  }
170
193
  if (commandArgs.length > 0) {
171
194
  splitArgs.push("--", ...commandArgs);
@@ -177,7 +200,7 @@ async function cmdNewPane(args) {
177
200
  process.exit(1);
178
201
  }
179
202
  const db = initDb();
180
- registerPeerEdge(db, myPaneId, newPaneId, "child");
203
+ registerPeerEdge(db, myPaneId, newPaneId, "child", description);
181
204
  db.close();
182
205
  console.log(`Created pane ${newPaneId} and added to peer group.`);
183
206
  }
@@ -188,12 +211,22 @@ async function cmdNewTab(args) {
188
211
  const myPaneId = getMyPaneId();
189
212
  const spawnArgs = [];
190
213
  let commandArgs = [];
191
- const separatorIndex = args.indexOf("--");
214
+ let description;
215
+ const filteredArgs = [];
216
+ for (let i = 0;i < args.length; i++) {
217
+ if (args[i] === "--description" && i + 1 < args.length) {
218
+ description = args[i + 1];
219
+ i++;
220
+ } else {
221
+ filteredArgs.push(args[i]);
222
+ }
223
+ }
224
+ const separatorIndex = filteredArgs.indexOf("--");
192
225
  if (separatorIndex >= 0) {
193
- spawnArgs.push(...args.slice(0, separatorIndex));
194
- commandArgs = args.slice(separatorIndex + 1);
226
+ spawnArgs.push(...filteredArgs.slice(0, separatorIndex));
227
+ commandArgs = filteredArgs.slice(separatorIndex + 1);
195
228
  } else {
196
- spawnArgs.push(...args);
229
+ spawnArgs.push(...filteredArgs);
197
230
  }
198
231
  if (commandArgs.length > 0) {
199
232
  spawnArgs.push("--", ...commandArgs);
@@ -205,7 +238,7 @@ async function cmdNewTab(args) {
205
238
  process.exit(1);
206
239
  }
207
240
  const db = initDb();
208
- registerPeerEdge(db, myPaneId, newPaneId, "child");
241
+ registerPeerEdge(db, myPaneId, newPaneId, "child", description);
209
242
  db.close();
210
243
  console.log(`Created tab with pane ${newPaneId} and added to peer group.`);
211
244
  }
@@ -337,8 +370,8 @@ switch (command) {
337
370
  console.log(" list List panes (same tab + peer group)");
338
371
  console.log(" peek <pane-id> Read terminal text from a pane");
339
372
  console.log(" inbox <open|send> Manage inbox messages");
340
- console.log(" new-pane [opts] [-- cmd] Split a new pane in current tab");
341
- console.log(" new-tab [opts] [-- cmd] Spawn a new tab and add to peer group");
373
+ console.log(" new-pane [opts] [--description text] [-- cmd] Split a new pane");
374
+ console.log(" new-tab [opts] [--description text] [-- cmd] Spawn a new tab");
342
375
  console.log(" history [pane-id] Show message history");
343
376
  console.log(" clean Reset the message database");
344
377
  process.exit(command ? 1 : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoppingjaws/peer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI tool for managing wezterm panes, peer groups, and inter-pane messaging",
5
5
  "type": "module",
6
6
  "bin": {