cortico-world-agent-speed 0.2.0 → 0.2.2

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 (189) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +0 -14
  3. package/README.md +29 -11
  4. package/THIRD_PARTY_NOTICES.md +69 -0
  5. package/activity.d.ts +15 -0
  6. package/activity.js +88 -3
  7. package/describe.json +806 -0
  8. package/dist/webui.css +2 -0
  9. package/dist/webui.css.map +7 -0
  10. package/dist/webui.js +2 -0
  11. package/dist/webui.js.map +7 -0
  12. package/host/app-store.cjs +68 -0
  13. package/host/cursor.cjs +67 -0
  14. package/host/electron-main.cjs +666 -0
  15. package/host/input-shape.cjs +63 -0
  16. package/host/mouse-lease.cjs +77 -0
  17. package/host/overlay.cjs +139 -0
  18. package/host/portrait.cjs +52 -0
  19. package/host/preload.cjs +60 -14
  20. package/host/renderer-gone.cjs +24 -0
  21. package/host/windows.cjs +251 -0
  22. package/package.json +27 -7
  23. package/scripts/build-webui.mjs +40 -0
  24. package/scripts/speech-bank/build.py +166 -0
  25. package/scripts/speech-bank/dicts.py +76 -0
  26. package/src/ENV_PROMPT.en.md +51 -0
  27. package/src/ENV_PROMPT.md +51 -0
  28. package/src/asr/address.ts +25 -0
  29. package/src/asr/hotkey.ts +335 -0
  30. package/src/asr/result.ts +51 -0
  31. package/src/asr/segmenter.ts +269 -0
  32. package/src/asr/sherpa.ts +280 -0
  33. package/src/asr/simplify.ts +38 -0
  34. package/src/asr/system-recognizer.ts +292 -0
  35. package/src/asr/system-sapi.ps1 +173 -0
  36. package/src/asr/transcription-api.ts +176 -0
  37. package/src/chat.ts +212 -0
  38. package/src/config.ts +481 -0
  39. package/src/cua/ENV_PROMPT.en.md +29 -0
  40. package/src/cua/ENV_PROMPT.md +29 -0
  41. package/src/cua/config.ts +88 -0
  42. package/src/cua/cua.ts +712 -0
  43. package/src/cua/engine/darwin.ts +410 -0
  44. package/src/cua/engine/display.ts +55 -0
  45. package/src/cua/engine/fail.ts +15 -0
  46. package/src/cua/engine/foreground.ts +8 -0
  47. package/src/cua/engine/image.ts +57 -0
  48. package/src/cua/engine/keys.ts +70 -0
  49. package/src/cua/engine/linux-keys.ts +29 -0
  50. package/src/cua/engine/linux.ts +343 -0
  51. package/src/cua/engine/mac-keys.ts +57 -0
  52. package/src/cua/engine/user-activity.ts +54 -0
  53. package/src/cua/engine/wait-idle.ts +31 -0
  54. package/src/cua/engine/win32.ts +299 -0
  55. package/src/cua/engine-child.ts +274 -0
  56. package/src/cua/engine-ipc.ts +140 -0
  57. package/src/cua/i18n/de.ts +53 -0
  58. package/src/cua/i18n/en.ts +63 -0
  59. package/src/cua/i18n/es-419.ts +53 -0
  60. package/src/cua/i18n/fr.ts +53 -0
  61. package/src/cua/i18n/index.ts +26 -0
  62. package/src/cua/i18n/it.ts +53 -0
  63. package/src/cua/i18n/ja.ts +53 -0
  64. package/src/cua/i18n/ko.ts +53 -0
  65. package/src/cua/i18n/pt-BR.ts +53 -0
  66. package/src/cua/i18n/ru.ts +59 -0
  67. package/src/cua/i18n/zh-Hant.ts +53 -0
  68. package/src/cua/i18n/zh.ts +59 -0
  69. package/src/cua/model-text.ts +252 -0
  70. package/src/cua/terminal.ts +31 -0
  71. package/src/cua/tools.ts +153 -0
  72. package/src/definition.ts +146 -0
  73. package/src/host-reason.ts +32 -0
  74. package/src/i18n/de.ts +409 -0
  75. package/src/i18n/en.ts +443 -0
  76. package/src/i18n/es-419.ts +409 -0
  77. package/src/i18n/fr.ts +409 -0
  78. package/src/i18n/index.ts +56 -0
  79. package/src/i18n/it.ts +409 -0
  80. package/src/i18n/ja.ts +409 -0
  81. package/src/i18n/ko.ts +409 -0
  82. package/src/i18n/pt-BR.ts +409 -0
  83. package/src/i18n/ru.ts +415 -0
  84. package/src/i18n/zh-Hant.ts +409 -0
  85. package/src/i18n/zh.ts +440 -0
  86. package/src/index.ts +15 -0
  87. package/src/model-text.ts +344 -0
  88. package/src/moves.ts +101 -0
  89. package/src/pack-import.ts +361 -0
  90. package/src/packs.ts +449 -0
  91. package/src/runtime/download.ts +29 -0
  92. package/src/runtime/store.ts +293 -0
  93. package/src/script.ts +202 -0
  94. package/src/self.ts +247 -0
  95. package/src/server.ts +479 -0
  96. package/src/speech/data/CMUDICT-LICENSE +33 -0
  97. package/src/speech/data/IPADIC-COPYING +71 -0
  98. package/src/speech/data/UNICODE-LICENSE +39 -0
  99. package/src/speech/data/en.tsv.gz +0 -0
  100. package/src/speech/data/ja-ipadic.tsv.gz +0 -0
  101. package/src/speech/data/ja-unihan.tsv.gz +0 -0
  102. package/src/speech/data/zh.json +1 -0
  103. package/src/speech/index.ts +204 -0
  104. package/src/speech/ipa.ts +83 -0
  105. package/src/speech/japanese.ts +105 -0
  106. package/src/speech/jukujikun.ts +22 -0
  107. package/src/speech/korean.ts +35 -0
  108. package/src/speech/lang.ts +151 -0
  109. package/src/speech/rules.ts +72 -0
  110. package/src/speech/syllable.ts +76 -0
  111. package/src/status.ts +164 -0
  112. package/src/tools.ts +110 -0
  113. package/src/webui/api-rows.css +2 -0
  114. package/src/webui/api-rows.ts +44 -0
  115. package/src/webui/client.ts +451 -0
  116. package/src/webui/dress-dialog.css +14 -0
  117. package/src/webui/dress-dialog.ts +117 -0
  118. package/src/webui/dress-panel.ts +160 -0
  119. package/src/webui/key-capture.ts +60 -0
  120. package/src/webui/shared/modal.css +13 -0
  121. package/src/webui/shared/modal.ts +77 -0
  122. package/src/webui/shared/problem.css +15 -0
  123. package/src/webui/shared/problem.ts +217 -0
  124. package/src/webui/shared/strings.ts +5 -0
  125. package/src/webui/style.css +50 -0
  126. package/src/window-host.ts +116 -0
  127. package/src/world.ts +2926 -0
  128. package/web/activity-motion.js +117 -0
  129. package/web/appearance.js +60 -0
  130. package/web/body-host.js +257 -0
  131. package/web/coo/coo.js +384 -0
  132. package/web/coo/figure.js +15 -0
  133. package/web/coo/figure.json +1224 -0
  134. package/web/dist/dress-dialog.css +1 -0
  135. package/web/dist/dress-dialog.js +1 -0
  136. package/web/drag-row.js +49 -0
  137. package/web/drag.js +149 -0
  138. package/web/dress.css +170 -0
  139. package/web/dress.html +37 -0
  140. package/web/dress.js +786 -0
  141. package/web/figure-frame.html +16 -0
  142. package/web/figure-frame.js +128 -0
  143. package/web/frame-loop.js +55 -0
  144. package/web/hints.js +77 -0
  145. package/web/i18n/de.js +170 -0
  146. package/web/i18n/en.js +177 -0
  147. package/web/i18n/es-419.js +170 -0
  148. package/web/i18n/fr.js +170 -0
  149. package/web/i18n/it.js +170 -0
  150. package/web/i18n/ja.js +170 -0
  151. package/web/i18n/ko.js +170 -0
  152. package/web/i18n/pt-BR.js +170 -0
  153. package/web/i18n/ru.js +170 -0
  154. package/web/i18n/zh-Hant.js +170 -0
  155. package/web/i18n/zh.js +175 -0
  156. package/web/i18n.js +54 -0
  157. package/{renderer/vendor → web}/kit/body.js +31 -58
  158. package/web/looks.js +70 -0
  159. package/web/mic-worklet.js +36 -0
  160. package/web/mic.js +117 -0
  161. package/web/motion-frames.js +80 -0
  162. package/web/motion-level.js +40 -0
  163. package/web/new-year-2027.svg +238 -0
  164. package/web/overlay.html +16 -0
  165. package/web/overlay.js +100 -0
  166. package/web/pet-app.js +3000 -0
  167. package/web/pet.css +642 -0
  168. package/web/pet.html +21 -0
  169. package/web/scale-slider.js +259 -0
  170. package/web/show-hide.js +49 -0
  171. package/web/sound.js +245 -0
  172. package/web/speech/zh.json +1 -0
  173. package/web/speech/zh.ogg +0 -0
  174. package/web/speech.js +197 -0
  175. package/web/stage.js +160 -0
  176. package/web/swap-motion.js +119 -0
  177. package/web/ui.js +195 -0
  178. package/host/launch.js +0 -187
  179. package/host/library.cjs +0 -638
  180. package/host/main.cjs +0 -389
  181. package/index.js +0 -93
  182. package/renderer/index.html +0 -22
  183. package/renderer/pet-sandbox.html +0 -11
  184. package/renderer/pet.css +0 -38
  185. package/renderer/pet.js +0 -251
  186. package/renderer/vendor/activity-motion.js +0 -101
  187. package/renderer/vendor/figure-frame.js +0 -115
  188. package/renderer/vendor/pack.css +0 -2
  189. /package/{renderer/vendor → web}/kit/rig.js +0 -0
package/web/ui.js ADDED
@@ -0,0 +1,195 @@
1
+ /** The pages' round buttons: icons (24 units, currentColor) and the theme switch. */
2
+ import { t } from './i18n.js';
3
+
4
+ export const f = n => Math.round(n * 10) / 10;
5
+ export const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
6
+
7
+ /** A bubble's border in pixels (pet.css `.bubble`). */
8
+ export const BUBBLE_BORDER = 2.5;
9
+ /**
10
+ * The width a bubble tail's slanted line is drawn at on a display of `dpr` device pixels per pixel (`--tail-line`,
11
+ * pet.css): the width the border is drawn at there, which Chromium rounds down to whole device pixels (2px of the 2.5
12
+ * at 100%), so the tail carries as much ink along its length as the border does.
13
+ */
14
+ export const tailLine = (dpr) => Math.max(1, Math.floor(BUBBLE_BORDER * dpr)) / dpr;
15
+
16
+ /**
17
+ * Bubbles up to TAIL_CENTER wide (empty, or a word or two) point their tail from their middle; wider ones move it over
18
+ * to Coo by TAIL_FOLLOW wide. Between the two it slides, so a bubble growing as the line types out carries its tail
19
+ * along with it.
20
+ */
21
+ export const TAIL_CENTER = 70, TAIL_FOLLOW = 130;
22
+ /**
23
+ * How far from a bubble's side its tail's tip keeps, at bubble size 1: the tail's base reaches 10.25px either side of
24
+ * the tip (pet.css `.bubble::before`) and the corner rounds over 18px (`.bubble` border-radius), both grown with
25
+ * `--bubble-size`, so the base stays on the border's straight run. The narrowest bubble (`.bubble` min-width, 58px)
26
+ * leaves room for it on both sides.
27
+ */
28
+ export const TAIL_EDGE = 29;
29
+ /** Where the tail's tip sits along a bubble `bw` wide whose left edge is `x` left of Coo, at bubble size `size`. */
30
+ export function tailAt(bw, x, size = 1) {
31
+ const k = clamp((bw - TAIL_CENTER) / (TAIL_FOLLOW - TAIL_CENTER), 0, 1), edge = Math.min(TAIL_EDGE * size, bw / 2);
32
+ return bw / 2 + (clamp(x, edge, bw - edge) - bw / 2) * k;
33
+ }
34
+
35
+ /**
36
+ * The narrowest width `el` can take without its text wrapping into more lines than at its widest: a wrapped line no
37
+ * longer leaves its bubble as wide as the widest it may be with blank space after the shorter lines, and the lines come
38
+ * out about as long as each other (the search react-wrap-balancer runs). `el` is laid out with its whole text and
39
+ * nothing clamping its height, and measured at its widest under its style sheet; its own width and max-width are left
40
+ * as they were. Returns the width to cap it at in pixels, border and padding in.
41
+ */
42
+ export function balancedWidth(el) {
43
+ const keep = [el.style.width, el.style.maxWidth];
44
+ el.style.width = el.style.maxWidth = '';
45
+ const widest = el.offsetWidth, height = el.offsetHeight;
46
+ let lo = 0, hi = widest;
47
+ while (hi - lo > 1) {
48
+ const mid = (lo + hi) / 2;
49
+ el.style.width = mid + 'px';
50
+ if (el.offsetHeight > height) lo = mid; else hi = mid;
51
+ }
52
+ // offsetWidth rounds the widest down by under a pixel (172 of 172.4), and a width at the edge wraps the text: the
53
+ // width is checked as the caller will use it, a max-width, and grows a pixel at a time until it holds, at most to
54
+ // the widest plus that pixel.
55
+ el.style.width = '';
56
+ let w = Math.ceil(hi);
57
+ for (el.style.maxWidth = w + 'px'; el.offsetHeight > height && w <= widest; el.style.maxWidth = w + 'px') w++;
58
+ [el.style.width, el.style.maxWidth] = keep;
59
+ return w;
60
+ }
61
+
62
+ /**
63
+ * Lays a grid of buttons (`grid-auto-flow: column`) `reach` out from a body standing at `x`, on the right unless that
64
+ * runs off a page `pageWidth` wide. On the left its columns run right to left, so the first column is next to the body
65
+ * on either side and a button keeps its place relative to the body whichever side the grid takes. `--dx` points the
66
+ * pop-in back at the body. Returns whether the grid went on the right.
67
+ */
68
+ export function layBeside(el, x, reach, pageWidth) {
69
+ const w = el.offsetWidth;
70
+ const onRight = x + reach + w <= pageWidth - 8;
71
+ el.style.left = f(clamp(onRight ? x + reach : x - reach - w, 8, pageWidth - w - 8)) + 'px';
72
+ el.style.direction = onRight ? '' : 'rtl';
73
+ el.style.setProperty('--dx', onRight ? '-16px' : '16px');
74
+ return onRight;
75
+ }
76
+
77
+ /**
78
+ * The http(s) addresses written out in `text`, as [start, end) pairs. An address runs to the first
79
+ * space or non-ASCII character, so one written straight into Chinese prose ends there; a sentence's
80
+ * closing punctuation is left out. Only written-out addresses become links: the text of a link is
81
+ * where it goes.
82
+ */
83
+ export function urlRanges(text) {
84
+ const out = [];
85
+ for (const m of text.matchAll(/https?:\/\/[!-~]+/g)) {
86
+ let url = m[0];
87
+ // a closing bracket stays when the address opened it, as in a wiki title
88
+ while (/[.,;:!?'"]$/.test(url) || (/[)\]}>]$/.test(url) && count(url, OPENERS[url.at(-1)]) < count(url, url.at(-1)))) url = url.slice(0, -1);
89
+ try { new URL(url); } catch { continue; }
90
+ out.push([m.index, m.index + url.length]);
91
+ }
92
+ return out;
93
+ }
94
+ const OPENERS = { ')': '(', ']': '[', '}': '{', '>': '<' };
95
+ const count = (s, c) => s.split(c).length - 1;
96
+
97
+ /** The first `n` characters of `text` as nodes of `doc`; an address typed out in full is a link that opens outside the window. */
98
+ export function linked(text, n = text.length, doc = document) {
99
+ const frag = doc.createDocumentFragment();
100
+ let at = 0;
101
+ for (const [start, end] of urlRanges(text)) {
102
+ if (end > n) break;
103
+ const a = Object.assign(doc.createElement('a'), { href: text.slice(start, end), target: '_blank', rel: 'noopener noreferrer' });
104
+ a.textContent = text.slice(start, end);
105
+ frag.append(text.slice(at, start), a);
106
+ at = end;
107
+ }
108
+ frag.append(text.slice(at, n));
109
+ return frag;
110
+ }
111
+
112
+ const icon = d => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${d}</svg>`;
113
+ // eight flat teeth around a hub
114
+ const gear = icon(`<path d="${Array.from({ length: 32 }, (_, i) => {
115
+ const a = (i - .5) * Math.PI / 16, r = i % 4 < 2 ? 9.6 : 7.2;
116
+ return `${i ? 'L' : 'M'}${f(12 + r * Math.cos(a))} ${f(12 + r * Math.sin(a))}`;
117
+ }).join('')}Z"/><circle cx="12" cy="12" r="3"/>`);
118
+ export const ICONS = {
119
+ chat: icon('<path d="M6 4.5h12a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3h-6l-4.5 3.5v-3.5H6a3 3 0 0 1-3-3v-7a3 3 0 0 1 3-3z"/>'),
120
+ moon: icon('<path d="M20 14.6A8.2 8.2 0 1 1 9.4 4a6.6 6.6 0 0 0 10.6 10.6z"/>'),
121
+ sun: icon('<circle cx="12" cy="12" r="4"/><path d="M12 2.8v1.6M12 19.6v1.6M2.8 12h1.6M19.6 12h1.6M5.5 5.5l1.1 1.1M17.4 17.4l1.1 1.1M5.5 18.5l1.1-1.1M17.4 6.6l1.1-1.1"/>'),
122
+ play: icon('<path d="M8 5.5v13l10.5-6.5z"/>'),
123
+ pause: icon('<path d="M9 5.5v13M15 5.5v13"/>'),
124
+ settings: gear,
125
+ power: icon('<path d="M12 3.5v8M7.2 6.3a8 8 0 1 0 9.6 0"/>'),
126
+ mic: icon('<rect x="8.5" y="3" width="7" height="11.5" rx="3.5"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>'),
127
+ // the same microphone struck through
128
+ micOff: icon('<rect x="8.5" y="3" width="7" height="11.5" rx="3.5"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3M4 4l16 16"/>'),
129
+ sound: icon('<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M15.5 9a4 4 0 0 1 0 6M18 6.5a7.5 7.5 0 0 1 0 11"/>'),
130
+ soundOff: icon('<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M16 9.5l5 5M21 9.5l-5 5"/>'),
131
+ // a frame open at its top right corner, a smaller corner inside it and an arrow out to the open corner: the size on screen
132
+ resize: icon('<path d="M11 3.5H5.5a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h13a2 2 0 0 0 2-2V13"/><path d="M13.5 15H9v-4.5"/><path d="M20.5 3.5 10 14M15 3.5h5.5V9"/>'),
133
+ // a circle half filled: the transparency slider
134
+ fade: icon('<circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 0 0 17z" fill="currentColor"/>'),
135
+ // a screen with a pointer on it: computer use, and struck through while it is off
136
+ computer: icon('<rect x="3" y="4" width="18" height="12.5" rx="2"/><path d="M8.5 20.5h7M12 16.5v4"/><path d="m10 7.5 1.6 5.2 1.1-2 2.1-1.1z"/>'),
137
+ computerOff: icon('<rect x="3" y="4" width="18" height="12.5" rx="2"/><path d="M8.5 20.5h7M12 16.5v4"/><path d="m10 7.5 1.6 5.2 1.1-2 2.1-1.1z"/><path d="M4 3l16 16"/>'),
138
+ // a T-shirt: the dressing page
139
+ shirt: icon('<path d="M8.5 3.5 4 6l-1.5 4.5L6 12v8.5h12V12l3.5-1.5L20 6l-4.5-2.5a3.5 3.5 0 0 1-7 0z"/>'),
140
+ eye: icon('<path d="M3 12s3.2-6 9-6 9 6 9 6-3.2 6-9 6-9-6-9-6z"/><circle cx="12" cy="12" r="3"/>'),
141
+ // the chat page: the typing box's button that carries the draft there, and the mark on what was sent from it
142
+ expand: icon('<path d="M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7"/>'),
143
+ // a page that opens in the browser
144
+ external: icon('<path d="M14 4h6v6M20 4l-8.5 8.5M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4"/>'),
145
+ // three stacked layers: the list of Worlds
146
+ boxes: icon('<path d="m12 4 7 4-7 4-7-4 7-4Z"/><path d="m5 12 7 4 7-4"/><path d="m5 16 7 4 7-4"/>'),
147
+ // a pointer over a dashed window: clicks pass through to what lies below
148
+ through: icon('<path d="m4 4 5.2 13 1.9-5.4 5.4-1.9z"/><path d="M14 14h6.5v6.5H14z" stroke-dasharray="2 2.2"/>'),
149
+ eyeOff: icon('<path d="M3 12s3.2-6 9-6c1.6 0 3 .4 4.2 1M21 12s-3.2 6-9 6c-1.6 0-3-.4-4.2-1"/><path d="M9.9 14.1a3 3 0 0 1 4.2-4.2M4 4l16 16"/>'),
150
+ // how much the pet walks on its own, as a gauge: low, middle, high
151
+ roam_off: icon('<path d="M4 16a8 8 0 0 1 16 0"/><path d="M12 16 7 13.2"/><circle cx="12" cy="16" r="1.2" fill="currentColor"/>'),
152
+ roam_calm: icon('<path d="M4 16a8 8 0 0 1 16 0"/><path d="M12 16V10"/><circle cx="12" cy="16" r="1.2" fill="currentColor"/>'),
153
+ roam_free: icon('<path d="M4 16a8 8 0 0 1 16 0"/><path d="M12 16l5-2.8"/><circle cx="12" cy="16" r="1.2" fill="currentColor"/><path d="M19.5 6.5l1.5-1.5M21 10h1.5"/>'),
154
+ // the personas the introduction offers (pet.css gives each its move when picked): a magnifier, a goblet, a hammer,
155
+ // a heart, a snowflake, the whale with its spout
156
+ persona_coo: icon('<circle cx="10.5" cy="10.5" r="6"/><path d="M15 15l5 5"/>'),
157
+ persona_grail: icon('<path d="M6.5 4h11v3.5a5.5 5.5 0 0 1-11 0z"/><path d="M12 13v6M8 20h8"/>'),
158
+ persona_forge: icon('<path d="M12.5 5.5l3-3 5 5-3 3z"/><path d="M14 9l-9.5 9.5"/>'),
159
+ persona_heart: icon('<path d="M12 19.5s-7-4.3-7-9.6a3.9 3.9 0 0 1 7-2.4 3.9 3.9 0 0 1 7 2.4c0 5.3-7 9.6-7 9.6z"/>'),
160
+ persona_winter: icon('<path d="M12 3v18M4.2 7.5l15.6 9M4.2 16.5l15.6-9"/><path d="M9.5 4.5L12 6l2.5-1.5M9.5 19.5L12 18l2.5 1.5"/>'),
161
+ persona_whale: icon('<path d="M3 13c0-3 2.6-5 6.5-5 3.3 0 5.4 1.6 7 3.3.8.8 1.6 1.2 2.5 1.2"/><path d="M3 13c0 3.1 3 5 7.5 5 4.4 0 7.5-2.2 8.5-5.5"/><path d="M19 12.5c.2-1.8 1-3.2 2.5-4-1.6-.2-2.8.3-3.6 1.4-.4-1.4-1.4-2.2-3-2.4"/><path class="spout" d="M8 5.5V3.5M6.3 4.3 8 5.5l1.7-1.2"/><circle cx="7" cy="12" r=".6" fill="currentColor"/>'),
162
+ // activity above the pet; separate parts let each small icon move in its own way
163
+ status_think: icon('<circle cx="4" cy="12" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="20" cy="12" r="1.5"/>'),
164
+ status_read: icon('<path d="M6 3h9l4 4v14H6zM14 3v5h5"/><path class="scan" d="M9 11h7"/>'),
165
+ status_browse: icon('<path d="M3 19V5h7l2 3h9v11"/><path class="flap" d="M3 19 5 10h17l-3 9z"/>'),
166
+ status_search: icon('<circle cx="10" cy="10" r="6"/><path d="m15 15 6 6"/>'),
167
+ status_write: icon('<path d="m5 15 11-11 4 4L9 19l-5 1zM13 7l4 4M5 15l4 4"/>'),
168
+ status_delete: icon('<path d="m6 8 1 13h10l1-13M10 11v6M14 11v6"/><path class="lid" d="M4 6h16M9 6V3h6v3"/>'),
169
+ status_save: icon('<path d="M4 15v6h16v-6"/><path class="arrow" d="M12 3v12m-4-4 4 4 4-4"/>'),
170
+ status_look: icon('<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle class="pupil" cx="12" cy="12" r="2.5"/>'),
171
+ status_click: icon('<path d="m5 3 3 17 4-6 7-2z"/><path class="ripple" d="M3 7H1M8 2V1M2 2l1 1"/>'),
172
+ status_scroll: icon('<rect x="5" y="2" width="14" height="20" rx="7"/><path class="wheel" d="M12 6v5m-2-3 2-2 2 2"/>'),
173
+ status_type: icon('<path d="M3 20h18"/><g class="keycap"><rect x="5" y="4" width="14" height="12" rx="3"/><path d="M9 8h6m-3 0v5"/></g>'),
174
+ status_wait: icon('<path d="M5 3h14M5 21h14M7 3v4l10 10v4M17 3v4L7 17v4M9 6h6M9 19h6"/>'),
175
+ status_alarm: icon('<circle cx="12" cy="13" r="7"/><path d="M12 9v4l3 2M3 5l3-3M18 2l3 3M7 20l-2 2M17 20l2 2"/>'),
176
+ status_work: gear,
177
+ pencil: icon('<path d="M4 20l1-4.5L15.5 5a2.1 2.1 0 0 1 3 3L8 18.5zM13.5 7l3 3"/>'),
178
+ /** A five-pointed star: save the look worn as a new one. */
179
+ addLook: icon('<path d="M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z"/>'),
180
+ /** A floppy disk: save the changes to the look picked. */
181
+ saveLook: icon('<path d="M5 3.5h11l3 3V20.5H5z"/><path d="M8.5 3.5v5h6v-5M8 20.5v-6.5h8v6.5"/>'),
182
+ trash: icon('<path d="M4 6.5h16M9.5 6.5V4.5h5v2M6.5 6.5l1 13.5h9l1-13.5M10 10.5v6M14 10.5v6"/>'),
183
+ };
184
+ /** Sets `theme` ('dark' | 'light') on the page; `button`, when given, shows the mode a click switches to. */
185
+ export function applyTheme(theme, button) {
186
+ document.documentElement.dataset.theme = theme;
187
+ if (button) themeButton(theme, button);
188
+ }
189
+ /** Draws `button` as the switch away from `theme`, without changing the page's theme. */
190
+ export function themeButton(theme, button) {
191
+ const toLight = theme === 'dark';
192
+ button.innerHTML = toLight ? ICONS.sun : ICONS.moon;
193
+ button.title = t(toLight ? 'theme.toLight' : 'theme.toDark');
194
+ button.setAttribute('aria-label', button.title);
195
+ }
package/host/launch.js DELETED
@@ -1,187 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { accessSync, constants, readFileSync } from 'node:fs';
3
- import { createRequire } from 'node:module';
4
- import { dirname, join } from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { Worker } from 'node:worker_threads';
7
-
8
- const require = createRequire(import.meta.url);
9
- const appPath = fileURLToPath(new URL('./main.cjs', import.meta.url));
10
- const READY_MS = 12_000;
11
- const STOP_GRACE_MS = 1_200;
12
-
13
- function electronDistribution() {
14
- let packageDir;
15
- try {
16
- packageDir = dirname(require.resolve('electron/package.json'));
17
- } catch (cause) {
18
- throw new Error('Agent Speed requires its npm Electron dependency.', { cause });
19
- }
20
- // Resolve the installed npm distribution, not PATH, Coopanion's executable,
21
- // the CLI wrapper, or ELECTRON_OVERRIDE_DIST_PATH.
22
- const leaf = process.platform === 'darwin' ? 'Electron.app/Contents/MacOS/Electron'
23
- : process.platform === 'win32' ? 'electron.exe' : 'electron';
24
- const executable = join(packageDir, 'dist', leaf);
25
- return {
26
- executable,
27
- installer: join(packageDir, 'install.js'),
28
- installed() {
29
- try {
30
- // The installer writes the marker last, so a partial extraction isn't a valid runtime.
31
- if (readFileSync(join(packageDir, 'path.txt'), 'utf8') !== leaf) return false;
32
- accessSync(executable, constants.X_OK);
33
- return true;
34
- } catch {
35
- return false;
36
- }
37
- },
38
- };
39
- }
40
-
41
- export function launchPet(dataDir, onState) {
42
- const distribution = electronDistribution();
43
- const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(?:ELECTRON_|NODE_)/i.test(key)));
44
- onState('loading');
45
- if (distribution.installed()) return spawnPet(distribution.executable, dataDir, env, onState);
46
-
47
- // Electron 42+ defers downloading the binary until first use. The npm entry
48
- // point starts process.execPath to do that; under Coopanion that's the host
49
- // Electron. Run the pinned npm installer in a thread instead so its exit calls
50
- // cannot exit the World process and no host executable is launched.
51
- const installerEnv = Object.fromEntries(Object.entries(env).filter(([key]) =>
52
- !/^npm_config_(?:electron|arch$|platform$)/i.test(key)));
53
- const worker = new Worker(distribution.installer, { env: installerEnv, execArgv: [] });
54
- let installationError;
55
- let cancelled = false;
56
- let latest = null;
57
- let pet;
58
- worker.once('error', (error) => { installationError = error; });
59
- const installed = new Promise((resolve) => {
60
- worker.once('exit', (code) => {
61
- if (!cancelled) {
62
- try {
63
- if (installationError) throw installationError;
64
- if (code !== 0 || !distribution.installed()) throw new Error(`Electron installer did not complete (${code}).`);
65
- pet = spawnPet(distribution.executable, dataDir, env, onState);
66
- pet.setActivity(latest);
67
- } catch (error) {
68
- console.error('[Agent Speed] Cannot provision pet process:', error.message);
69
- onState('error');
70
- }
71
- }
72
- resolve();
73
- });
74
- });
75
-
76
- return {
77
- setActivity(snapshot) {
78
- if (pet) pet.setActivity(snapshot);
79
- else latest = snapshot;
80
- },
81
- async stop() {
82
- cancelled = true;
83
- if (pet) await pet.stop();
84
- else {
85
- await worker.terminate();
86
- await installed;
87
- }
88
- },
89
- };
90
- }
91
-
92
- function spawnPet(executable, dataDir, env, onState) {
93
- const child = spawn(executable, [appPath, `--agent-speed-data-dir=${dataDir}`], {
94
- env,
95
- stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
96
- windowsHide: true,
97
- });
98
-
99
- let latest = null;
100
- let dirty = true;
101
- let sending = false;
102
- let ready = false;
103
- let stopping = false;
104
- let failed = false;
105
- let closed = false;
106
- let requestedStop = false;
107
- let terminateTimer;
108
- let killTimer;
109
- const readyTimer = setTimeout(() => {
110
- fail(new Error('Window did not report ready.'));
111
- }, READY_MS).unref();
112
-
113
- function fail(error) {
114
- if (!failed && !requestedStop && !closed) {
115
- failed = true;
116
- console.error('[Agent Speed] Pet process:', error.message);
117
- onState('error');
118
- }
119
- shutdown();
120
- }
121
-
122
- function shutdown() {
123
- if (stopping || closed) return;
124
- stopping = true;
125
- clearTimeout(readyTimer);
126
- if (child.connected) child.send({ type: 'stop' }, () => {});
127
- terminateTimer = setTimeout(() => child.kill('SIGTERM'), STOP_GRACE_MS);
128
- killTimer = setTimeout(() => child.kill('SIGKILL'), 2 * STOP_GRACE_MS);
129
- }
130
-
131
- const exited = new Promise((resolve) => {
132
- child.once('close', (code, signal) => {
133
- closed = true;
134
- clearTimeout(readyTimer);
135
- clearTimeout(terminateTimer);
136
- clearTimeout(killTimer);
137
- if (!requestedStop && !failed && (!ready || code !== 0)) {
138
- failed = true;
139
- console.error(`[Agent Speed] Pet process exited (${signal ?? code}).`);
140
- }
141
- onState(!requestedStop && failed ? 'error' : 'offline');
142
- resolve();
143
- });
144
- });
145
-
146
- function flush() {
147
- if (!ready || stopping || !child.connected || !dirty || sending) return;
148
- // At most one write in flight. Backpressure drops intermediate samples,
149
- // keeping the latest target rather than a backlog of animation states.
150
- dirty = false;
151
- sending = true;
152
- child.send({ type: 'activity', snapshot: latest }, (error) => {
153
- sending = false;
154
- if (error) {
155
- // Closing the normal window can race a write to its IPC channel.
156
- if (!child.connected || stopping) shutdown();
157
- else fail(error);
158
- return;
159
- }
160
- flush();
161
- });
162
- }
163
-
164
- child.on('error', fail);
165
- child.on('disconnect', shutdown);
166
- child.on('message', (message) => {
167
- if (closed || stopping || ready || message?.type !== 'ready') return;
168
- ready = true;
169
- clearTimeout(readyTimer);
170
- onState('online');
171
- flush();
172
- });
173
-
174
- return {
175
- setActivity(snapshot) {
176
- if (closed || stopping) return;
177
- latest = snapshot;
178
- dirty = true;
179
- flush();
180
- },
181
- stop() {
182
- requestedStop = true;
183
- shutdown();
184
- return exited;
185
- },
186
- };
187
- }