@linxin666/dsh-pet 0.1.13 → 0.1.15

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 (57) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +11 -7
  3. package/README.zh.md +11 -7
  4. package/lib/client.js +38 -17
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +393 -150
  7. package/lib/invariant.js +1 -1
  8. package/lib/{state-C9EyycwI.js → state-CFyJv0sQ.js} +22 -7
  9. package/lib/types/affinity.d.ts +15 -0
  10. package/lib/types/affinity.d.ts.map +1 -1
  11. package/lib/types/affinity.js +14 -0
  12. package/lib/types/client/PluginSettingsCard.d.ts +26 -11
  13. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
  14. package/lib/types/client/PluginSettingsCard.js +27 -7
  15. package/lib/types/client/WhalePet.d.ts.map +1 -1
  16. package/lib/types/client/WhalePet.js +2 -1
  17. package/lib/types/client/index.d.ts +1 -1
  18. package/lib/types/client/index.js +3 -3
  19. package/lib/types/client/settings-form.d.ts +14 -5
  20. package/lib/types/client/settings-form.d.ts.map +1 -1
  21. package/lib/types/client/settings-form.js +38 -10
  22. package/lib/types/dsh-home.d.ts +17 -0
  23. package/lib/types/dsh-home.d.ts.map +1 -0
  24. package/lib/types/dsh-home.js +34 -0
  25. package/lib/types/event-projection.d.ts +36 -0
  26. package/lib/types/event-projection.d.ts.map +1 -0
  27. package/lib/types/event-projection.js +98 -0
  28. package/lib/types/ledger.d.ts +77 -0
  29. package/lib/types/ledger.d.ts.map +1 -0
  30. package/lib/types/ledger.js +139 -0
  31. package/lib/types/persist.d.ts +5 -1
  32. package/lib/types/persist.d.ts.map +1 -1
  33. package/lib/types/persist.js +7 -3
  34. package/lib/types/service.d.ts +24 -44
  35. package/lib/types/service.d.ts.map +1 -1
  36. package/lib/types/service.js +98 -131
  37. package/lib/types/state.d.ts +10 -12
  38. package/lib/types/state.d.ts.map +1 -1
  39. package/lib/types/state.js +14 -10
  40. package/package.json +1 -1
  41. package/src/affinity.ts +33 -0
  42. package/src/client/PluginSettingsCard.tsx +83 -17
  43. package/src/client/WhalePet.test.tsx +25 -1
  44. package/src/client/WhalePet.tsx +6 -0
  45. package/src/client/index.ts +3 -3
  46. package/src/client/pet.module.css +9 -0
  47. package/src/client/settings-card.module.css +6 -0
  48. package/src/client/settings-form.ts +41 -9
  49. package/src/dsh-home.test.ts +35 -0
  50. package/src/dsh-home.ts +36 -0
  51. package/src/event-projection.ts +128 -0
  52. package/src/ledger.test.ts +67 -0
  53. package/src/ledger.ts +183 -0
  54. package/src/persist.ts +7 -3
  55. package/src/service.ts +110 -171
  56. package/src/state.test.ts +4 -1
  57. package/src/state.ts +17 -13
package/src/state.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  /**
2
- * Pet state machine — pure, clock-injected. Maps the pet's working-phase
3
- * vocabulary (the service derives it from core session events) onto the
4
- * 9-state Codex pet animation contract, plus the session lifecycle
5
- * transitions the web UI exposes (turn end celebration, no-session idle).
2
+ * Pet state machine — pure, clock-injected. Maps official DSH session activity
3
+ * and the legacy `activity/status` vocabulary onto the 9-state Codex pet
4
+ * animation contract, plus turn-end celebration and no-session idle.
6
5
  *
7
6
  * The machine is deliberately dumb: it holds the last input phase, the
8
7
  * animation decision, and a one-shot "celebration" window after `done` so the
@@ -11,8 +10,8 @@
11
10
  * @module @linxin666/dsh-pet/state
12
11
  */
13
12
 
14
- /** The pet's working-phase vocabulary (derived from core session events by the service). */
15
- export type ActivityPhase = 'idle' | 'waiting' | 'thinking' | 'tool' | 'done'
13
+ /** Activity phases understood by the pet host. */
14
+ export type ActivityPhase = 'idle' | 'waiting' | 'thinking' | 'tool' | 'review' | 'done' | 'failed'
16
15
 
17
16
  /** The Codex-compatible 9-state animation contract (spritesheet rows). */
18
17
  export type PetAnimation =
@@ -28,7 +27,7 @@ export type PetAnimation =
28
27
 
29
28
  /** One input snapshot consumed by the machine. */
30
29
  export interface PetStateInput {
31
- /** Current working phase of the active session. */
30
+ /** Current activity phase of the active session. */
32
31
  phase: ActivityPhase
33
32
  /** Human-readable status line (plain text). */
34
33
  line?: string
@@ -60,20 +59,21 @@ export const defaultPetStateConfig: PetStateConfig = { celebrateMs: 2400 }
60
59
 
61
60
  /**
62
61
  * Map one activity phase onto the animation contract.
63
- * - thinking / tool → `running` (focused work), with `running-right` as the
64
- * side-alternating variant the client may use for tool activity.
62
+ * - thinking → `running` and tool `running-right` (focused work).
63
+ * - review `review` while answer text is streaming.
65
64
  * - waiting → `waiting` (expectant pose, needs user input).
66
65
  * - done → `jumping` (celebration), then back to `idle` after the window.
66
+ * - failed → `failed` until another activity event arrives.
67
67
  * - idle → `idle` (calm breathing loop).
68
- * `failed` has no DSH phase source yet; the machine keeps the mapping table
69
- * so a future error event can light it up.
70
68
  */
71
69
  export function animationForPhase(phase: ActivityPhase): PetAnimation {
72
70
  switch (phase) {
73
71
  case 'thinking': return 'running'
74
72
  case 'tool': return 'running-right'
73
+ case 'review': return 'review'
75
74
  case 'waiting': return 'waiting'
76
75
  case 'done': return 'jumping'
76
+ case 'failed': return 'failed'
77
77
  case 'idle': return 'idle'
78
78
  }
79
79
  }
@@ -110,7 +110,7 @@ export class PetStateMachine {
110
110
  private readonly now: () => number = Date.now,
111
111
  ) {}
112
112
 
113
- /** Consume one phase snapshot (fed by the service from session events). */
113
+ /** Consume one projected activity update. */
114
114
  onActivityStatus(input: PetStateInput): void {
115
115
  this.phase = input.phase
116
116
  this.line = input.line
@@ -144,7 +144,11 @@ export class PetStateMachine {
144
144
  animation = 'idle'
145
145
  }
146
146
  }
147
- const bubble = this.phrase ?? this.line
147
+ const bubble = this.phase === 'done'
148
+ && this.doneAt !== undefined
149
+ && nowMs - this.doneAt >= this.config.celebrateMs
150
+ ? undefined
151
+ : this.phrase ?? this.line
148
152
  return {
149
153
  animation,
150
154
  ...(bubble === undefined ? {} : { bubble }),