@pulsarinteractive/geniustasker 0.1.0-beta.10 → 0.1.0-beta.12
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 +24 -0
- package/README.md +7 -1
- package/docs/ARCHITECTURE.md +15 -13
- package/docs/CLI.md +109 -1
- package/docs/INTEGRATIONS.md +2 -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 +112 -1
- package/remote/workflows.json +33 -2
- package/skills/geniustasker/SKILL.md +5 -0
- 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/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 +15 -5
- package/skills/geniustasker-memory/references/knowledge-workflows.md +42 -0
- package/skills/geniustasker-planning/SKILL.md +6 -1
- package/src/cli.mjs +70 -5
- package/src/client.mjs +7 -0
- package/src/command-catalog.mjs +753 -562
- package/src/command-input-schemas.d.mts +8 -0
- package/src/command-input-schemas.mjs +470 -0
- package/src/commands.mjs +70 -25
- package/src/mcp.mjs +31 -3
- package/src/protocols.mjs +122 -0
- package/src/recovery.mjs +80 -0
- package/src/run-events.mjs +145 -0
- package/src/transport.mjs +20 -4
- package/src/update-runtime.mjs +169 -0
- package/src/update.mjs +306 -0
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
|
+
}
|