@tinchu0/knitt 0.1.0-beta.3 → 0.1.0-beta.4
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 +15 -20
- package/dist/apps/server/src/server.js +37 -147
- package/dist/packages/adapters/src/cli.js +15 -163
- package/dist/packages/adapters/src/command.js +18 -149
- package/dist/packages/adapters/src/hooks.js +23 -96
- package/dist/packages/adapters/src/launch.js +3 -10
- package/dist/packages/adapters/src/repository.js +5 -21
- package/dist/packages/adapters/src/transcript.js +15 -70
- package/dist/packages/installer/src/cli.js +75 -190
- package/dist/packages/installer/src/connections.js +79 -196
- package/dist/packages/installer/src/runtime.js +37 -94
- package/dist/packages/memory/src/store.js +23 -201
- package/dist/scripts/connector-setup.js +1 -1
- package/dist/skills/{continue-chat → knit}/SKILL.md +2 -2
- package/docs/clients/connector-setup.md +1 -1
- package/docs/clients/npm-installation.md +17 -22
- package/docs/clients/support-matrix.md +37 -0
- package/docs/usage.md +179 -0
- package/package.json +5 -4
- 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/docs/clients/local-agent-memory.md +0 -50
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
? appRoot
|
|
15
|
-
: dirname(appRoot);
|
|
16
|
-
const metadata = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { createInterface } from 'node:readline/promises';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { join, resolve, dirname } from 'node:path';
|
|
6
|
+
import { existsSync, readFileSync, accessSync, constants, rmSync } from 'node:fs';
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { planConnection, applyConnectionPlan, planUninstall, clients, atomicWrite, readConnectionState } from './connections.js';
|
|
9
|
+
import { installRuntime, readInstallation, defaultHome, runtimePaths, withInstallLock, activateRuntime, packageName } from './runtime.js';
|
|
10
|
+
import { resolveRepository } from '../../adapters/src/repository.js';
|
|
11
|
+
const appRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
12
|
+
const packageRoot = existsSync(join(appRoot, 'package.json')) ? appRoot : dirname(appRoot);
|
|
13
|
+
const metadata = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
|
|
17
14
|
const version = metadata.version;
|
|
18
15
|
async function confirm(text, yes = false) {
|
|
19
16
|
if (yes)
|
|
20
17
|
return true;
|
|
21
18
|
if (!process.stdin.isTTY)
|
|
22
|
-
throw new Error(
|
|
23
|
-
const reader = createInterface({
|
|
24
|
-
input: process.stdin,
|
|
25
|
-
output: process.stdout,
|
|
26
|
-
});
|
|
19
|
+
throw new Error('Use --yes for noninteractive apply, or --preview to inspect without changes');
|
|
20
|
+
const reader = createInterface({ input: process.stdin, output: process.stdout });
|
|
27
21
|
try {
|
|
28
|
-
return /^y(es)?$/i.test((await reader.question(text +
|
|
22
|
+
return /^y(es)?$/i.test((await reader.question(text + ' [y/N] ')).trim());
|
|
29
23
|
}
|
|
30
24
|
finally {
|
|
31
25
|
reader.close();
|
|
@@ -33,11 +27,8 @@ async function confirm(text, yes = false) {
|
|
|
33
27
|
}
|
|
34
28
|
async function ask(prompt) {
|
|
35
29
|
if (!process.stdin.isTTY)
|
|
36
|
-
throw new Error(
|
|
37
|
-
const reader = createInterface({
|
|
38
|
-
input: process.stdin,
|
|
39
|
-
output: process.stdout,
|
|
40
|
-
});
|
|
30
|
+
throw new Error('Pass --workspace and --client for noninteractive setup');
|
|
31
|
+
const reader = createInterface({ input: process.stdin, output: process.stdout });
|
|
41
32
|
try {
|
|
42
33
|
return (await reader.question(prompt)).trim();
|
|
43
34
|
}
|
|
@@ -47,9 +38,9 @@ async function ask(prompt) {
|
|
|
47
38
|
}
|
|
48
39
|
function preview(plan) {
|
|
49
40
|
for (const [path, content] of Object.entries(plan.changes)) {
|
|
50
|
-
if (path.includes(
|
|
41
|
+
if (path.includes('npm-connection'))
|
|
51
42
|
continue;
|
|
52
|
-
console.log((content === null ?
|
|
43
|
+
console.log((content === null ? 'remove ' : 'merge ') + join(plan.workspace, path));
|
|
53
44
|
if (content !== null && content !== plan.expected[path])
|
|
54
45
|
console.log(content);
|
|
55
46
|
}
|
|
@@ -69,9 +60,7 @@ function applyAll(plans, commit) {
|
|
|
69
60
|
// Already-written files are restored as one transaction; unrelated concurrent
|
|
70
61
|
// edits are protected by each plan's optimistic concurrency check.
|
|
71
62
|
const target = join(plan.workspace, path);
|
|
72
|
-
const current = existsSync(target)
|
|
73
|
-
? readFileSync(target, "utf8")
|
|
74
|
-
: null;
|
|
63
|
+
const current = existsSync(target) ? readFileSync(target, 'utf8') : null;
|
|
75
64
|
if (current !== plan.changes[path])
|
|
76
65
|
continue;
|
|
77
66
|
if (content !== null)
|
|
@@ -82,238 +71,134 @@ function applyAll(plans, commit) {
|
|
|
82
71
|
throw error;
|
|
83
72
|
}
|
|
84
73
|
}
|
|
85
|
-
function plansFor(runtime, projects) {
|
|
86
|
-
return projects.map((project) => planConnection({
|
|
87
|
-
...project,
|
|
88
|
-
appRoot: runtime.appRoot,
|
|
89
|
-
node: runtime.node,
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
74
|
+
function plansFor(runtime, projects) { return projects.map(project => planConnection({ ...project, appRoot: runtime.appRoot, node: runtime.node })); }
|
|
92
75
|
async function main() {
|
|
93
|
-
const { values, positionals } = parseArgs({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
client: { type: "string", multiple: true },
|
|
99
|
-
home: { type: "string" },
|
|
100
|
-
package: { type: "string" },
|
|
101
|
-
yes: { type: "boolean" },
|
|
102
|
-
preview: { type: "boolean" },
|
|
103
|
-
"capture-new-sessions": { type: "boolean" },
|
|
104
|
-
version: { type: "boolean" },
|
|
105
|
-
help: { type: "boolean" },
|
|
106
|
-
},
|
|
107
|
-
});
|
|
76
|
+
const { values, positionals } = parseArgs({ allowPositionals: true, options: {
|
|
77
|
+
workspace: { type: 'string' }, client: { type: 'string', multiple: true }, home: { type: 'string' },
|
|
78
|
+
package: { type: 'string' }, yes: { type: 'boolean' }, preview: { type: 'boolean' },
|
|
79
|
+
version: { type: 'boolean' }, help: { type: 'boolean' },
|
|
80
|
+
} });
|
|
108
81
|
if (values.version) {
|
|
109
82
|
console.log(version);
|
|
110
83
|
return;
|
|
111
84
|
}
|
|
112
85
|
const action = positionals[0];
|
|
113
86
|
if (!action || values.help) {
|
|
114
|
-
console.log(
|
|
115
|
-
version +
|
|
116
|
-
"\nCommands: setup, doctor, update, rollback, uninstall, serve, continue\nOptions: --workspace PATH --client codex|claude-code|antigravity|claude-desktop (repeatable)\n --capture-new-sessions --preview --yes --home PATH --package TARBALL_OR_VERSION_SPEC\nSetup configures a persistent local runtime; remote/team service is configured separately.");
|
|
87
|
+
console.log('Knitt ' + version + '\nCommands: setup, doctor, update, rollback, uninstall, serve\nOptions: --workspace PATH --client codex|claude-code|antigravity|claude-desktop (repeatable)\n --preview --yes --home PATH --package TARBALL_OR_VERSION_SPEC\nSetup configures a persistent local runtime; remote/team service is configured separately.');
|
|
117
88
|
return;
|
|
118
89
|
}
|
|
119
90
|
const home = resolve(values.home ?? defaultHome()), paths = runtimePaths(home);
|
|
120
|
-
if (action ===
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const common = (cwd) => execFileSync("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
124
|
-
const expected = common(resolve(values.workspace));
|
|
125
|
-
const state = readInstallation(home);
|
|
126
|
-
const project = state?.projects.find((p) => {
|
|
127
|
-
try {
|
|
128
|
-
return common(p.workspace) === expected;
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
if (!project?.captureNewSessions)
|
|
135
|
-
throw new Error("This project has not opted into local conversation mode; run setup --capture-new-sessions first");
|
|
136
|
-
process.env.MEMORY_DB = project.database;
|
|
137
|
-
process.env.MEMORY_REPO = project.repoId;
|
|
138
|
-
process.env.MEMORY_CONVERSATION_MODE = "1";
|
|
139
|
-
await import("../../adapters/src/command.js");
|
|
91
|
+
if (action === 'serve') {
|
|
92
|
+
process.env.MEMORY_DB ??= join(paths.data, 'events.sqlite');
|
|
93
|
+
await import('../../../apps/server/src/main.js');
|
|
140
94
|
return;
|
|
141
95
|
}
|
|
142
|
-
if (action ===
|
|
143
|
-
process.env.MEMORY_DB ??= join(paths.data, "events.sqlite");
|
|
144
|
-
await import("../../../apps/server/src/main.js");
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (action === "doctor") {
|
|
96
|
+
if (action === 'doctor') {
|
|
148
97
|
const state = readInstallation(home), problems = [];
|
|
149
|
-
if (Number(process.versions.node.split(
|
|
150
|
-
problems.push(
|
|
98
|
+
if (Number(process.versions.node.split('.')[0]) < 24)
|
|
99
|
+
problems.push('Install Node.js 24+');
|
|
151
100
|
try {
|
|
152
|
-
execFileSync(
|
|
101
|
+
execFileSync('git', ['--version'], { stdio: 'ignore' });
|
|
153
102
|
}
|
|
154
103
|
catch {
|
|
155
|
-
problems.push(
|
|
104
|
+
problems.push('Install Git and add it to PATH');
|
|
156
105
|
}
|
|
157
106
|
if (!state)
|
|
158
|
-
problems.push(
|
|
107
|
+
problems.push('No persistent runtime installed. Run setup.');
|
|
159
108
|
else {
|
|
160
|
-
for (const file of [
|
|
161
|
-
state.current.node,
|
|
162
|
-
join(state.current.appRoot, "apps/server/src/main.js"),
|
|
163
|
-
])
|
|
109
|
+
for (const file of [state.current.node, join(state.current.appRoot, 'apps/server/src/main.js')])
|
|
164
110
|
if (!existsSync(file))
|
|
165
|
-
problems.push(
|
|
111
|
+
problems.push('Missing runtime path: ' + file + '. Run setup again.');
|
|
166
112
|
try {
|
|
167
113
|
accessSync(paths.data, constants.W_OK);
|
|
168
114
|
}
|
|
169
115
|
catch {
|
|
170
|
-
problems.push(
|
|
116
|
+
problems.push('Data directory is not writable: ' + paths.data);
|
|
171
117
|
}
|
|
172
118
|
for (const project of state.projects) {
|
|
173
119
|
try {
|
|
174
120
|
const managed = readConnectionState(project.workspace);
|
|
175
121
|
if (!Object.keys(managed.files).length)
|
|
176
|
-
problems.push(
|
|
122
|
+
problems.push('Missing connector state: ' + project.workspace);
|
|
177
123
|
for (const [path, snapshot] of Object.entries(managed.files)) {
|
|
178
|
-
const current = readFileSync(join(project.workspace, path),
|
|
124
|
+
const current = readFileSync(join(project.workspace, path), 'utf8');
|
|
179
125
|
if (current !== snapshot.after)
|
|
180
|
-
problems.push(
|
|
181
|
-
join(project.workspace, path));
|
|
126
|
+
problems.push('Configuration changed; review before setup: ' + join(project.workspace, path));
|
|
182
127
|
}
|
|
183
128
|
}
|
|
184
129
|
catch {
|
|
185
|
-
problems.push(
|
|
130
|
+
problems.push('Missing or invalid project configuration: ' + project.workspace);
|
|
186
131
|
}
|
|
187
132
|
}
|
|
188
133
|
}
|
|
189
|
-
|
|
190
|
-
.filter((p) => p.captureNewSessions)
|
|
191
|
-
.map((project) => {
|
|
192
|
-
const observations = project.clients
|
|
193
|
-
.flatMap((client) => readCaptureStatuses(join(dirname(project.database), "queue", client === "claude-code" ? "claude" : client)))
|
|
194
|
-
.filter((s) => s.session.repoId === project.repoId);
|
|
195
|
-
return {
|
|
196
|
-
workspace: project.workspace,
|
|
197
|
-
captureObserved: observations.some((s) => s.lastCaptureAt !== null),
|
|
198
|
-
startupObserved: observations.length > 0,
|
|
199
|
-
sessions: observations,
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
console.log(JSON.stringify({
|
|
203
|
-
capture,
|
|
204
|
-
status: problems.length ? "attention_required" : "configured",
|
|
205
|
-
runtime: state?.current.version,
|
|
206
|
-
problems,
|
|
207
|
-
note: "Configuration check only; agent login/trust and live handoff are not verified.",
|
|
208
|
-
}, null, 2));
|
|
134
|
+
console.log(JSON.stringify({ status: problems.length ? 'attention_required' : 'configured', runtime: state?.current.version, problems, note: 'Configuration check only; agent login/trust and live handoff are not verified.' }, null, 2));
|
|
209
135
|
if (problems.length)
|
|
210
136
|
process.exitCode = 1;
|
|
211
137
|
return;
|
|
212
138
|
}
|
|
213
|
-
if (![
|
|
214
|
-
throw new Error(
|
|
139
|
+
if (!['setup', 'update', 'rollback', 'uninstall'].includes(action))
|
|
140
|
+
throw new Error('Unknown command: ' + action);
|
|
215
141
|
let project;
|
|
216
|
-
if (action ===
|
|
217
|
-
const directory = values.workspace ??
|
|
218
|
-
const selected = values.client ??
|
|
219
|
-
(await ask("Agents (comma separated: " + clients.join(", ") + "): "))
|
|
220
|
-
.split(",")
|
|
221
|
-
.map((v) => v.trim());
|
|
142
|
+
if (action === 'setup') {
|
|
143
|
+
const directory = values.workspace ?? await ask('Project folder: ');
|
|
144
|
+
const selected = values.client ?? (await ask('Agents (comma separated: ' + clients.join(', ') + '): ')).split(',').map(v => v.trim());
|
|
222
145
|
const { workspace, repoId } = resolveRepository(resolve(directory));
|
|
223
|
-
project = {
|
|
224
|
-
workspace,
|
|
225
|
-
repoId,
|
|
226
|
-
clients: selected,
|
|
227
|
-
database: join(paths.data, "events.sqlite"),
|
|
228
|
-
...(values["capture-new-sessions"] ? { captureNewSessions: true } : {}),
|
|
229
|
-
};
|
|
146
|
+
project = { workspace, repoId, clients: selected, database: join(paths.data, 'events.sqlite') };
|
|
230
147
|
// Validate and show changes before installing dependencies or writing settings.
|
|
231
|
-
const previousProject = readInstallation(home)?.projects.find((p) => p.workspace === workspace);
|
|
232
|
-
if (previousProject)
|
|
233
|
-
project.repoId = previousProject.repoId;
|
|
234
148
|
const plan = planConnection({ ...project, appRoot });
|
|
235
149
|
preview(plan);
|
|
236
150
|
if (values.preview) {
|
|
237
|
-
console.log(
|
|
151
|
+
console.log('Preview only. No runtime or configuration installed.');
|
|
238
152
|
return;
|
|
239
153
|
}
|
|
240
154
|
}
|
|
241
155
|
else {
|
|
242
156
|
const state = readInstallation(home);
|
|
243
157
|
if (!state)
|
|
244
|
-
throw new Error(
|
|
245
|
-
if (action ===
|
|
246
|
-
const target = values.workspace
|
|
247
|
-
? resolveRepository(resolve(values.workspace)).workspace
|
|
248
|
-
: null;
|
|
158
|
+
throw new Error('No installation found. Run setup first.');
|
|
159
|
+
if (action === 'uninstall') {
|
|
160
|
+
const target = values.workspace ? resolveRepository(resolve(values.workspace)).workspace : null;
|
|
249
161
|
if (!target)
|
|
250
|
-
throw new Error(
|
|
251
|
-
if (!state.projects.some(
|
|
252
|
-
throw new Error(
|
|
162
|
+
throw new Error('Pass --workspace to uninstall one project; memory data is always retained');
|
|
163
|
+
if (!state.projects.some(p => p.workspace === target))
|
|
164
|
+
throw new Error('Project is not managed by this installation');
|
|
253
165
|
preview(planUninstall(target));
|
|
254
166
|
}
|
|
255
167
|
else
|
|
256
|
-
console.log(action +
|
|
257
|
-
" runtime for " +
|
|
258
|
-
state.projects.length +
|
|
259
|
-
" project(s); user memory is retained.");
|
|
168
|
+
console.log(action + ' runtime for ' + state.projects.length + ' project(s); user memory is retained.');
|
|
260
169
|
if (values.preview)
|
|
261
170
|
return;
|
|
262
171
|
}
|
|
263
|
-
if (!
|
|
264
|
-
console.log(
|
|
172
|
+
if (!await confirm('Apply ' + action + '?', values.yes)) {
|
|
173
|
+
console.log('Cancelled. No changes applied.');
|
|
265
174
|
return;
|
|
266
175
|
}
|
|
267
176
|
await withInstallLock(home, async () => {
|
|
268
177
|
const state = readInstallation(home);
|
|
269
|
-
if (action ===
|
|
178
|
+
if (action === 'uninstall') {
|
|
270
179
|
const target = resolveRepository(resolve(values.workspace)).workspace;
|
|
271
180
|
const plan = planUninstall(target);
|
|
272
|
-
applyAll([plan], () => atomicWrite(paths.state, JSON.stringify({
|
|
273
|
-
|
|
274
|
-
projects: state.projects.filter((p) => p.workspace !== target),
|
|
275
|
-
}, null, 2)));
|
|
276
|
-
console.log("Project connectors removed where unchanged. User-edited settings and all memory retained. Runtime retained for other projects.");
|
|
181
|
+
applyAll([plan], () => atomicWrite(paths.state, JSON.stringify({ ...state, projects: state.projects.filter(p => p.workspace !== target) }, null, 2)));
|
|
182
|
+
console.log('Project connectors removed where unchanged. User-edited settings and all memory retained. Runtime retained for other projects.');
|
|
277
183
|
return;
|
|
278
184
|
}
|
|
279
185
|
if (project) {
|
|
280
|
-
const existing = state?.projects.find(
|
|
281
|
-
if (existing)
|
|
282
|
-
project.
|
|
283
|
-
project.clients = [
|
|
284
|
-
...new Set([...existing.clients, ...project.clients]),
|
|
285
|
-
];
|
|
286
|
-
if (existing.captureNewSessions)
|
|
287
|
-
project.captureNewSessions = true;
|
|
288
|
-
}
|
|
186
|
+
const existing = state?.projects.find(p => p.workspace === project.workspace);
|
|
187
|
+
if (existing)
|
|
188
|
+
project.clients = [...new Set([...existing.clients, ...project.clients])];
|
|
289
189
|
}
|
|
290
|
-
const projects = project
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
]
|
|
295
|
-
: state.projects;
|
|
296
|
-
if (action !== "rollback" && metadata.private && !values.package)
|
|
297
|
-
throw new Error("This package is unpublished. Pass --package /absolute/path/to/the-built.tgz; registry installation is disabled until release.");
|
|
298
|
-
const runtime = action === "rollback"
|
|
299
|
-
? state?.previous
|
|
300
|
-
: installRuntime(home, values.package ??
|
|
301
|
-
packageName +
|
|
302
|
-
"@" +
|
|
303
|
-
(action === "update"
|
|
304
|
-
? version.includes("-")
|
|
305
|
-
? "next"
|
|
306
|
-
: "latest"
|
|
307
|
-
: version));
|
|
190
|
+
const projects = project ? [...(state?.projects ?? []).filter(p => p.workspace !== project.workspace), project] : state.projects;
|
|
191
|
+
if (action !== 'rollback' && metadata.private && !values.package)
|
|
192
|
+
throw new Error('This package is unpublished. Pass --package /absolute/path/to/the-built.tgz; registry installation is disabled until release.');
|
|
193
|
+
const runtime = action === 'rollback' ? state?.previous : installRuntime(home, values.package ?? packageName + '@' + (action === 'update' ? (version.includes('-') ? 'next' : 'latest') : version));
|
|
308
194
|
if (!runtime)
|
|
309
|
-
throw new Error(
|
|
310
|
-
assertRuntimeCompatibility(runtime, projects);
|
|
195
|
+
throw new Error('No previous runtime available');
|
|
311
196
|
const plans = plansFor(runtime, projects);
|
|
312
197
|
applyAll(plans, () => activateRuntime(home, runtime, projects));
|
|
313
|
-
console.log(
|
|
314
|
-
console.log(
|
|
315
|
-
if (projects.some(
|
|
316
|
-
console.log(
|
|
198
|
+
console.log('Installed runtime ' + runtime.version + '. Data: ' + paths.data);
|
|
199
|
+
console.log('Restart connected agents and review MCP/hook trust prompts. Use /knit to select your conversation.');
|
|
200
|
+
if (projects.some(p => p.clients.includes('claude-desktop')))
|
|
201
|
+
console.log('Claude Desktop: merge the generated project .memory/connectors/claude-desktop.json fragment into Desktop MCP settings, then restart.');
|
|
317
202
|
});
|
|
318
203
|
}
|
|
319
204
|
try {
|