@myrialabs/clopen 0.4.29 → 0.4.31
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/backend/chat/stream-manager.ts +1 -1
- package/backend/database/migrations/067_add_memory_graph_layout.ts +91 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/graph-queries.ts +417 -32
- package/backend/db-client/drivers/mssql.ts +57 -22
- package/backend/db-client/drivers/mysql.ts +69 -48
- package/backend/db-client/drivers/postgres.ts +65 -53
- package/backend/engine/adapters/claude/stream.ts +81 -15
- package/backend/engine/adapters/codex/stream.ts +6 -3
- package/backend/engine/adapters/opencode/server.ts +13 -4
- package/backend/engine/bootstrap-default-engine.ts +67 -38
- package/backend/engine/docs/artifacts.md +1 -1
- package/backend/engine/docs/quick-reference.md +1 -1
- package/backend/engine/engine-cli.ts +313 -0
- package/backend/engine/engine-setup.ts +40 -3
- package/backend/engine/install-recipes.test.ts +99 -5
- package/backend/engine/install-recipes.ts +47 -11
- package/backend/engine/install-runner.ts +34 -16
- package/backend/engine/stack-project.ts +72 -0
- package/backend/index.ts +5 -0
- package/backend/memory/bootstrap.ts +9 -0
- package/backend/memory/layout.ts +985 -0
- package/backend/memory/notify.ts +33 -7
- package/backend/memory/view.ts +375 -69
- package/backend/permissions/index.ts +4 -2
- package/backend/permissions/resolve.ts +7 -5
- package/backend/utils/path-enrich.ts +2 -0
- package/backend/utils/process-warnings.ts +41 -0
- package/backend/ws/engine/claude/accounts.ts +9 -4
- package/backend/ws/engine/codex/accounts.ts +8 -5
- package/backend/ws/engine/codex/status.ts +10 -17
- package/backend/ws/memory/crud.ts +50 -2
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/stack/access.ts +5 -2
- package/dist/assets/{index-C7e5TWG3.js → index-DUc5T21e.js} +1 -1
- package/dist/assets/{index-Derlqeyy.js → index-DYwQ5bP8.js} +1 -1
- package/dist/assets/main-VgdjTBLR.css +1 -0
- package/dist/assets/{main-OGhsRKU1.js → main-r0iv2PDz.js} +393 -386
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/memory.ts +70 -0
- package/dist/assets/main-CqzaPnux.css +0 -1
|
@@ -15,15 +15,24 @@
|
|
|
15
15
|
* `readEngineSdkVersion` compounds it: `loadEngineSdk` only enforces a version
|
|
16
16
|
* match when a required version exists, so an unpinned package also loses the
|
|
17
17
|
* "needs update" check that would otherwise surface the drift in Settings → Stack.
|
|
18
|
+
*
|
|
19
|
+
* Engine CLIs (engine-cli.ts) are pinned one step removed — through their SDK's
|
|
20
|
+
* version, since a platform binary has no business in devDependencies — and
|
|
21
|
+
* they only work if bun is allowed to run their postinstall. Both of those are
|
|
22
|
+
* silent failures too: an unpinned CLI floats to @latest, and an untrusted one
|
|
23
|
+
* installs a stub that fails at the first spawn.
|
|
18
24
|
*/
|
|
19
25
|
|
|
20
26
|
import { describe, expect, test } from 'bun:test';
|
|
21
|
-
import { readFileSync } from 'node:fs';
|
|
27
|
+
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
|
|
28
|
+
import { tmpdir } from 'node:os';
|
|
22
29
|
import { join } from 'node:path';
|
|
23
30
|
import type { EngineType } from '$shared/types/unified';
|
|
24
|
-
import { ENGINE_PACKAGES, type ToolId } from './install-recipes';
|
|
25
|
-
import { ENGINE_SDK } from './engine-setup';
|
|
31
|
+
import { ENGINE_PACKAGES, engineInstallArgs, type ToolId } from './install-recipes';
|
|
32
|
+
import { ENGINE_SDK, TOOL_FOR_ENGINE } from './engine-setup';
|
|
26
33
|
import { getRequiredSdkVersion } from './sdk-loader';
|
|
34
|
+
import { ENGINE_CLI, engineCliTrustedPackages, getRequiredCliVersion } from './engine-cli';
|
|
35
|
+
import { ensureStackProject } from './stack-project';
|
|
27
36
|
|
|
28
37
|
const pkg = JSON.parse(
|
|
29
38
|
readFileSync(join(import.meta.dir, '..', '..', 'package.json'), 'utf8')
|
|
@@ -71,7 +80,7 @@ describe('on-demand engine SDKs', () => {
|
|
|
71
80
|
// would probe a package nobody installs — reporting an installed engine as
|
|
72
81
|
// missing, or worse, waving through one that cannot load. TypeScript only
|
|
73
82
|
// forces the keys to exist; the values have to be checked.
|
|
74
|
-
const
|
|
83
|
+
const expectedToolForEngine: Record<EngineType, ToolId> = {
|
|
75
84
|
'claude-code': 'claude',
|
|
76
85
|
opencode: 'opencode',
|
|
77
86
|
copilot: 'copilot',
|
|
@@ -82,7 +91,11 @@ describe('on-demand engine SDKs', () => {
|
|
|
82
91
|
cursor: 'cursor',
|
|
83
92
|
};
|
|
84
93
|
|
|
85
|
-
|
|
94
|
+
// The mapping ships in engine-setup (readiness and status both resolve a
|
|
95
|
+
// tool id through it); this independent copy is what detects a silent edit.
|
|
96
|
+
expect(TOOL_FOR_ENGINE).toEqual(expectedToolForEngine);
|
|
97
|
+
|
|
98
|
+
const drift = Object.entries(expectedToolForEngine).flatMap(([engine, tool]) => {
|
|
86
99
|
const probed = ENGINE_SDK[engine as EngineType];
|
|
87
100
|
const installed = ENGINE_PACKAGES[tool]?.[0];
|
|
88
101
|
if (installed === undefined) return [`${engine}: no install recipe for tool "${tool}"`];
|
|
@@ -103,3 +116,84 @@ describe('on-demand engine SDKs', () => {
|
|
|
103
116
|
}
|
|
104
117
|
});
|
|
105
118
|
});
|
|
119
|
+
|
|
120
|
+
describe('on-demand engine CLIs', () => {
|
|
121
|
+
const cliEntries = Object.entries(ENGINE_CLI).map(([tool, spec]) => ({ tool: tool as ToolId, spec }));
|
|
122
|
+
|
|
123
|
+
test('the registry is non-empty', () => {
|
|
124
|
+
// Open Code is the one engine that needs a CLI; an emptied registry would
|
|
125
|
+
// make every check below vacuous and re-open the bug it exists to prevent.
|
|
126
|
+
expect(cliEntries.length).toBeGreaterThan(0);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('every CLI is pinned through a declared, exact SDK version', () => {
|
|
130
|
+
// A CLI is not in package.json (it is a platform binary weighing hundreds
|
|
131
|
+
// of megabytes), so its version rides on the SDK it ships with or is
|
|
132
|
+
// released in lockstep with. If that source is missing or floated, a
|
|
133
|
+
// separately-installed CLI lands at @latest against a pinned SDK.
|
|
134
|
+
const unpinned = cliEntries
|
|
135
|
+
.filter(({ spec }) => !/^\d+\.\d+\.\d+/.test(declared[spec.versionSource] ?? ''))
|
|
136
|
+
.map(({ tool, spec }) => `${tool}: pins via "${spec.versionSource}" (${declared[spec.versionSource]})`);
|
|
137
|
+
|
|
138
|
+
expect(unpinned).toEqual([]);
|
|
139
|
+
|
|
140
|
+
for (const { spec } of cliEntries) {
|
|
141
|
+
expect(getRequiredCliVersion(spec)).toBe(declared[spec.versionSource]!);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('the installer installs a separate CLI alongside the SDK', () => {
|
|
146
|
+
// Installing the SDK alone is exactly the half-install that reported
|
|
147
|
+
// "installed" in Settings → Stack and then failed at the first spawn.
|
|
148
|
+
// CLIs bundled with their SDK need no extra package and must not add one.
|
|
149
|
+
for (const { tool, spec } of cliEntries) {
|
|
150
|
+
const args = engineInstallArgs(tool);
|
|
151
|
+
if (spec.installPackage) {
|
|
152
|
+
expect(args).toContain(`${spec.installPackage}@${declared[spec.versionSource]}`);
|
|
153
|
+
} else {
|
|
154
|
+
expect(args).toEqual(ENGINE_PACKAGES[tool]!.map(name => `${name}@${declared[name]}`));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('only an engine-blocking CLI gates the install state', () => {
|
|
160
|
+
// `required` decides whether a missing binary makes Settings → Stack report
|
|
161
|
+
// the engine as not installed. Marking a bundled CLI required would flip a
|
|
162
|
+
// working engine to "not installed" the moment our own path guess drifts
|
|
163
|
+
// from the SDK's; leaving Open Code's optional would restore the original
|
|
164
|
+
// bug, where an unspawnable engine reported itself ready.
|
|
165
|
+
const required = cliEntries.filter(({ spec }) => spec.required).map(({ tool }) => tool);
|
|
166
|
+
expect(required).toEqual(['opencode']);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('the managed dir trusts every CLI postinstall', () => {
|
|
170
|
+
// bun blocks postinstall scripts for untrusted packages, and these CLIs
|
|
171
|
+
// ship a stub whose postinstall copies the real binary into place.
|
|
172
|
+
const dir = mkdtempSync(join(tmpdir(), 'clopen-stack-'));
|
|
173
|
+
ensureStackProject(dir);
|
|
174
|
+
|
|
175
|
+
const created = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as { trustedDependencies?: string[] };
|
|
176
|
+
expect(created.trustedDependencies).toEqual(engineCliTrustedPackages().sort());
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('an older managed dir is upgraded in place', () => {
|
|
180
|
+
// Machines bootstrapped by earlier builds already have a package.json
|
|
181
|
+
// without the field; merging (not just creating) is what repairs them.
|
|
182
|
+
const dir = mkdtempSync(join(tmpdir(), 'clopen-stack-'));
|
|
183
|
+
writeFileSync(
|
|
184
|
+
join(dir, 'package.json'),
|
|
185
|
+
JSON.stringify({ name: 'clopen-stack-engines', private: true, version: '0.0.0', dependencies: { '@opencode-ai/sdk': '1.18.18' } })
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
ensureStackProject(dir);
|
|
189
|
+
|
|
190
|
+
const merged = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as {
|
|
191
|
+
dependencies?: Record<string, string>;
|
|
192
|
+
trustedDependencies?: string[];
|
|
193
|
+
};
|
|
194
|
+
expect(merged.dependencies).toEqual({ '@opencode-ai/sdk': '1.18.18' });
|
|
195
|
+
for (const pkg of engineCliTrustedPackages()) {
|
|
196
|
+
expect(merged.trustedDependencies).toContain(pkg);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -20,6 +20,7 @@ import { getClopenDir } from '$backend/utils/paths';
|
|
|
20
20
|
import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
|
|
21
21
|
import { resolveStaticCurlAsset } from '$backend/utils/static-curl';
|
|
22
22
|
import { getStackEnginesDir, readEngineSdkVersion, getRequiredSdkVersion } from './sdk-loader';
|
|
23
|
+
import { engineCliInstallArg, getEngineCliSpec, getRequiredEngineCliSpec, resolveEngineCli } from './engine-cli';
|
|
23
24
|
|
|
24
25
|
export type ToolId = 'git' | 'claude' | 'opencode' | 'copilot' | 'codex' | 'qwen' | 'pi' | 'cline' | 'cursor' | 'chrome';
|
|
25
26
|
|
|
@@ -123,13 +124,23 @@ function isEngineTool(tool: ToolId): boolean {
|
|
|
123
124
|
return tool in ENGINE_PACKAGES;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
/**
|
|
127
|
-
|
|
127
|
+
/**
|
|
128
|
+
* `bun add` arg vector for an engine: each package pinned to its package.json
|
|
129
|
+
* version, plus the engine's CLI package when it needs one (see engine-cli.ts).
|
|
130
|
+
* The CLI is pinned through its SDK's version instead of a package.json entry
|
|
131
|
+
* of its own — it is a platform binary, not something to put in devDependencies.
|
|
132
|
+
*/
|
|
133
|
+
export function engineInstallArgs(tool: ToolId): string[] {
|
|
128
134
|
const packages = ENGINE_PACKAGES[tool] ?? [];
|
|
129
|
-
|
|
135
|
+
const args = packages.map(name => {
|
|
130
136
|
const v = getRequiredSdkVersion(name);
|
|
131
137
|
return v ? `${name}@${v}` : name;
|
|
132
138
|
});
|
|
139
|
+
|
|
140
|
+
const cli = getEngineCliSpec(tool);
|
|
141
|
+
const cliArg = cli ? engineCliInstallArg(cli) : null;
|
|
142
|
+
if (cliArg) args.push(cliArg);
|
|
143
|
+
return args;
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
|
|
@@ -269,14 +280,38 @@ export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
|
|
|
269
280
|
|
|
270
281
|
if (isEngineTool(tool)) {
|
|
271
282
|
// Engines are detected by the presence of their SDK in the clopen-managed
|
|
272
|
-
// stack dir (installed on demand there)
|
|
273
|
-
// SDK is what the engine adapter actually needs.
|
|
283
|
+
// stack dir (installed on demand there) — that is what the adapter loads.
|
|
274
284
|
const sdkPkg = ENGINE_PACKAGES[tool]![0];
|
|
275
|
-
const
|
|
285
|
+
const sdkVersion = readEngineSdkVersion(sdkPkg);
|
|
276
286
|
const requiredVersion = getRequiredSdkVersion(sdkPkg);
|
|
277
|
-
if (!
|
|
278
|
-
const
|
|
279
|
-
|
|
287
|
+
if (!sdkVersion) return { tool, installed: false, version: null, source: null, requiredVersion, needsUpdate: false };
|
|
288
|
+
const sdkNeedsUpdate = requiredVersion !== null && sdkVersion !== requiredVersion;
|
|
289
|
+
|
|
290
|
+
// Only a CLI the engine cannot run without gates its install state; a CLI
|
|
291
|
+
// the SDK bundles and locates itself arrives with the engine anyway.
|
|
292
|
+
const cliSpec = getRequiredEngineCliSpec(tool);
|
|
293
|
+
if (!cliSpec) {
|
|
294
|
+
return { tool, installed: true, version: sdkVersion, source: getStackEnginesDir(), requiredVersion, needsUpdate: sdkNeedsUpdate };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Engines that cannot run without an external CLI (Open Code) count as
|
|
298
|
+
// installed only when a runnable binary exists. Reporting the SDK alone is
|
|
299
|
+
// what let Stack show "installed" for an engine nothing could spawn.
|
|
300
|
+
const cli = await resolveEngineCli(tool);
|
|
301
|
+
if (!cli) return { tool, installed: false, version: null, source: null, requiredVersion, needsUpdate: false };
|
|
302
|
+
|
|
303
|
+
// The CLI is the artifact that actually runs, so it decides the reported
|
|
304
|
+
// version — a user's own older copy on PATH surfaces as "needs update"
|
|
305
|
+
// instead of hiding behind the pinned SDK version.
|
|
306
|
+
const cliNeedsUpdate = requiredVersion !== null && cli.version !== null && cli.version !== requiredVersion;
|
|
307
|
+
return {
|
|
308
|
+
tool,
|
|
309
|
+
installed: true,
|
|
310
|
+
version: cli.version ?? sdkVersion,
|
|
311
|
+
source: cli.path,
|
|
312
|
+
requiredVersion,
|
|
313
|
+
needsUpdate: sdkNeedsUpdate || cliNeedsUpdate
|
|
314
|
+
};
|
|
280
315
|
}
|
|
281
316
|
|
|
282
317
|
const resolved = await resolveBinaryWithRefresh(tool);
|
|
@@ -421,8 +456,9 @@ function attachCurlRequirement(base: Recipe, toolLabel: string): boolean {
|
|
|
421
456
|
* Engine install recipe — installs the exact engine SDK package(s) declared in
|
|
422
457
|
* package.json (the single source of truth) into the clopen-managed stack dir
|
|
423
458
|
* (`~/.clopen/stack/engines`), NOT the user's global bun store. Installing the
|
|
424
|
-
* SDK also pulls whatever CLI binary the SDK bundles
|
|
425
|
-
*
|
|
459
|
+
* SDK also pulls whatever CLI binary the SDK bundles, plus — for engines whose
|
|
460
|
+
* SDK bundles none (Open Code) — the separate package that carries the CLI.
|
|
461
|
+
* Versions are pinned, never floated to `latest`.
|
|
426
462
|
*/
|
|
427
463
|
function resolveEngineRecipe(tool: ToolId): Recipe {
|
|
428
464
|
const args = engineInstallArgs(tool);
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { freemem, totalmem } from 'node:os';
|
|
21
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
22
|
-
import { join } from 'node:path';
|
|
23
21
|
import { debug } from '$shared/utils/logger';
|
|
24
22
|
import { ws } from '$backend/utils/ws';
|
|
25
23
|
import { getCleanSpawnEnv } from '$backend/utils/env';
|
|
@@ -27,26 +25,21 @@ import { refreshProcessPath } from '$backend/utils/path-enrich';
|
|
|
27
25
|
import { ensureCurlAvailable } from '$backend/utils/static-curl';
|
|
28
26
|
import type { Recipe, ToolId } from './install-recipes';
|
|
29
27
|
import { resolveRecipe } from './install-recipes';
|
|
28
|
+
import { ensureStackProject } from './stack-project';
|
|
29
|
+
import { invalidateEngineCliCache } from './engine-cli';
|
|
30
30
|
|
|
31
31
|
const RING_BUFFER_LINES = 10_000;
|
|
32
32
|
const RETENTION_MS = 5 * 60 * 1000;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Ensure a recipe's working directory
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
* Ensure a recipe's working directory is ready before `bun add` runs there.
|
|
36
|
+
* Engine recipes install into the clopen-managed stack dir
|
|
37
|
+
* (`~/.clopen/stack/engines`), whose package.json both roots the install and
|
|
38
|
+
* carries the `trustedDependencies` that let engine CLI postinstalls run.
|
|
39
39
|
*/
|
|
40
40
|
function ensureRecipeCwd(recipe: Recipe): void {
|
|
41
41
|
if (!recipe.cwd) return;
|
|
42
|
-
|
|
43
|
-
const pkgJsonPath = join(recipe.cwd, 'package.json');
|
|
44
|
-
if (!existsSync(pkgJsonPath)) {
|
|
45
|
-
writeFileSync(
|
|
46
|
-
pkgJsonPath,
|
|
47
|
-
JSON.stringify({ name: 'clopen-stack-engines', private: true, version: '0.0.0' }, null, 2) + '\n'
|
|
48
|
-
);
|
|
49
|
-
}
|
|
42
|
+
ensureStackProject(recipe.cwd);
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
export type SessionStatus = 'running' | 'success' | 'failed' | 'cancelled';
|
|
@@ -74,6 +67,8 @@ interface Session {
|
|
|
74
67
|
|
|
75
68
|
const sessions = new Map<string, Session>();
|
|
76
69
|
const activeByTool = new Map<ToolId, string>();
|
|
70
|
+
/** Run promise per session, so callers can await an install they didn't start. */
|
|
71
|
+
const runs = new Map<string, Promise<void>>();
|
|
77
72
|
|
|
78
73
|
function newRingBuffer(): RingBuffer {
|
|
79
74
|
return { lines: [], total: 0 };
|
|
@@ -91,6 +86,7 @@ function scheduleRetention(session: Session): void {
|
|
|
91
86
|
if (session.retentionTimer) clearTimeout(session.retentionTimer);
|
|
92
87
|
session.retentionTimer = setTimeout(() => {
|
|
93
88
|
sessions.delete(session.id);
|
|
89
|
+
runs.delete(session.id);
|
|
94
90
|
if (activeByTool.get(session.tool) === session.id) {
|
|
95
91
|
activeByTool.delete(session.tool);
|
|
96
92
|
}
|
|
@@ -189,6 +185,11 @@ function finalizeSession(session: Session, preferredStatus: SessionStatus, exitC
|
|
|
189
185
|
session.endedAt = Date.now();
|
|
190
186
|
session.proc = null;
|
|
191
187
|
|
|
188
|
+
// An install can replace the binary a previous resolution cached (a user's
|
|
189
|
+
// own older copy on PATH, or a stub swapped for the real thing at the same
|
|
190
|
+
// path), so the next lookup must probe again rather than trust the cache.
|
|
191
|
+
invalidateEngineCliCache(session.tool);
|
|
192
|
+
|
|
192
193
|
debug.log('path', `[install:${session.id}] Finished status=${session.status} exit=${exitCode}`);
|
|
193
194
|
|
|
194
195
|
ws.emit.user(session.startedBy, 'stack:install-finished', {
|
|
@@ -307,6 +308,14 @@ async function runInstall(session: Session, env: Record<string, string>): Promis
|
|
|
307
308
|
finalizeSession(session, exitCode === 0 ? 'success' : 'failed', exitCode);
|
|
308
309
|
}
|
|
309
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Owner id for installs clopen starts itself (startup repair), rather than a
|
|
313
|
+
* user clicking Install. Sessions carry an owner so one admin cannot drive
|
|
314
|
+
* another's install; system-owned sessions are readable by any admin instead
|
|
315
|
+
* (see `requireInstallSessionAccess`) so the repair is visible and cancellable.
|
|
316
|
+
*/
|
|
317
|
+
export const SYSTEM_INSTALL_USER = 'system';
|
|
318
|
+
|
|
310
319
|
export async function startInstall(tool: ToolId, userId: string): Promise<Session> {
|
|
311
320
|
await refreshProcessPath();
|
|
312
321
|
|
|
@@ -356,15 +365,24 @@ export async function startInstall(tool: ToolId, userId: string): Promise<Sessio
|
|
|
356
365
|
startedAt: session.startedAt
|
|
357
366
|
});
|
|
358
367
|
|
|
359
|
-
runInstall(session, env).catch((err) => {
|
|
368
|
+
runs.set(id, runInstall(session, env).catch((err) => {
|
|
360
369
|
debug.error('path', `[install:${id}] runner crash:`, err);
|
|
361
370
|
emitStream(session, 'stderr', `runner crash: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
362
371
|
finalizeSession(session, 'failed', -1);
|
|
363
|
-
});
|
|
372
|
+
}));
|
|
364
373
|
|
|
365
374
|
return session;
|
|
366
375
|
}
|
|
367
376
|
|
|
377
|
+
/**
|
|
378
|
+
* Resolve once the install has finished (success, failure or cancellation).
|
|
379
|
+
* Resolves immediately for an unknown or already-collected session, so callers
|
|
380
|
+
* can await without racing session retention.
|
|
381
|
+
*/
|
|
382
|
+
export function awaitInstall(sessionId: string): Promise<void> {
|
|
383
|
+
return runs.get(sessionId) ?? Promise.resolve();
|
|
384
|
+
}
|
|
385
|
+
|
|
368
386
|
export function cancelInstall(sessionId: string): boolean {
|
|
369
387
|
const session = sessions.get(sessionId);
|
|
370
388
|
if (!session || session.status !== 'running') return false;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Managed stack project bootstrap
|
|
3
|
+
*
|
|
4
|
+
* `~/.clopen/stack/engines` is a minimal bun project. A package.json must exist
|
|
5
|
+
* there before `bun add` runs, or bun walks up the tree and installs into
|
|
6
|
+
* whatever project happens to contain the directory.
|
|
7
|
+
*
|
|
8
|
+
* It must also declare `trustedDependencies`. bun blocks postinstall scripts
|
|
9
|
+
* for untrusted packages, and an engine CLI package ships only a stub — its
|
|
10
|
+
* real binary is copied into place by exactly that postinstall. Without the
|
|
11
|
+
* entry the install still reports success and leaves behind a shell script that
|
|
12
|
+
* prints "postinstall script was not run", which is precisely the half-installed
|
|
13
|
+
* state that used to reach the adapter.
|
|
14
|
+
*
|
|
15
|
+
* Both install paths (the user-triggered runner and the startup bootstrap) go
|
|
16
|
+
* through here, and the file is MERGED rather than only created, so a stack dir
|
|
17
|
+
* written by an older clopen picks the field up on its next install.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { debug } from '$shared/utils/logger';
|
|
23
|
+
import { engineCliTrustedPackages } from './engine-cli';
|
|
24
|
+
|
|
25
|
+
interface StackPackageJson {
|
|
26
|
+
name?: string;
|
|
27
|
+
private?: boolean;
|
|
28
|
+
version?: string;
|
|
29
|
+
trustedDependencies?: string[];
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const BASE: StackPackageJson = {
|
|
34
|
+
name: 'clopen-stack-engines',
|
|
35
|
+
private: true,
|
|
36
|
+
version: '0.0.0'
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function readExisting(path: string): StackPackageJson | null {
|
|
40
|
+
if (!existsSync(path)) return null;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8')) as unknown;
|
|
43
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
44
|
+
return parsed as StackPackageJson;
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// Corrupt file: fall through and rewrite from the base template rather
|
|
48
|
+
// than leaving a package.json bun will choke on.
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Ensure `dir` is a bun project that trusts every engine CLI package. Safe to
|
|
55
|
+
* call repeatedly; writes only when the file is missing or would change.
|
|
56
|
+
*/
|
|
57
|
+
export function ensureStackProject(dir: string): void {
|
|
58
|
+
mkdirSync(dir, { recursive: true });
|
|
59
|
+
const path = join(dir, 'package.json');
|
|
60
|
+
|
|
61
|
+
const existing = readExisting(path);
|
|
62
|
+
const merged: StackPackageJson = { ...BASE, ...(existing ?? {}) };
|
|
63
|
+
|
|
64
|
+
const trusted = new Set([...(merged.trustedDependencies ?? []), ...engineCliTrustedPackages()]);
|
|
65
|
+
merged.trustedDependencies = [...trusted].sort();
|
|
66
|
+
|
|
67
|
+
const next = JSON.stringify(merged, null, 2) + '\n';
|
|
68
|
+
if (existing !== null && readFileSync(path, 'utf8') === next) return;
|
|
69
|
+
|
|
70
|
+
writeFileSync(path, next);
|
|
71
|
+
debug.log('engine', `Stack project package.json ${existing ? 'updated' : 'created'}: ${path}`);
|
|
72
|
+
}
|
package/backend/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { bootstrapAfterDbInit } from './bootstrap';
|
|
|
27
27
|
import { disposeAllEngines } from './engine';
|
|
28
28
|
import { connectionManager } from './db-client/connection-manager';
|
|
29
29
|
import { refreshProcessPath } from './utils/path-enrich';
|
|
30
|
+
import { installProcessWarningFilter } from './utils/process-warnings';
|
|
30
31
|
import { debug } from '$shared/utils/logger';
|
|
31
32
|
import { networkInterfaces } from 'os';
|
|
32
33
|
import { resolve } from 'node:path';
|
|
@@ -381,6 +382,10 @@ globalThis.addEventListener('unhandledrejection', (event: PromiseRejectionEvent)
|
|
|
381
382
|
reportUnhandledRejection(event.reason);
|
|
382
383
|
});
|
|
383
384
|
|
|
385
|
+
// Owns every `process.emitWarning` line in the server log (see the module for
|
|
386
|
+
// why registering a listener means we must re-print what we keep).
|
|
387
|
+
installProcessWarningFilter();
|
|
388
|
+
|
|
384
389
|
process.on('uncaughtException', (error) => {
|
|
385
390
|
try {
|
|
386
391
|
debug.error('server', 'Uncaught exception (server still running):', error);
|
|
@@ -20,6 +20,7 @@ import { notifyMemoryReadiness } from './notify';
|
|
|
20
20
|
import { resetGraphEmptiness } from './context';
|
|
21
21
|
import { reconcileVectorIndex } from './indexer';
|
|
22
22
|
import { startMemoryMaintenance } from './maintenance';
|
|
23
|
+
import { resetGraphLayoutState, scheduleGraphLayout } from './layout';
|
|
23
24
|
import { ensureMemoryModel } from './model';
|
|
24
25
|
import { startExtractionRunner } from './extract';
|
|
25
26
|
|
|
@@ -42,6 +43,14 @@ export function bootstrapMemoryGraph(): void {
|
|
|
42
43
|
vectorCache.reset();
|
|
43
44
|
resetGraphEmptiness();
|
|
44
45
|
|
|
46
|
+
// Same reason as the caches above: "Clear All Data" wipes the database under a
|
|
47
|
+
// live process, so what the last pass laid out describes rows that no longer
|
|
48
|
+
// exist. Scheduling one here is also what places an EXISTING graph the first
|
|
49
|
+
// time the upgrade runs — until it lands the view falls back to the flat
|
|
50
|
+
// listing it always used, so nothing is missing meanwhile.
|
|
51
|
+
resetGraphLayoutState();
|
|
52
|
+
scheduleGraphLayout();
|
|
53
|
+
|
|
45
54
|
// Duplicate collapse and retention are pure SQL and are worth running whether
|
|
46
55
|
// or not the artifact ever lands, so maintenance starts independently of the
|
|
47
56
|
// download. Its own first tick is minutes away, well clear of startup.
|