@myrialabs/clopen 0.4.38 → 0.4.40
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/auth/permissions.ts +48 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +9 -1
- 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/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/db-client-connection-queries.ts +19 -0
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +10 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- package/backend/database/queries/worktree-branch-queries.ts +331 -0
- package/backend/db-client/cloning.test.ts +161 -0
- package/backend/db-client/cloning.ts +672 -0
- package/backend/db-client/connection-url.test.ts +117 -0
- package/backend/db-client/connection-url.ts +126 -0
- package/backend/db-client/drivers/mongodb.ts +2 -14
- package/backend/db-client/drivers/mysql.ts +2 -8
- package/backend/db-client/drivers/postgres.ts +10 -13
- package/backend/db-client/drivers/redis.ts +2 -6
- package/backend/db-client/env/detect.ts +438 -0
- package/backend/db-client/env/diff.ts +94 -0
- package/backend/db-client/env/env.test.ts +574 -0
- package/backend/db-client/env/index.ts +15 -0
- package/backend/db-client/env/naming.ts +202 -0
- package/backend/db-client/env/service.ts +487 -0
- package/backend/db-client/integrations/index.ts +44 -0
- package/backend/db-client/integrations/links.ts +564 -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/neon/adapter.ts +522 -0
- package/backend/db-client/providers/neon/api-types.ts +182 -0
- package/backend/db-client/providers/neon/client.ts +298 -0
- package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
- package/backend/db-client/providers/neon/endpoints.ts +314 -0
- package/backend/db-client/providers/neon/list.test.ts +181 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +523 -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 +194 -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/env-files/discovery.ts +48 -0
- package/backend/env-files/edit.ts +213 -0
- package/backend/env-files/env-files.test.ts +515 -0
- package/backend/env-files/git.ts +27 -0
- package/backend/env-files/index.ts +44 -0
- package/backend/env-files/keys.ts +69 -0
- package/backend/env-files/parse.ts +157 -0
- package/backend/env-files/write.ts +229 -0
- package/backend/index.ts +4 -0
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +28 -9
- package/backend/integrations/registry/index.ts +8 -1
- package/backend/integrations/registry/providers/context7.ts +1 -0
- package/backend/integrations/registry/providers/firecrawl.ts +1 -0
- package/backend/integrations/registry/providers/github.ts +1 -0
- package/backend/integrations/registry/providers/neon.ts +55 -0
- package/backend/integrations/registry/providers/supabase.ts +62 -0
- package/backend/integrations/registry/providers/vercel.ts +47 -0
- package/backend/integrations/registry/types.ts +2 -0
- 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/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/start-work.ts +4 -0
- package/backend/worktrees/branching/engine.ts +557 -0
- package/backend/worktrees/branching/index.ts +56 -0
- package/backend/worktrees/branching/naming.test.ts +118 -0
- package/backend/worktrees/branching/naming.ts +97 -0
- package/backend/worktrees/branching/projector.test.ts +229 -0
- package/backend/worktrees/branching/projector.ts +139 -0
- package/backend/worktrees/branching/providers/neon.ts +220 -0
- package/backend/worktrees/branching/registry.ts +27 -0
- package/backend/worktrees/branching/service.ts +620 -0
- package/backend/worktrees/branching/suggest.test.ts +154 -0
- package/backend/worktrees/branching/suggest.ts +202 -0
- package/backend/worktrees/branching/types.ts +88 -0
- package/backend/worktrees/index.ts +7 -0
- package/backend/worktrees/service.ts +48 -1
- 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/env.ts +142 -0
- package/backend/ws/db-client/index.ts +22 -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/index.ts +6 -2
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/projects/index.ts +6 -1
- package/backend/ws/projects/info.ts +70 -6
- package/backend/ws/projects/overview.test.ts +108 -0
- package/backend/ws/projects/overview.ts +300 -0
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/backend/ws/system/device-info.ts +307 -76
- package/backend/ws/worktrees/branching.ts +212 -0
- package/backend/ws/worktrees/crud.ts +33 -7
- package/backend/ws/worktrees/index.ts +14 -0
- package/dist/assets/{index-DSHIANSy.js → index-D4igjF6e.js} +1 -1
- package/dist/assets/{index-CyH7fSbR.js → index-DONNwiXm.js} +1 -1
- package/dist/assets/main-BrfXH1bL.js +1205 -0
- package/dist/assets/main-CT1PygsW.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +13 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +3 -0
- package/shared/types/db-client/integrations.ts +204 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +2 -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-D2IOjftb.css +0 -1
- package/dist/assets/main-DM-tHKbW.js +0 -1152
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn file changes, read from checkpoint snapshots.
|
|
3
|
+
*
|
|
4
|
+
* This is the source of truth for "what did this turn change", and it is
|
|
5
|
+
* deliberately NOT derived from tool calls. A snapshot is a gitignore-aware
|
|
6
|
+
* disk diff, so it sees a file rewritten by `sed`, a formatter, a codemod, an
|
|
7
|
+
* `apply_patch`, a notebook edit or a sub-agent — none of which necessarily
|
|
8
|
+
* surface as an Edit/Write tool_use, and several of which reach the frontend
|
|
9
|
+
* with their inputs stripped (see subagent-wire-trim.ts). Reading the disk
|
|
10
|
+
* instead of the transcript means a tool that does not exist yet is already
|
|
11
|
+
* handled.
|
|
12
|
+
*
|
|
13
|
+
* The trade-off is honest and must stay visible in the UI: a turn's delta is
|
|
14
|
+
* everything that changed on disk while the turn ran, which can include the
|
|
15
|
+
* user's own save or a build artifact that no .gitignore covers. It is "changed
|
|
16
|
+
* during this turn", not "provably written by the model".
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { SessionScopedChanges } from '$shared/types/database/schema';
|
|
20
|
+
import { countLineChanges, isBinaryBuffer } from '$shared/utils/diff-calculator';
|
|
21
|
+
|
|
22
|
+
export { isBinaryBuffer };
|
|
23
|
+
|
|
24
|
+
export type TurnFileStatus = 'added' | 'modified' | 'deleted';
|
|
25
|
+
|
|
26
|
+
export interface TurnFileChange {
|
|
27
|
+
/** Project-relative path with forward slashes, as stored in the snapshot. */
|
|
28
|
+
path: string;
|
|
29
|
+
status: TurnFileStatus;
|
|
30
|
+
insertions: number;
|
|
31
|
+
deletions: number;
|
|
32
|
+
isBinary: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* False when a blob this file needs is no longer readable. The change still
|
|
35
|
+
* happened — only its content is gone — so the row is kept and the UI says
|
|
36
|
+
* so, rather than rendering a diff of nothing.
|
|
37
|
+
*/
|
|
38
|
+
contentAvailable: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Which way a file moved, decided by which side of the change has content. */
|
|
42
|
+
export function statusOf(oldHash: string, newHash: string): TurnFileStatus {
|
|
43
|
+
if (!oldHash) return 'added';
|
|
44
|
+
if (!newHash) return 'deleted';
|
|
45
|
+
return 'modified';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Turn one checkpoint's `session_changes` into a displayable file list.
|
|
50
|
+
*
|
|
51
|
+
* `readBlob` is injected so this stays a pure function over its inputs — the
|
|
52
|
+
* only I/O is the reader the caller hands in.
|
|
53
|
+
*/
|
|
54
|
+
export async function buildTurnFiles(
|
|
55
|
+
changes: SessionScopedChanges,
|
|
56
|
+
readBlob: (hash: string) => Promise<Buffer>
|
|
57
|
+
): Promise<TurnFileChange[]> {
|
|
58
|
+
const files: TurnFileChange[] = [];
|
|
59
|
+
|
|
60
|
+
for (const [path, change] of Object.entries(changes)) {
|
|
61
|
+
const status = statusOf(change.oldHash, change.newHash);
|
|
62
|
+
|
|
63
|
+
let oldBuf: Buffer | null = null;
|
|
64
|
+
let newBuf: Buffer | null = null;
|
|
65
|
+
let contentAvailable = true;
|
|
66
|
+
|
|
67
|
+
if (change.oldHash) {
|
|
68
|
+
try {
|
|
69
|
+
oldBuf = await readBlob(change.oldHash);
|
|
70
|
+
} catch {
|
|
71
|
+
contentAvailable = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (change.newHash) {
|
|
75
|
+
try {
|
|
76
|
+
newBuf = await readBlob(change.newHash);
|
|
77
|
+
} catch {
|
|
78
|
+
contentAvailable = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const isBinary =
|
|
83
|
+
(oldBuf !== null && isBinaryBuffer(oldBuf)) || (newBuf !== null && isBinaryBuffer(newBuf));
|
|
84
|
+
|
|
85
|
+
let insertions = 0;
|
|
86
|
+
let deletions = 0;
|
|
87
|
+
if (contentAvailable && !isBinary) {
|
|
88
|
+
const counts = countLineChanges(
|
|
89
|
+
oldBuf ? oldBuf.toString('utf8') : '',
|
|
90
|
+
newBuf ? newBuf.toString('utf8') : ''
|
|
91
|
+
);
|
|
92
|
+
insertions = counts.additions;
|
|
93
|
+
deletions = counts.deletions;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
files.push({ path, status, insertions, deletions, isBinary, contentAvailable });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Alphabetical: a turn's file list is read as a checklist, and a stable order
|
|
100
|
+
// is what lets the eye return to the same row after a refetch.
|
|
101
|
+
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
102
|
+
return files;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The prompt excerpt a turn row shows.
|
|
107
|
+
*
|
|
108
|
+
* Bounded because a single instruction can run to thousands of characters and
|
|
109
|
+
* every turn of the chat is sent at once, but cut marks itself with an ellipsis:
|
|
110
|
+
* a row that silently ends mid-sentence reads as the whole question.
|
|
111
|
+
*/
|
|
112
|
+
export function excerptPrompt(text: string, limit: number): string {
|
|
113
|
+
const trimmed = text.trim();
|
|
114
|
+
if (trimmed.length <= limit) return trimmed;
|
|
115
|
+
return `${trimmed.slice(0, limit).trimEnd()}…`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Roll a turn's file list up into the numbers a turn header shows. */
|
|
119
|
+
export function summariseTurnFiles(files: TurnFileChange[]): {
|
|
120
|
+
filesChanged: number;
|
|
121
|
+
insertions: number;
|
|
122
|
+
deletions: number;
|
|
123
|
+
} {
|
|
124
|
+
let insertions = 0;
|
|
125
|
+
let deletions = 0;
|
|
126
|
+
for (const file of files) {
|
|
127
|
+
insertions += file.insertions;
|
|
128
|
+
deletions += file.deletions;
|
|
129
|
+
}
|
|
130
|
+
return { filesChanged: files.length, insertions, deletions };
|
|
131
|
+
}
|
|
@@ -41,6 +41,10 @@ function slugify(text: string, maxWords = 6): string {
|
|
|
41
41
|
return text
|
|
42
42
|
.toLowerCase()
|
|
43
43
|
.normalize('NFKD')
|
|
44
|
+
// Combining marks are dropped rather than left for the character class to
|
|
45
|
+
// turn into spaces: `ü` decomposes to `u` + a diaeresis, and without this
|
|
46
|
+
// an issue titled "münchen" produces the branch `mu-nchen`.
|
|
47
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
44
48
|
.replace(/[^\w\s-]/g, ' ')
|
|
45
49
|
.trim()
|
|
46
50
|
.split(/[\s_-]+/)
|