opencode-terminal-progress 0.2.1 → 0.3.0

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 +55 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -17,14 +17,27 @@ function createOsc() {
17
17
  const inTmux = !!process.env["TMUX"];
18
18
  return (payload) => {
19
19
  const esc = inTmux ? `\x1BPtmux;\x1B\x1B]${payload}\x07\x1B\\` : `\x1B]${payload}\x07`;
20
- process.stdout.write(esc);
20
+ process.stderr.write(esc);
21
21
  };
22
22
  }
23
+ function toolProgress(messages) {
24
+ let total = 0;
25
+ let done = 0;
26
+ for (const stats of messages.values()) {
27
+ total += stats.total;
28
+ done += stats.done;
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,55 @@ 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 key = tp.messageID;
100
+ const stats = tools.get(key) ?? { total: 0, done: 0 };
101
+ if (tp.state.status === "pending" || tp.state.status === "running") {
102
+ if (tp.state.status === "pending") {
103
+ stats.total++;
104
+ }
105
+ } else {
106
+ stats.done++;
107
+ }
108
+ tools.set(key, stats);
109
+ if (busy)
110
+ showBusy();
111
+ }
112
+ break;
113
+ }
63
114
  case "permission.asked":
64
115
  pause();
65
116
  break;
66
117
  case "permission.replied":
67
118
  resume();
68
- progress("3");
119
+ showBusy();
69
120
  break;
70
121
  }
71
122
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-terminal-progress",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "OpenCode plugin that shows agent progress in terminal tabs (iTerm2, WezTerm, Windows Terminal)",
5
5
  "author": {
6
6
  "name": "Pedro Pombeiro",