cortico-world-screen-peek 0.1.0 → 0.1.3
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/index.ts +33 -5
- package/package.json +7 -2
package/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ const TEXT = {
|
|
|
52
52
|
width: { title: '截图最长边', suffix: 'px', description: '越小越省 token;1280 大约是一次 1000 多 token 的图。' },
|
|
53
53
|
next: '下一次',
|
|
54
54
|
later: (m: number) => `${m} 分钟内`,
|
|
55
|
+
disabled: '已关闭',
|
|
55
56
|
glance: '(你刚才无意间瞥了一眼主人的屏幕,画面在下面。只是一眼:大多数时候看完就算了,什么都别说;只有真的有意思、或者他正好需要你搭话时,才用一句话带过。不要复述屏幕上的内容,也不要提你看到了哪些窗口、代码或文件。画面里可能有你自己的窗口,别被自己吓到。)',
|
|
56
57
|
fallback: (w: number, h: number) => `[主人屏幕的截图,${w}×${h}]`,
|
|
57
58
|
off: '只在 macOS 上可用',
|
|
@@ -66,6 +67,7 @@ const TEXT = {
|
|
|
66
67
|
width: { title: 'Longest side of the screenshot', suffix: 'px', description: 'Smaller costs fewer tokens; 1280 is about a thousand tokens a look.' },
|
|
67
68
|
next: 'Next',
|
|
68
69
|
later: (m: number) => `within ${m} min`,
|
|
70
|
+
disabled: 'off',
|
|
69
71
|
glance: '(You just happened to glance at the person\'s screen — the picture is below. It was a glance, nothing more: most of the time, just look and say nothing at all; only when something is genuinely interesting, or when they need a word from you, say one short line. Do not repeat what is on the screen, and do not mention which windows, code or files you saw. Your own window may be in the picture; do not be startled by it.)',
|
|
70
72
|
fallback: (w: number, h: number) => `[A screenshot of the person's screen, ${w}×${h}]`,
|
|
71
73
|
off: 'macOS only',
|
|
@@ -116,6 +118,9 @@ class Peek implements World {
|
|
|
116
118
|
readonly id = ID;
|
|
117
119
|
private host: WorldHost | null = null;
|
|
118
120
|
private timer: NodeJS.Timeout | null = null;
|
|
121
|
+
/** 轮询配置的变化:配置页改了间隔/开关,15 秒内就重新安排,不用等当前这一轮走完。 */
|
|
122
|
+
private watch: NodeJS.Timeout | null = null;
|
|
123
|
+
private signature = '';
|
|
119
124
|
private nextAt = 0;
|
|
120
125
|
/** 模型正在一轮对话里(模型调用/工具/交接):这一刻不插队。 */
|
|
121
126
|
private busy = false;
|
|
@@ -143,7 +148,7 @@ class Peek implements World {
|
|
|
143
148
|
this.language = language;
|
|
144
149
|
const t = textFor(language);
|
|
145
150
|
const minutes = Math.max(1, Math.round((this.nextAt - Date.now()) / 60_000));
|
|
146
|
-
const off = { label: t.next, value:
|
|
151
|
+
const off = { label: t.next, value: t.disabled, tone: 'off' as const };
|
|
147
152
|
const group: ConfigGroup = {
|
|
148
153
|
id: `world:${ID}`,
|
|
149
154
|
owner: `world:${ID}`,
|
|
@@ -161,7 +166,7 @@ class Peek implements World {
|
|
|
161
166
|
};
|
|
162
167
|
return {
|
|
163
168
|
label: t.label,
|
|
164
|
-
|
|
169
|
+
badges: [this.cfg.enabled && this.nextAt > 0 ? { label: t.next, value: t.later(minutes), tone: 'plain' as const } : off],
|
|
165
170
|
config: [group],
|
|
166
171
|
};
|
|
167
172
|
}
|
|
@@ -172,13 +177,18 @@ class Peek implements World {
|
|
|
172
177
|
host.log.warn(`随手瞥一眼只支持 macOS,${process.platform} 上不启用`);
|
|
173
178
|
return;
|
|
174
179
|
}
|
|
180
|
+
this.signature = this.signatureOf();
|
|
175
181
|
this.schedule();
|
|
182
|
+
this.watch = setInterval(() => this.sync(), 15_000);
|
|
183
|
+
this.watch.unref?.();
|
|
176
184
|
}
|
|
177
185
|
|
|
178
186
|
async stop(): Promise<void> {
|
|
179
187
|
this.host = null;
|
|
180
188
|
if (this.timer) clearTimeout(this.timer);
|
|
189
|
+
if (this.watch) clearInterval(this.watch);
|
|
181
190
|
this.timer = null;
|
|
191
|
+
this.watch = null;
|
|
182
192
|
this.nextAt = 0;
|
|
183
193
|
}
|
|
184
194
|
|
|
@@ -192,15 +202,30 @@ class Peek implements World {
|
|
|
192
202
|
*/
|
|
193
203
|
private schedule(): void {
|
|
194
204
|
if (this.timer) clearTimeout(this.timer);
|
|
195
|
-
|
|
205
|
+
this.timer = null;
|
|
206
|
+
this.nextAt = 0;
|
|
207
|
+
if (!this.cfg.enabled) return;
|
|
196
208
|
const min = Math.max(1, this.cfg.everyMinutesMin);
|
|
197
209
|
const max = Math.max(min, this.cfg.everyMinutesMax);
|
|
198
|
-
const minutes =
|
|
210
|
+
const minutes = min + Math.random() * (max - min);
|
|
199
211
|
this.nextAt = Date.now() + minutes * 60_000;
|
|
200
212
|
this.timer = setTimeout(() => { void this.glance(); }, minutes * 60_000);
|
|
201
213
|
this.timer.unref?.();
|
|
202
214
|
}
|
|
203
215
|
|
|
216
|
+
/** 间隔或开关变了:按新值重新安排,而不是等旧的那一轮走完。 */
|
|
217
|
+
private sync(): void {
|
|
218
|
+
const signature = this.signatureOf();
|
|
219
|
+
if (signature === this.signature) return;
|
|
220
|
+
this.signature = signature;
|
|
221
|
+
this.schedule();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private signatureOf(): string {
|
|
225
|
+
const { enabled, everyMinutesMin: min, everyMinutesMax: max } = this.cfg;
|
|
226
|
+
return `${enabled}|${min}|${max}`;
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
/** 看一眼,推一条事件;无论如何都排下一次。 */
|
|
205
230
|
private async glance(): Promise<void> {
|
|
206
231
|
this.timer = null;
|
|
@@ -233,7 +258,10 @@ class Peek implements World {
|
|
|
233
258
|
} catch (err) {
|
|
234
259
|
host.log.warn(`随手瞥一眼失败:${err instanceof Error ? err.message : String(err)}`);
|
|
235
260
|
} finally {
|
|
236
|
-
if (this.host)
|
|
261
|
+
if (this.host) {
|
|
262
|
+
this.signature = this.signatureOf();
|
|
263
|
+
this.schedule();
|
|
264
|
+
}
|
|
237
265
|
}
|
|
238
266
|
}
|
|
239
267
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-screen-peek",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "大肥鱼偶尔随手瞥一眼屏幕:随机间隔、只在有人在的时候,看到什么算什么,不点击也不操作。",
|
|
6
6
|
"keywords": [
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"displayName": "A quick glance",
|
|
36
36
|
"description": "The pet now and then glances at the screen at random, only when someone is there, and never clicks or types."
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
|
+
"tags": [
|
|
40
|
+
"companion",
|
|
41
|
+
"sensitive-data",
|
|
42
|
+
"high-cost"
|
|
43
|
+
]
|
|
39
44
|
}
|
|
40
45
|
}
|