@pulsarinteractive/geniustasker 0.1.0-beta.11 → 0.1.0-beta.13
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/CHANGELOG.md +22 -0
- package/README.md +14 -1
- package/docs/ARCHITECTURE.md +15 -13
- package/docs/CHATGPT.md +6 -0
- package/docs/CLI.md +153 -5
- package/docs/INTEGRATIONS.md +25 -2
- package/docs/MEMORY.md +9 -0
- package/docs/WORKFLOWS.md +14 -0
- package/examples/codex.toml +1 -1
- package/examples/mcp.json +1 -1
- package/mcp.json +1 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/remote/tool-catalog.json +296 -1
- package/remote/workflows.json +53 -2
- package/skills/geniustasker/SKILL.md +15 -1
- package/skills/geniustasker/references/agent-runs.md +144 -0
- package/skills/geniustasker/references/host-events.md +116 -0
- package/skills/geniustasker/references/importance.md +90 -0
- package/skills/geniustasker/references/metric-goals.md +143 -0
- package/skills/geniustasker/references/metrics-observations.md +184 -0
- package/skills/geniustasker/references/metrics.md +136 -0
- package/skills/geniustasker/references/protocols.md +156 -0
- package/skills/geniustasker/references/updates.md +31 -0
- package/skills/geniustasker-graph/SKILL.md +10 -0
- package/skills/geniustasker-memory/SKILL.md +19 -6
- package/skills/geniustasker-memory/references/knowledge-workflows.md +42 -0
- package/skills/geniustasker-planning/SKILL.md +6 -1
- package/src/changes.mjs +3 -5
- package/src/cli.mjs +108 -14
- package/src/command-catalog.mjs +849 -562
- package/src/command-input-schemas.d.mts +8 -0
- package/src/command-input-schemas.mjs +1021 -0
- package/src/commands.mjs +78 -25
- package/src/mcp.mjs +48 -20
- package/src/protocols.mjs +122 -0
- package/src/resources.mjs +98 -0
- package/src/run-events.mjs +145 -0
- package/src/update-runtime.mjs +169 -0
- package/src/update.mjs +306 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { constants, unlinkSync } from 'node:fs';
|
|
2
|
+
import { lstat, mkdir, open, opendir, realpath, rmdir, unlink } from 'node:fs/promises';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { fail } from './errors.mjs';
|
|
8
|
+
|
|
9
|
+
const installation = fileURLToPath(new URL('../', import.meta.url));
|
|
10
|
+
// The package's canonical path separates global, npx and source installations.
|
|
11
|
+
// This directory never contains account IDs, credentials or operation bodies.
|
|
12
|
+
export async function runtimePath(packageDirectory = installation) {
|
|
13
|
+
const path = await realpath(packageDirectory);
|
|
14
|
+
const key = createHash('sha256').update(path).digest('hex').slice(0, 24);
|
|
15
|
+
return join(homedir(), '.cache', 'geniustasker', 'cli-runtime', key);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function busy() {
|
|
19
|
+
fail('update_runtime_busy', 'Another GeniusTasker process or installer is active.', {
|
|
20
|
+
status: 409,
|
|
21
|
+
remediation:
|
|
22
|
+
'Let CLI commands finish and close local MCP servers before updating. Retry the same saved operation after restarting; do not remove its journal. An interrupted installer leaves install.lock; remove that empty directory only after all clients and npm installers have stopped.',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function privateDirectory(path) {
|
|
26
|
+
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
27
|
+
const info = await lstat(path);
|
|
28
|
+
if (
|
|
29
|
+
!info.isDirectory() ||
|
|
30
|
+
info.isSymbolicLink() ||
|
|
31
|
+
(process.getuid && info.uid !== process.getuid()) ||
|
|
32
|
+
(process.platform !== 'win32' && info.mode & 0o077)
|
|
33
|
+
) {
|
|
34
|
+
fail(
|
|
35
|
+
'unsafe_update_runtime',
|
|
36
|
+
'The local update runtime directory must be private and owned by you.',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function exists(path) {
|
|
41
|
+
try {
|
|
42
|
+
await lstat(path);
|
|
43
|
+
return true;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error.code === 'ENOENT') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Readers register before checking the writer barrier. Writers create that
|
|
53
|
+
* barrier before checking readers. Every interleaving either observes a reader
|
|
54
|
+
* or rejects it before work begins; regular commands can still run concurrently.
|
|
55
|
+
*/
|
|
56
|
+
export async function acquireRuntime(directory = runtimePath()) {
|
|
57
|
+
directory = await directory;
|
|
58
|
+
await privateDirectory(directory);
|
|
59
|
+
const active = join(directory, 'active');
|
|
60
|
+
await privateDirectory(active);
|
|
61
|
+
const path = join(active, `${process.pid}-${randomUUID()}.lock`);
|
|
62
|
+
const handle = await open(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o600);
|
|
63
|
+
await handle.close();
|
|
64
|
+
const cleanup = () => {
|
|
65
|
+
try {
|
|
66
|
+
unlinkSync(path);
|
|
67
|
+
} catch {
|
|
68
|
+
/* Dead-process records are reclaimed on install. */
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
process.once('exit', cleanup);
|
|
72
|
+
let released = false;
|
|
73
|
+
const release = async () => {
|
|
74
|
+
if (released) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
released = true;
|
|
78
|
+
process.removeListener('exit', cleanup);
|
|
79
|
+
await unlink(path).catch((error) => {
|
|
80
|
+
if (error.code !== 'ENOENT') {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
if (await exists(join(directory, 'install.lock'))) {
|
|
87
|
+
busy();
|
|
88
|
+
}
|
|
89
|
+
return release;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
await release();
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function processAlive(pid) {
|
|
97
|
+
try {
|
|
98
|
+
process.kill(pid, 0);
|
|
99
|
+
return true;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return error.code !== 'ESRCH';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export async function acquireInstallation(directory = runtimePath()) {
|
|
105
|
+
directory = await directory;
|
|
106
|
+
await privateDirectory(directory);
|
|
107
|
+
const active = join(directory, 'active');
|
|
108
|
+
await privateDirectory(active);
|
|
109
|
+
const lock = join(directory, 'install.lock');
|
|
110
|
+
try {
|
|
111
|
+
await mkdir(lock, { mode: 0o700 });
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error.code === 'EEXIST') {
|
|
114
|
+
busy();
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
let released = false;
|
|
119
|
+
const release = async () => {
|
|
120
|
+
if (released) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
released = true;
|
|
124
|
+
await rmdir(lock);
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const entries = await opendir(active);
|
|
128
|
+
let count = 0;
|
|
129
|
+
for await (const entry of entries) {
|
|
130
|
+
if (++count > 256) {
|
|
131
|
+
busy();
|
|
132
|
+
}
|
|
133
|
+
const match = /^([1-9]\d*)-[a-f0-9-]{36}\.lock$/.exec(entry.name);
|
|
134
|
+
const path = join(active, entry.name);
|
|
135
|
+
let info;
|
|
136
|
+
try {
|
|
137
|
+
info = await lstat(path);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error.code === 'ENOENT') {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
if (
|
|
145
|
+
!match ||
|
|
146
|
+
!info.isFile() ||
|
|
147
|
+
info.isSymbolicLink() ||
|
|
148
|
+
info.nlink !== 1 ||
|
|
149
|
+
(process.getuid && info.uid !== process.getuid()) ||
|
|
150
|
+
(process.platform !== 'win32' && info.mode & 0o077) ||
|
|
151
|
+
!Number.isSafeInteger(Number(match[1])) ||
|
|
152
|
+
processAlive(Number(match[1]))
|
|
153
|
+
) {
|
|
154
|
+
busy();
|
|
155
|
+
}
|
|
156
|
+
// Unique filenames are never reused. Only positively dead processes are
|
|
157
|
+
// reclaimed; PID reuse and inaccessible processes conservatively block.
|
|
158
|
+
await unlink(path).catch((error) => {
|
|
159
|
+
if (error.code !== 'ENOENT') {
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return release;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
await release();
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/update.mjs
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, mkdir, open, opendir, readFile, realpath, unlink } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import metadata from '../package.json' with { type: 'json' };
|
|
9
|
+
import { fail } from './errors.mjs';
|
|
10
|
+
import { acquireInstallation, runtimePath } from './update-runtime.mjs';
|
|
11
|
+
|
|
12
|
+
const packageName = '@pulsarinteractive/geniustasker';
|
|
13
|
+
const registry = 'https://registry.npmjs.org';
|
|
14
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
15
|
+
const packageDirectory = fileURLToPath(new URL('../', import.meta.url));
|
|
16
|
+
const offlineCommands = new Set([
|
|
17
|
+
'help',
|
|
18
|
+
'doctor',
|
|
19
|
+
'mcp',
|
|
20
|
+
'workflow show',
|
|
21
|
+
'commands describe',
|
|
22
|
+
'commands prepare',
|
|
23
|
+
'commands inspect',
|
|
24
|
+
'media prepare',
|
|
25
|
+
'docs status',
|
|
26
|
+
'docs unlock',
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
// Accept only this product's stable/beta release versions, never an npm spec,
|
|
30
|
+
// URL, Git reference, shell token or an arbitrary dist tag from a response.
|
|
31
|
+
function versionParts(value) {
|
|
32
|
+
if (typeof value !== 'string' || value.length > 64) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-beta\.(0|[1-9]\d*))?$/.exec(value);
|
|
36
|
+
if (!match) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const numbers = match.slice(1).map((v) => (v === undefined ? null : Number(v)));
|
|
40
|
+
return numbers.every((v) => v === null || Number.isSafeInteger(v)) ? numbers : null;
|
|
41
|
+
}
|
|
42
|
+
function newer(candidate, current) {
|
|
43
|
+
const a = versionParts(candidate),
|
|
44
|
+
b = versionParts(current);
|
|
45
|
+
if (!a || !b) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < 3; i++) {
|
|
49
|
+
if (a[i] !== b[i]) {
|
|
50
|
+
return a[i] > b[i];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return a[3] === null ? b[3] !== null : b[3] !== null && a[3] > b[3];
|
|
54
|
+
}
|
|
55
|
+
function selectedChannel(channel, currentVersion) {
|
|
56
|
+
const selected = channel ?? (currentVersion.includes('-beta.') ? 'beta' : 'stable');
|
|
57
|
+
if (!['beta', 'stable'].includes(selected)) {
|
|
58
|
+
fail('invalid_arguments', 'Update channel must be beta or stable.');
|
|
59
|
+
}
|
|
60
|
+
return selected;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function checkUpdate({
|
|
64
|
+
channel,
|
|
65
|
+
currentVersion = metadata.version,
|
|
66
|
+
fetchImpl = globalThis.fetch,
|
|
67
|
+
timeoutMs = 1500,
|
|
68
|
+
signal,
|
|
69
|
+
} = {}) {
|
|
70
|
+
channel = selectedChannel(channel, currentVersion);
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const abort = () => controller.abort();
|
|
73
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
74
|
+
if (signal?.aborted) {
|
|
75
|
+
abort();
|
|
76
|
+
}
|
|
77
|
+
let timer;
|
|
78
|
+
const expired = new Promise((_, reject) => {
|
|
79
|
+
timer = setTimeout(() => {
|
|
80
|
+
controller.abort();
|
|
81
|
+
reject(Error('deadline'));
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
const manifest = await Promise.race([
|
|
86
|
+
(async () => {
|
|
87
|
+
const response = await fetchImpl(
|
|
88
|
+
`${registry}/@pulsarinteractive%2Fgeniustasker/${channel === 'stable' ? 'latest' : 'beta'}`,
|
|
89
|
+
{
|
|
90
|
+
headers: { Accept: 'application/json' },
|
|
91
|
+
redirect: 'error',
|
|
92
|
+
signal: controller.signal,
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
if (
|
|
96
|
+
!response.ok ||
|
|
97
|
+
response.redirected ||
|
|
98
|
+
!response.body ||
|
|
99
|
+
!/^application\/json(?:;|$)/i.test(response.headers.get('content-type') ?? '')
|
|
100
|
+
) {
|
|
101
|
+
throw Error('response');
|
|
102
|
+
}
|
|
103
|
+
const reader = response.body.getReader(),
|
|
104
|
+
parts = [];
|
|
105
|
+
let size = 0;
|
|
106
|
+
try {
|
|
107
|
+
while (true) {
|
|
108
|
+
const next = await reader.read();
|
|
109
|
+
if (next.done) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
size += next.value.byteLength;
|
|
113
|
+
if (size > 65536) {
|
|
114
|
+
throw Error('size');
|
|
115
|
+
}
|
|
116
|
+
parts.push(Buffer.from(next.value));
|
|
117
|
+
}
|
|
118
|
+
} finally {
|
|
119
|
+
// Cancellation must not extend the fixed update-check deadline.
|
|
120
|
+
void reader.cancel().catch(() => {});
|
|
121
|
+
}
|
|
122
|
+
return JSON.parse(Buffer.concat(parts).toString('utf8'));
|
|
123
|
+
})(),
|
|
124
|
+
expired,
|
|
125
|
+
]);
|
|
126
|
+
if (
|
|
127
|
+
manifest.name !== packageName ||
|
|
128
|
+
!versionParts(manifest.version) ||
|
|
129
|
+
(channel === 'stable' && manifest.version.includes('-'))
|
|
130
|
+
) {
|
|
131
|
+
throw Error('manifest');
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
package: packageName,
|
|
135
|
+
installedVersion: currentVersion,
|
|
136
|
+
channel,
|
|
137
|
+
availableVersion: manifest.version,
|
|
138
|
+
updateAvailable: newer(manifest.version, currentVersion),
|
|
139
|
+
updateCommand: `npm install --global --registry=${registry} --@pulsarinteractive:registry=${registry} --ignore-scripts --engine-strict ${packageName}@${manifest.version}`,
|
|
140
|
+
source: 'npm_registry',
|
|
141
|
+
};
|
|
142
|
+
} catch {
|
|
143
|
+
fail('update_check_unavailable', 'Could not check for a GeniusTasker update.', {
|
|
144
|
+
retryable: true,
|
|
145
|
+
remediation: 'Keep using the installed version. Try update check later.',
|
|
146
|
+
});
|
|
147
|
+
} finally {
|
|
148
|
+
clearTimeout(timer);
|
|
149
|
+
controller.abort();
|
|
150
|
+
signal?.removeEventListener('abort', abort);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const executeFile = promisify(execFile);
|
|
155
|
+
async function runNpm(args, { signal } = {}) {
|
|
156
|
+
// Standard Windows Node installations include npm-cli.js beside node.exe.
|
|
157
|
+
// Other layouts fail with manual guidance; never use a shell for npm specs.
|
|
158
|
+
const executable = process.platform === 'win32' ? process.execPath : 'npm';
|
|
159
|
+
const values =
|
|
160
|
+
process.platform === 'win32'
|
|
161
|
+
? [join(dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js'), ...args]
|
|
162
|
+
: args;
|
|
163
|
+
return executeFile(executable, values, { signal, timeout: 120000, maxBuffer: 65536 });
|
|
164
|
+
}
|
|
165
|
+
export async function installUpdate({
|
|
166
|
+
channel,
|
|
167
|
+
currentVersion = metadata.version,
|
|
168
|
+
fetchImpl,
|
|
169
|
+
signal,
|
|
170
|
+
npmImpl = runNpm,
|
|
171
|
+
installedDirectory = packageDirectory,
|
|
172
|
+
runtimeDirectory,
|
|
173
|
+
} = {}) {
|
|
174
|
+
const result = await checkUpdate({ channel, currentVersion, fetchImpl, signal });
|
|
175
|
+
if (!result.updateAvailable) {
|
|
176
|
+
return { ...result, state: 'up_to_date', installed: false };
|
|
177
|
+
}
|
|
178
|
+
let globalDirectory;
|
|
179
|
+
try {
|
|
180
|
+
const { stdout } = await npmImpl(['root', '--global'], { signal });
|
|
181
|
+
if (typeof stdout !== 'string' || stdout.length > 4096) {
|
|
182
|
+
throw Error('root');
|
|
183
|
+
}
|
|
184
|
+
globalDirectory = join(stdout.trim(), '@pulsarinteractive', 'geniustasker');
|
|
185
|
+
const installed = await lstat(globalDirectory);
|
|
186
|
+
if (
|
|
187
|
+
!installed.isDirectory() ||
|
|
188
|
+
installed.isSymbolicLink() ||
|
|
189
|
+
(await realpath(globalDirectory)) !== (await realpath(installedDirectory))
|
|
190
|
+
) {
|
|
191
|
+
throw Error('installation');
|
|
192
|
+
}
|
|
193
|
+
} catch {
|
|
194
|
+
fail('update_manual_required', 'This copy is not the active global npm installation.', {
|
|
195
|
+
remediation: `For a global installation, run ${result.updateCommand}. For npx or a project, update its pinned package version.`,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const release = await acquireInstallation(runtimeDirectory ?? runtimePath(installedDirectory));
|
|
199
|
+
try {
|
|
200
|
+
await npmImpl(
|
|
201
|
+
[
|
|
202
|
+
'install',
|
|
203
|
+
'--global',
|
|
204
|
+
`--registry=${registry}`,
|
|
205
|
+
`--@pulsarinteractive:registry=${registry}`,
|
|
206
|
+
'--ignore-scripts',
|
|
207
|
+
'--engine-strict',
|
|
208
|
+
`${packageName}@${result.availableVersion}`,
|
|
209
|
+
],
|
|
210
|
+
{ signal },
|
|
211
|
+
);
|
|
212
|
+
const manifest = JSON.parse(await readFile(join(globalDirectory, 'package.json'), 'utf8'));
|
|
213
|
+
if (manifest.name !== packageName || manifest.version !== result.availableVersion) {
|
|
214
|
+
throw Error('verification');
|
|
215
|
+
}
|
|
216
|
+
} catch {
|
|
217
|
+
fail('update_install_unconfirmed', 'The update could not be confirmed.', {
|
|
218
|
+
remediation: `Check the global installation before retrying. You can run ${result.updateCommand}. Your GeniusTasker connection and saved operations were not changed by the updater.`,
|
|
219
|
+
});
|
|
220
|
+
} finally {
|
|
221
|
+
await release();
|
|
222
|
+
}
|
|
223
|
+
return { ...result, state: 'installed', installed: true, restartMcp: true };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** One atomic attempt marker per installed version and UTC date, outside
|
|
227
|
+
* account storage. A killed checker consumes only today's attempt and cannot
|
|
228
|
+
* block tomorrow. Keep at most the recent marker window; no live lock stealing. */
|
|
229
|
+
export async function maybeNotifyUpdate({
|
|
230
|
+
command,
|
|
231
|
+
options = {},
|
|
232
|
+
isTTY,
|
|
233
|
+
stdout,
|
|
234
|
+
stderr,
|
|
235
|
+
env = process.env,
|
|
236
|
+
cacheDirectory = join(homedir(), '.cache', 'geniustasker', 'cli-updates'),
|
|
237
|
+
now = Date.now(),
|
|
238
|
+
currentVersion = metadata.version,
|
|
239
|
+
fetchImpl,
|
|
240
|
+
signal,
|
|
241
|
+
} = {}) {
|
|
242
|
+
if (
|
|
243
|
+
!isTTY ||
|
|
244
|
+
!stdout?.isTTY ||
|
|
245
|
+
!stderr?.isTTY ||
|
|
246
|
+
options.json ||
|
|
247
|
+
options.help ||
|
|
248
|
+
offlineCommands.has(command) ||
|
|
249
|
+
command.startsWith('update') ||
|
|
250
|
+
env.CI ||
|
|
251
|
+
env.GENIUSTASKER_NO_UPDATE_CHECK === '1' ||
|
|
252
|
+
signal?.aborted ||
|
|
253
|
+
!versionParts(currentVersion) ||
|
|
254
|
+
!Number.isSafeInteger(now) ||
|
|
255
|
+
now < 0
|
|
256
|
+
) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
await mkdir(cacheDirectory, { recursive: true, mode: 0o700 });
|
|
261
|
+
const directory = await lstat(cacheDirectory);
|
|
262
|
+
if (
|
|
263
|
+
!directory.isDirectory() ||
|
|
264
|
+
directory.isSymbolicLink() ||
|
|
265
|
+
(process.platform !== 'win32' && directory.mode & 0o077) ||
|
|
266
|
+
(process.getuid && directory.uid !== process.getuid())
|
|
267
|
+
) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const day = Math.floor(now / dayMs);
|
|
271
|
+
const entries = await opendir(cacheDirectory);
|
|
272
|
+
let scanned = 0;
|
|
273
|
+
for await (const entry of entries) {
|
|
274
|
+
// Only this updater's dated, ordinary files are reclaimed. Unexpected
|
|
275
|
+
// entries are left alone; a damaged cache cannot trigger an account read.
|
|
276
|
+
const match = /^attempt-(\d+)-([0-9]+\.[0-9]+\.[0-9]+(?:-beta\.[0-9]+)?)\.json$/.exec(
|
|
277
|
+
entry.name,
|
|
278
|
+
);
|
|
279
|
+
if (match && entry.isFile() && Number(match[1]) < day - 1) {
|
|
280
|
+
await unlink(join(cacheDirectory, entry.name)).catch(() => {});
|
|
281
|
+
}
|
|
282
|
+
if (++scanned >= 64) {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const path = join(cacheDirectory, `attempt-${day}-${currentVersion}.json`);
|
|
287
|
+
const attempt = await open(
|
|
288
|
+
path,
|
|
289
|
+
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL,
|
|
290
|
+
0o600,
|
|
291
|
+
);
|
|
292
|
+
try {
|
|
293
|
+
await attempt.writeFile(JSON.stringify({ installedVersion: currentVersion, checkedAt: now }));
|
|
294
|
+
} finally {
|
|
295
|
+
await attempt.close();
|
|
296
|
+
}
|
|
297
|
+
const result = await checkUpdate({ currentVersion, fetchImpl, signal, timeoutMs: 900 });
|
|
298
|
+
if (result.updateAvailable) {
|
|
299
|
+
stderr.write(
|
|
300
|
+
`GeniusTasker ${result.availableVersion} is available. Run geniustasker update install to update.\n`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
} catch {
|
|
304
|
+
// Optional discovery cannot change a command receipt or leak diagnostics.
|
|
305
|
+
}
|
|
306
|
+
}
|