eversince 0.2.17 → 0.3.0
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/dist/bridge.js +50 -6
- package/dist/commands/app.js +387 -0
- package/dist/commands/init.js +19 -0
- package/dist/commands/skills.js +52 -0
- package/dist/index.js +24 -0
- package/dist/skills-refresh.js +185 -0
- package/dist/source.sha256 +1 -1
- package/package.json +1 -1
package/dist/bridge.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DoorBlocked, cacheFile as cacheFileFor, isBlocked, isRefused, probe, reachApp, unreachedMessage, readJson, readState, sandboxedWithoutNetwork, stateFile as defaultStateFile, } from './door.js';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { isConnectFailure } from './retry.js';
|
|
4
|
+
const PAGE_KEEP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
4
5
|
const EMPTY_LISTS = {
|
|
5
6
|
'resources/list': { resources: [] },
|
|
6
7
|
'resources/templates/list': { resourceTemplates: [] },
|
|
@@ -19,6 +20,24 @@ function rpcError(id, message, code = -32000) {
|
|
|
19
20
|
export function runBridge(options) {
|
|
20
21
|
const file = options.stateFile ?? defaultStateFile();
|
|
21
22
|
const cacheFile = cacheFileFor(file);
|
|
23
|
+
const pagesFile = cacheFile.replace(/agent-door-cache\.json$/, 'agent-door-pages.json');
|
|
24
|
+
const isPage = (message) => {
|
|
25
|
+
const uri = message?.method === 'resources/read' ? message.params?.uri : null;
|
|
26
|
+
return typeof uri === 'string' && uri.startsWith('ui://eversince/') ? uri : null;
|
|
27
|
+
};
|
|
28
|
+
function keepPage(uri, result) {
|
|
29
|
+
if (!JSON.stringify(result).includes('/app/view/assets/view.js'))
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const pages = readJson(pagesFile) ?? {};
|
|
33
|
+
pages[uri] = { result, at: Date.now() };
|
|
34
|
+
const temp = `${pagesFile}.${process.pid}.tmp`;
|
|
35
|
+
writeFileSync(temp, JSON.stringify(pages), { mode: 0o600 });
|
|
36
|
+
renameSync(temp, pagesFile);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
22
41
|
const self = options.command ?? 'eversince';
|
|
23
42
|
const reconnect = options.reconnect ?? `Run \`${self} init --agent ${options.agent}\` to connect it again.`;
|
|
24
43
|
function connectionFor(state) {
|
|
@@ -29,11 +48,12 @@ export function runBridge(options) {
|
|
|
29
48
|
process.stderr.write(`eversince: the Eversince app is not set up on this computer. Install it, open it and sign in, or run \`${self} init --cloud\` to connect this agent to eversince.ai instead.\n`);
|
|
30
49
|
process.exit(1);
|
|
31
50
|
}
|
|
51
|
+
let drawsCards = false;
|
|
32
52
|
let listFromCache = null;
|
|
33
53
|
let opening = null;
|
|
34
54
|
function open() {
|
|
35
55
|
if (!opening) {
|
|
36
|
-
opening = reachApp(file, () =>
|
|
56
|
+
opening = reachApp(file, () => undefined).finally(() => { opening = null; });
|
|
37
57
|
}
|
|
38
58
|
return opening;
|
|
39
59
|
}
|
|
@@ -62,7 +82,7 @@ export function runBridge(options) {
|
|
|
62
82
|
throw new Gone();
|
|
63
83
|
return fetch(`http://127.0.0.1:${state.port}/mcp`, {
|
|
64
84
|
method: 'POST',
|
|
65
|
-
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', authorization: `Bearer ${connection.token}
|
|
85
|
+
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', authorization: `Bearer ${connection.token}`, ...(drawsCards ? { 'x-eversince-draws-cards': '1' } : {}) },
|
|
66
86
|
body,
|
|
67
87
|
});
|
|
68
88
|
}
|
|
@@ -76,6 +96,12 @@ export function runBridge(options) {
|
|
|
76
96
|
const empty = EMPTY_LISTS[message.method];
|
|
77
97
|
if (empty)
|
|
78
98
|
return { reply: { jsonrpc: '2.0', id, result: empty } };
|
|
99
|
+
const page = isPage(message);
|
|
100
|
+
if (page) {
|
|
101
|
+
const kept = readJson(pagesFile)?.[page];
|
|
102
|
+
if (kept?.result && typeof kept.at === 'number' && Date.now() - kept.at < PAGE_KEEP_MS)
|
|
103
|
+
return { reply: { jsonrpc: '2.0', id, result: kept.result } };
|
|
104
|
+
}
|
|
79
105
|
const cache = readJson(cacheFile);
|
|
80
106
|
if (!cache)
|
|
81
107
|
return null;
|
|
@@ -86,7 +112,8 @@ export function runBridge(options) {
|
|
|
86
112
|
return null;
|
|
87
113
|
const capabilities = (result.capabilities ?? {});
|
|
88
114
|
const tools = { ...(capabilities.tools ?? {}), listChanged: true };
|
|
89
|
-
|
|
115
|
+
const resources = capabilities.resources ?? {};
|
|
116
|
+
return { reply: { jsonrpc: '2.0', id, result: { ...result, capabilities: { ...capabilities, tools, resources } } } };
|
|
90
117
|
}
|
|
91
118
|
if (message.method === 'tools/list' && !message.params?.cursor && cache.tools) {
|
|
92
119
|
listFromCache = JSON.stringify(cache.tools);
|
|
@@ -151,6 +178,10 @@ export function runBridge(options) {
|
|
|
151
178
|
return;
|
|
152
179
|
}
|
|
153
180
|
const id = idOf(message);
|
|
181
|
+
if (message?.method === 'initialize') {
|
|
182
|
+
const extensions = message.params?.capabilities?.extensions;
|
|
183
|
+
drawsCards = !!extensions?.['io.modelcontextprotocol/ui'];
|
|
184
|
+
}
|
|
154
185
|
const canDoWork = message?.method === 'tools/call';
|
|
155
186
|
try {
|
|
156
187
|
let res;
|
|
@@ -173,10 +204,23 @@ export function runBridge(options) {
|
|
|
173
204
|
write(cached.reply);
|
|
174
205
|
return;
|
|
175
206
|
}
|
|
207
|
+
const opens = canDoWork || message?.method === 'initialize' || message?.method === 'tools/list';
|
|
208
|
+
if (!opens) {
|
|
209
|
+
if (id !== null)
|
|
210
|
+
write(rpcError(id, 'The Eversince app is closed. It opens when a tool is called.'));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
process.stderr.write(`eversince: opening the Eversince app for ${message?.method ?? 'a request'}\n`);
|
|
176
214
|
res = await post(line, true);
|
|
177
215
|
}
|
|
178
|
-
if (id !== null)
|
|
179
|
-
|
|
216
|
+
if (id !== null) {
|
|
217
|
+
const answer = await answerFor(id, res);
|
|
218
|
+
const page = isPage(message);
|
|
219
|
+
const result = answer?.result;
|
|
220
|
+
if (page && result)
|
|
221
|
+
keepPage(page, result);
|
|
222
|
+
write(answer);
|
|
223
|
+
}
|
|
180
224
|
await checkList();
|
|
181
225
|
}
|
|
182
226
|
catch (error) {
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { createReadStream, createWriteStream, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { homedir, hostname } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { pipeline } from 'node:stream/promises';
|
|
8
|
+
import { resolveBaseUrl } from '../config.js';
|
|
9
|
+
import { probe, readState, stateFile } from '../door.js';
|
|
10
|
+
import { detectHostAgent } from '../host-agent.js';
|
|
11
|
+
import { line, note, printResult } from '../output.js';
|
|
12
|
+
import { installCoreSkills } from '../skills-refresh.js';
|
|
13
|
+
const FEED = (process.env.ES_DESKTOP_FEED || 'https://desktop.eversince.ai').replace(/\/+$/, '');
|
|
14
|
+
const START_WAIT_MS = 90_000;
|
|
15
|
+
const SIGN_IN_WAIT_MS = 15 * 60_000;
|
|
16
|
+
const dataHome = () => process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share');
|
|
17
|
+
const configHome = () => process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
|
|
18
|
+
const installRoot = () => join(dataHome(), 'eversince');
|
|
19
|
+
const currentDir = () => join(installRoot(), 'current');
|
|
20
|
+
const launcherPath = () => join(currentDir(), 'eversince-headless');
|
|
21
|
+
const logFile = () => join(installRoot(), 'app.log');
|
|
22
|
+
const pidFile = () => join(configHome(), 'Eversince', 'headless.pid');
|
|
23
|
+
const pendingFile = () => join(configHome(), 'Eversince', 'sign-in-pending.json');
|
|
24
|
+
function linuxOnly() {
|
|
25
|
+
if (process.platform !== 'linux') {
|
|
26
|
+
throw new Error('eversince app is for Linux. On a Mac or Windows computer, install the app from https://eversince.ai/download.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function arch() {
|
|
30
|
+
if (process.arch === 'x64' || process.arch === 'arm64')
|
|
31
|
+
return process.arch;
|
|
32
|
+
throw new Error(`The Eversince app runs on x64 and arm64 Linux; this computer is ${process.arch}.`);
|
|
33
|
+
}
|
|
34
|
+
async function manifest() {
|
|
35
|
+
const res = await fetch(`${FEED}/latest-linux.json`, { signal: AbortSignal.timeout(20_000) });
|
|
36
|
+
if (!res.ok)
|
|
37
|
+
throw new Error(`The app's download list could not be read (${res.status}). Try again.`);
|
|
38
|
+
return (await res.json());
|
|
39
|
+
}
|
|
40
|
+
function installedVersion() {
|
|
41
|
+
try {
|
|
42
|
+
return readFileSync(join(currentDir(), 'version'), 'utf8').trim() || null;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function canInstallPackages() {
|
|
49
|
+
if (process.getuid?.() === 0)
|
|
50
|
+
return 'root';
|
|
51
|
+
return spawnSync('sudo', ['-n', 'true'], { stdio: 'ignore' }).status === 0 ? 'sudo' : null;
|
|
52
|
+
}
|
|
53
|
+
const APT_PACKAGES = ['xvfb', 'xauth', 'libnss3', 'libgbm1', 'libxss1', 'libxtst6', 'libxkbcommon0', 'libdrm2', 'fonts-dejavu-core', 'fonts-liberation', 'fonts-noto-color-emoji'];
|
|
54
|
+
const APT_RENAMED = [['libgtk-3-0t64', 'libgtk-3-0'], ['libasound2t64', 'libasound2']];
|
|
55
|
+
const DNF_PACKAGES = ['xorg-x11-server-Xvfb', 'nss', 'mesa-libgbm', 'libXScrnSaver', 'libXtst', 'libxkbcommon', 'gtk3', 'alsa-lib', 'dejavu-sans-fonts', 'liberation-fonts', 'google-noto-emoji-color-fonts'];
|
|
56
|
+
const APPARMOR_PROFILE = `abi <abi/4.0>,
|
|
57
|
+
include <tunables/global>
|
|
58
|
+
|
|
59
|
+
profile eversince @{HOME}/.local/share/eversince/versions/*/eversince flags=(unconfined) {
|
|
60
|
+
userns,
|
|
61
|
+
include if exists <local/eversince>
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
function userNamespacesRestricted() {
|
|
65
|
+
try {
|
|
66
|
+
return readFileSync('/proc/sys/kernel/apparmor_restrict_unprivileged_userns', 'utf8').trim() === '1';
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function allowSandbox(mode) {
|
|
73
|
+
if (process.getuid?.() === 0 || !userNamespacesRestricted() || existsSync('/etc/apparmor.d/eversince'))
|
|
74
|
+
return;
|
|
75
|
+
if (canInstallPackages() !== 'sudo')
|
|
76
|
+
return;
|
|
77
|
+
const tmp = join(installRoot(), 'apparmor-profile');
|
|
78
|
+
writeFileSync(tmp, APPARMOR_PROFILE);
|
|
79
|
+
const ok = spawnSync('sudo', ['-n', 'install', '-m', '644', tmp, '/etc/apparmor.d/eversince'], { stdio: 'ignore' }).status === 0
|
|
80
|
+
&& spawnSync('sudo', ['-n', 'apparmor_parser', '-r', '/etc/apparmor.d/eversince'], { stdio: 'ignore' }).status === 0;
|
|
81
|
+
rmSync(tmp, { force: true });
|
|
82
|
+
if (!ok && !mode.json)
|
|
83
|
+
note('Chromium\'s sandbox could not be allowed on this machine; the app runs without it.');
|
|
84
|
+
}
|
|
85
|
+
function missingLibraries(executable) {
|
|
86
|
+
const out = spawnSync('ldd', [executable], { encoding: 'utf8' });
|
|
87
|
+
return (out.stdout ?? '').split('\n').filter((l) => l.includes('not found')).map((l) => l.trim().split(' ')[0]);
|
|
88
|
+
}
|
|
89
|
+
function hasXvfb() {
|
|
90
|
+
return spawnSync('sh', ['-c', 'command -v Xvfb'], { stdio: 'ignore' }).status === 0;
|
|
91
|
+
}
|
|
92
|
+
function installPackages(mode) {
|
|
93
|
+
const how = canInstallPackages();
|
|
94
|
+
const apt = spawnSync('sh', ['-c', 'command -v apt-get'], { stdio: 'ignore' }).status === 0;
|
|
95
|
+
const dnf = !apt && spawnSync('sh', ['-c', 'command -v dnf'], { stdio: 'ignore' }).status === 0;
|
|
96
|
+
const list = apt ? [...APT_PACKAGES, ...APT_RENAMED.map(([a]) => a)] : DNF_PACKAGES;
|
|
97
|
+
const command = apt ? `sudo apt-get install -y ${list.join(' ')}` : dnf ? `sudo dnf install -y ${list.join(' ')}` : null;
|
|
98
|
+
if (!command)
|
|
99
|
+
throw new Error(`This computer needs Xvfb and Electron's libraries (${APT_PACKAGES.join(', ')} or their equivalents), and has neither apt nor dnf to install them.`);
|
|
100
|
+
if (!how)
|
|
101
|
+
throw new Error(`This computer needs a few system packages, and installing them asks for a password. Run: ${command}`);
|
|
102
|
+
if (!mode.json)
|
|
103
|
+
note('Installing the system packages the app needs.');
|
|
104
|
+
const run = (args) => {
|
|
105
|
+
const [file, ...rest] = how === 'sudo' ? ['sudo', '-n', 'env', 'DEBIAN_FRONTEND=noninteractive', ...args] : args;
|
|
106
|
+
const done = spawnSync(file, rest, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, env: { ...process.env, DEBIAN_FRONTEND: 'noninteractive' } });
|
|
107
|
+
if (done.status !== 0 && !mode.json)
|
|
108
|
+
process.stderr.write(`${`${done.stdout ?? ''}${done.stderr ?? ''}`.split('\n').slice(-20).join('\n')}\n`);
|
|
109
|
+
return done.status === 0;
|
|
110
|
+
};
|
|
111
|
+
if (apt) {
|
|
112
|
+
run(['apt-get', 'update', '-qq']);
|
|
113
|
+
const renamed = APT_RENAMED.map(([now, before]) => (spawnSync('apt-cache', ['show', now], { stdio: 'ignore' }).status === 0 ? now : before));
|
|
114
|
+
if (!run(['apt-get', 'install', '-y', '-qq', '--no-install-recommends', ...APT_PACKAGES, ...renamed]))
|
|
115
|
+
throw new Error(`The system packages could not be installed. Run: ${command}`);
|
|
116
|
+
}
|
|
117
|
+
else if (!run(['dnf', 'install', '-y', ...DNF_PACKAGES])) {
|
|
118
|
+
throw new Error(`The system packages could not be installed. Run: ${command}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function sha256File(file) {
|
|
122
|
+
const hash = createHash('sha256');
|
|
123
|
+
await pipeline(createReadStream(file), hash);
|
|
124
|
+
return hash.digest('hex');
|
|
125
|
+
}
|
|
126
|
+
async function download(mode) {
|
|
127
|
+
const list = await manifest();
|
|
128
|
+
const entry = list[arch()];
|
|
129
|
+
if (!entry)
|
|
130
|
+
throw new Error(`No Eversince app for ${arch()} Linux yet.`);
|
|
131
|
+
if (!/^\d+\.\d+\.\d+[\w.-]*$/.test(list.version) || !/^[\w.-]+\.tar\.gz$/.test(entry.file) || !/^[a-f0-9]{64}$/.test(entry.sha256)) {
|
|
132
|
+
throw new Error('The app\'s download list could not be read. Try again.');
|
|
133
|
+
}
|
|
134
|
+
const dir = join(installRoot(), 'versions', list.version);
|
|
135
|
+
if (existsSync(join(dir, 'eversince'))) {
|
|
136
|
+
pointCurrent(dir);
|
|
137
|
+
return { version: list.version, fresh: false };
|
|
138
|
+
}
|
|
139
|
+
mkdirSync(join(installRoot(), 'versions'), { recursive: true });
|
|
140
|
+
const archive = join(installRoot(), `${entry.file}.part`);
|
|
141
|
+
if (!mode.json)
|
|
142
|
+
note(`Downloading Eversince ${list.version} (${Math.round(entry.size / 1e6)} MB).`);
|
|
143
|
+
const res = await fetch(`${FEED}/${entry.file}`);
|
|
144
|
+
if (!res.ok || !res.body)
|
|
145
|
+
throw new Error(`The app could not be downloaded (${res.status}). Try again.`);
|
|
146
|
+
await pipeline(Readable.fromWeb(res.body), createWriteStream(archive));
|
|
147
|
+
if ((await sha256File(archive)) !== entry.sha256) {
|
|
148
|
+
rmSync(archive, { force: true });
|
|
149
|
+
throw new Error('The downloaded app did not match its checksum and was removed. Try again.');
|
|
150
|
+
}
|
|
151
|
+
const unpacking = `${dir}.part`;
|
|
152
|
+
rmSync(unpacking, { recursive: true, force: true });
|
|
153
|
+
mkdirSync(unpacking, { recursive: true });
|
|
154
|
+
const tar = spawnSync('tar', ['-xzf', archive, '-C', unpacking, '--strip-components=1'], { stdio: 'ignore' });
|
|
155
|
+
rmSync(archive, { force: true });
|
|
156
|
+
if (tar.status !== 0 || !existsSync(join(unpacking, 'eversince'))) {
|
|
157
|
+
rmSync(unpacking, { recursive: true, force: true });
|
|
158
|
+
throw new Error('The app could not be unpacked. Check the free disk space and try again.');
|
|
159
|
+
}
|
|
160
|
+
writeFileSync(join(unpacking, 'version'), `${list.version}\n`);
|
|
161
|
+
renameSync(unpacking, dir);
|
|
162
|
+
const before = installedVersion();
|
|
163
|
+
pointCurrent(dir);
|
|
164
|
+
const running = runningPid() ? before : null;
|
|
165
|
+
for (const old of readdirSync(join(installRoot(), 'versions'))) {
|
|
166
|
+
if (old !== list.version && old !== running)
|
|
167
|
+
rmSync(join(installRoot(), 'versions', old), { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
return { version: list.version, fresh: true };
|
|
170
|
+
}
|
|
171
|
+
function pointCurrent(dir) {
|
|
172
|
+
const link = currentDir();
|
|
173
|
+
const next = `${link}.next`;
|
|
174
|
+
rmSync(next, { force: true });
|
|
175
|
+
symlinkSync(dir, next);
|
|
176
|
+
renameSync(next, link);
|
|
177
|
+
}
|
|
178
|
+
function runningPid() {
|
|
179
|
+
try {
|
|
180
|
+
const pid = Number(readFileSync(pidFile(), 'utf8').trim());
|
|
181
|
+
if (!Number.isInteger(pid) || pid <= 1)
|
|
182
|
+
return null;
|
|
183
|
+
if (!readFileSync(`/proc/${pid}/cmdline`, 'utf8').includes('eversince-headless'))
|
|
184
|
+
return null;
|
|
185
|
+
return pid;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function answering() {
|
|
192
|
+
const state = readState(stateFile());
|
|
193
|
+
if (!state)
|
|
194
|
+
return null;
|
|
195
|
+
return (await probe(state).catch(() => 'closed')) === 'ours' ? state : null;
|
|
196
|
+
}
|
|
197
|
+
async function waitForApp(ms) {
|
|
198
|
+
const until = Date.now() + ms;
|
|
199
|
+
while (Date.now() < until) {
|
|
200
|
+
const state = await answering();
|
|
201
|
+
if (state)
|
|
202
|
+
return state;
|
|
203
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
async function startApp(mode) {
|
|
208
|
+
const already = await answering();
|
|
209
|
+
if (already)
|
|
210
|
+
return already;
|
|
211
|
+
if (!existsSync(launcherPath()))
|
|
212
|
+
throw new Error('The Eversince app is not installed. Run: eversince app install');
|
|
213
|
+
if (!process.env.DISPLAY && !hasXvfb())
|
|
214
|
+
throw new Error('The app needs Xvfb to run with no screen. Run: eversince app install');
|
|
215
|
+
if (!mode.json)
|
|
216
|
+
note('Starting the Eversince app.');
|
|
217
|
+
mkdirSync(installRoot(), { recursive: true });
|
|
218
|
+
const out = openSync(logFile(), 'a');
|
|
219
|
+
const env = { ...process.env };
|
|
220
|
+
delete env.ELECTRON_RUN_AS_NODE;
|
|
221
|
+
const child = spawn(launcherPath(), [], { detached: true, stdio: ['ignore', out, out], env });
|
|
222
|
+
child.unref();
|
|
223
|
+
const state = await waitForApp(START_WAIT_MS);
|
|
224
|
+
if (!state)
|
|
225
|
+
throw new Error(`The app did not start within ${START_WAIT_MS / 1000} seconds. Its log is ${logFile()}.`);
|
|
226
|
+
return state;
|
|
227
|
+
}
|
|
228
|
+
async function stopApp() {
|
|
229
|
+
const pid = runningPid();
|
|
230
|
+
if (!pid)
|
|
231
|
+
return false;
|
|
232
|
+
process.kill(pid, 'SIGTERM');
|
|
233
|
+
for (let i = 0; i < 30 && runningPid(); i++)
|
|
234
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
async function door(state, method, body) {
|
|
238
|
+
const res = await fetch(`http://127.0.0.1:${state.port}/sign-in`, {
|
|
239
|
+
method,
|
|
240
|
+
headers: { authorization: `Bearer ${state.connectKey}`, ...(body ? { 'content-type': 'application/json' } : {}) },
|
|
241
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
242
|
+
signal: AbortSignal.timeout(60_000),
|
|
243
|
+
});
|
|
244
|
+
return { status: res.status, data: ((await res.json().catch(() => ({}))) ?? {}) };
|
|
245
|
+
}
|
|
246
|
+
async function signedIn(state) {
|
|
247
|
+
const { status, data } = await door(state, 'GET');
|
|
248
|
+
if (status !== 200)
|
|
249
|
+
throw new Error('The app did not say whether it is signed in. Try again in a few seconds.');
|
|
250
|
+
return { signedIn: data.signed_in === true, email: typeof data.email === 'string' ? data.email : null };
|
|
251
|
+
}
|
|
252
|
+
function readPending() {
|
|
253
|
+
try {
|
|
254
|
+
const p = JSON.parse(readFileSync(pendingFile(), 'utf8'));
|
|
255
|
+
return p.until > Date.now() ? p : null;
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function signIn(state, connection, mode, opts) {
|
|
262
|
+
const now = await signedIn(state);
|
|
263
|
+
if (now.signedIn)
|
|
264
|
+
return { status: 'signed_in', email: now.email };
|
|
265
|
+
const base = await resolveBaseUrl(connection.baseUrl);
|
|
266
|
+
let pending = readPending();
|
|
267
|
+
if (!pending) {
|
|
268
|
+
const name = opts.name ?? detectHostAgent()?.name ?? hostname();
|
|
269
|
+
const res = await fetch(`${base}/api/v1/connect`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ name, kind: 'app' }) });
|
|
270
|
+
const body = (await res.json().catch(() => ({})));
|
|
271
|
+
if (!res.ok || !body.link || !body.device_code)
|
|
272
|
+
throw new Error(body.message ?? `A sign-in link could not be made (${res.status}). Try again.`);
|
|
273
|
+
pending = { link: body.link, device_code: body.device_code, until: Date.now() + (body.expires_in ?? 900) * 1000, interval: body.interval ?? 5, name };
|
|
274
|
+
mkdirSync(join(configHome(), 'Eversince'), { recursive: true });
|
|
275
|
+
writeFileSync(pendingFile(), JSON.stringify(pending), { mode: 0o600 });
|
|
276
|
+
}
|
|
277
|
+
if (!mode.json)
|
|
278
|
+
line(`Open this link on a phone or computer to sign the app in: ${pending.link}`);
|
|
279
|
+
const until = Math.min(pending.until, Date.now() + opts.waitMs);
|
|
280
|
+
while (Date.now() < until || opts.waitMs === 0) {
|
|
281
|
+
const res = await fetch(`${base}/api/v1/connect/claim`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ device_code: pending.device_code }) });
|
|
282
|
+
const body = (await res.json().catch(() => ({})));
|
|
283
|
+
if (res.status === 200 && body.sign_in?.access_token && body.sign_in.refresh_token) {
|
|
284
|
+
rmSync(pendingFile(), { force: true });
|
|
285
|
+
const handOver = { access_token: body.sign_in.access_token, refresh_token: body.sign_in.refresh_token, workspace_id: body.workspace_id, name: body.sign_in.name ?? pending.name ?? hostname() };
|
|
286
|
+
let done = await door(state, 'POST', handOver);
|
|
287
|
+
for (let i = 0; i < 6 && (done.status === 503 || done.status === 504); i++) {
|
|
288
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
289
|
+
done = await door(state, 'POST', handOver);
|
|
290
|
+
}
|
|
291
|
+
if (done.status !== 200)
|
|
292
|
+
throw new Error((done.data.error?.message) ?? 'The app could not finish signing in. Run eversince app sign-in again.');
|
|
293
|
+
return { status: 'signed_in', email: typeof done.data.email === 'string' ? done.data.email : null };
|
|
294
|
+
}
|
|
295
|
+
if (res.status === 403 || res.status === 410) {
|
|
296
|
+
rmSync(pendingFile(), { force: true });
|
|
297
|
+
throw new Error(res.status === 403 ? 'The user did not allow the sign-in.' : 'The sign-in link ran out. Run eversince app sign-in for a new one.');
|
|
298
|
+
}
|
|
299
|
+
if (opts.waitMs === 0)
|
|
300
|
+
break;
|
|
301
|
+
await new Promise((r) => setTimeout(r, pending.interval * 1000));
|
|
302
|
+
}
|
|
303
|
+
return { status: 'waiting', link: pending.link };
|
|
304
|
+
}
|
|
305
|
+
export async function appCommand(argv, connection, mode) {
|
|
306
|
+
linuxOnly();
|
|
307
|
+
const waitMs = argv.noWait ? 0 : argv.timeout !== undefined ? argv.timeout * 1000 : SIGN_IN_WAIT_MS;
|
|
308
|
+
switch (argv.action) {
|
|
309
|
+
case 'install': {
|
|
310
|
+
const { version, fresh } = await download(mode);
|
|
311
|
+
if (!hasXvfb() || missingLibraries(join(currentDir(), 'eversince')).length > 0)
|
|
312
|
+
installPackages(mode);
|
|
313
|
+
const missing = missingLibraries(join(currentDir(), 'eversince'));
|
|
314
|
+
if (missing.length > 0)
|
|
315
|
+
throw new Error(`The app still cannot find ${missing.join(', ')} on this computer.`);
|
|
316
|
+
allowSandbox(mode);
|
|
317
|
+
if (fresh && runningPid())
|
|
318
|
+
await stopApp();
|
|
319
|
+
const state = await startApp(mode);
|
|
320
|
+
const signed = await signIn(state, connection, mode, { name: argv.name, waitMs });
|
|
321
|
+
await installCoreSkills([join(homedir(), '.agents', 'skills'), ...(existsSync(join(homedir(), '.claude')) ? [join(homedir(), '.claude', 'skills')] : [])]);
|
|
322
|
+
printResult(mode, { installed: version, running: true, ...signed }, () => {
|
|
323
|
+
line(`Eversince ${version} is running on this computer.`);
|
|
324
|
+
if (signed.status === 'signed_in')
|
|
325
|
+
line(`Signed in${signed.email ? ` as ${signed.email}` : ''}. Commands and the MCP connection now go through the app.`);
|
|
326
|
+
else
|
|
327
|
+
line('Waiting for the sign-in. Run eversince app sign-in once the link is allowed.');
|
|
328
|
+
});
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
case 'start': {
|
|
332
|
+
const state = await startApp(mode);
|
|
333
|
+
const now = await signedIn(state);
|
|
334
|
+
printResult(mode, { running: true, signed_in: now.signedIn, email: now.email }, () => {
|
|
335
|
+
line('The Eversince app is running.');
|
|
336
|
+
if (!now.signedIn)
|
|
337
|
+
line('It is not signed in. Run: eversince app sign-in');
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
case 'stop': {
|
|
342
|
+
const stopped = await stopApp();
|
|
343
|
+
printResult(mode, { stopped }, () => line(stopped ? 'The Eversince app stopped.' : 'The Eversince app was not running.'));
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
case 'status': {
|
|
347
|
+
const state = await answering();
|
|
348
|
+
const now = state ? await signedIn(state) : null;
|
|
349
|
+
const version = installedVersion();
|
|
350
|
+
const newest = version ? await manifest().then((m) => m.version, () => null) : null;
|
|
351
|
+
const behind = !!newest && newest !== version;
|
|
352
|
+
printResult(mode, { installed: version, ...(newest ? { newest } : {}), running: !!state, signed_in: now?.signedIn ?? false, email: now?.email ?? null }, () => {
|
|
353
|
+
line(version ? `Eversince ${version} is installed.` : 'The Eversince app is not installed. Run: eversince app install');
|
|
354
|
+
if (version)
|
|
355
|
+
line(state ? `It is running, ${now?.signedIn ? `signed in${now.email ? ` as ${now.email}` : ''}` : 'not signed in'}.` : 'It is not running.');
|
|
356
|
+
if (behind)
|
|
357
|
+
line(`Eversince ${newest} is out. Run: eversince app install`);
|
|
358
|
+
});
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
case 'sign-in': {
|
|
362
|
+
const state = await startApp(mode);
|
|
363
|
+
const signed = await signIn(state, connection, mode, { name: argv.name, waitMs });
|
|
364
|
+
printResult(mode, signed, () => {
|
|
365
|
+
if (signed.status === 'signed_in')
|
|
366
|
+
line(`Signed in${signed.email ? ` as ${signed.email}` : ''}.`);
|
|
367
|
+
else
|
|
368
|
+
line('Waiting for the sign-in. Run eversince app sign-in again once the link is allowed.');
|
|
369
|
+
});
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
case 'uninstall': {
|
|
373
|
+
const stopped = await stopApp();
|
|
374
|
+
rmSync(installRoot(), { recursive: true, force: true });
|
|
375
|
+
const everything = argv.all === true;
|
|
376
|
+
if (everything)
|
|
377
|
+
rmSync(join(configHome(), 'Eversince'), { recursive: true, force: true });
|
|
378
|
+
printResult(mode, { uninstalled: true, stopped, removed_data: everything }, () => {
|
|
379
|
+
line('The Eversince app was removed from this computer.');
|
|
380
|
+
line(everything ? 'Its sign-in and local data were removed too.' : 'Its sign-in and local data stay; eversince app uninstall --all removes them.');
|
|
381
|
+
});
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
default:
|
|
385
|
+
throw new Error('eversince app takes install, start, stop, status, sign-in or uninstall.');
|
|
386
|
+
}
|
|
387
|
+
}
|
package/dist/commands/init.js
CHANGED
|
@@ -8,6 +8,7 @@ import { resolveBaseUrl, hostOf } from '../config.js';
|
|
|
8
8
|
import { line, note, printResult } from '../output.js';
|
|
9
9
|
import { connectThroughApp, desktopInstalled, hereCommand, openApp, stableLauncher } from '../local.js';
|
|
10
10
|
import { detectHostAgent } from '../host-agent.js';
|
|
11
|
+
import { installCoreSkills } from '../skills-refresh.js';
|
|
11
12
|
export const APP_AGENTS = ['claude-code', 'codex', 'cursor', 'vscode', 'claude-desktop', 'other', 'cli'];
|
|
12
13
|
function checkAgent(given) {
|
|
13
14
|
if (given === undefined)
|
|
@@ -62,6 +63,20 @@ async function writeAtomic(path, text) {
|
|
|
62
63
|
await writeFile(temp, text, { mode });
|
|
63
64
|
await rename(temp, path);
|
|
64
65
|
}
|
|
66
|
+
async function installCore(scope, agents, mode) {
|
|
67
|
+
const root = scope === 'project' ? process.cwd() : homedir();
|
|
68
|
+
const user = { 'claude-code': '.claude/skills', codex: '.agents/skills', cursor: '.cursor/skills', vscode: '.copilot/skills', other: '.agents/skills' };
|
|
69
|
+
const folders = [...new Set(agents.flatMap((agent) => {
|
|
70
|
+
if (!user[agent])
|
|
71
|
+
return [];
|
|
72
|
+
return [scope === 'project' && agent !== 'claude-code' ? '.agents/skills' : user[agent]];
|
|
73
|
+
}))].map((dir) => join(root, dir));
|
|
74
|
+
if (folders.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
const { written } = await installCoreSkills(folders);
|
|
77
|
+
if (written > 0 && !mode.json)
|
|
78
|
+
note('Added the Eversince start skill and its four master skills; the rest load through the connection.');
|
|
79
|
+
}
|
|
65
80
|
function skillTargets(scope) {
|
|
66
81
|
const root = scope === 'project' ? process.cwd() : homedir();
|
|
67
82
|
return [{ agent: 'Claude Code', path: join(root, '.claude', 'skills', 'eversince-cli', 'SKILL.md') }];
|
|
@@ -249,6 +264,8 @@ async function initThroughApp(argv, scope, mode) {
|
|
|
249
264
|
for (const target of skillTargets(scope)) {
|
|
250
265
|
changes.push(await writeSkill(target, body, argv.force === true, dryRun));
|
|
251
266
|
}
|
|
267
|
+
if (!dryRun)
|
|
268
|
+
await installCore(scope, agents, mode);
|
|
252
269
|
}
|
|
253
270
|
const shadowed = agents.includes('claude-code') ? await projectEntryShadows() : null;
|
|
254
271
|
printResult(mode, {
|
|
@@ -314,6 +331,8 @@ export async function init(argv, connection, mode) {
|
|
|
314
331
|
for (const target of skillTargets(scope)) {
|
|
315
332
|
changes.push(await writeSkill(target, body, argv.force === true, dryRun));
|
|
316
333
|
}
|
|
334
|
+
if (!dryRun)
|
|
335
|
+
await installCore(scope, agent ? [agent] : ['claude-code'], mode);
|
|
317
336
|
}
|
|
318
337
|
const connected = !(entries.length > 0 && entries.every((entry) => entry.points_to));
|
|
319
338
|
if (!dryRun && connected) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { stateDir } from '../auth/store.js';
|
|
5
|
+
import { refreshInstalledSkills } from '../skills-refresh.js';
|
|
6
|
+
import { line } from '../output.js';
|
|
7
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
8
|
+
const stampPath = () => join(stateDir(), 'skills.json');
|
|
9
|
+
async function readStamp() {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(await readFile(stampPath(), 'utf8'));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function writeStamp(stamp) {
|
|
18
|
+
await mkdir(stateDir(), { recursive: true, mode: 0o700 });
|
|
19
|
+
await writeFile(stampPath(), JSON.stringify(stamp), { mode: 0o600 });
|
|
20
|
+
}
|
|
21
|
+
export async function skillsCommand(argv, mode) {
|
|
22
|
+
if (argv.action !== 'update')
|
|
23
|
+
throw new Error('`eversince skills update` brings installed Eversince skills to the latest.');
|
|
24
|
+
const stamp = await readStamp();
|
|
25
|
+
const result = await refreshInstalledSkills({ cwd: process.cwd(), stamp: argv.quiet ? stamp.folders : {} });
|
|
26
|
+
await writeStamp({ checkedAt: Date.now(), folders: result.stamp });
|
|
27
|
+
if (argv.quiet)
|
|
28
|
+
return;
|
|
29
|
+
if (mode.json) {
|
|
30
|
+
line(JSON.stringify({ ok: true, data: { version: result.version, folders: result.folders, updated: result.updated, added: result.added, removed: result.removed } }));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (result.version === null)
|
|
34
|
+
line('No Eversince skills are installed here. npx skills add eversince-ai/skills installs them.');
|
|
35
|
+
else if (result.folders.length === 0)
|
|
36
|
+
line('The installed Eversince skills are current.');
|
|
37
|
+
else
|
|
38
|
+
line(`Eversince skills brought to the latest in ${result.folders.length} folder${result.folders.length === 1 ? '' : 's'}: ${result.updated} updated, ${result.added} added, ${result.removed} removed.`);
|
|
39
|
+
}
|
|
40
|
+
export async function refreshSkillsSoon(entry) {
|
|
41
|
+
if (process.env.EVERSINCE_SKIP_SKILLS === '1' || process.env.CI)
|
|
42
|
+
return;
|
|
43
|
+
const stamp = await readStamp();
|
|
44
|
+
if (stamp.checkedAt && Date.now() - stamp.checkedAt < DAY_MS)
|
|
45
|
+
return;
|
|
46
|
+
await writeStamp({ ...stamp, checkedAt: Date.now() }).catch(() => undefined);
|
|
47
|
+
try {
|
|
48
|
+
spawn(process.execPath, [entry, 'skills', 'update', '--quiet'], { detached: true, stdio: 'ignore', cwd: process.cwd(), env: { ...process.env, EVERSINCE_SKIP_SKILLS: '1' } }).unref();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ import { upload } from './commands/upload.js';
|
|
|
8
8
|
import { download } from './commands/download.js';
|
|
9
9
|
import { jobs } from './commands/jobs.js';
|
|
10
10
|
import { init, APP_AGENTS } from './commands/init.js';
|
|
11
|
+
import { appCommand } from './commands/app.js';
|
|
12
|
+
import { refreshSkillsSoon, skillsCommand } from './commands/skills.js';
|
|
11
13
|
import { runBridge } from './bridge.js';
|
|
12
14
|
import { selfCommand } from './local.js';
|
|
13
15
|
import { fail, line } from './output.js';
|
|
@@ -26,6 +28,20 @@ Getting set up
|
|
|
26
28
|
eversince mcp --agent <agent> the desktop app as a stdio MCP server;
|
|
27
29
|
init writes this into the agent's settings
|
|
28
30
|
|
|
31
|
+
The app on Linux (a computer with no screen, an agent's own machine)
|
|
32
|
+
eversince app install download the app and what it needs, start
|
|
33
|
+
it and sign it in by a link the user opens
|
|
34
|
+
eversince app sign-in that link again (--no-wait to print it
|
|
35
|
+
and return; run again to collect)
|
|
36
|
+
eversince app start | stop | status
|
|
37
|
+
eversince app uninstall remove the app (--all: its sign-in and
|
|
38
|
+
local data too; the workspace is untouched)
|
|
39
|
+
|
|
40
|
+
Skills
|
|
41
|
+
eversince skills update installed Eversince skills to the latest
|
|
42
|
+
(done by itself once a day; npx skills add
|
|
43
|
+
eversince-ai/skills installs them)
|
|
44
|
+
|
|
29
45
|
Working
|
|
30
46
|
eversince tools [name] what this workspace can do, live
|
|
31
47
|
eversince tools --all every tool's input fields, once
|
|
@@ -106,6 +122,8 @@ const OPTIONS = {
|
|
|
106
122
|
timeout: { type: 'string' },
|
|
107
123
|
'idempotency-key': { type: 'string' },
|
|
108
124
|
'no-browser': { type: 'boolean', default: false },
|
|
125
|
+
'no-wait': { type: 'boolean', default: false },
|
|
126
|
+
quiet: { type: 'boolean', default: false },
|
|
109
127
|
scope: { type: 'string' },
|
|
110
128
|
agent: { type: 'string' },
|
|
111
129
|
connection: { type: 'string' },
|
|
@@ -149,6 +167,8 @@ async function main() {
|
|
|
149
167
|
timeout,
|
|
150
168
|
cloud: values.cloud,
|
|
151
169
|
};
|
|
170
|
+
if (command !== 'skills')
|
|
171
|
+
void refreshSkillsSoon(process.argv[1] ?? '').catch(() => undefined);
|
|
152
172
|
try {
|
|
153
173
|
switch (command) {
|
|
154
174
|
case 'login':
|
|
@@ -190,6 +210,10 @@ async function main() {
|
|
|
190
210
|
runBridge({ agent, connectionId: values.connection, command: selfCommand() });
|
|
191
211
|
return;
|
|
192
212
|
}
|
|
213
|
+
case 'skills':
|
|
214
|
+
return await skillsCommand({ action: rest[0], quiet: values.quiet }, mode);
|
|
215
|
+
case 'app':
|
|
216
|
+
return await appCommand({ action: rest[0], name: values.name, timeout, noWait: values['no-wait'], all: values.all }, connection, mode);
|
|
193
217
|
case 'init':
|
|
194
218
|
return await init({
|
|
195
219
|
scope: values.scope,
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { lstat, mkdir, readdir, readFile, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const BASE = process.env.EVERSINCE_SKILLS_BASE || 'https://raw.githubusercontent.com/eversince-ai/skills/main/';
|
|
5
|
+
const PUBLISHER = /^\s*publisher:\s*eversince\s*$/m;
|
|
6
|
+
const NAME = /^eversince(-[a-z0-9-]+)?$/;
|
|
7
|
+
const FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/;
|
|
8
|
+
function roots(cwd) {
|
|
9
|
+
const home = homedir();
|
|
10
|
+
const user = [
|
|
11
|
+
'.agents/skills', '.claude/skills', '.cursor/skills', '.config/opencode/skills', '.config/agents/skills',
|
|
12
|
+
'.gemini/skills', '.copilot/skills', '.codex/skills', '.factory/skills', '.kilo/skills',
|
|
13
|
+
].map((dir) => join(home, dir));
|
|
14
|
+
const project = cwd ? ['.agents/skills', '.claude/skills', '.cursor/skills'].map((dir) => join(cwd, dir)) : [];
|
|
15
|
+
return [...user, ...project];
|
|
16
|
+
}
|
|
17
|
+
async function insideRepo(dir) {
|
|
18
|
+
for (let at = dir;; at = dirname(at)) {
|
|
19
|
+
if (await lstat(join(at, '.git')).then(() => true, () => false))
|
|
20
|
+
return true;
|
|
21
|
+
if (dirname(at) === at)
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function ours(dir) {
|
|
26
|
+
try {
|
|
27
|
+
return PUBLISHER.test((await readFile(join(dir, 'SKILL.md'), 'utf8')).split('\n---')[0] ?? '');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function installed(cwd) {
|
|
34
|
+
const found = new Map();
|
|
35
|
+
const linkedFrom = new Map();
|
|
36
|
+
const all = roots(cwd);
|
|
37
|
+
const known = new Set((await Promise.all(all.map(async (root) => {
|
|
38
|
+
const real = await realpath(root).catch(() => null);
|
|
39
|
+
if (!real)
|
|
40
|
+
return null;
|
|
41
|
+
const linked = (await lstat(root).catch(() => null))?.isSymbolicLink();
|
|
42
|
+
return linked && (await insideRepo(real)) ? null : real;
|
|
43
|
+
}))).filter((r) => !!r));
|
|
44
|
+
for (const root of all) {
|
|
45
|
+
let names;
|
|
46
|
+
try {
|
|
47
|
+
names = await readdir(root);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
for (const name of names) {
|
|
53
|
+
if (!NAME.test(name))
|
|
54
|
+
continue;
|
|
55
|
+
const dir = join(root, name);
|
|
56
|
+
if (!(await ours(dir)))
|
|
57
|
+
continue;
|
|
58
|
+
const real = await realpath(dir).catch(() => null);
|
|
59
|
+
if (!real)
|
|
60
|
+
continue;
|
|
61
|
+
const parent = dirname(real);
|
|
62
|
+
if (!known.has(parent))
|
|
63
|
+
continue;
|
|
64
|
+
const set = found.get(parent) ?? new Set();
|
|
65
|
+
set.add(name);
|
|
66
|
+
found.set(parent, set);
|
|
67
|
+
if ((await lstat(dir)).isSymbolicLink()) {
|
|
68
|
+
const links = linkedFrom.get(parent) ?? new Set();
|
|
69
|
+
links.add(root);
|
|
70
|
+
linkedFrom.set(parent, links);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { found, linkedFrom };
|
|
75
|
+
}
|
|
76
|
+
async function fetchText(url) {
|
|
77
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(15_000) });
|
|
78
|
+
if (!response.ok)
|
|
79
|
+
throw new Error(`${url} answered ${response.status}`);
|
|
80
|
+
return response.text();
|
|
81
|
+
}
|
|
82
|
+
function readManifest(text) {
|
|
83
|
+
const raw = JSON.parse(text);
|
|
84
|
+
if (typeof raw?.version !== 'string' || !Array.isArray(raw.skills))
|
|
85
|
+
throw new Error('The skills manifest is not one this CLI reads.');
|
|
86
|
+
for (const skill of raw.skills) {
|
|
87
|
+
if (!NAME.test(skill.name) || !Array.isArray(skill.files) || !skill.files.every((f) => FILE.test(f)))
|
|
88
|
+
throw new Error('The skills manifest names a file this CLI does not write.');
|
|
89
|
+
}
|
|
90
|
+
return raw;
|
|
91
|
+
}
|
|
92
|
+
async function writeSkill(parent, skill, texts) {
|
|
93
|
+
const dir = join(parent, skill.name);
|
|
94
|
+
const next = `${dir}.eversince-next`;
|
|
95
|
+
await rm(next, { recursive: true, force: true });
|
|
96
|
+
await mkdir(next, { recursive: true });
|
|
97
|
+
for (const file of skill.files)
|
|
98
|
+
await writeFile(join(next, file), texts.get(`${skill.name}/${file}`) ?? '');
|
|
99
|
+
const old = `${dir}.eversince-old`;
|
|
100
|
+
await rm(old, { recursive: true, force: true });
|
|
101
|
+
const had = await lstat(dir).then(() => true, () => false);
|
|
102
|
+
if (had)
|
|
103
|
+
await rename(dir, old);
|
|
104
|
+
await rename(next, dir);
|
|
105
|
+
if (had)
|
|
106
|
+
await rm(old, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
export const CORE_SKILLS = ['eversince', 'eversince-make-content', 'eversince-make-videos', 'eversince-make-images', 'eversince-promote'];
|
|
109
|
+
export async function installCoreSkills(folders) {
|
|
110
|
+
try {
|
|
111
|
+
const manifest = readManifest(await fetchText(`${BASE}manifest.json`));
|
|
112
|
+
const core = manifest.skills.filter((s) => CORE_SKILLS.includes(s.name));
|
|
113
|
+
const texts = new Map();
|
|
114
|
+
let written = 0;
|
|
115
|
+
for (const folder of folders) {
|
|
116
|
+
await mkdir(folder, { recursive: true });
|
|
117
|
+
for (const skill of core) {
|
|
118
|
+
for (const file of skill.files) {
|
|
119
|
+
const key = `${skill.name}/${file}`;
|
|
120
|
+
if (!texts.has(key))
|
|
121
|
+
texts.set(key, await fetchText(`${BASE}skills/${key}`));
|
|
122
|
+
}
|
|
123
|
+
await writeSkill(folder, skill, texts);
|
|
124
|
+
written += 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { written };
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return { written: 0 };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export async function refreshInstalledSkills(options = {}) {
|
|
134
|
+
const stamp = { ...(options.stamp ?? {}) };
|
|
135
|
+
const result = { version: null, folders: [], updated: 0, added: 0, removed: 0, stamp };
|
|
136
|
+
const { found, linkedFrom } = await installed(options.cwd);
|
|
137
|
+
if (found.size === 0)
|
|
138
|
+
return result;
|
|
139
|
+
const manifest = readManifest(await fetchText(`${BASE}manifest.json`));
|
|
140
|
+
result.version = manifest.version;
|
|
141
|
+
const due = [...found.entries()].filter(([parent]) => stamp[parent] !== manifest.version);
|
|
142
|
+
if (due.length === 0)
|
|
143
|
+
return result;
|
|
144
|
+
const texts = new Map();
|
|
145
|
+
const want = async (skill) => {
|
|
146
|
+
for (const file of skill.files) {
|
|
147
|
+
const key = `${skill.name}/${file}`;
|
|
148
|
+
if (!texts.has(key))
|
|
149
|
+
texts.set(key, await fetchText(`${BASE}skills/${key}`));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
for (const [parent, names] of due) {
|
|
153
|
+
const whole = manifest.skills.filter((s) => names.has(s.name)).length * 2 > manifest.skills.length;
|
|
154
|
+
for (const skill of manifest.skills) {
|
|
155
|
+
if (!names.has(skill.name) && !whole)
|
|
156
|
+
continue;
|
|
157
|
+
await want(skill);
|
|
158
|
+
await writeSkill(parent, skill, texts);
|
|
159
|
+
if (names.has(skill.name)) {
|
|
160
|
+
result.updated += 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
result.added += 1;
|
|
164
|
+
for (const root of linkedFrom.get(parent) ?? []) {
|
|
165
|
+
const link = join(root, skill.name);
|
|
166
|
+
if (!(await lstat(link).then(() => true, () => false)))
|
|
167
|
+
await symlink(join(parent, skill.name), link, 'dir').catch(() => undefined);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const name of names) {
|
|
171
|
+
if (manifest.skills.some((s) => s.name === name))
|
|
172
|
+
continue;
|
|
173
|
+
await rm(join(parent, name), { recursive: true, force: true });
|
|
174
|
+
for (const root of linkedFrom.get(parent) ?? []) {
|
|
175
|
+
const link = join(root, name);
|
|
176
|
+
if ((await lstat(link).catch(() => null))?.isSymbolicLink())
|
|
177
|
+
await rm(link, { force: true });
|
|
178
|
+
}
|
|
179
|
+
result.removed += 1;
|
|
180
|
+
}
|
|
181
|
+
stamp[parent] = manifest.version;
|
|
182
|
+
result.folders.push(parent);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
package/dist/source.sha256
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
d47630c2d852ddfd5fa5c3f1eb40c76e5951b604223b47f84ec38fac69829722
|
package/package.json
CHANGED