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
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Starts and stops the process that shows the pet window: an Electron main process running
3
+ * `host/electron-main.cjs`, which opens a transparent, frameless, always-on-top window over
4
+ * the work area of one display (the primary one at start) and loads the pet page.
5
+ *
6
+ * Use the configured standalone Electron executable or the managed runtime from the panel.
7
+ * Coopanion's CORTICO_DESKTOP_PET_HOST launches its bundled pet host, not the copy in this
8
+ * extension: its preload and renderer protocol would not match ours.
9
+ *
10
+ * Why the window is not there (`HostState.reason`) is kept as data: the bot reads it in its receipts in the
11
+ * model-text language (`model-text.ts`), people read it in the page's language (`i18n/`).
12
+ */
13
+ import { spawn, type ChildProcess } from 'node:child_process';
14
+ import { existsSync } from 'node:fs';
15
+ import { fileURLToPath } from 'node:url';
16
+ import type { Logger } from 'cortico/core/types.ts';
17
+ import type { HostReason } from './host-reason.ts';
18
+
19
+ const HOST_MAIN = fileURLToPath(new URL('../host/electron-main.cjs', import.meta.url));
20
+
21
+ export type HostPhase = 'stopped' | 'running' | 'missing' | 'error';
22
+
23
+ export interface HostState {
24
+ phase: HostPhase;
25
+ pid: number | null;
26
+ /** Which command runs the window. */
27
+ source: string | null;
28
+ reason: HostReason | null;
29
+ }
30
+
31
+ export type HostCommand = { command: string; args: string[]; source: string } | { missing: HostReason };
32
+
33
+ export function resolveHostCommand(url: string, electronFile: string, managed: string | null): HostCommand {
34
+ const args = [HOST_MAIN, `--pet-url=${url}`];
35
+ if (electronFile) {
36
+ if (!existsSync(electronFile)) return { missing: { kind: 'noElectronFile', file: electronFile } };
37
+ return { command: electronFile, args, source: electronFile };
38
+ }
39
+ if (managed) return { command: managed, args, source: managed };
40
+ return { missing: { kind: 'noElectron' } };
41
+ }
42
+
43
+ export class WindowHost {
44
+ private child: ChildProcess | null = null;
45
+ private st: HostState = { phase: 'stopped', pid: null, source: null, reason: null };
46
+
47
+ constructor(private readonly log: Logger) {}
48
+
49
+ state(): HostState {
50
+ return { ...this.st, pid: this.child?.pid ?? null };
51
+ }
52
+
53
+ start(cmd: HostCommand): void {
54
+ if (this.child) return;
55
+ if ('missing' in cmd) {
56
+ this.st = { phase: 'missing', pid: null, source: null, reason: cmd.missing };
57
+ return;
58
+ }
59
+ const env = { ...process.env };
60
+ // In the desktop app Core runs under Electron's Node mode. The pet gets a fresh Electron app,
61
+ // not the embedding process's loader flags.
62
+ delete env.ELECTRON_RUN_AS_NODE;
63
+ delete env.NODE_OPTIONS;
64
+ let child: ChildProcess;
65
+ try {
66
+ // the window closes by itself if this process dies without stopping it
67
+ child = spawn(cmd.command, [...cmd.args, `--parent-pid=${process.pid}`], { env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: false });
68
+ } catch (err) {
69
+ this.st = { phase: 'error', pid: null, source: cmd.source, reason: { kind: 'startFailed', why: (err as Error).message } };
70
+ return;
71
+ }
72
+ this.child = child;
73
+ this.st = { phase: 'running', pid: child.pid ?? null, source: cmd.source, reason: null };
74
+ const log = this.log.child('window');
75
+ // a line the window process starts with `[warn] ` (host/electron-main.cjs) is a warning
76
+ const forward = (d: Buffer) => {
77
+ for (const line of d.toString().split(/\r?\n/)) {
78
+ if (line.startsWith('[warn] ')) log.warn(line.slice('[warn] '.length));
79
+ else if (line.trim()) log.debug(line);
80
+ }
81
+ };
82
+ child.stdout?.on('data', forward);
83
+ child.stderr?.on('data', forward);
84
+ child.on('error', (err) => {
85
+ log.warn(`窗口进程出错:${err.message}`);
86
+ if (this.child !== child) return;
87
+ // A failed spawn emits error and close, but does not emit exit.
88
+ if (!child.pid) this.child = null;
89
+ this.st = { ...this.st, phase: 'error', reason: { kind: 'error', message: err.message } };
90
+ });
91
+ child.on('exit', (code, signal) => {
92
+ if (this.child !== child) return;
93
+ this.child = null;
94
+ // a window process that ends on its own with a failure is logged; Windows exit codes such as 0x80000003 read in hex
95
+ if (code !== 0) {
96
+ const how = code === null ? signal : process.platform === 'win32' ? `0x${(code >>> 0).toString(16).toUpperCase()}` : code;
97
+ log.warn(`窗口进程退出(退出码 ${how})`);
98
+ }
99
+ this.st = { phase: code === 0 ? 'stopped' : 'error', pid: null, source: cmd.source, reason: code === 0 ? { kind: 'closed' } : { kind: 'exited', code } };
100
+ });
101
+ }
102
+
103
+ async stop(): Promise<void> {
104
+ const child = this.child;
105
+ this.child = null;
106
+ this.st = { ...this.st, phase: 'stopped', pid: null, reason: null };
107
+ if (!child || child.exitCode !== null) return;
108
+ const exited = new Promise<void>((r) => child.once('exit', () => r()));
109
+ child.kill();
110
+ await Promise.race([exited, new Promise((r) => setTimeout(r, 3000))]);
111
+ if (child.exitCode === null && child.pid) {
112
+ if (process.platform === 'win32') spawn('taskkill', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true });
113
+ else child.kill('SIGKILL');
114
+ }
115
+ }
116
+ }