@myrialabs/clopen 0.4.37 → 0.4.39
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 +2 -2
- package/backend/auth/permissions.ts +39 -0
- package/backend/bootstrap.ts +16 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/envelope.test.ts +93 -0
- package/backend/database/crypto/envelope.ts +127 -0
- package/backend/database/crypto/index.ts +22 -0
- package/backend/database/crypto/master-key.ts +129 -0
- package/backend/database/crypto/secret-columns.ts +151 -0
- package/backend/database/migrations/071_create_notes_tables.ts +90 -0
- package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
- package/backend/database/migrations/073_create_integration_tables.ts +119 -0
- package/backend/database/migrations/074_create_work_tables.ts +94 -0
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/index.ts +49 -0
- package/backend/database/queries/db-client-connection-queries.ts +42 -12
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/engine-queries.ts +23 -10
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +10 -1
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +325 -0
- package/backend/database/queries/mcp-server-queries.ts +38 -11
- package/backend/database/queries/note-queries.test.ts +190 -0
- package/backend/database/queries/note-queries.ts +269 -0
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/ssh-connection-queries.ts +19 -8
- package/backend/database/queries/work-queries.ts +210 -0
- package/backend/db-client/integrations/index.ts +37 -0
- package/backend/db-client/integrations/links.ts +533 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +500 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +137 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -0
- package/backend/engine/docs/artifacts.md +22 -9
- package/backend/files/os-clipboard.test.ts +209 -0
- package/backend/files/os-clipboard.ts +567 -0
- package/backend/http/integration-hooks.ts +42 -0
- package/backend/http/notes-images.test.ts +228 -0
- package/backend/http/notes-images.ts +196 -0
- package/backend/index.ts +13 -0
- package/backend/integrations/accounts.ts +229 -0
- package/backend/integrations/health.ts +146 -0
- package/backend/integrations/index.ts +36 -0
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.test.ts +204 -0
- package/backend/integrations/projections/mcp-projector.ts +163 -0
- package/backend/integrations/projections/types.ts +63 -0
- package/backend/integrations/registry/define.ts +38 -0
- package/backend/integrations/registry/index.ts +60 -0
- package/backend/integrations/registry/providers/context7.ts +44 -0
- package/backend/integrations/registry/providers/firecrawl.ts +41 -0
- package/backend/integrations/registry/providers/github.ts +78 -0
- package/backend/integrations/registry/providers/supabase.ts +61 -0
- package/backend/integrations/registry/providers/vercel.ts +46 -0
- package/backend/integrations/registry/types.ts +96 -0
- package/backend/integrations/webhooks/gateway.ts +160 -0
- package/backend/integrations/webhooks/verify.ts +65 -0
- package/backend/mcp/README.md +25 -3
- package/backend/mcp/external/config.ts +35 -1
- package/backend/mcp/index.ts +1 -1
- package/backend/mcp/internal/config.ts +1 -1
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/notes/access.test.ts +82 -0
- package/backend/notes/access.ts +27 -0
- package/backend/notes/storage.test.ts +77 -0
- package/backend/notes/storage.ts +114 -0
- package/backend/permissions/service.ts +2 -2
- package/backend/profiles/service.ts +1 -1
- package/backend/projects/project-cleanup.ts +6 -0
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -0
- package/backend/work/bindings.ts +124 -0
- package/backend/work/index.ts +42 -0
- package/backend/work/prompts.ts +150 -0
- package/backend/work/providers/github/actions-logs.ts +180 -0
- package/backend/work/providers/github/adapter.test.ts +88 -0
- package/backend/work/providers/github/adapter.ts +1255 -0
- package/backend/work/providers/github/client.ts +280 -0
- package/backend/work/providers/github/list-range.test.ts +158 -0
- package/backend/work/providers/github/token-kind.test.ts +42 -0
- package/backend/work/pull-requests.ts +242 -0
- package/backend/work/registry.ts +27 -0
- package/backend/work/service.ts +436 -0
- package/backend/work/start-work.test.ts +71 -0
- package/backend/work/start-work.ts +232 -0
- package/backend/work/types.ts +180 -0
- package/backend/ws/db-client/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/index.ts +20 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/files/clipboard.ts +78 -0
- package/backend/ws/files/index.ts +5 -0
- package/backend/ws/git/diff-budget.ts +70 -11
- package/backend/ws/index.ts +16 -2
- package/backend/ws/integrations/crud.ts +219 -0
- package/backend/ws/integrations/index.ts +22 -0
- package/backend/ws/mcp/crud.ts +25 -1
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/notes/index.ts +278 -0
- package/backend/ws/profiles/crud.ts +1 -1
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/backend/ws/work/actions.ts +206 -0
- package/backend/ws/work/context.ts +51 -0
- package/backend/ws/work/crud.ts +347 -0
- package/backend/ws/work/index.ts +17 -0
- package/backend/ws/work/pull-requests.ts +177 -0
- package/backend/ws/work/schemas.ts +226 -0
- package/dist/assets/{index-sJmS_CCm.js → index-BrF6nqld.js} +1 -1
- package/dist/assets/{index-Bik9TCBi.js → index-C8Gi-b6U.js} +1 -1
- package/dist/assets/main-Bd3gb79F.css +1 -0
- package/dist/assets/main-Bo1hD7mt.js +1191 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/tool-icons.ts +42 -0
- package/shared/types/database/schema.ts +41 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/index.ts +2 -0
- package/shared/types/db-client/integrations.ts +174 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +140 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/stores/settings.ts +8 -0
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/work.ts +426 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +4 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-DLqolBI2.css +0 -1
- package/dist/assets/main-Df1I3hnw.js +0 -1096
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the note attachment path contract.
|
|
3
|
+
*
|
|
4
|
+
* The reason these exist: `note_images.storage_path` used to be an absolute
|
|
5
|
+
* path, which pinned every attachment to the machine and OS that uploaded it.
|
|
6
|
+
* The rules below are what make a `~/.clopen` portable between a `CLOPEN_DATA_DIR`
|
|
7
|
+
* move and between platforms, so they are pinned rather than left to review.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect } from 'bun:test';
|
|
11
|
+
import { join, isAbsolute } from 'node:path';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
getNotesRootDir,
|
|
15
|
+
noteImageRelPath,
|
|
16
|
+
resolveNoteImagePath,
|
|
17
|
+
sanitizeImageFileName
|
|
18
|
+
} from './storage';
|
|
19
|
+
|
|
20
|
+
describe('noteImageRelPath', () => {
|
|
21
|
+
it('is relative and POSIX-separated so the row survives a move between platforms', () => {
|
|
22
|
+
const rel = noteImageRelPath('coll-1', 'note-1', 'abc-photo.png');
|
|
23
|
+
expect(rel).toBe('notes/coll-1/note-1/abc-photo.png');
|
|
24
|
+
expect(isAbsolute(rel)).toBe(false);
|
|
25
|
+
expect(rel).not.toContain('\\');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('resolveNoteImagePath', () => {
|
|
30
|
+
it('resolves a stored relative path under the current data dir', () => {
|
|
31
|
+
const rel = noteImageRelPath('coll-1', 'note-1', 'abc-photo.png');
|
|
32
|
+
expect(resolveNoteImagePath(rel)).toBe(join(getNotesRootDir(), 'coll-1', 'note-1', 'abc-photo.png'));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('still resolves an absolute path written before the relative format', () => {
|
|
36
|
+
const absolute = join(getNotesRootDir(), 'coll-1', 'note-1', 'legacy.png');
|
|
37
|
+
expect(resolveNoteImagePath(absolute)).toBe(absolute);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('refuses a path that escapes the notes root', () => {
|
|
41
|
+
expect(resolveNoteImagePath('notes/../../.ssh/id_rsa')).toBeNull();
|
|
42
|
+
expect(resolveNoteImagePath('../../../etc/passwd')).toBeNull();
|
|
43
|
+
expect(resolveNoteImagePath('/etc/passwd')).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('refuses an empty path rather than resolving to the data dir', () => {
|
|
47
|
+
expect(resolveNoteImagePath('')).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('sanitizeImageFileName', () => {
|
|
52
|
+
it('keeps only characters that are legal on every platform', () => {
|
|
53
|
+
expect(sanitizeImageFileName('my photo (1).png')).toBe('my_photo__1_.png');
|
|
54
|
+
expect(sanitizeImageFileName('re:port|v2*.jpg')).toBe('re_port_v2_.jpg');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('strips any directory component from both separator styles', () => {
|
|
58
|
+
expect(sanitizeImageFileName('../../etc/passwd')).toBe('passwd');
|
|
59
|
+
expect(sanitizeImageFileName('C:\\Users\\me\\shot.png')).toBe('shot.png');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('drops trailing dots and spaces, which Windows removes behind our back', () => {
|
|
63
|
+
// A stored `shot.png.` would leave the row pointing at a name the OS
|
|
64
|
+
// never actually wrote.
|
|
65
|
+
expect(sanitizeImageFileName('shot.png.')).toBe('shot.png');
|
|
66
|
+
expect(sanitizeImageFileName('shot.png ')).toBe('shot.png');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('caps the length so the full path stays under the Windows 260-char limit', () => {
|
|
70
|
+
expect(sanitizeImageFileName(`${'a'.repeat(400)}.png`).length).toBeLessThanOrEqual(64);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('never returns an empty name', () => {
|
|
74
|
+
expect(sanitizeImageFileName('')).toBe('image');
|
|
75
|
+
expect(sanitizeImageFileName('...')).toBe('image');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-disk storage for note image attachments.
|
|
3
|
+
*
|
|
4
|
+
* Files live at `<DATA_DIR>/notes/<collectionId>/<noteId>/<uuid>-<name>`, but
|
|
5
|
+
* `note_images.storage_path` holds that location *relative* to the data dir,
|
|
6
|
+
* with forward slashes. An absolute path would pin every attachment to the
|
|
7
|
+
* machine that uploaded it: `CLOPEN_DATA_DIR` is a supported override, and a
|
|
8
|
+
* `~/.clopen` copied from macOS to Windows would carry `/Users/...` paths that
|
|
9
|
+
* resolve nowhere on the target. Relative + POSIX separators survives both.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { join, resolve } from 'node:path';
|
|
13
|
+
import { rm } from 'node:fs/promises';
|
|
14
|
+
|
|
15
|
+
import { getClopenDir } from '../utils/paths';
|
|
16
|
+
import { noteCollectionQueries } from '../database/queries/note-queries';
|
|
17
|
+
// One exported implementation already lives with the worktree paths; notes
|
|
18
|
+
// resolve the same class of "is this inside the directory I own" question.
|
|
19
|
+
import { isPathInside } from '../worktrees/paths';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Longest attachment file name kept after sanitizing.
|
|
23
|
+
*
|
|
24
|
+
* Windows still caps a full path at 260 characters by default. The rest of an
|
|
25
|
+
* attachment path costs roughly 150 (data dir + `notes` + two UUID directories
|
|
26
|
+
* + the UUID prefix), so anything past 64 risks an upload that succeeds on
|
|
27
|
+
* macOS and Linux and fails on Windows with ENAMETOOLONG.
|
|
28
|
+
*/
|
|
29
|
+
const MAX_FILE_NAME_LENGTH = 64;
|
|
30
|
+
|
|
31
|
+
/** Root that holds every note attachment of every project. */
|
|
32
|
+
export function getNotesRootDir(): string {
|
|
33
|
+
return join(getClopenDir(), 'notes');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Directory that holds one collection's note attachments. */
|
|
37
|
+
export function getCollectionNotesDir(collectionId: string): string {
|
|
38
|
+
return join(getNotesRootDir(), collectionId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Directory that holds one note's attachments. */
|
|
42
|
+
export function getNoteDir(collectionId: string, noteId: string): string {
|
|
43
|
+
return join(getCollectionNotesDir(collectionId), noteId);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reduce a client-supplied name to something safe on every filesystem.
|
|
48
|
+
*
|
|
49
|
+
* Windows rejects `<>:"/\|?*` and silently drops trailing dots and spaces — a
|
|
50
|
+
* dropped trailing dot would leave the database pointing at a file name the OS
|
|
51
|
+
* never wrote. Reserved device names (CON, NUL, …) can't occur because the
|
|
52
|
+
* stored name is always prefixed with the image UUID.
|
|
53
|
+
*/
|
|
54
|
+
export function sanitizeImageFileName(name: string): string {
|
|
55
|
+
const flattened = name.split(/[\\/]/).pop() ?? '';
|
|
56
|
+
// Trailing dots and spaces go before the character replacement, not after:
|
|
57
|
+
// afterwards a trailing space is already an underscore and would survive.
|
|
58
|
+
const trimmed = flattened.replace(/[.\s]+$/, '').trim();
|
|
59
|
+
const cleaned = trimmed
|
|
60
|
+
.replace(/[^a-zA-Z0-9._-]/g, '_')
|
|
61
|
+
.slice(0, MAX_FILE_NAME_LENGTH)
|
|
62
|
+
// The length cap can land on a dot, which puts one back at the end.
|
|
63
|
+
.replace(/\.+$/, '');
|
|
64
|
+
return cleaned || 'image';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The value to persist in `note_images.storage_path`. */
|
|
68
|
+
export function noteImageRelPath(collectionId: string, noteId: string, fileName: string): string {
|
|
69
|
+
return `notes/${collectionId}/${noteId}/${fileName}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Turn a stored path back into an absolute one under the current data dir.
|
|
74
|
+
*
|
|
75
|
+
* Returns null when the value escapes the notes root — a stored path is always
|
|
76
|
+
* server-generated, so an escape means the row was tampered with and the read
|
|
77
|
+
* must not fall through to an arbitrary file.
|
|
78
|
+
*/
|
|
79
|
+
export function resolveNoteImagePath(storagePath: string): string | null {
|
|
80
|
+
if (!storagePath) return null;
|
|
81
|
+
const absolute = storagePath.startsWith('/') || /^[A-Za-z]:[\\/]/.test(storagePath)
|
|
82
|
+
? resolve(storagePath)
|
|
83
|
+
: resolve(join(getClopenDir(), ...storagePath.split('/')));
|
|
84
|
+
return isPathInside(getNotesRootDir(), absolute) ? absolute : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Remove one note's attachment directory. Best-effort: never throws. */
|
|
88
|
+
export async function removeNoteFiles(collectionId: string, noteId: string): Promise<void> {
|
|
89
|
+
await rm(getNoteDir(collectionId, noteId), { recursive: true, force: true }).catch(() => {});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Remove one collection's attachment directory. Best-effort: never throws. */
|
|
93
|
+
export async function removeCollectionFiles(collectionId: string): Promise<void> {
|
|
94
|
+
const root = getNotesRootDir();
|
|
95
|
+
const dir = getCollectionNotesDir(collectionId);
|
|
96
|
+
// The directory is derived from the id, so an empty or traversing id would
|
|
97
|
+
// aim this recursive delete at the notes root itself.
|
|
98
|
+
if (dir === root || !isPathInside(root, dir)) return;
|
|
99
|
+
await rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Remove every attachment belonging to a project's note collections.
|
|
104
|
+
*
|
|
105
|
+
* Deleting the project cascades the collections, notes and image rows away, so
|
|
106
|
+
* without this the files would have no row left to point at them and would sit
|
|
107
|
+
* in the data dir until the user found them by hand. Runs before the project
|
|
108
|
+
* row is deleted, while the collection ids can still be resolved.
|
|
109
|
+
*/
|
|
110
|
+
export async function removeProjectNotes(projectId: string): Promise<void> {
|
|
111
|
+
for (const collectionId of noteCollectionQueries.idsByProject(projectId)) {
|
|
112
|
+
await removeCollectionFiles(collectionId);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The inventory (what the UI offers as allow/deny targets) is the union of:
|
|
7
7
|
* - built-in engine tools ({@link ENGINE_BUILTIN_TOOLS}),
|
|
8
|
-
* - live MCP tools from enabled
|
|
8
|
+
* - live MCP tools from enabled connectors (best-effort; a server that fails to
|
|
9
9
|
* connect is simply skipped),
|
|
10
10
|
* - tool names named by subagent allowlists.
|
|
11
11
|
*/
|
|
@@ -142,7 +142,7 @@ export const permissionService = {
|
|
|
142
142
|
const tools = await listExternalServerTools(server.slug);
|
|
143
143
|
// Claude-style namespaced name (`mcp__<namespace>__<tool>`) — the form
|
|
144
144
|
// the authoritative Claude hook sees. MCP exposure is primarily
|
|
145
|
-
// governed by
|
|
145
|
+
// governed by Integrations (Prompt 2); these are a belt-and-suspenders
|
|
146
146
|
// deny target.
|
|
147
147
|
for (const tool of tools) mcpSet.add(`mcp__${server.namespace}__${tool.name}`);
|
|
148
148
|
} catch (error) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* resolution consumed by the artifact/MCP sync path.
|
|
4
4
|
*
|
|
5
5
|
* A Profile is a reusable, named set of references to existing artifacts
|
|
6
|
-
* (Skills, Commands, Subagents,
|
|
6
|
+
* (Skills, Commands, Subagents, Integrations). It NARROWS which of the
|
|
7
7
|
* instance-global artifacts are active for a session, without duplicating any
|
|
8
8
|
* artifact data — `profile_items` only stores slugs.
|
|
9
9
|
*
|
|
@@ -7,6 +7,7 @@ import { fileWatcher } from '../files/file-watcher';
|
|
|
7
7
|
import { clearProjectPresence } from '../project/status-manager';
|
|
8
8
|
import { registerProjectCleanup } from './project-cleanup-registry';
|
|
9
9
|
import { removeProjectWorktrees } from '../worktrees';
|
|
10
|
+
import { removeProjectNotes } from '../notes/storage';
|
|
10
11
|
|
|
11
12
|
registerProjectCleanup({
|
|
12
13
|
name: 'engine',
|
|
@@ -36,3 +37,8 @@ registerProjectCleanup({
|
|
|
36
37
|
name: 'worktrees',
|
|
37
38
|
run: (projectId) => removeProjectWorktrees(projectId)
|
|
38
39
|
});
|
|
40
|
+
|
|
41
|
+
registerProjectCleanup({
|
|
42
|
+
name: 'notes',
|
|
43
|
+
run: (projectId) => removeProjectNotes(projectId)
|
|
44
|
+
});
|
|
@@ -2,8 +2,8 @@ import { snapshotQueries, messageQueries, checkpointQueries } from '../database/
|
|
|
2
2
|
import { blobStore } from './blob-store';
|
|
3
3
|
import { debug } from '$shared/utils/logger';
|
|
4
4
|
import { loadMessage } from '$shared/utils/message-formatter';
|
|
5
|
-
import {
|
|
6
|
-
import type { DatabaseMessage } from '$shared/types/database/schema';
|
|
5
|
+
import { buildTurnFiles, summariseTurnFiles } from './turn-changes';
|
|
6
|
+
import type { DatabaseMessage, SessionScopedChanges } from '$shared/types/database/schema';
|
|
7
7
|
import type { UnifiedMessage, UserMessage } from '$shared/types/unified';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -318,9 +318,16 @@ export function isDescendant(
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
321
|
+
* The numbers a checkpoint shows: files changed, and lines in and out.
|
|
322
|
+
*
|
|
323
|
+
* Recomputed from the blobs rather than read off the snapshot row, through the
|
|
324
|
+
* same `buildTurnFiles` the Changes surface uses. Two reasons, and both were
|
|
325
|
+
* live bugs: rows written before binary files stopped being line-counted claim
|
|
326
|
+
* a PNG's bytes as source lines, and any second implementation of "how many
|
|
327
|
+
* lines is this" eventually disagrees with the first one on screen.
|
|
328
|
+
*
|
|
329
|
+
* Falls back to the stored numbers when the blobs are gone, which is the one
|
|
330
|
+
* case where the row knows something this cannot recover.
|
|
324
331
|
*/
|
|
325
332
|
export async function getCheckpointFileStats(
|
|
326
333
|
checkpointMsg: DatabaseMessage
|
|
@@ -330,42 +337,29 @@ export async function getCheckpointFileStats(
|
|
|
330
337
|
return { filesChanged: 0, insertions: 0, deletions: 0 };
|
|
331
338
|
}
|
|
332
339
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
try { previousSnapshot[filepath] = await blobStore.readBlob(entry.oldHash); }
|
|
353
|
-
catch { allBlobsOk = false; break; }
|
|
354
|
-
}
|
|
355
|
-
if (entry.newHash) {
|
|
356
|
-
try { currentSnapshot[filepath] = await blobStore.readBlob(entry.newHash); }
|
|
357
|
-
catch { allBlobsOk = false; break; }
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (allBlobsOk) {
|
|
361
|
-
const recomputed = calculateFileChangeStats(previousSnapshot, currentSnapshot);
|
|
362
|
-
filesChanged = recomputed.filesChanged;
|
|
363
|
-
insertions = recomputed.insertions;
|
|
364
|
-
deletions = recomputed.deletions;
|
|
365
|
-
}
|
|
340
|
+
const stored = {
|
|
341
|
+
filesChanged: snapshot.files_changed || 0,
|
|
342
|
+
insertions: snapshot.insertions || 0,
|
|
343
|
+
deletions: snapshot.deletions || 0
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
if (!snapshot.session_changes) return stored;
|
|
347
|
+
|
|
348
|
+
try {
|
|
349
|
+
const changes = JSON.parse(snapshot.session_changes as string) as SessionScopedChanges;
|
|
350
|
+
if (Object.keys(changes).length === 0) return stored;
|
|
351
|
+
|
|
352
|
+
let blobMissing = false;
|
|
353
|
+
const files = await buildTurnFiles(changes, async (hash) => {
|
|
354
|
+
try {
|
|
355
|
+
return await blobStore.readBlob(hash);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
blobMissing = true;
|
|
358
|
+
throw err;
|
|
366
359
|
}
|
|
367
|
-
}
|
|
360
|
+
});
|
|
361
|
+
return blobMissing ? stored : summariseTurnFiles(files);
|
|
362
|
+
} catch {
|
|
363
|
+
return stored;
|
|
368
364
|
}
|
|
369
|
-
|
|
370
|
-
return { filesChanged, insertions, deletions };
|
|
371
365
|
}
|
|
@@ -139,6 +139,96 @@ export class SnapshotService {
|
|
|
139
139
|
return this.sessionBaselines.get(sessionId) || {};
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// ========================================================================
|
|
143
|
+
// In-flight turn
|
|
144
|
+
// ========================================================================
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Changes made since the last capture, for a turn that is still running.
|
|
148
|
+
*
|
|
149
|
+
* The settled source of truth is `captureSnapshot`, but it only lands when
|
|
150
|
+
* the stream ends — and the AI-change indicators have to light up while the
|
|
151
|
+
* model is still working. This answers the same question early, from the
|
|
152
|
+
* same baseline, without writing anything: no snapshot row, no baseline
|
|
153
|
+
* move, no dirty-set clear. Whatever it reports is replaced wholesale by the
|
|
154
|
+
* real capture a moment later.
|
|
155
|
+
*
|
|
156
|
+
* Candidates come from the file watcher's dirty set, so the cost is
|
|
157
|
+
* proportional to what actually changed rather than to repository size. The
|
|
158
|
+
* watcher only runs while a client is watching the project — which is
|
|
159
|
+
* exactly when a panel that renders these indicators is mounted — and any
|
|
160
|
+
* event it missed is recovered by the full scan at turn end.
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* The hash a file had when the running turn started.
|
|
164
|
+
*
|
|
165
|
+
* `known: false` means this session has no baseline at all, which is not the
|
|
166
|
+
* same as "the file is new" — the caller must not read an absent baseline as
|
|
167
|
+
* an empty file, or every file in the project would look freshly created.
|
|
168
|
+
*/
|
|
169
|
+
getBaselineHash(sessionId: string, relativePath: string): { known: boolean; hash: string } {
|
|
170
|
+
const baseline = this.sessionBaselines.get(sessionId);
|
|
171
|
+
if (!baseline) return { known: false, hash: '' };
|
|
172
|
+
return { known: true, hash: baseline[relativePath] || '' };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async getPendingChanges(
|
|
176
|
+
projectPath: string,
|
|
177
|
+
scopeKey: string,
|
|
178
|
+
sessionId: string
|
|
179
|
+
): Promise<SessionScopedChanges> {
|
|
180
|
+
// No baseline means this session has not captured or initialised yet.
|
|
181
|
+
// Building one here would hash the mid-turn disk state and declare it
|
|
182
|
+
// unchanged, blinding the indicators for the whole turn — so decline.
|
|
183
|
+
const baseline = this.sessionBaselines.get(sessionId);
|
|
184
|
+
if (!baseline) return {};
|
|
185
|
+
|
|
186
|
+
const dirty = fileWatcher.getDirtyFiles(scopeKey);
|
|
187
|
+
if (dirty.size === 0) return {};
|
|
188
|
+
|
|
189
|
+
// A path already in the baseline passed the gitignore-aware scan once, so
|
|
190
|
+
// it needs no second opinion. Only genuinely new paths do, and only those
|
|
191
|
+
// make us pay for a scan.
|
|
192
|
+
let eligible: Set<string> | null = null;
|
|
193
|
+
const hasNewPaths = Array.from(dirty).some((relativePath) => !(relativePath in baseline));
|
|
194
|
+
if (hasNewPaths) {
|
|
195
|
+
try {
|
|
196
|
+
const files = await getSnapshotFiles(projectPath);
|
|
197
|
+
eligible = new Set(
|
|
198
|
+
files.map((filepath) => path.relative(projectPath, filepath).replace(/\\/g, '/'))
|
|
199
|
+
);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
debug.warn('snapshot', 'Pending-change scan failed, reporting tracked files only:', error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const changes: SessionScopedChanges = {};
|
|
206
|
+
|
|
207
|
+
for (const relativePath of dirty) {
|
|
208
|
+
// An unknown path is only reported once the scan has vouched for it —
|
|
209
|
+
// so a build artifact or an ignored temp file never becomes a dot.
|
|
210
|
+
const oldHash = baseline[relativePath] || '';
|
|
211
|
+
if (!oldHash && !eligible?.has(relativePath)) continue;
|
|
212
|
+
|
|
213
|
+
const fullPath = path.join(projectPath, relativePath);
|
|
214
|
+
try {
|
|
215
|
+
const stat = await fs.stat(fullPath);
|
|
216
|
+
if (stat.size > MAX_FILE_SIZE) continue;
|
|
217
|
+
|
|
218
|
+
const result = await blobStore.hashFile(relativePath, fullPath);
|
|
219
|
+
if (result.hash !== oldHash) {
|
|
220
|
+
changes[relativePath] = { oldHash, newHash: result.hash };
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
// Gone from disk: a deletion when we knew the file, nothing otherwise
|
|
224
|
+
// (a temp file the turn created and removed again).
|
|
225
|
+
if (oldHash) changes[relativePath] = { oldHash, newHash: '' };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return changes;
|
|
230
|
+
}
|
|
231
|
+
|
|
142
232
|
// ========================================================================
|
|
143
233
|
// Snapshot Capture
|
|
144
234
|
// ========================================================================
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning a checkpoint's stored hashes into a file list.
|
|
3
|
+
*
|
|
4
|
+
* This is what every AI-change surface counts on: the dot in Files, the gutter
|
|
5
|
+
* in the editor, and the Changes tab all describe the same turn, so a file that
|
|
6
|
+
* this function drops is a change the user is never told about. The cases that
|
|
7
|
+
* matter are the ones where a side is absent — a creation, a deletion, a blob
|
|
8
|
+
* the store no longer has — because each of those used to be either invisible
|
|
9
|
+
* or a diff of nothing.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it, expect } from 'bun:test';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
buildTurnFiles,
|
|
16
|
+
statusOf,
|
|
17
|
+
isBinaryBuffer,
|
|
18
|
+
summariseTurnFiles,
|
|
19
|
+
excerptPrompt
|
|
20
|
+
} from './turn-changes';
|
|
21
|
+
|
|
22
|
+
/** Blob reader over an in-memory store, so the tests own their failure modes. */
|
|
23
|
+
function readerFor(blobs: Record<string, string | Buffer>) {
|
|
24
|
+
return async (hash: string): Promise<Buffer> => {
|
|
25
|
+
const value = blobs[hash];
|
|
26
|
+
if (value === undefined) throw new Error(`missing blob ${hash}`);
|
|
27
|
+
return Buffer.isBuffer(value) ? value : Buffer.from(value, 'utf8');
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('statusOf', () => {
|
|
32
|
+
it('reads a missing old side as a creation and a missing new side as a deletion', () => {
|
|
33
|
+
expect(statusOf('', 'new')).toBe('added');
|
|
34
|
+
expect(statusOf('old', '')).toBe('deleted');
|
|
35
|
+
expect(statusOf('old', 'new')).toBe('modified');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('isBinaryBuffer', () => {
|
|
40
|
+
it('calls a NUL byte binary and plain text not', () => {
|
|
41
|
+
expect(isBinaryBuffer(Buffer.from([0x68, 0x00, 0x69]))).toBe(true);
|
|
42
|
+
expect(isBinaryBuffer(Buffer.from('hello\nworld', 'utf8'))).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('buildTurnFiles', () => {
|
|
47
|
+
it('counts a modification with the lines that actually changed', async () => {
|
|
48
|
+
const files = await buildTurnFiles(
|
|
49
|
+
{ 'src/a.ts': { oldHash: 'h1', newHash: 'h2' } },
|
|
50
|
+
readerFor({ h1: 'a\nb\nc\n', h2: 'a\nB\nc\n' })
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(files).toEqual([
|
|
54
|
+
{
|
|
55
|
+
path: 'src/a.ts',
|
|
56
|
+
status: 'modified',
|
|
57
|
+
insertions: 1,
|
|
58
|
+
deletions: 1,
|
|
59
|
+
isBinary: false,
|
|
60
|
+
contentAvailable: true
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('counts a created file as all insertions', async () => {
|
|
66
|
+
const [file] = await buildTurnFiles(
|
|
67
|
+
{ 'src/new.ts': { oldHash: '', newHash: 'h2' } },
|
|
68
|
+
readerFor({ h2: 'one\ntwo\n' })
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(file.status).toBe('added');
|
|
72
|
+
expect(file.insertions).toBe(2);
|
|
73
|
+
expect(file.deletions).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('reports a deleted file, which a tool-call reading could never see', async () => {
|
|
77
|
+
const [file] = await buildTurnFiles(
|
|
78
|
+
{ 'src/gone.ts': { oldHash: 'h1', newHash: '' } },
|
|
79
|
+
readerFor({ h1: 'one\ntwo\nthree\n' })
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(file.status).toBe('deleted');
|
|
83
|
+
expect(file.insertions).toBe(0);
|
|
84
|
+
expect(file.deletions).toBe(3);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('keeps a binary file in the list but does not pretend to count its lines', async () => {
|
|
88
|
+
const [file] = await buildTurnFiles(
|
|
89
|
+
{ 'assets/logo.png': { oldHash: 'h1', newHash: 'h2' } },
|
|
90
|
+
readerFor({ h1: Buffer.from([0x89, 0x00, 0x01]), h2: Buffer.from([0x89, 0x00, 0x02]) })
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(file.isBinary).toBe(true);
|
|
94
|
+
expect(file.insertions).toBe(0);
|
|
95
|
+
expect(file.deletions).toBe(0);
|
|
96
|
+
expect(file.contentAvailable).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('keeps the row when a blob is gone, flagged so the UI can say why', async () => {
|
|
100
|
+
const [file] = await buildTurnFiles(
|
|
101
|
+
{ 'src/a.ts': { oldHash: 'missing', newHash: 'h2' } },
|
|
102
|
+
readerFor({ h2: 'a\n' })
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(file.status).toBe('modified');
|
|
106
|
+
expect(file.contentAvailable).toBe(false);
|
|
107
|
+
expect(file.insertions).toBe(0);
|
|
108
|
+
expect(file.deletions).toBe(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('orders files by path, so a refetch does not move rows under the cursor', async () => {
|
|
112
|
+
const files = await buildTurnFiles(
|
|
113
|
+
{
|
|
114
|
+
'src/z.ts': { oldHash: '', newHash: 'h' },
|
|
115
|
+
'src/a.ts': { oldHash: '', newHash: 'h' },
|
|
116
|
+
'README.md': { oldHash: '', newHash: 'h' }
|
|
117
|
+
},
|
|
118
|
+
readerFor({ h: 'x\n' })
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
expect(files.map((f) => f.path)).toEqual(['README.md', 'src/a.ts', 'src/z.ts']);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('answers an empty turn with an empty list', async () => {
|
|
125
|
+
expect(await buildTurnFiles({}, readerFor({}))).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('summariseTurnFiles', () => {
|
|
130
|
+
it('adds up a turn for its header', async () => {
|
|
131
|
+
const files = await buildTurnFiles(
|
|
132
|
+
{
|
|
133
|
+
'src/a.ts': { oldHash: 'h1', newHash: 'h2' },
|
|
134
|
+
'src/b.ts': { oldHash: '', newHash: 'h3' }
|
|
135
|
+
},
|
|
136
|
+
readerFor({ h1: 'a\n', h2: 'b\n', h3: 'c\nd\n' })
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(summariseTurnFiles(files)).toEqual({
|
|
140
|
+
filesChanged: 2,
|
|
141
|
+
insertions: 3,
|
|
142
|
+
deletions: 1
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('excerptPrompt', () => {
|
|
148
|
+
it('returns a short prompt whole, trimmed', () => {
|
|
149
|
+
expect(excerptPrompt(' make the theme green ', 20)).toBe('make the theme green');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('marks a cut prompt, so a row never reads as the whole question', () => {
|
|
153
|
+
expect(excerptPrompt('abcdefghij', 5)).toBe('abcde…');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('does not leave the ellipsis hanging off a space', () => {
|
|
157
|
+
expect(excerptPrompt('abc def ghi', 4)).toBe('abc…');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('answers empty for an empty prompt', () => {
|
|
161
|
+
expect(excerptPrompt(' ', 10)).toBe('');
|
|
162
|
+
});
|
|
163
|
+
});
|