opencode-terminal-progress 0.2.2 → 0.3.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 +57 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20,11 +20,24 @@ function createOsc() {
20
20
  process.stderr.write(esc);
21
21
  };
22
22
  }
23
+ function toolProgress(messages) {
24
+ let total = 0;
25
+ let done = 0;
26
+ for (const tracker of messages.values()) {
27
+ total += tracker.known.size;
28
+ done += tracker.done.size;
29
+ }
30
+ if (total === 0)
31
+ return;
32
+ return Math.min(Math.round(done / total * 100), 99);
33
+ }
23
34
  var TerminalProgressPlugin = async () => {
24
35
  if (!detectTerminal())
25
36
  return {};
26
37
  const osc = createOsc();
27
38
  let waitingForInput = false;
39
+ let busy = false;
40
+ const tools = new Map;
28
41
  function progress(code) {
29
42
  osc(`9;4;${code}`);
30
43
  }
@@ -35,6 +48,19 @@ var TerminalProgressPlugin = async () => {
35
48
  function resume() {
36
49
  waitingForInput = false;
37
50
  }
51
+ function reset() {
52
+ tools.clear();
53
+ }
54
+ function showBusy() {
55
+ if (waitingForInput)
56
+ return;
57
+ const pct = toolProgress(tools);
58
+ if (pct !== undefined) {
59
+ progress(`1;${pct}`);
60
+ } else {
61
+ progress("3");
62
+ }
63
+ }
38
64
  return {
39
65
  event: async ({ event }) => {
40
66
  switch (event.type) {
@@ -42,30 +68,58 @@ var TerminalProgressPlugin = async () => {
42
68
  const { status } = event.properties;
43
69
  switch (status.type) {
44
70
  case "busy":
45
- if (!waitingForInput)
46
- progress("3");
71
+ busy = true;
72
+ showBusy();
47
73
  break;
48
74
  case "idle":
75
+ busy = false;
49
76
  resume();
77
+ reset();
50
78
  progress("0");
51
79
  break;
52
80
  }
53
81
  break;
54
82
  }
55
83
  case "session.idle":
84
+ busy = false;
56
85
  resume();
86
+ reset();
57
87
  progress("0");
58
88
  break;
59
89
  case "session.error":
90
+ busy = false;
60
91
  resume();
92
+ reset();
61
93
  progress("2");
62
94
  break;
95
+ case "message.part.updated": {
96
+ const { part } = event.properties;
97
+ if (part.type === "tool") {
98
+ const tp = part;
99
+ const tracker = tools.get(tp.messageID) ?? {
100
+ known: new Set,
101
+ done: new Set
102
+ };
103
+ tracker.known.add(tp.callID);
104
+ if (tp.state.status === "completed" || tp.state.status === "error") {
105
+ tracker.done.add(tp.callID);
106
+ }
107
+ if (tracker.done.size === tracker.known.size) {
108
+ tools.delete(tp.messageID);
109
+ } else {
110
+ tools.set(tp.messageID, tracker);
111
+ }
112
+ if (busy)
113
+ showBusy();
114
+ }
115
+ break;
116
+ }
63
117
  case "permission.asked":
64
118
  pause();
65
119
  break;
66
120
  case "permission.replied":
67
121
  resume();
68
- progress("3");
122
+ showBusy();
69
123
  break;
70
124
  }
71
125
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-terminal-progress",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "OpenCode plugin that shows agent progress in terminal tabs (iTerm2, WezTerm, Windows Terminal)",
5
5
  "author": {
6
6
  "name": "Pedro Pombeiro",