@7ots/cli 0.1.17 → 0.1.36
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/.env.example +14 -0
- package/README.md +11 -0
- package/brand/logos/base.svg +1 -0
- package/brand/logos/clawpump.png +0 -0
- package/brand/logos/conductors.svg +1 -0
- package/brand/logos/notlogin.svg +12 -0
- package/brand/logos/pumpfun.png +0 -0
- package/brand/logos/solana.png +0 -0
- package/brand/logos/spawnerbot.svg +1 -0
- package/brand/logos/virtuals.png +0 -0
- package/cli/7ots.mjs +61 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +92 -14
- package/cli/lib/brain.mjs +84 -11
- package/cli/lib/card-shot.mjs +1 -1
- package/cli/lib/config.mjs +14 -3
- package/cli/lib/desktop-sync.mjs +177 -0
- package/cli/lib/i18n.mjs +9 -0
- package/cli/lib/inferences.mjs +19 -2
- package/cli/lib/integrations.mjs +98 -13
- package/cli/lib/mcp.mjs +1 -1
- package/cli/lib/open.mjs +3 -1
- package/cli/lib/pet-server.mjs +352 -41
- package/cli/lib/prompts.mjs +1 -1
- package/cli/lib/screen.mjs +1 -1
- package/cli/lib/senses/gestures.mjs +121 -0
- package/cli/lib/senses/index.mjs +490 -0
- package/cli/lib/senses/rules.mjs +159 -0
- package/cli/lib/senses/sources/activity.mjs +95 -0
- package/cli/lib/senses/sources/calendar.mjs +75 -0
- package/cli/lib/senses/sources/index.mjs +17 -0
- package/cli/lib/senses/sources/mail.mjs +48 -0
- package/cli/lib/senses/sources/system.mjs +39 -0
- package/cli/lib/senses/util.mjs +41 -0
- package/cli/lib/senses/vendor.mjs +78 -0
- package/cli/lib/stt-local.py +16 -8
- package/cli/lib/stt.mjs +53 -6
- package/cli/lib/tooluse.mjs +56 -0
- package/cli/lib/tts-local.mjs +2 -2
- package/cli/lib/vm.mjs +2 -2
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +190 -8
- package/cli/pet/pet.html +153 -34
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +815 -74
- package/dist/7ots.esm.js +373 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +373 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +18 -4
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +84 -14
- package/server/settings.mjs +3 -0
- package/server/site.mjs +401 -0
- package/server/tts.mjs +29 -5
- package/src/avatar/AvatarStage.js +2 -2
- package/src/avatar/three.js +3 -2
- package/src/character/AvatarEditor.js +2 -1
- package/src/character/Character.js +38 -5
- package/src/character/TradingCard.js +2 -0
- package/src/character/beat.js +64 -2
- package/src/character/mods/orc.js +8 -1
- package/src/character/mods.js +104 -10
- package/src/character/motion.js +252 -1
- package/src/character/parts.js +40 -38
- package/src/character/styles.js +40 -38
- package/src/character3d/Character3D.js +26 -5
- package/src/character3d/body.js +14 -12
- package/src/character3d/export.js +693 -0
- package/src/character3d/fx.js +13 -0
- package/src/character3d/index.js +2 -0
- package/src/character3d/materials.js +106 -10
- package/src/character3d/room-themes.js +1184 -0
- package/src/character3d/room.js +487 -0
- package/src/character3d/stage.js +14 -2
- package/src/creator/StepCreator.js +316 -0
- package/src/i18n/index.js +3 -3
- package/src/i18n/messages/character.js +352 -4
- package/src/i18n/messages/creator.js +138 -0
- package/src/i18n/messages/identity.js +89 -1
- package/src/i18n/messages/platform.js +270 -4
- package/src/i18n/messages/server.js +443 -1
- package/src/i18n/messages/widget.js +233 -0
- package/src/identity/random.js +14 -2
- package/src/identity/schema.js +2 -1
- package/src/index.js +9 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -319
- package/server/platform/connect.mjs +0 -387
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -275
- package/server/platform/device.mjs +0 -222
- package/server/platform/integrations.mjs +0 -169
- package/server/platform/look.mjs +0 -20
- package/server/platform/mods.mjs +0 -222
- package/server/platform/orquesta.mjs +0 -577
- package/server/platform/profile.mjs +0 -161
- package/server/platform/routes.mjs +0 -542
- package/server/platform/runtime.mjs +0 -242
- package/server/platform/sites.mjs +0 -146
- package/server/platform/store.mjs +0 -456
- package/server/platform/vm.mjs +0 -1057
package/cli/lib/brain.mjs
CHANGED
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { spawn, spawnSync } from 'node:child_process';
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
15
|
import { homedir } from 'node:os';
|
|
15
|
-
import { delimiter, dirname, join } from 'node:path';
|
|
16
|
+
import { delimiter, dirname, join, win32 } from 'node:path';
|
|
16
17
|
import { identityPrompt } from '../../src/identity/schema.js';
|
|
17
18
|
import { createLLM } from '../../server/llm.mjs';
|
|
19
|
+
import { SEVENOTS_URL } from './account.mjs';
|
|
18
20
|
import { env, loadConfig, ORQUESTA_URL } from './config.mjs';
|
|
19
21
|
import { characterPrompt, integrationsPrompt } from './integrations.mjs';
|
|
20
22
|
import { ensureHome, PET_PORT } from './paths.mjs';
|
|
@@ -30,7 +32,7 @@ import { SPEECH_TAGS_PROMPT } from '../../src/voice/tags.js';
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export const AI_CLIS = {
|
|
33
|
-
claude: { bin: 'claude', json: true, args: (p, m, files) => ['-p', p, '--output-format', 'json', ...(m ? ['--model', m] : []), ...(files ? ['--allowedTools', 'Read'] : [])], vision: true, minTimeoutMs: 120000 }, // claude -p can take ~30 s just to start (hooks, plugins, MCP servers)
|
|
35
|
+
claude: { bin: 'claude', json: true, args: (p, m, files, web) => ['-p', p, '--output-format', 'json', ...(m ? ['--model', m] : []), ...(files || web ? ['--allowedTools', [files && 'Read', web && 'WebSearch', web && 'WebFetch'].filter(Boolean).join(',')] : [])], vision: true, minTimeoutMs: 120000 }, // claude -p can take ~30 s just to start (hooks, plugins, MCP servers)
|
|
34
36
|
codex: { bin: 'codex', args: (p, m) => ['exec', '--skip-git-repo-check', ...(m ? ['-m', m] : []), p] },
|
|
35
37
|
gemini: { bin: 'gemini', args: (p, m) => ['-p', p, ...(m ? ['-m', m] : [])] },
|
|
36
38
|
ollama: { bin: 'ollama', args: (p, m) => ['run', m || 'llama3.2', p] },
|
|
@@ -39,12 +41,16 @@ export const AI_CLIS = {
|
|
|
39
41
|
|
|
40
42
|
const LANG_NAME = { en: 'English', es: 'Spanish', pt: 'Portuguese' };
|
|
41
43
|
|
|
42
|
-
/** Which AI CLIs are installed (for the wizard and `--mode auto`). */
|
|
44
|
+
/** Which AI CLIs are installed (for the wizard and `--mode auto`). Cached a minute: settings polls it. */
|
|
45
|
+
let clisSeen = null;
|
|
43
46
|
export function detectClis() {
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
if (clisSeen && Date.now() - clisSeen.at < 60000) return clisSeen.list;
|
|
48
|
+
const list = Object.keys(AI_CLIS).filter((k) => {
|
|
49
|
+
const r = spawnSync(process.platform === 'win32' ? 'where' : 'which', [AI_CLIS[k].bin], { stdio: 'ignore', windowsHide: true });
|
|
46
50
|
return r.status === 0;
|
|
47
51
|
});
|
|
52
|
+
clisSeen = { at: Date.now(), list };
|
|
53
|
+
return list;
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
/** System prompt shared by every brain. */
|
|
@@ -73,12 +79,51 @@ export function petSystem(identity, { lang, role = 'pet' } = {}) {
|
|
|
73
79
|
return `${base}${sheet ? `\n${sheet}` : ''}\n${job}${tools ? `\n${tools}` : ''}${tone}\n${lang === 'auto' ? 'Always answer in the language your human writes in.' : `Always answer in ${L}.`}`;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
/**
|
|
83
|
+
* On Windows, npm installs global CLIs as `orquesta.cmd` shims, and spawn() without a shell only finds
|
|
84
|
+
* .exe/.com (no PATHEXT), so `spawn('orquesta')` fails with ENOENT although `where orquesta` finds it.
|
|
85
|
+
* A shell is no way out: cmd.exe can't carry the prompt's newlines and re-parses its quotes. So we read
|
|
86
|
+
* the npm shim and run its script with node directly (the same thing the shim does); a real .exe runs as is.
|
|
87
|
+
* Elsewhere the name goes through unchanged.
|
|
88
|
+
*/
|
|
89
|
+
export function resolveCliCommand(bin, args, { platform = process.platform, where = whereAll, read = (f) => readFileSync(f, 'utf8'), exists = existsSync } = {}) {
|
|
90
|
+
if (platform !== 'win32' || /[\\/]/.test(bin)) return { cmd: bin, args };
|
|
91
|
+
const found = where(bin);
|
|
92
|
+
const exe = found.find((f) => /\.(exe|com)$/i.test(f));
|
|
93
|
+
if (exe) return { cmd: exe, args };
|
|
94
|
+
for (const shim of found.filter((f) => /\.(cmd|bat)$/i.test(f))) {
|
|
95
|
+
let text = '';
|
|
96
|
+
try {
|
|
97
|
+
text = read(shim);
|
|
98
|
+
} catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
// npm/cmd-shim: "%_prog%" "%dp0%\node_modules\pkg\bin.js" %* (older: "%~dp0\..." )
|
|
102
|
+
const m = text.match(/"%(?:~dp0|dp0%)\\?([^"%]+?\.(?:c|m)?js)"\s+%\*/i);
|
|
103
|
+
if (!m) continue;
|
|
104
|
+
const dir = win32.dirname(shim);
|
|
105
|
+
const script = win32.resolve(dir, m[1]);
|
|
106
|
+
if (!exists(script)) continue;
|
|
107
|
+
const local = win32.join(dir, 'node.exe'); // the shim prefers a node.exe next to it, then the one on PATH
|
|
108
|
+
const node = exists(local) ? local : where('node').find((f) => /\.exe$/i.test(f)) || 'node';
|
|
109
|
+
return { cmd: node, args: [script, ...args] };
|
|
110
|
+
}
|
|
111
|
+
return { cmd: bin, args }; // not installed: spawn reports ENOENT as before
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function whereAll(bin) {
|
|
115
|
+
const r = spawnSync('where', [bin], { encoding: 'utf8', windowsHide: true });
|
|
116
|
+
return r.status === 0 ? String(r.stdout).split(/\r?\n/).map((s) => s.trim()).filter(Boolean) : [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function runCli({ cli, model, command }, prompt, timeoutMs, files, web = false) {
|
|
77
120
|
const spec = cli === 'custom' ? { bin: '/bin/sh', args: (p) => ['-c', command, 'sh', p] } : AI_CLIS[cli];
|
|
78
121
|
if (!spec) return Promise.reject(new Error(`unknown cli ${cli}`));
|
|
79
122
|
return new Promise((resolve, reject) => {
|
|
80
|
-
const
|
|
123
|
+
const run = resolveCliCommand(spec.bin, spec.args(prompt, model, files, web));
|
|
124
|
+
const child = spawn(run.cmd, run.args, {
|
|
81
125
|
cwd: ensureHome(),
|
|
126
|
+
windowsHide: true,
|
|
82
127
|
env: { ...process.env, SEVENOTS_PET_BRAIN: '1', NO_COLOR: '1' },
|
|
83
128
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
84
129
|
});
|
|
@@ -87,7 +132,7 @@ function runCli({ cli, model, command }, prompt, timeoutMs, files) {
|
|
|
87
132
|
child.kill('SIGTERM');
|
|
88
133
|
reject(new Error('timeout'));
|
|
89
134
|
}, Math.max(timeoutMs, spec.minTimeoutMs || 0));
|
|
90
|
-
child.stdout.on('data', (d) => (out += d).length > 20000 && child.kill('SIGTERM'));
|
|
135
|
+
child.stdout.on('data', (d) => (out += d).length > (web ? 200000 : 20000) && child.kill('SIGTERM'));
|
|
91
136
|
child.on('error', (e) => {
|
|
92
137
|
clearTimeout(timer);
|
|
93
138
|
reject(e);
|
|
@@ -109,6 +154,22 @@ function runCli({ cli, model, command }, prompt, timeoutMs, files) {
|
|
|
109
154
|
});
|
|
110
155
|
}
|
|
111
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Batuta only takes Orquesta's sign-in token (oclt_…, from `7ots login orquesta` / "Sign in with Orquesta") or a
|
|
159
|
+
* project's agent token. An API key from Orquesta → Settings → API keys (oak_…) is found but has no project, and
|
|
160
|
+
* Batuta answers 403 "Could not resolve organization for token": say which token it needs instead.
|
|
161
|
+
* `code` lets the settings page translate it; the message stays readable in logs.
|
|
162
|
+
*/
|
|
163
|
+
export function batutaError(e, token = '') {
|
|
164
|
+
const status = e?.status;
|
|
165
|
+
const msg = String(e?.message || '');
|
|
166
|
+
const wrongKind = /^(oak_|mcp_)/.test(token) || (status === 403 && /resolve organization/i.test(msg));
|
|
167
|
+
if (wrongKind) return Object.assign(new Error('batuta: this Orquesta token has no organization for Batuta (an API key?); sign in with Orquesta to get a CLI token (oclt_)'), { code: 'batuta_wrong_token', status });
|
|
168
|
+
if (status === 401) return Object.assign(new Error(`batuta: Orquesta rejected the token (${msg.replace(/^\d+\s*/, '').slice(0, 80) || 'invalid'}); sign in with Orquesta again`), { code: 'batuta_bad_token', status });
|
|
169
|
+
if (status === 402 || (status === 403 && /billing|limit|access|plan|add-on/i.test(msg))) return Object.assign(new Error(`batuta: ${msg.replace(/^\d+\s*/, '').slice(0, 160)}`), { code: 'batuta_no_plan', status });
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
|
|
112
173
|
/** Last meaningful paragraph of a CLI's output, cleaned of ANSI and quotes. */
|
|
113
174
|
export function cleanReply(text, max = 400) {
|
|
114
175
|
const s = String(text || '')
|
|
@@ -141,6 +202,10 @@ export function createBrain(brain = { kind: 'lines' }, home = {}) {
|
|
|
141
202
|
onUsage?.(usage || { in: Math.round(prompt.length / 4), out: Math.round(out.length / 4), approx: true });
|
|
142
203
|
return raw ? out : cleanReply(out);
|
|
143
204
|
},
|
|
205
|
+
// long work (the assistant's offload) on this computer: minutes, not seconds; web = may search and read pages (claude)
|
|
206
|
+
async work(prompt, { web = false, timeoutMs = 10 * 60 * 1000 } = {}) {
|
|
207
|
+
return (await runCli(brain, prompt, timeoutMs, null, web)).text;
|
|
208
|
+
},
|
|
144
209
|
};
|
|
145
210
|
}
|
|
146
211
|
if (brain.kind === 'api' || brain.kind === 'batuta') {
|
|
@@ -160,7 +225,13 @@ export function createBrain(brain = { kind: 'lines' }, home = {}) {
|
|
|
160
225
|
return {
|
|
161
226
|
kind: brain.kind,
|
|
162
227
|
async think({ system, messages, raw = false, onUsage }) {
|
|
163
|
-
|
|
228
|
+
if (brain.kind === 'batuta' && !keys.ORQUESTA_TOKEN) throw Object.assign(new Error('batuta: no Orquesta token'), { code: 'batuta_no_token' });
|
|
229
|
+
let r;
|
|
230
|
+
try {
|
|
231
|
+
r = await llm.step({ system, messages, tools: [] });
|
|
232
|
+
} catch (e) {
|
|
233
|
+
throw brain.kind === 'batuta' ? batutaError(e, keys.ORQUESTA_TOKEN) : e;
|
|
234
|
+
}
|
|
164
235
|
if (r.usage) onUsage?.(r.usage);
|
|
165
236
|
return raw ? r.text : cleanReply(r.text);
|
|
166
237
|
},
|
|
@@ -171,10 +242,12 @@ export function createBrain(brain = { kind: 'lines' }, home = {}) {
|
|
|
171
242
|
return {
|
|
172
243
|
kind: '7ots',
|
|
173
244
|
async think({ system, messages, timeoutMs = 45000, raw = false, onUsage }) {
|
|
174
|
-
//
|
|
245
|
+
// On 7ots.com the owner's device token opens its own ot's home; a self-hosted home only serves its
|
|
246
|
+
// domains (add http://127.0.0.1:<port> to them). The token never goes to another server.
|
|
247
|
+
const token = new URL(url).origin === new URL(SEVENOTS_URL).origin && env().SEVENOTS_TOKEN;
|
|
175
248
|
const res = await fetch(url, {
|
|
176
249
|
method: 'POST',
|
|
177
|
-
headers: { 'Content-Type': 'application/json', Origin: `http://127.0.0.1:${PET_PORT}` },
|
|
250
|
+
headers: { 'Content-Type': 'application/json', Origin: `http://127.0.0.1:${PET_PORT}`, ...(token ? { Authorization: `Bearer ${token}` } : {}) },
|
|
178
251
|
body: JSON.stringify({ system, messages, tools: [] }),
|
|
179
252
|
signal: AbortSignal.timeout(timeoutMs),
|
|
180
253
|
});
|
package/cli/lib/card-shot.mjs
CHANGED
|
@@ -23,7 +23,7 @@ export async function cardShot(url, { scale = 4, gl = false, timeout = 45000 } =
|
|
|
23
23
|
const dir = mkdtempSync(join(tmpdir(), '7ots-card-'));
|
|
24
24
|
const args = ['--headless=new', '--remote-debugging-pipe', '--no-first-run', '--no-default-browser-check', '--hide-scrollbars', `--user-data-dir=${dir}`,
|
|
25
25
|
...(gl ? ['--use-angle=swiftshader', '--enable-unsafe-swiftshader'] : ['--disable-gpu']), 'about:blank'];
|
|
26
|
-
const p = spawn(chrome, args, { stdio: ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'] });
|
|
26
|
+
const p = spawn(chrome, args, { windowsHide: true, stdio: ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'] });
|
|
27
27
|
const [toChrome, fromChrome] = [p.stdio[3], p.stdio[4]];
|
|
28
28
|
let seq = 0;
|
|
29
29
|
const waiting = new Map();
|
package/cli/lib/config.mjs
CHANGED
|
@@ -20,12 +20,21 @@
|
|
|
20
20
|
* open: true, it may open sites in your browser (reminders, "open my mail")
|
|
21
21
|
* notify: true, desktop notifications when a reminder fires
|
|
22
22
|
* sites: true, for sites you mention, it reads their usage guide on Prowl.world (only the domain is sent; prowl.mjs)
|
|
23
|
+
* prowl: false, share which tools work: host, ok and latency of remote integrations go to your 7ots.com ot
|
|
24
|
+
* and from there to Prowl's ranking (tooluse.mjs; never the tool, its arguments or results)
|
|
23
25
|
* screen: false, it looks at the active window and, every screen.every minutes, a screenshot (screen.mjs)
|
|
24
26
|
* processes: false, it sees which programs run (name, cpu, memory) and can wait for one to finish
|
|
25
27
|
* logs: false, it may read the logs of running processes (journal, pm2, docker, a log file) when asked
|
|
26
28
|
* inbox: false, it may read your email (apumail inbox) when asked
|
|
27
29
|
vm: false, it may send long jobs to its worker on your own server (vm.mjs; context filtered by the above)
|
|
28
|
-
vmKinds: ['research','browse','long']
|
|
30
|
+
vmKinds: ['research','browse','long'], which kinds (code and shell only if you add them)
|
|
31
|
+
camera: false, senses: it reads your face and hand gestures (on this computer; only labels reach it)
|
|
32
|
+
activity: false, senses: active app, site and idle time, added up per day (~/.7ots/senses)
|
|
33
|
+
mail: false, senses: it notices new email (apumail) and tells you about urgent-looking ones
|
|
34
|
+
calendar: false, senses: your calendar's ICS address (key SENSES_ICS_URL), for upcoming events
|
|
35
|
+
whatsapp: false } not available yet (see senses/sources/index.mjs)
|
|
36
|
+
* senses { arm: true, holdMs: 600, fps: 5, reflect: true, pausedUntil? } camera gestures need the open
|
|
37
|
+
* palm first (arm), held holdMs; reflect = now and then it asks the brain if something is worth doing
|
|
29
38
|
* integrations { orquesta: { on, projectId?, projectName? } talk to your Orquesta agents
|
|
30
39
|
* apumail: { on, inbox } email (APUMAIL_TOKEN)
|
|
31
40
|
* custom: [{ id, name, instructions, url?, command?, envVar?, on }] } told to the brain
|
|
@@ -40,7 +49,7 @@
|
|
|
40
49
|
|
|
41
50
|
import { homeFile, readJson, writeJson } from './paths.mjs';
|
|
42
51
|
|
|
43
|
-
export const KEY_NAMES = ['SEVENOTS_TOKEN', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'ORQUESTA_TOKEN', 'APUCHAT_VOICE_TOKEN', 'ELEVENLABS_API_KEY', 'XAI_API_KEY', 'FISH_API_KEY', 'LETTA_API_KEY', 'APUMAIL_TOKEN', 'SEVENOTS_VM_TOKEN'];
|
|
52
|
+
export const KEY_NAMES = ['SEVENOTS_TOKEN', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'ORQUESTA_TOKEN', 'APUCHAT_VOICE_TOKEN', 'ELEVENLABS_API_KEY', 'XAI_API_KEY', 'FISH_API_KEY', 'LETTA_API_KEY', 'APUMAIL_TOKEN', 'SEVENOTS_VM_TOKEN', 'SENSES_ICS_URL'];
|
|
44
53
|
export const ORQUESTA_URL = (process.env.ORQUESTA_URL || 'https://getorquesta.com').replace(/\/+$/, '');
|
|
45
54
|
|
|
46
55
|
export const CONFIG_DEFAULTS = Object.freeze({
|
|
@@ -49,7 +58,8 @@ export const CONFIG_DEFAULTS = Object.freeze({
|
|
|
49
58
|
brain: { kind: 'lines' },
|
|
50
59
|
voice: { kind: 'browser' },
|
|
51
60
|
pet: { mode: 'ask', annoy: 2, music: 'synth', musicVol: 0.5, entrance: { onStart: false, kind: 'wwe', dance: '' } },
|
|
52
|
-
access: { agent: true, memory: true, open: true, notify: true, sites: true, screen: false, processes: false, logs: false, inbox: false, vm: false, vmKinds: ['research', 'browse', 'long'] },
|
|
61
|
+
access: { agent: true, memory: true, open: true, notify: true, sites: true, prowl: false, screen: false, processes: false, logs: false, inbox: false, vm: false, vmKinds: ['research', 'browse', 'long'], camera: false, activity: false, mail: false, calendar: false, whatsapp: false },
|
|
62
|
+
senses: { arm: true, holdMs: 600, fps: 5, reflect: true },
|
|
53
63
|
screen: { every: 5 },
|
|
54
64
|
// conversation memory: recent turns up to `tokens` (≈chars/4), older ones compacted into a summary; 0 = off
|
|
55
65
|
memory: { tokens: 20000 },
|
|
@@ -68,6 +78,7 @@ export function loadConfig() {
|
|
|
68
78
|
pet: { ...CONFIG_DEFAULTS.pet, ...c.pet },
|
|
69
79
|
access: { ...CONFIG_DEFAULTS.access, ...c.access },
|
|
70
80
|
screen: { ...CONFIG_DEFAULTS.screen, ...c.screen },
|
|
81
|
+
senses: { ...CONFIG_DEFAULTS.senses, ...c.senses },
|
|
71
82
|
memory: { ...CONFIG_DEFAULTS.memory, ...c.memory },
|
|
72
83
|
integrations: {
|
|
73
84
|
orquesta: { ...CONFIG_DEFAULTS.integrations.orquesta, ...c.integrations?.orquesta },
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the desktop pet keeps of its ot, the same on every computer signed in to 7ots.com
|
|
3
|
+
* (GET/PUT /api/device/ots/:id/desktop, server/platform/device.mjs). account.mjs sync() covers the
|
|
4
|
+
* identity (look, mods, personality); this covers the rest:
|
|
5
|
+
*
|
|
6
|
+
* settings config.json: brain, voice, pet, access, screen, memory, integrations
|
|
7
|
+
* (not home/account/lang/character: those are this computer's or the identity's)
|
|
8
|
+
* progress the tamagotchi's born, xp and stats (food/energy/fun stay per computer: they decay anyway)
|
|
9
|
+
* notes memory.json · reminders.json · watchers.json
|
|
10
|
+
*
|
|
11
|
+
* Three-way merge against the last state both sides agreed on (~/.7ots/sync-desktop.json), so what one
|
|
12
|
+
* computer deleted (a fired reminder, a forgotten note) does not come back from the other:
|
|
13
|
+
* settings, per key: the side that changed wins; both → the newer one. A computer that never synced
|
|
14
|
+
* takes what 7ots.com has (a new install should not wipe your settings with its defaults),
|
|
15
|
+
* unless 7ots.com only has the default and this computer changed it.
|
|
16
|
+
* lists: union by id, minus what either side removed since the base.
|
|
17
|
+
* progress: each side's gains since the base add up; born is the oldest.
|
|
18
|
+
* Keys (keys.json) never leave the computer.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { existsSync, statSync } from 'node:fs';
|
|
22
|
+
import { api, signedIn } from './account.mjs';
|
|
23
|
+
import { CONFIG_DEFAULTS, loadConfig, saveConfig } from './config.mjs';
|
|
24
|
+
import { homeFile, readJson, writeJson } from './paths.mjs';
|
|
25
|
+
import { xpForLevel } from './pet-core.mjs';
|
|
26
|
+
|
|
27
|
+
const SETTINGS = ['brain', 'voice', 'pet', 'access', 'screen', 'memory', 'integrations'];
|
|
28
|
+
// what the senses may read is decided per computer (a camera allowed at home is not allowed at the office)
|
|
29
|
+
const LOCAL_ACCESS = ['camera', 'activity', 'mail', 'calendar', 'whatsapp'];
|
|
30
|
+
const shared = (k, v) => (k === 'access' && v && typeof v === 'object' ? Object.fromEntries(Object.entries(v).filter(([a]) => !LOCAL_ACCESS.includes(a))) : v);
|
|
31
|
+
const STATS = ['ok', 'fail', 'turns'];
|
|
32
|
+
const MAX_NOTES = 200;
|
|
33
|
+
const LISTS = {
|
|
34
|
+
notes: { file: 'memory.json', key: (n) => `${n.at}|${n.text}`, order: (n) => n.at || 0, keep: (n) => n && typeof n.text === 'string' },
|
|
35
|
+
reminders: { file: 'reminders.json', key: (r) => r.id, order: (r) => r.at || 0, keep: (r) => r?.id && !r.done },
|
|
36
|
+
watchers: { file: 'watchers.json', key: (w) => w.id, order: (w) => w.created || 0, keep: (w) => w?.id && !w.done },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// equal regardless of key order (each computer's config.json writes its keys in its own order)
|
|
40
|
+
const canon = (v) => (Array.isArray(v) ? v.map(canon) : v && typeof v === 'object' ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, canon(v[k])])) : v);
|
|
41
|
+
const same = (a, b) => JSON.stringify(canon(a ?? null)) === JSON.stringify(canon(b ?? null));
|
|
42
|
+
const mtime = (f) => (existsSync(homeFile(f)) ? statSync(homeFile(f)).mtimeMs : 0);
|
|
43
|
+
|
|
44
|
+
/** xp as one number (level 3 with 10 xp = everything it took to get there + 10). */
|
|
45
|
+
export function totalXp({ level = 1, xp = 0 } = {}) {
|
|
46
|
+
let t = Math.max(0, Number(xp) || 0);
|
|
47
|
+
for (let l = 1; l < level; l++) t += xpForLevel(l);
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
export function levelOf(total) {
|
|
51
|
+
let level = 1;
|
|
52
|
+
let xp = Math.max(0, Math.round(total));
|
|
53
|
+
while (xp >= xpForLevel(level)) xp -= xpForLevel(level++);
|
|
54
|
+
return { level, xp };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** This computer's side. `pet` is the live tamagotchi object when the pet is running. */
|
|
58
|
+
export function localState(pet = readJson(homeFile('pet.json')) || {}) {
|
|
59
|
+
const config = loadConfig();
|
|
60
|
+
const lists = Object.fromEntries(Object.entries(LISTS).map(([k, l]) => [k, (readJson(homeFile(l.file), []) || []).filter(l.keep)]));
|
|
61
|
+
return {
|
|
62
|
+
settings: Object.fromEntries(SETTINGS.map((k) => [k, shared(k, config[k])])),
|
|
63
|
+
progress: { born: pet.born || Date.now(), xp: totalXp(pet), stats: Object.fromEntries(STATS.map((k) => [k, Number(pet.stats?.[k]) || 0])) },
|
|
64
|
+
...lists,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function mergeList(name, base, local, remote) {
|
|
69
|
+
const { key, order } = LISTS[name];
|
|
70
|
+
if (!remote) return local;
|
|
71
|
+
const inB = new Set((base || []).map(key));
|
|
72
|
+
const inL = new Set(local.map(key));
|
|
73
|
+
const inR = new Set(remote.map(key));
|
|
74
|
+
const out = new Map();
|
|
75
|
+
for (const x of [...local, ...remote]) {
|
|
76
|
+
const k = key(x);
|
|
77
|
+
if (out.has(k)) continue; // the local copy came first
|
|
78
|
+
if (base && inB.has(k) && (!inL.has(k) || !inR.has(k))) continue; // removed on one side
|
|
79
|
+
out.set(k, x);
|
|
80
|
+
}
|
|
81
|
+
const list = [...out.values()].sort((a, b) => order(a) - order(b));
|
|
82
|
+
return name === 'notes' ? list.slice(-MAX_NOTES) : list;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function mergeProgress(base, local, remote) {
|
|
86
|
+
if (!remote) return local;
|
|
87
|
+
const born = Math.min(...[base?.born, local.born, remote.born].filter(Boolean));
|
|
88
|
+
// no base: this computer never synced; its counts may overlap the cloud's, so the larger wins
|
|
89
|
+
const add = (b, l, r) => (b == null ? Math.max(l, r) : Math.max(0, b + (l - b) + (r - b)));
|
|
90
|
+
return { born, xp: add(base?.xp, local.xp, remote.xp), stats: Object.fromEntries(STATS.map((k) => [k, add(base?.stats?.[k], local.stats[k], remote.stats?.[k] || 0)])) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @returns the merged state, with when each setting last changed (settingsAt) */
|
|
94
|
+
export function merge(base, local, remote, localAt = Date.now()) {
|
|
95
|
+
const settings = {};
|
|
96
|
+
const settingsAt = {};
|
|
97
|
+
for (const k of SETTINGS) {
|
|
98
|
+
const l = local.settings[k];
|
|
99
|
+
const r = remote?.settings?.[k];
|
|
100
|
+
const b = base?.settings?.[k];
|
|
101
|
+
const rAt = remote?.settingsAt?.[k] || 0;
|
|
102
|
+
let useLocal;
|
|
103
|
+
if (r === undefined) useLocal = true;
|
|
104
|
+
// first sync here: what 7ots.com has wins (your settings from another computer), unless only this side was customized
|
|
105
|
+
else if (!base) useLocal = same(shared(k, r), shared(k, CONFIG_DEFAULTS[k])) && !same(l, shared(k, CONFIG_DEFAULTS[k]));
|
|
106
|
+
else {
|
|
107
|
+
const lc = !same(l, b);
|
|
108
|
+
const rc = !same(r, b);
|
|
109
|
+
useLocal = lc && rc ? localAt > rAt : lc;
|
|
110
|
+
}
|
|
111
|
+
settings[k] = useLocal ? l : r;
|
|
112
|
+
settingsAt[k] = useLocal ? (base && same(l, b) ? base.settingsAt?.[k] || rAt : localAt) : rAt;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
v: 1,
|
|
116
|
+
settings,
|
|
117
|
+
settingsAt,
|
|
118
|
+
progress: mergeProgress(base?.progress, local.progress, remote?.progress),
|
|
119
|
+
...Object.fromEntries(Object.keys(LISTS).map((k) => [k, mergeList(k, base?.[k], local[k], remote?.[k])])),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Writes what changed here. @returns the sections it wrote */
|
|
124
|
+
function apply(next, local, pet) {
|
|
125
|
+
const wrote = [];
|
|
126
|
+
if (!same(next.settings, local.settings)) {
|
|
127
|
+
const now = loadConfig();
|
|
128
|
+
const mine = Object.fromEntries(LOCAL_ACCESS.map((a) => [a, now.access[a]]));
|
|
129
|
+
saveConfig({ ...now, ...next.settings, access: { ...shared('access', next.settings.access), ...mine } });
|
|
130
|
+
wrote.push('settings');
|
|
131
|
+
}
|
|
132
|
+
if (!same(next.progress, local.progress)) {
|
|
133
|
+
const p = pet || readJson(homeFile('pet.json')) || {};
|
|
134
|
+
Object.assign(p, levelOf(next.progress.xp), { born: next.progress.born, stats: { ...p.stats, ...next.progress.stats } });
|
|
135
|
+
if (!pet) writeJson(homeFile('pet.json'), p);
|
|
136
|
+
wrote.push('progress');
|
|
137
|
+
}
|
|
138
|
+
for (const [k, l] of Object.entries(LISTS)) {
|
|
139
|
+
if (same(next[k], local[k])) continue;
|
|
140
|
+
writeJson(homeFile(l.file), next[k]);
|
|
141
|
+
wrote.push(k);
|
|
142
|
+
}
|
|
143
|
+
return wrote;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* One round. `pet`: the running pet's tamagotchi (it saves it itself, so progress goes there, not to the file).
|
|
148
|
+
* @returns {Promise<{action: 'off'|'same'|'push'|'pull', wrote?: string[]}>} pull = something changed here
|
|
149
|
+
*/
|
|
150
|
+
export async function syncDesktop({ pet } = {}) {
|
|
151
|
+
const otsId = loadConfig().account?.otsId;
|
|
152
|
+
if (!signedIn() || !otsId) return { action: 'off' };
|
|
153
|
+
const file = homeFile('sync-desktop.json');
|
|
154
|
+
const saved = readJson(file) || {};
|
|
155
|
+
const base = saved.otsId === otsId ? saved.state : null;
|
|
156
|
+
const local = localState(pet);
|
|
157
|
+
const localAt = Math.max(mtime('config.json'), 1);
|
|
158
|
+
const path = `/ots/${encodeURIComponent(otsId)}/desktop`;
|
|
159
|
+
let { state: remote, rev } = await api(path);
|
|
160
|
+
let next;
|
|
161
|
+
let pushed = false;
|
|
162
|
+
for (let tries = 0; ; tries++) {
|
|
163
|
+
next = merge(base, local, remote, localAt);
|
|
164
|
+
if (same(next, remote)) break;
|
|
165
|
+
try {
|
|
166
|
+
({ rev } = await api(path, { method: 'PUT', body: { state: next, rev } }));
|
|
167
|
+
pushed = true;
|
|
168
|
+
break;
|
|
169
|
+
} catch (e) {
|
|
170
|
+
if (e.status !== 409 || tries >= 2) throw e;
|
|
171
|
+
({ state: remote, rev } = e.data); // another computer wrote meanwhile: merge with that
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const wrote = apply(next, local, pet);
|
|
175
|
+
writeJson(file, { otsId, rev, at: Date.now(), state: next });
|
|
176
|
+
return { action: wrote.length ? 'pull' : pushed ? 'push' : 'same', wrote };
|
|
177
|
+
}
|
package/cli/lib/i18n.mjs
CHANGED
|
@@ -16,9 +16,11 @@ const M = {
|
|
|
16
16
|
7ots pet --tmux the terminal pet in a tmux side pane
|
|
17
17
|
7ots feed | play | sleep | wake | say <text> | stop
|
|
18
18
|
7ots dance [name] [--ms N] [--no-music] [--list] | entrance [--dance name]
|
|
19
|
+
7ots aura [sixseven|mewing|tikio|garza|deal|siu] [--no-music] [--list] aura farming (+aura, its own counter; phonk, or your tracks in ~/.7ots/music/aura)
|
|
19
20
|
7ots status [--line|--json] pet state (--line: one line for tmux)
|
|
20
21
|
7ots ask <text> talk to it: "remind me to check email in 10 min", "open my calendar", "remember that…"
|
|
21
22
|
7ots reminders [--cancel <id>] pending reminders and what it remembers
|
|
23
|
+
7ots senses [status|rules|pause [min]|resume|reflect|forget] what it notices (camera, apps, mail) and its rules
|
|
22
24
|
7ots config [--print] settings page: brain, what it can see, notes
|
|
23
25
|
7ots hooks install|remove [--claude] [--shell] [--global]
|
|
24
26
|
7ots meet --new | "<invite or call URL>" join apuchat meet with this identity
|
|
@@ -104,6 +106,7 @@ Docs: https://7ots.com/llms.txt`,
|
|
|
104
106
|
'err.unknown': 'Unknown command "{cmd}". Try: 7ots help',
|
|
105
107
|
'err.noPet': 'The pet is not awake. Start it with: 7ots pet',
|
|
106
108
|
'pet.settings': 'Opening the settings in your browser.',
|
|
109
|
+
'usage.senses': '7ots senses [status|rules|pause [min]|resume|reflect|forget] [--json]\n\n Turn them on in settings → Senses (7ots config).',
|
|
107
110
|
'usage.ask': '7ots ask <text>\n\n e.g. 7ots ask "remind me to check email in 10 minutes and open it"\n 7ots ask "remember that Fridays we demo" · 7ots ask "my reminders"\n Seeing your screen or processes: coming soon.',
|
|
108
111
|
'err.noIdentity': 'No identity yet. Create one with "7ots new" or run "7ots setup".',
|
|
109
112
|
'w.title': '7ots setup — {name}',
|
|
@@ -207,9 +210,11 @@ Docs: https://7ots.com/llms.txt`,
|
|
|
207
210
|
7ots pet --tmux la mascota de terminal en un panel de tmux
|
|
208
211
|
7ots feed | play | sleep | wake | say <texto> | stop
|
|
209
212
|
7ots dance [nombre] [--ms N] [--no-music] [--list] | entrance [--dance nombre]
|
|
213
|
+
7ots aura [sixseven|mewing|tikio|garza|deal|siu] [--no-music] [--list] farmeo de aura (+aura, su propio contador; phonk, o tus temas en ~/.7ots/music/aura)
|
|
210
214
|
7ots status [--line|--json] estado (--line: una línea para tmux)
|
|
211
215
|
7ots ask <texto> háblale: "recuérdame ver el correo en 10 min", "abre mi calendario", "anota que…"
|
|
212
216
|
7ots reminders [--cancel <id>] recordatorios pendientes y lo que recuerda
|
|
217
|
+
7ots senses [status|rules|pause [min]|resume|reflect|forget] lo que nota (cámara, apps, correo) y sus reglas
|
|
213
218
|
7ots config [--print] ajustes: cerebro, qué puede ver, notas
|
|
214
219
|
7ots hooks install|remove [--claude] [--shell] [--global]
|
|
215
220
|
7ots meet --new | "<invitación o enlace>" entra a apuchat meet con esta identidad
|
|
@@ -295,6 +300,7 @@ Docs: https://7ots.com/llms.txt`,
|
|
|
295
300
|
'err.unknown': 'Comando desconocido «{cmd}». Prueba: 7ots help',
|
|
296
301
|
'err.noPet': 'La mascota no está despierta. Iníciala con: 7ots pet',
|
|
297
302
|
'pet.settings': 'Abriendo los ajustes en tu navegador.',
|
|
303
|
+
'usage.senses': '7ots senses [status|rules|pause [min]|resume|reflect|forget] [--json]\n\n Se activan en ajustes → Sentidos (7ots config).',
|
|
298
304
|
'usage.ask': '7ots ask <texto>\n\n ej. 7ots ask "recuérdame ver el correo en 10 minutos y ábrelo"\n 7ots ask "anota que los viernes hay demo" · 7ots ask "mis recordatorios"\n Ver tu pantalla o tus procesos: muy pronto.',
|
|
299
305
|
'err.noIdentity': 'Aún no hay identidad. Crea una con «7ots new» o corre «7ots setup».',
|
|
300
306
|
'w.title': 'Configuración de 7ots — {name}',
|
|
@@ -398,9 +404,11 @@ Docs: https://7ots.com/llms.txt`,
|
|
|
398
404
|
7ots pet --tmux o bichinho de terminal num painel do tmux
|
|
399
405
|
7ots feed | play | sleep | wake | say <texto> | stop
|
|
400
406
|
7ots dance [nombre] [--ms N] [--no-music] [--list] | entrance [--dance nombre]
|
|
407
|
+
7ots aura [sixseven|mewing|tikio|garza|deal|siu] [--no-music] [--list] farmar aura (+aura, seu próprio contador; phonk, ou suas músicas em ~/.7ots/music/aura)
|
|
401
408
|
7ots status [--line|--json] estado (--line: uma linha para tmux)
|
|
402
409
|
7ots ask <texto> fale com ele: "me lembre de ver o e-mail em 10 min", "abra minha agenda", "anote que…"
|
|
403
410
|
7ots reminders [--cancel <id>] lembretes pendentes e o que ele lembra
|
|
411
|
+
7ots senses [status|rules|pause [min]|resume|reflect|forget] o que ele nota (câmera, apps, e-mail) e suas regras
|
|
404
412
|
7ots config [--print] ajustes: cérebro, o que pode ver, notas
|
|
405
413
|
7ots hooks install|remove [--claude] [--shell] [--global]
|
|
406
414
|
7ots meet --new | "<convite ou link>" entra no apuchat meet com esta identidade
|
|
@@ -486,6 +494,7 @@ Docs: https://7ots.com/llms.txt`,
|
|
|
486
494
|
'err.unknown': 'Comando desconhecido «{cmd}». Tente: 7ots help',
|
|
487
495
|
'err.noPet': 'O bichinho não está acordado. Inicie com: 7ots pet',
|
|
488
496
|
'pet.settings': 'Abrindo os ajustes no seu navegador.',
|
|
497
|
+
'usage.senses': '7ots senses [status|rules|pause [min]|resume|reflect|forget] [--json]\n\n Ative em ajustes → Sentidos (7ots config).',
|
|
489
498
|
'usage.ask': '7ots ask <texto>\n\n ex. 7ots ask "me lembre de ver o e-mail em 10 minutos e abra"\n 7ots ask "anote que às sextas tem demo" · 7ots ask "meus lembretes"\n Ver sua tela ou processos: em breve.',
|
|
490
499
|
'err.noIdentity': 'Ainda não há identidade. Crie uma com «7ots new» ou rode «7ots setup».',
|
|
491
500
|
'w.title': 'Configuração do 7ots — {name}',
|
package/cli/lib/inferences.mjs
CHANGED
|
@@ -34,8 +34,9 @@ export function otherInferences() {
|
|
|
34
34
|
} catch {}
|
|
35
35
|
const host = companion ? [{ home: root, id: readJson(join(root, 'config.json'))?.account?.otsId || 'local' }] : [];
|
|
36
36
|
return [...host, ...ids.map((id) => ({ home: join(dir, id), id }))].flatMap(({ home, id }) => {
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const idy = readJson(join(home, 'identity.json'));
|
|
38
|
+
const ot = { id, name: idy?.name || id, character: idy?.look?.character || null }; // its look: settings draws it on the filter
|
|
39
|
+
return readRows(join(home, 'inferences.jsonl')).map((r) => ({ ...r, ot }));
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -84,6 +85,22 @@ export function createInferenceLog() {
|
|
|
84
85
|
throw e;
|
|
85
86
|
}
|
|
86
87
|
},
|
|
88
|
+
// long local work (only CLI brains have it); undefined otherwise so callers fall back to the cloud
|
|
89
|
+
get work() {
|
|
90
|
+
if (typeof getBrain().work !== 'function') return undefined;
|
|
91
|
+
return async (prompt, o) => {
|
|
92
|
+
const t0 = Date.now();
|
|
93
|
+
const row = { at: t0, purpose: 'work', brain: label(), input: [{ role: 'user', content: cut(prompt, 8000) }] };
|
|
94
|
+
try {
|
|
95
|
+
const text = await getBrain().work(prompt, o);
|
|
96
|
+
add({ ...row, ok: true, output: cut(text, 4000), ms: Date.now() - t0 });
|
|
97
|
+
return text;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
add({ ...row, ok: false, error: cut(e.message, 300), ms: Date.now() - t0 });
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
},
|
|
87
104
|
};
|
|
88
105
|
}
|
|
89
106
|
|