@op1/threads 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 (3) hide show
  1. package/README.md +4 -0
  2. package/package.json +3 -2
  3. package/tui.ts +29 -0
package/README.md CHANGED
@@ -75,6 +75,8 @@ Plugin option `maxWorkers` defaults to 4 and accepts integers from 1 through 32.
75
75
 
76
76
  The terminal synchronizes workers before opening native tabs without changing focus. A TUI memory index survives plugin reloads and respects manually closed tabs. `/threads` explicitly reopens workers for open coordinator tabs. A new TUI recovers workers from durable storage. Closing the TUI does not interrupt workers.
77
77
 
78
+ All open native root-session tabs are automatically grouped by OpenCode project ID, including sessions not managed by this plugin. Projects follow their first appearance in the current tab order; sessions keep their relative order within each project. Worktrees with the same project ID stay together. Each tab with unloaded project metadata stays in its own group until that metadata becomes available. Reconciliation moves only out-of-order tabs, without changing focus or closing and reopening them. Native tabs do not support divider rows.
79
+
78
80
  The read-only RPC definition is `ThreadsRpc` in `src/rpc.ts`, with ID `threads` and method `snapshot`:
79
81
 
80
82
  ```ts
@@ -88,6 +90,8 @@ The input accepts at most 100 coordinator IDs. Raw HTTP RPC requests wrap the in
88
90
 
89
91
  Run `bun run typecheck`, `bun test`, and `bun run verify:live`. The live check requires OpenCode 2.0.3, Python, and `uv`. It starts a separate local server, a deterministic model endpoint, and a terminal process with isolated configuration and data. It verifies actual tool calls, durable messages, permission restrictions, worker limits, deleted-worker cleanup, restart behavior, and native tab visibility, busy state, and focus.
90
92
 
93
+ Run `bun run verify:tabs` to verify project grouping across real git worktrees, new worker insertion, focus preservation, and TUI reopening.
94
+
91
95
  Pass an extracted package directory to test the release artifact: `bun run verify:live /absolute/path/to/package`.
92
96
 
93
97
  The native session and plugin index are separate writes. A crash after session creation but before indexing requires an explicit identical spawn retry. A crash after native report admission but before saving the report view requires an explicit report retry; the native coordinator notification remains canonical and is not duplicated. There is no custom outbox or startup task replay.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op1/threads",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Visible top-level worker sessions for OpenCode V2, with native tabs and durable reports.",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -24,7 +24,8 @@
24
24
  "scripts": {
25
25
  "typecheck": "tsc --noEmit",
26
26
  "test": "bun test",
27
- "verify:live": "uv run --with pyte python scripts/verify-live.py"
27
+ "verify:live": "uv run --with pyte python scripts/verify-live.py",
28
+ "verify:tabs": "uv run --with pyte python scripts/verify-tab-groups.py"
28
29
  },
29
30
  "dependencies": {
30
31
  "@opencode/plugin": "2.0.3",
package/tui.ts CHANGED
@@ -11,6 +11,33 @@ export default Plugin.define({
11
11
  let running = false;
12
12
  let reopenPending = false;
13
13
  let lastError: string | undefined;
14
+ function groupTabs() {
15
+ const tabs = ctx.ui.tabs.list().map((tab) => {
16
+ const projectID = ctx.data.session.get(tab.sessionID)?.projectID;
17
+ return {
18
+ sessionID: tab.sessionID,
19
+ projectID:
20
+ typeof projectID === "string" && projectID.length > 0
21
+ ? projectID
22
+ : undefined,
23
+ };
24
+ });
25
+ const groups = new Map<string, string[]>();
26
+ for (const tab of tabs) {
27
+ const key =
28
+ tab.projectID === undefined
29
+ ? `session:${tab.sessionID}`
30
+ : `project:${tab.projectID}`;
31
+ const group = groups.get(key);
32
+ if (group) group.push(tab.sessionID);
33
+ else groups.set(key, [tab.sessionID]);
34
+ }
35
+ const ordered = [...groups.values()].flat();
36
+ for (const [index, sessionID] of ordered.entries()) {
37
+ if (ctx.ui.tabs.list()[index]?.sessionID === sessionID) continue;
38
+ if (!ctx.ui.tabs.move(sessionID, index)) break;
39
+ }
40
+ }
14
41
  async function reconcile(reopen = false) {
15
42
  if (stopped || !ctx.ui.tabs.enabled()) return;
16
43
  if (running) {
@@ -19,6 +46,7 @@ export default Plugin.define({
19
46
  }
20
47
  running = true;
21
48
  try {
49
+ groupTabs();
22
50
  const route = ctx.ui.router.current();
23
51
  const coordinatorIDs = [
24
52
  ...new Set([
@@ -45,6 +73,7 @@ export default Plugin.define({
45
73
  });
46
74
  }
47
75
  }
76
+ if (!stopped && ctx.ui.tabs.enabled()) groupTabs();
48
77
  } finally {
49
78
  running = false;
50
79
  if (reopenPending) {