opencube 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencube",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "A tiny Three.js desktop pet for opencode session activity.",
5
5
  "main": "src/main.js",
6
6
  "exports": {
package/src/main.js CHANGED
@@ -27,6 +27,7 @@ let petSignals = []
27
27
  let sessionMap = new Map()
28
28
  let activeToolsBySession = new Map()
29
29
  let pendingPermissionsByRequest = new Map()
30
+ let pendingQuestionsByRequest = new Map()
30
31
  let cleanupTimer = null
31
32
  let dragState = null
32
33
 
@@ -133,6 +134,7 @@ function recordEvent(event) {
133
134
  applySessionEvent(item)
134
135
  applyToolEvent(item)
135
136
  applyPermissionEvent(item)
137
+ applyQuestionEvent(item)
136
138
  if (item.type === "hello" || item.type === "fancy_hello") {
137
139
  petSignals.push({
138
140
  id: item.id,
@@ -180,6 +182,33 @@ function clearPendingPermissionsForSession(sessionID) {
180
182
  }
181
183
  }
182
184
 
185
+ function applyQuestionEvent(event) {
186
+ if (!event || typeof event.sessionID !== "string") return
187
+
188
+ if (event.type === "question.ask") {
189
+ const requestID = typeof event.requestID === "string" ? event.requestID : event.id
190
+ if (!requestID) return
191
+ pendingQuestionsByRequest.set(requestID, {
192
+ requestID,
193
+ sessionID: event.sessionID,
194
+ questions: event.questions,
195
+ tool: event.tool,
196
+ askedAt: event.receivedAt || Date.now(),
197
+ })
198
+ return
199
+ }
200
+
201
+ if (event.type === "question.reply" || event.type === "question.reject") {
202
+ if (typeof event.requestID === "string") pendingQuestionsByRequest.delete(event.requestID)
203
+ }
204
+ }
205
+
206
+ function clearPendingQuestionsForSession(sessionID) {
207
+ for (const [requestID, question] of pendingQuestionsByRequest) {
208
+ if (question?.sessionID === sessionID) pendingQuestionsByRequest.delete(requestID)
209
+ }
210
+ }
211
+
183
212
  function applyToolEvent(event) {
184
213
  if (!event || typeof event.sessionID !== "string" || typeof event.callID !== "string") return
185
214
  if (event.type !== "tool.start" && event.type !== "tool.finish") return
@@ -237,6 +266,7 @@ function applySessionEvent(event) {
237
266
  if (event.type === "session.idle") {
238
267
  activeToolsBySession.delete(event.sessionID)
239
268
  clearPendingPermissionsForSession(event.sessionID)
269
+ clearPendingQuestionsForSession(event.sessionID)
240
270
  sessionMap.set(event.sessionID, {
241
271
  sessionID: event.sessionID,
242
272
  state: "idle",
@@ -259,6 +289,7 @@ function pruneIdleSessions(refresh = true) {
259
289
  sessionMap.delete(sessionID)
260
290
  activeToolsBySession.delete(sessionID)
261
291
  clearPendingPermissionsForSession(sessionID)
292
+ clearPendingQuestionsForSession(sessionID)
262
293
  changed = true
263
294
  }
264
295
  }
@@ -294,6 +325,7 @@ function getPetState() {
294
325
  color: DEFAULT_SESSION_COLORS[index % DEFAULT_SESSION_COLORS.length],
295
326
  })),
296
327
  permissions: Array.from(pendingPermissionsByRequest.values()),
328
+ questions: Array.from(pendingQuestionsByRequest.values()),
297
329
  signals: petSignals,
298
330
  }
299
331
  }
@@ -759,7 +791,7 @@ function petHtml3D() {
759
791
  const dragParticleTexture = createDragParticleTexture()
760
792
  const faceGeometry = new THREE.PlaneGeometry(0.60, 0.60)
761
793
  const glowGeometry = new THREE.PlaneGeometry(1.18, 1.18)
762
- const permissionGlowGeometry = new THREE.PlaneGeometry(1.42, 1.42)
794
+ const permissionGlowGeometry = new THREE.PlaneGeometry(1.62, 1.62)
763
795
  const rad = THREE.MathUtils.degToRad
764
796
 
765
797
  function createGlowTexture() {
@@ -1279,7 +1311,7 @@ function petHtml3D() {
1279
1311
  permissionGlowGeometry,
1280
1312
  new THREE.MeshBasicMaterial({
1281
1313
  map: glowTexture,
1282
- color: 0xff2448,
1314
+ color: 0xffffff,
1283
1315
  transparent: true,
1284
1316
  opacity: 0,
1285
1317
  blending: THREE.AdditiveBlending,
@@ -1287,7 +1319,7 @@ function petHtml3D() {
1287
1319
  side: THREE.DoubleSide,
1288
1320
  }),
1289
1321
  )
1290
- permissionGlow.position.set(...glowPosition.map((value) => value === 0 ? 0 : value * 1.055))
1322
+ permissionGlow.position.set(...glowPosition.map((value) => value === 0 ? 0 : value * 1.072))
1291
1323
  permissionGlow.rotation.set(...rotation)
1292
1324
  cubeGroup.add(permissionGlow)
1293
1325
  permissionGlowMeshes.set(name, permissionGlow)
@@ -1494,13 +1526,15 @@ function petHtml3D() {
1494
1526
  const sessionID = Array.from(pendingSessionIDs).find((id) => sessionFaceMap.get(id) === faceName)
1495
1527
  if (!sessionID) {
1496
1528
  permissionGlow.material.opacity = 0
1529
+ permissionGlow.scale.setScalar(1)
1497
1530
  continue
1498
1531
  }
1499
1532
 
1500
- permissionGlow.material.color.setRGB(1, 0.08, 0.16)
1501
- permissionGlow.material.opacity = 0.16 + pulse * 0.62
1502
- permissionGlow.scale.setScalar(1.00 + pulse * 0.34)
1503
- active[faceName] = { sessionID, pulse, pending: true }
1533
+ const color = sessionColorMap.get(sessionID) || randomSessionGlowColor()
1534
+ permissionGlow.material.color.setRGB(color.r / 255, color.g / 255, color.b / 255)
1535
+ permissionGlow.material.opacity = 0.14 + pulse * 0.60
1536
+ permissionGlow.scale.setScalar(1.06 + pulse * 0.42)
1537
+ active[faceName] = { sessionID, pulse, pending: true, color: color.name, rgb: [color.r, color.g, color.b] }
1504
1538
  }
1505
1539
 
1506
1540
  return active
@@ -1565,7 +1599,8 @@ function petHtml3D() {
1565
1599
  const toolParticles = updateToolParticles(sessions, dt, now)
1566
1600
  processSignals(snapshot.signals || [], now)
1567
1601
  const helloFlashes = applyFlashFaces(now)
1568
- const permissionGlows = applyPermissionGlowFaces(snapshot.permissions || [], now)
1602
+ const pendingAttention = [...(snapshot.permissions || []), ...(snapshot.questions || [])]
1603
+ const permissionGlows = applyPermissionGlowFaces(pendingAttention, now)
1569
1604
  renderCube()
1570
1605
  latestDebug = {
1571
1606
  now: Date.now(),
@@ -169,6 +169,45 @@ module.exports = {
169
169
  return
170
170
  }
171
171
 
172
+ if (event.type === "question.asked") {
173
+ const question = event.properties || {}
174
+ await sendEvent({
175
+ type: "question.ask",
176
+ message: "opencode is waiting for a question answer",
177
+ sessionID: question.sessionID,
178
+ requestID: question.id,
179
+ questions: question.questions,
180
+ tool: question.tool,
181
+ source: "opencube-plugin",
182
+ })
183
+ return
184
+ }
185
+
186
+ if (event.type === "question.replied") {
187
+ const question = event.properties || {}
188
+ await sendEvent({
189
+ type: "question.reply",
190
+ message: "opencode question was answered",
191
+ sessionID: question.sessionID,
192
+ requestID: question.requestID,
193
+ answers: question.answers,
194
+ source: "opencube-plugin",
195
+ })
196
+ return
197
+ }
198
+
199
+ if (event.type === "question.rejected") {
200
+ const question = event.properties || {}
201
+ await sendEvent({
202
+ type: "question.reject",
203
+ message: "opencode question was rejected",
204
+ sessionID: question.sessionID,
205
+ requestID: question.requestID,
206
+ source: "opencube-plugin",
207
+ })
208
+ return
209
+ }
210
+
172
211
  if (event.type !== "session.status") return
173
212
 
174
213
  const sessionID = event.properties?.sessionID