@tinchu0/knitt 0.1.0-beta.5 → 0.1.0-beta.6
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/README.md +25 -27
- package/dist/apps/server/src/cloud-picker.js +245 -0
- package/dist/apps/server/src/onboarding.js +266 -0
- package/dist/apps/server/src/plugin-bootstrap.js +82 -0
- package/dist/apps/server/src/plugin-hook.js +51 -0
- package/dist/apps/server/src/plugin-main.js +10 -0
- package/dist/apps/server/src/server.js +126 -258
- package/dist/packages/adapters/src/cli.js +59 -190
- package/dist/packages/adapters/src/command.js +18 -149
- package/dist/packages/adapters/src/handoff.js +2 -3
- package/dist/packages/adapters/src/histories.js +2 -3
- package/dist/packages/adapters/src/hooks.js +43 -122
- package/dist/packages/adapters/src/launch.js +3 -10
- package/dist/packages/adapters/src/question-ui.js +4 -4
- package/dist/packages/adapters/src/repository.js +5 -32
- package/dist/packages/adapters/src/scope.js +1 -1
- package/dist/packages/adapters/src/server-name.js +1 -2
- package/dist/packages/adapters/src/transcript.js +15 -70
- package/dist/packages/cloud/src/client.js +40 -0
- package/dist/packages/cloud/src/local-sync.js +300 -0
- package/dist/packages/installer/src/antigravity.js +3 -3
- package/dist/packages/installer/src/cli.js +79 -194
- package/dist/packages/installer/src/cloud-cli.js +199 -0
- package/dist/packages/installer/src/connections.js +43 -170
- package/dist/packages/installer/src/runtime.js +10 -72
- package/dist/packages/memory/src/store.js +58 -200
- package/dist/skills/knit/SKILL.md +20 -4
- package/docs/clients/npm-installation.md +17 -13
- package/docs/usage.md +19 -10
- package/package.json +9 -7
- package/dist/apps/server/src/conversation-server.js +0 -203
- package/dist/memory-schema.json +0 -1
- package/dist/packages/adapters/src/discovery.js +0 -128
- package/dist/packages/adapters/src/providers/jsonl.js +0 -105
- package/dist/packages/adapters/src/status.js +0 -81
- package/dist/packages/contracts/src/conversations.js +0 -30
- package/dist/packages/memory/src/checkpoints.js +0 -68
- package/dist/packages/memory/src/context.js +0 -91
- package/dist/packages/memory/src/conversations.js +0 -148
- package/dist/packages/memory/src/migrations.js +0 -55
- package/dist/skills/continue-chat/SKILL.md +0 -15
- package/docs/clients/local-agent-memory.md +0 -50
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { antigravityServerName } from '../../adapters/src/server-name.js';
|
|
2
2
|
import { hookCommand, isManagedHook } from './platform.js';
|
|
3
|
-
import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync, realpathSync
|
|
3
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { join, dirname, resolve } from 'node:path';
|
|
5
5
|
import { execFileSync } from 'node:child_process';
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { parse as parseToml } from 'smol-toml';
|
|
8
|
-
export const clients = [
|
|
9
|
-
'codex',
|
|
10
|
-
'claude-code',
|
|
11
|
-
'antigravity',
|
|
12
|
-
'claude-desktop',
|
|
13
|
-
];
|
|
8
|
+
export const clients = ['codex', 'claude-code', 'antigravity', 'claude-desktop'];
|
|
14
9
|
const begin = '# BEGIN shared-agent-memory', end = '# END shared-agent-memory';
|
|
15
10
|
const statePath = '.memory/npm-connection.json';
|
|
16
11
|
const read = (path) => existsSync(path) ? readFileSync(path, 'utf8') : null;
|
|
@@ -33,19 +28,11 @@ export function atomicWrite(path, content) {
|
|
|
33
28
|
function restore(before, after, current) {
|
|
34
29
|
if (equal(current, after))
|
|
35
30
|
return before;
|
|
36
|
-
if (object(after) &&
|
|
37
|
-
object(current) &&
|
|
38
|
-
typeof after.command === 'string' &&
|
|
39
|
-
Array.isArray(after.args))
|
|
31
|
+
if (object(after) && object(current) && typeof after.command === 'string' && Array.isArray(after.args))
|
|
40
32
|
return current;
|
|
41
|
-
if (object(after) &&
|
|
42
|
-
object(current) &&
|
|
43
|
-
(before === undefined || object(before))) {
|
|
33
|
+
if (object(after) && object(current) && (before === undefined || object(before))) {
|
|
44
34
|
const result = { ...current };
|
|
45
|
-
for (const key of new Set([
|
|
46
|
-
...Object.keys(before ?? {}),
|
|
47
|
-
...Object.keys(after),
|
|
48
|
-
])) {
|
|
35
|
+
for (const key of new Set([...Object.keys(before ?? {}), ...Object.keys(after)])) {
|
|
49
36
|
if (equal(before?.[key], after[key]))
|
|
50
37
|
continue;
|
|
51
38
|
const value = restore(before?.[key], after[key], current[key]);
|
|
@@ -54,18 +41,14 @@ function restore(before, after, current) {
|
|
|
54
41
|
else
|
|
55
42
|
result[key] = value;
|
|
56
43
|
}
|
|
57
|
-
return Object.keys(result).length === 0 && before === undefined
|
|
58
|
-
? undefined
|
|
59
|
-
: result;
|
|
44
|
+
return Object.keys(result).length === 0 && before === undefined ? undefined : result;
|
|
60
45
|
}
|
|
61
|
-
if (Array.isArray(after) &&
|
|
62
|
-
Array.isArray(current) &&
|
|
63
|
-
(before === undefined || Array.isArray(before))) {
|
|
46
|
+
if (Array.isArray(after) && Array.isArray(current) && (before === undefined || Array.isArray(before))) {
|
|
64
47
|
const previous = before ?? [];
|
|
65
|
-
const added = after.filter(
|
|
66
|
-
const result = current.filter(
|
|
48
|
+
const added = after.filter(v => !previous.some((p) => equal(p, v)));
|
|
49
|
+
const result = current.filter(v => !added.some(a => equal(a, v)));
|
|
67
50
|
for (const v of previous)
|
|
68
|
-
if (!after.some(
|
|
51
|
+
if (!after.some(a => equal(a, v)) && !result.some(a => equal(a, v)))
|
|
69
52
|
result.push(v);
|
|
70
53
|
return result.length === 0 && before === undefined ? undefined : result;
|
|
71
54
|
}
|
|
@@ -79,112 +62,48 @@ export function readConnectionState(workspace) {
|
|
|
79
62
|
if (value.schema !== 1 || !object(value.files))
|
|
80
63
|
throw new Error('Unsupported connector state');
|
|
81
64
|
for (const [file, snapshot] of Object.entries(value.files)) {
|
|
82
|
-
if (![
|
|
83
|
-
'.
|
|
84
|
-
'.codex/config.toml',
|
|
85
|
-
'.codex/hooks.json',
|
|
86
|
-
'.agents/hooks.json',
|
|
87
|
-
'.agents/mcp_config.json',
|
|
88
|
-
'.agents/skills/continue-chat/SKILL.md',
|
|
89
|
-
'.agents/skills/knit/SKILL.md',
|
|
90
|
-
'.claude/settings.local.json',
|
|
91
|
-
'.claude/skills/continue-chat/SKILL.md',
|
|
92
|
-
'.claude/skills/knit/SKILL.md',
|
|
93
|
-
'.memory/connectors/claude-desktop.json',
|
|
94
|
-
'.memory/connectors/antigravity.json',
|
|
95
|
-
].includes(file) ||
|
|
96
|
-
!object(snapshot) ||
|
|
97
|
-
typeof snapshot.after !== 'string' ||
|
|
98
|
-
!(snapshot.before === null || typeof snapshot.before === 'string'))
|
|
65
|
+
if (!['.mcp.json', '.codex/config.toml', '.codex/hooks.json', '.agents/hooks.json', '.agents/mcp_config.json', '.agents/skills/continue-chat/SKILL.md', '.agents/skills/knit/SKILL.md', '.claude/settings.local.json', '.claude/skills/continue-chat/SKILL.md', '.claude/skills/knit/SKILL.md', '.memory/connectors/claude-desktop.json', '.memory/connectors/antigravity.json'].includes(file)
|
|
66
|
+
|| !object(snapshot) || typeof snapshot.after !== 'string' || !(snapshot.before === null || typeof snapshot.before === 'string'))
|
|
99
67
|
throw new Error('Invalid connector state');
|
|
100
68
|
}
|
|
101
69
|
return value;
|
|
102
70
|
}
|
|
103
71
|
export function planConnection(opts) {
|
|
104
|
-
const workspace = realpathSync
|
|
105
|
-
if (!opts.clients.length ||
|
|
106
|
-
opts.clients.some((c) => !clients.includes(c)))
|
|
72
|
+
const workspace = realpathSync(opts.workspace), app = resolve(opts.appRoot), node = opts.node ?? process.execPath;
|
|
73
|
+
if (!opts.clients.length || opts.clients.some(c => !clients.includes(c)))
|
|
107
74
|
throw new Error('Choose a supported client');
|
|
108
|
-
const extension = existsSync(join(app, 'apps/server/src/main.js'))
|
|
109
|
-
? 'js'
|
|
110
|
-
: 'ts';
|
|
75
|
+
const extension = existsSync(join(app, 'apps/server/src/main.js')) ? 'js' : 'ts';
|
|
111
76
|
const server = join(app, 'apps/server/src/main.' + extension), runner = join(app, 'packages/adapters/src/cli.' + extension);
|
|
112
77
|
if (!existsSync(server) || !existsSync(runner))
|
|
113
78
|
throw new Error('Runtime files missing');
|
|
114
79
|
const state = readConnectionState(workspace), changes = {}, expected = {};
|
|
115
|
-
const get = (path) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
if (!object(v))
|
|
123
|
-
throw new Error(path + ' must be an object');
|
|
124
|
-
return v;
|
|
125
|
-
};
|
|
126
|
-
const env = {
|
|
127
|
-
MEMORY_DB: resolve(opts.database),
|
|
128
|
-
MEMORY_REPO: opts.repoId,
|
|
129
|
-
MEMORY_WORKSPACE: workspace,
|
|
130
|
-
MEMORY_SESSION_SELECTION: '1',
|
|
131
|
-
...(opts.captureNewSessions
|
|
132
|
-
? { MEMORY_CONVERSATION_MODE: '1', MEMORY_CAPTURE_NEW_SESSIONS: '1' }
|
|
133
|
-
: {}),
|
|
134
|
-
};
|
|
135
|
-
const handler = (client, action) => ({
|
|
136
|
-
type: 'command',
|
|
137
|
-
timeout: 10,
|
|
138
|
-
command: hookCommand({
|
|
139
|
-
...env,
|
|
140
|
-
...(client === 'antigravity'
|
|
141
|
-
? { MEMORY_MCP_SERVER: antigravityServerName(workspace) }
|
|
142
|
-
: {}),
|
|
143
|
-
MEMORY_QUEUE: join(dirname(opts.database), 'queue', client),
|
|
144
|
-
MEMORY_MANAGED: 'shared-agent-memory',
|
|
145
|
-
}, node, [runner, action, client]),
|
|
146
|
-
});
|
|
147
|
-
const connection = (desktop = false, client = 'claude') => {
|
|
148
|
-
const clientEnv = {
|
|
149
|
-
...env,
|
|
150
|
-
MEMORY_CLIENT: client,
|
|
151
|
-
...(client === 'antigravity' && !opts.captureNewSessions ? { MEMORY_PICKER_MODE: 'native_question' } : {}),
|
|
152
|
-
...(desktop ? { MEMORY_CHAT_CLIENT: 'claude-desktop' } : {}),
|
|
153
|
-
...(!desktop && opts.captureNewSessions ? { MEMORY_CLIENT: client } : {}),
|
|
154
|
-
};
|
|
155
|
-
if (desktop) {
|
|
156
|
-
delete clientEnv.MEMORY_CONVERSATION_MODE;
|
|
157
|
-
delete clientEnv.MEMORY_CAPTURE_NEW_SESSIONS;
|
|
158
|
-
}
|
|
159
|
-
return { command: node, args: [server], env: clientEnv };
|
|
160
|
-
};
|
|
80
|
+
const get = (path) => { const content = read(join(workspace, path)); expected[path] = content; return content; };
|
|
81
|
+
const json = (path) => { const v = JSON.parse(get(path) ?? '{}'); if (!object(v))
|
|
82
|
+
throw new Error(path + ' must be an object'); return v; };
|
|
83
|
+
const env = { MEMORY_DB: resolve(opts.database), MEMORY_REPO: opts.repoId, MEMORY_WORKSPACE: workspace, MEMORY_SESSION_SELECTION: '1',
|
|
84
|
+
...(opts.installationHome ? { SHARED_MEMORY_HOME: resolve(opts.installationHome), KNITT_HOME: resolve(opts.installationHome) } : {}) };
|
|
85
|
+
const handler = (client, action) => ({ type: 'command', timeout: 10, command: hookCommand({ ...env, ...(client === 'antigravity' ? { MEMORY_MCP_SERVER: antigravityServerName(workspace) } : {}), MEMORY_QUEUE: join(dirname(opts.database), 'queue', client), MEMORY_MANAGED: 'shared-agent-memory' }, node, [runner, action, client]) });
|
|
86
|
+
const connection = (desktop = false, chat = false) => ({ command: node, args: [server], env: { ...env, MEMORY_CLIENT: chat ? 'antigravity' : 'claude', ...(chat ? { MEMORY_PICKER_MODE: 'native_question' } : {}), ...(desktop ? { MEMORY_CHAT_CLIENT: 'claude-desktop' } : {}) } });
|
|
161
87
|
function owned(path, location, current) {
|
|
162
88
|
if (current === undefined)
|
|
163
89
|
return;
|
|
164
90
|
const prior = state.files[path];
|
|
165
|
-
const previous = prior
|
|
166
|
-
? location.reduce((v, key) => v?.[key], JSON.parse(prior.after))
|
|
167
|
-
: undefined;
|
|
91
|
+
const previous = prior ? location.reduce((v, key) => v?.[key], JSON.parse(prior.after)) : undefined;
|
|
168
92
|
if (!equal(current, previous))
|
|
169
93
|
throw new Error('Unmanaged or modified connector conflict in ' + path);
|
|
170
94
|
}
|
|
171
|
-
function mcp(path, desktop = false,
|
|
95
|
+
function mcp(path, desktop = false, chat = false) {
|
|
172
96
|
const value = json(path);
|
|
173
97
|
value.mcpServers ??= {};
|
|
174
98
|
owned(path, ['mcpServers', 'shared-memory'], value.mcpServers['shared-memory']);
|
|
175
|
-
value.mcpServers['shared-memory'] = connection(desktop,
|
|
99
|
+
value.mcpServers['shared-memory'] = connection(desktop, chat);
|
|
176
100
|
changes[path] = dump(value);
|
|
177
101
|
}
|
|
178
102
|
function hooks(path, client) {
|
|
179
103
|
const value = json(path);
|
|
180
104
|
value.hooks ??= {};
|
|
181
|
-
const prior = state.files[path]
|
|
182
|
-
|
|
183
|
-
: {};
|
|
184
|
-
for (const [event, action] of [
|
|
185
|
-
['SessionStart', 'recall'],
|
|
186
|
-
['Stop', 'capture'],
|
|
187
|
-
]) {
|
|
105
|
+
const prior = state.files[path] ? JSON.parse(state.files[path].after).hooks : {};
|
|
106
|
+
for (const [event, action] of [['SessionStart', 'recall'], ['Stop', 'capture']]) {
|
|
188
107
|
const old = prior?.[event] ?? [];
|
|
189
108
|
const groups = value.hooks[event] ?? [];
|
|
190
109
|
if (!Array.isArray(groups))
|
|
@@ -203,35 +122,26 @@ export function planConnection(opts) {
|
|
|
203
122
|
const current = get(path);
|
|
204
123
|
if (current && current !== state.files[path]?.after)
|
|
205
124
|
throw new Error('Unmanaged or modified skill conflict');
|
|
206
|
-
changes[path] = readFileSync(join(app, 'skills
|
|
207
|
-
}
|
|
208
|
-
const hasKnit = existsSync(join(app, 'skills/knit/SKILL.md'));
|
|
209
|
-
const hasContinue = existsSync(join(app, 'skills/continue-chat/SKILL.md'));
|
|
210
|
-
const skillNames = [...(hasKnit ? ['knit'] : []), ...(hasContinue ? ['continue-chat'] : [])];
|
|
211
|
-
if (!skillNames.length)
|
|
212
|
-
throw new Error('Target runtime has no continuation skill');
|
|
213
|
-
for (const name of skillNames) {
|
|
214
|
-
if (opts.clients.some(client => client === 'codex' || client === 'antigravity'))
|
|
215
|
-
skill('.agents/skills/' + name + '/SKILL.md');
|
|
216
|
-
if (opts.clients.includes('claude-code'))
|
|
217
|
-
skill('.claude/skills/' + name + '/SKILL.md');
|
|
125
|
+
changes[path] = readFileSync(join(app, 'skills/knit/SKILL.md'), 'utf8');
|
|
218
126
|
}
|
|
127
|
+
if (opts.clients.some(client => client === 'codex' || client === 'antigravity'))
|
|
128
|
+
skill('.agents/skills/knit/SKILL.md');
|
|
219
129
|
for (const client of opts.clients) {
|
|
220
130
|
if (client === 'claude-code') {
|
|
221
131
|
mcp('.mcp.json');
|
|
222
132
|
hooks('.claude/settings.local.json', 'claude');
|
|
133
|
+
skill('.claude/skills/knit/SKILL.md');
|
|
223
134
|
}
|
|
224
135
|
if (client === 'claude-desktop')
|
|
225
136
|
mcp('.memory/connectors/claude-desktop.json', true);
|
|
226
137
|
if (client === 'antigravity') {
|
|
227
|
-
|
|
228
|
-
|
|
138
|
+
// Antigravity loads MCP servers globally or from plugins, not this project file.
|
|
139
|
+
// Retain the legacy project entry for existing tooling and export a mergeable fragment.
|
|
140
|
+
mcp('.agents/mcp_config.json', false, true);
|
|
141
|
+
mcp('.memory/connectors/antigravity.json', false, true);
|
|
229
142
|
const path = '.agents/hooks.json', value = json(path);
|
|
230
143
|
owned(path, ['shared-memory'], value['shared-memory']);
|
|
231
|
-
value['shared-memory'] = {
|
|
232
|
-
SessionStart: [handler('antigravity', 'recall')],
|
|
233
|
-
Stop: [handler('antigravity', 'capture')],
|
|
234
|
-
};
|
|
144
|
+
value['shared-memory'] = { SessionStart: [handler('antigravity', 'recall')], Stop: [handler('antigravity', 'capture')] };
|
|
235
145
|
changes[path] = dump(value);
|
|
236
146
|
}
|
|
237
147
|
if (client === 'codex') {
|
|
@@ -248,33 +158,12 @@ export function planConnection(opts) {
|
|
|
248
158
|
}
|
|
249
159
|
else if (parsed.mcp_servers?.['shared-memory'])
|
|
250
160
|
throw new Error('Unmanaged Codex server conflict');
|
|
251
|
-
changes[path] =
|
|
252
|
-
base.trimEnd() +
|
|
253
|
-
'\n\n' +
|
|
254
|
-
begin +
|
|
255
|
-
'\n[mcp_servers.shared-memory]\ndefault_tools_approval_mode = "writes"\ncommand = ' +
|
|
256
|
-
JSON.stringify(node) +
|
|
257
|
-
'\nargs = ' +
|
|
258
|
-
JSON.stringify([server]) +
|
|
259
|
-
'\ncwd = ' +
|
|
260
|
-
JSON.stringify(workspace) +
|
|
261
|
-
'\nenv = { ' +
|
|
262
|
-
Object.entries({ ...env, MEMORY_CLIENT: 'codex' })
|
|
263
|
-
.map(([k, v]) => k + ' = ' + JSON.stringify(v))
|
|
264
|
-
.join(', ') +
|
|
265
|
-
' }\ntools.choose_conversation.approval_mode = "approve"\n' +
|
|
266
|
-
end +
|
|
267
|
-
'\n';
|
|
161
|
+
changes[path] = base.trimEnd() + '\n\n' + begin + '\n[mcp_servers.shared-memory]\ndefault_tools_approval_mode = "writes"\ncommand = ' + JSON.stringify(node) + '\nargs = ' + JSON.stringify([server]) + '\ncwd = ' + JSON.stringify(workspace) + '\nenv = { ' + Object.entries({ ...env, MEMORY_CLIENT: 'codex' }).map(([k, v]) => k + ' = ' + JSON.stringify(v)).join(', ') + ' }\ntools.choose_conversation.approval_mode = "approve"\n' + end + '\n';
|
|
268
162
|
parseToml(changes[path]);
|
|
269
163
|
}
|
|
270
164
|
}
|
|
271
165
|
for (const [path, after] of Object.entries(changes))
|
|
272
|
-
state.files[path] = {
|
|
273
|
-
before: state.files[path]
|
|
274
|
-
? unapply(path, state.files[path], expected[path] ?? null)
|
|
275
|
-
: (expected[path] ?? null),
|
|
276
|
-
after,
|
|
277
|
-
};
|
|
166
|
+
state.files[path] = { before: state.files[path] ? unapply(path, state.files[path], expected[path] ?? null) : expected[path] ?? null, after };
|
|
278
167
|
expected[statePath] = read(join(workspace, statePath));
|
|
279
168
|
changes[statePath] = dump(state);
|
|
280
169
|
return { workspace, changes, expected };
|
|
@@ -305,26 +194,12 @@ export function applyConnectionPlan(plan) {
|
|
|
305
194
|
throw error;
|
|
306
195
|
}
|
|
307
196
|
try {
|
|
308
|
-
const git = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
|
|
309
|
-
cwd: plan.workspace,
|
|
310
|
-
encoding: 'utf8',
|
|
311
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
312
|
-
}).trim();
|
|
197
|
+
const git = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { cwd: plan.workspace, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
313
198
|
const path = join(git, 'info/exclude'), current = read(path) ?? '';
|
|
314
|
-
const entries = [
|
|
315
|
-
|
|
316
|
-
...Object.keys(plan.changes)
|
|
317
|
-
.filter((p) => !p.startsWith('.memory/'))
|
|
318
|
-
.map((p) => '/' + p),
|
|
319
|
-
];
|
|
320
|
-
atomicWrite(path, current +
|
|
321
|
-
'\n' +
|
|
322
|
-
entries.filter((p) => !current.split('\n').includes(p)).join('\n') +
|
|
323
|
-
'\n');
|
|
324
|
-
}
|
|
325
|
-
catch {
|
|
326
|
-
/* Non-Git projects can use the planner; CLI validates Git separately. */
|
|
199
|
+
const entries = ['/.memory/', ...Object.keys(plan.changes).filter(p => !p.startsWith('.memory/')).map(p => '/' + p)];
|
|
200
|
+
atomicWrite(path, current + '\n' + entries.filter(p => !current.split('\n').includes(p)).join('\n') + '\n');
|
|
327
201
|
}
|
|
202
|
+
catch { /* Non-Git projects can use the planner; CLI validates Git separately. */ }
|
|
328
203
|
}
|
|
329
204
|
function unapply(path, snapshot, current) {
|
|
330
205
|
const { before, after } = snapshot;
|
|
@@ -374,6 +249,4 @@ export function planUninstall(workspace) {
|
|
|
374
249
|
changes[statePath] = null;
|
|
375
250
|
return { workspace, changes, expected };
|
|
376
251
|
}
|
|
377
|
-
export function uninstallConnections(workspace) {
|
|
378
|
-
applyConnectionPlan(planUninstall(workspace));
|
|
379
|
-
}
|
|
252
|
+
export function uninstallConnections(workspace) { applyConnectionPlan(planUninstall(workspace)); }
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
2
1
|
import { homedir } from 'node:os';
|
|
3
2
|
import { join, resolve } from 'node:path';
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, mkdtempSync, writeFileSync
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
5
4
|
import { execFileSync } from 'node:child_process';
|
|
6
5
|
import { randomUUID } from 'node:crypto';
|
|
7
6
|
import { npmCommand } from './platform.js';
|
|
@@ -16,21 +15,13 @@ export function defaultHome() {
|
|
|
16
15
|
return join(process.env.LOCALAPPDATA ?? join(homedir(), 'AppData/Local'), 'SharedAgentMemory');
|
|
17
16
|
return join(process.env.XDG_DATA_HOME ?? join(homedir(), '.local/share'), 'shared-agent-memory');
|
|
18
17
|
}
|
|
19
|
-
export function runtimePaths(home) {
|
|
20
|
-
return {
|
|
21
|
-
data: join(home, 'data'),
|
|
22
|
-
versions: join(home, 'versions'),
|
|
23
|
-
state: join(home, 'installation.json'),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
18
|
+
export function runtimePaths(home) { return { data: join(home, 'data'), versions: join(home, 'versions'), state: join(home, 'installation.json') }; }
|
|
26
19
|
export function readInstallation(home) {
|
|
27
20
|
const path = runtimePaths(home).state;
|
|
28
21
|
if (!existsSync(path))
|
|
29
22
|
return null;
|
|
30
23
|
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
31
|
-
if (value.schema !== 1 ||
|
|
32
|
-
!value.current?.appRoot ||
|
|
33
|
-
!Array.isArray(value.projects))
|
|
24
|
+
if (value.schema !== 1 || !value.current?.appRoot || !Array.isArray(value.projects))
|
|
34
25
|
throw new Error('Invalid installation metadata');
|
|
35
26
|
return value;
|
|
36
27
|
}
|
|
@@ -41,8 +32,7 @@ export async function withInstallLock(home, work) {
|
|
|
41
32
|
mkdirSync(lock, { mode: 0o700 });
|
|
42
33
|
}
|
|
43
34
|
catch {
|
|
44
|
-
throw new Error('Another installation is running, or a stale install.lock remains. Check for a running setup process before removing ' +
|
|
45
|
-
lock);
|
|
35
|
+
throw new Error('Another installation is running, or a stale install.lock remains. Check for a running setup process before removing ' + lock);
|
|
46
36
|
}
|
|
47
37
|
try {
|
|
48
38
|
writeFileSync(join(lock, 'owner.json'), JSON.stringify({ pid: process.pid, started: new Date().toISOString() }), { mode: 0o600 });
|
|
@@ -62,42 +52,19 @@ export function installRuntime(home, spec) {
|
|
|
62
52
|
try {
|
|
63
53
|
writeFileSync(join(staging, 'package.json'), JSON.stringify({ name: 'shared-memory-runtime', private: true }), { mode: 0o600 });
|
|
64
54
|
// Arguments are passed directly; no shell interpolation or install lifecycle scripts.
|
|
65
|
-
const npm = npmCommand([
|
|
66
|
-
|
|
67
|
-
'--prefix',
|
|
68
|
-
staging,
|
|
69
|
-
'--ignore-scripts',
|
|
70
|
-
'--omit=dev',
|
|
71
|
-
'--no-audit',
|
|
72
|
-
'--no-fund',
|
|
73
|
-
'--save-exact',
|
|
74
|
-
'--',
|
|
75
|
-
spec,
|
|
76
|
-
]);
|
|
77
|
-
execFileSync(npm.command, npm.args, {
|
|
78
|
-
encoding: 'utf8',
|
|
79
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
80
|
-
timeout: 180_000,
|
|
81
|
-
});
|
|
55
|
+
const npm = npmCommand(['install', '--prefix', staging, '--ignore-scripts', '--omit=dev', '--no-audit', '--no-fund', '--save-exact', '--', spec]);
|
|
56
|
+
execFileSync(npm.command, npm.args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 180_000 });
|
|
82
57
|
const root = join(staging, 'node_modules', packageName);
|
|
83
58
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
84
|
-
if (pkg.name !== packageName ||
|
|
85
|
-
!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(pkg.version))
|
|
59
|
+
if (pkg.name !== packageName || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(pkg.version))
|
|
86
60
|
throw new Error('Unexpected runtime package');
|
|
87
|
-
for (const file of [
|
|
88
|
-
'apps/server/src/main.js',
|
|
89
|
-
'packages/installer/src/cli.js',
|
|
90
|
-
])
|
|
61
|
+
for (const file of ['apps/server/src/main.js', 'packages/installer/src/cli.js'])
|
|
91
62
|
if (!existsSync(join(root, 'dist', file)))
|
|
92
63
|
throw new Error('Incomplete runtime: ' + file);
|
|
93
64
|
execFileSync(process.execPath, [join(root, 'dist/packages/installer/src/cli.js'), '--version'], { encoding: 'utf8', timeout: 10_000 });
|
|
94
65
|
const destination = join(paths.versions, pkg.version + '-' + randomUUID());
|
|
95
66
|
renameSync(staging, destination);
|
|
96
|
-
return {
|
|
97
|
-
version: pkg.version,
|
|
98
|
-
node: process.execPath,
|
|
99
|
-
appRoot: join(destination, 'node_modules', packageName, 'dist'),
|
|
100
|
-
};
|
|
67
|
+
return { version: pkg.version, node: process.execPath, appRoot: join(destination, 'node_modules', packageName, 'dist') };
|
|
101
68
|
}
|
|
102
69
|
finally {
|
|
103
70
|
rmSync(staging, { recursive: true, force: true });
|
|
@@ -105,34 +72,5 @@ export function installRuntime(home, spec) {
|
|
|
105
72
|
}
|
|
106
73
|
export function activateRuntime(home, current, projects, antigravityConfig) {
|
|
107
74
|
const previous = readInstallation(home);
|
|
108
|
-
atomicWrite(runtimePaths(home).state, JSON.stringify({
|
|
109
|
-
schema: 1,
|
|
110
|
-
current,
|
|
111
|
-
previous: previous?.current,
|
|
112
|
-
projects,
|
|
113
|
-
antigravityConfig: antigravityConfig ?? previous?.antigravityConfig,
|
|
114
|
-
}, null, 2) + '\n');
|
|
115
|
-
}
|
|
116
|
-
export function assertRuntimeCompatibility(runtime, projects) {
|
|
117
|
-
const marker = join(runtime.appRoot, 'memory-schema.json');
|
|
118
|
-
const supported = existsSync(marker)
|
|
119
|
-
? JSON.parse(readFileSync(marker, 'utf8')).supportedSchema
|
|
120
|
-
: 0;
|
|
121
|
-
if (!Number.isInteger(supported) || supported < 0)
|
|
122
|
-
throw new Error('Invalid runtime schema compatibility metadata');
|
|
123
|
-
for (const database of new Set(projects.map((p) => p.database))) {
|
|
124
|
-
if (!existsSync(database))
|
|
125
|
-
continue;
|
|
126
|
-
const db = new DatabaseSync(database, { readOnly: true });
|
|
127
|
-
try {
|
|
128
|
-
const actual = Number(db.prepare('PRAGMA user_version').get().user_version);
|
|
129
|
-
if (actual > supported)
|
|
130
|
-
throw new Error('Runtime is incompatible with memory schema ' +
|
|
131
|
-
actual +
|
|
132
|
-
'. Use a compatible runtime or explicitly restore a consistent backup; no data was changed.');
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
db.close();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
75
|
+
atomicWrite(runtimePaths(home).state, JSON.stringify({ schema: 1, current, previous: previous?.current, projects, antigravityConfig: antigravityConfig ?? previous?.antigravityConfig }, null, 2) + '\n');
|
|
138
76
|
}
|