redlinify 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +341 -2
- package/dist/_shared/atomicFs.d.ts +10 -0
- package/dist/_shared/atomicFs.d.ts.map +1 -0
- package/dist/_shared/atomicFs.js +86 -0
- package/dist/_shared/atomicFs.js.map +1 -0
- package/dist/_shared/browser.d.ts +7 -0
- package/dist/_shared/browser.d.ts.map +1 -0
- package/dist/_shared/browser.js +7 -0
- package/dist/_shared/browser.js.map +1 -0
- package/dist/_shared/canonical.d.ts +8 -0
- package/dist/_shared/canonical.d.ts.map +1 -0
- package/dist/_shared/canonical.js +28 -0
- package/dist/_shared/canonical.js.map +1 -0
- package/dist/_shared/diff.d.ts +78 -0
- package/dist/_shared/diff.d.ts.map +1 -0
- package/dist/_shared/diff.js +350 -0
- package/dist/_shared/diff.js.map +1 -0
- package/dist/_shared/errors.d.ts +29 -0
- package/dist/_shared/errors.d.ts.map +1 -0
- package/dist/_shared/errors.js +46 -0
- package/dist/_shared/errors.js.map +1 -0
- package/dist/_shared/fileLock.d.ts +11 -0
- package/dist/_shared/fileLock.d.ts.map +1 -0
- package/dist/_shared/fileLock.js +114 -0
- package/dist/_shared/fileLock.js.map +1 -0
- package/dist/_shared/guards.d.ts +20 -0
- package/dist/_shared/guards.d.ts.map +1 -0
- package/dist/_shared/guards.js +395 -0
- package/dist/_shared/guards.js.map +1 -0
- package/dist/_shared/hash.d.ts +12 -0
- package/dist/_shared/hash.d.ts.map +1 -0
- package/dist/_shared/hash.js +80 -0
- package/dist/_shared/hash.js.map +1 -0
- package/dist/_shared/index.d.ts +9 -0
- package/dist/_shared/index.d.ts.map +1 -0
- package/dist/_shared/index.js +9 -0
- package/dist/_shared/index.js.map +1 -0
- package/dist/_shared/schemas.d.ts +727 -0
- package/dist/_shared/schemas.d.ts.map +1 -0
- package/dist/_shared/schemas.js +352 -0
- package/dist/_shared/schemas.js.map +1 -0
- package/dist/_shared/storage.d.ts +174 -0
- package/dist/_shared/storage.d.ts.map +1 -0
- package/dist/_shared/storage.js +801 -0
- package/dist/_shared/storage.js.map +1 -0
- package/dist/_shared/threadStatus.d.ts +5 -0
- package/dist/_shared/threadStatus.d.ts.map +1 -0
- package/dist/_shared/threadStatus.js +18 -0
- package/dist/_shared/threadStatus.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +269 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +19 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +654 -0
- package/dist/mcp.js.map +1 -0
- package/dist/preferences.d.ts +5 -0
- package/dist/preferences.d.ts.map +1 -0
- package/dist/preferences.js +56 -0
- package/dist/preferences.js.map +1 -0
- package/dist/uiDaemon.d.ts +47 -0
- package/dist/uiDaemon.d.ts.map +1 -0
- package/dist/uiDaemon.js +351 -0
- package/dist/uiDaemon.js.map +1 -0
- package/dist/updater.d.ts +35 -0
- package/dist/updater.d.ts.map +1 -0
- package/dist/updater.js +336 -0
- package/dist/updater.js.map +1 -0
- package/dist/web.d.ts +29 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +648 -0
- package/dist/web.js.map +1 -0
- package/package.json +51 -4
- package/skill/SKILL.md +36 -0
- package/ui-dist/assets/elkjs-DuIp8wh-.js +26 -0
- package/ui-dist/assets/index-DhMWEByx.css +1 -0
- package/ui-dist/assets/index-Dy_FwyNG.js +99 -0
- package/ui-dist/assets/vendor-icons-IOjDvVjt.js +261 -0
- package/ui-dist/assets/vendor-react-5-35apmZ.js +49 -0
- package/ui-dist/assets/vendor-xyflow-BnuhLJ6X.css +1 -0
- package/ui-dist/assets/vendor-xyflow-cY2i6Lf0.js +23 -0
- package/ui-dist/index.html +29 -0
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { ZodError } from "zod";
|
|
7
|
+
import { pathExists, readJsonFile, writeJsonAtomic } from "./atomicFs.js";
|
|
8
|
+
import { computeSemanticDiff } from "./diff.js";
|
|
9
|
+
import { ConcurrencyConflictError, LockViolationError, NotFoundError, ValidationError, } from "./errors.js";
|
|
10
|
+
import { withFileLock } from "./fileLock.js";
|
|
11
|
+
export { writeJsonAtomic };
|
|
12
|
+
import { applyViewPatch, checkLockViolations, mergePreservedCodeRefs, } from "./guards.js";
|
|
13
|
+
import { computeViewHash } from "./hash.js";
|
|
14
|
+
import { CodeRefUpdateSchema, DesignThreadSchema, DesignViewSchema, ViewLayoutSchema, ViewRequestSchema, WorkspaceFileSchema, idSlugSchema, } from "./schemas.js";
|
|
15
|
+
const execFileAsync = promisify(execFile);
|
|
16
|
+
export const DESIGN_DIR_NAME = ".design";
|
|
17
|
+
const DESIGN_GITIGNORE_CONTENT = `.layout/
|
|
18
|
+
.checkpoint/
|
|
19
|
+
.lock
|
|
20
|
+
.tmp-*
|
|
21
|
+
.ui-server.json
|
|
22
|
+
`;
|
|
23
|
+
import { isThreadPendingForAgent, isThreadWaitingOnAgent, isThreadWaitingOnHuman, } from "./threadStatus.js";
|
|
24
|
+
export { isThreadPendingForAgent, isThreadWaitingOnAgent, isThreadWaitingOnHuman, };
|
|
25
|
+
/**
|
|
26
|
+
* Walks upward from `startDir` looking for `.design/` first, then `.git/`,
|
|
27
|
+
* falling back to `path.resolve(startDir)` if neither exists.
|
|
28
|
+
*/
|
|
29
|
+
export async function findProjectRoot(startDir) {
|
|
30
|
+
const start = path.resolve(startDir);
|
|
31
|
+
let current = start;
|
|
32
|
+
while (true) {
|
|
33
|
+
if (await pathExists(path.join(current, DESIGN_DIR_NAME))) {
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
if (await pathExists(path.join(current, ".git"))) {
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
const parent = path.dirname(current);
|
|
40
|
+
if (parent === current)
|
|
41
|
+
break;
|
|
42
|
+
current = parent;
|
|
43
|
+
}
|
|
44
|
+
return start;
|
|
45
|
+
}
|
|
46
|
+
export class DesignStorage {
|
|
47
|
+
rootDir;
|
|
48
|
+
designDir;
|
|
49
|
+
workspacePath;
|
|
50
|
+
viewsDir;
|
|
51
|
+
threadsDir;
|
|
52
|
+
layoutDir;
|
|
53
|
+
checkpointDir;
|
|
54
|
+
gitignorePath;
|
|
55
|
+
lockPath;
|
|
56
|
+
lockTimeoutMs;
|
|
57
|
+
staleLockMs;
|
|
58
|
+
constructor(rootDir, options) {
|
|
59
|
+
this.rootDir = path.resolve(rootDir);
|
|
60
|
+
this.designDir = path.join(this.rootDir, DESIGN_DIR_NAME);
|
|
61
|
+
this.workspacePath = path.join(this.designDir, "workspace.json");
|
|
62
|
+
this.viewsDir = path.join(this.designDir, "views");
|
|
63
|
+
this.threadsDir = path.join(this.designDir, "threads");
|
|
64
|
+
this.layoutDir = path.join(this.designDir, ".layout");
|
|
65
|
+
this.checkpointDir = path.join(this.designDir, ".checkpoint");
|
|
66
|
+
this.gitignorePath = path.join(this.designDir, ".gitignore");
|
|
67
|
+
this.lockPath = path.join(this.designDir, ".lock");
|
|
68
|
+
this.lockTimeoutMs = options?.lockTimeoutMs ?? 5000;
|
|
69
|
+
this.staleLockMs = options?.staleLockMs ?? 15000;
|
|
70
|
+
}
|
|
71
|
+
viewPath(viewId) {
|
|
72
|
+
const valid = idSlugSchema("view_id").parse(viewId);
|
|
73
|
+
return path.join(this.viewsDir, `${valid}.json`);
|
|
74
|
+
}
|
|
75
|
+
checkpointPath(viewId) {
|
|
76
|
+
const valid = idSlugSchema("view_id").parse(viewId);
|
|
77
|
+
return path.join(this.checkpointDir, `${valid}.json`);
|
|
78
|
+
}
|
|
79
|
+
layoutPath(viewId) {
|
|
80
|
+
const valid = idSlugSchema("view_id").parse(viewId);
|
|
81
|
+
return path.join(this.layoutDir, `${valid}.json`);
|
|
82
|
+
}
|
|
83
|
+
threadPath(threadId) {
|
|
84
|
+
const valid = idSlugSchema("thread_id").parse(threadId);
|
|
85
|
+
return path.join(this.threadsDir, `${valid}.json`);
|
|
86
|
+
}
|
|
87
|
+
async ensureDirsUnlocked() {
|
|
88
|
+
await fs.mkdir(this.designDir, { recursive: true });
|
|
89
|
+
await fs.mkdir(this.viewsDir, { recursive: true });
|
|
90
|
+
await fs.mkdir(this.threadsDir, { recursive: true });
|
|
91
|
+
await fs.mkdir(this.layoutDir, { recursive: true });
|
|
92
|
+
await fs.mkdir(this.checkpointDir, { recursive: true });
|
|
93
|
+
if (!(await pathExists(this.gitignorePath))) {
|
|
94
|
+
await fs.writeFile(this.gitignorePath, DESIGN_GITIGNORE_CONTENT, "utf8");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Acquires the cross-process `.design/.lock` mutex with retry backoff and
|
|
99
|
+
* stale-lock recovery before running `fn`. Never nest `withLock` calls.
|
|
100
|
+
*/
|
|
101
|
+
async withLock(fn) {
|
|
102
|
+
return withFileLock(this.lockPath, fn, {
|
|
103
|
+
lockTimeoutMs: this.lockTimeoutMs,
|
|
104
|
+
staleLockMs: this.staleLockMs,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async initWorkspace(projectName) {
|
|
108
|
+
return this.withLock(async () => {
|
|
109
|
+
await this.ensureDirsUnlocked();
|
|
110
|
+
if (!(await pathExists(this.gitignorePath))) {
|
|
111
|
+
await fs.writeFile(this.gitignorePath, DESIGN_GITIGNORE_CONTENT, "utf8");
|
|
112
|
+
}
|
|
113
|
+
if (await pathExists(this.workspacePath)) {
|
|
114
|
+
return this.readWorkspaceUnlocked();
|
|
115
|
+
}
|
|
116
|
+
const ws = WorkspaceFileSchema.parse({
|
|
117
|
+
version: 1,
|
|
118
|
+
project_name: projectName?.trim() || path.basename(this.rootDir) || "redlinify-project",
|
|
119
|
+
tabs: [],
|
|
120
|
+
view_requests: [],
|
|
121
|
+
});
|
|
122
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
123
|
+
return ws;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async readWorkspaceUnlocked() {
|
|
127
|
+
return readJsonFile(this.workspacePath, WorkspaceFileSchema, "workspace.json");
|
|
128
|
+
}
|
|
129
|
+
async ensureWorkspaceUnlocked() {
|
|
130
|
+
await this.ensureDirsUnlocked();
|
|
131
|
+
if (await pathExists(this.workspacePath)) {
|
|
132
|
+
return this.readWorkspaceUnlocked();
|
|
133
|
+
}
|
|
134
|
+
const ws = WorkspaceFileSchema.parse({
|
|
135
|
+
version: 1,
|
|
136
|
+
project_name: path.basename(this.rootDir) || "redlinify-project",
|
|
137
|
+
tabs: [],
|
|
138
|
+
view_requests: [],
|
|
139
|
+
});
|
|
140
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
141
|
+
return ws;
|
|
142
|
+
}
|
|
143
|
+
async readWorkspace() {
|
|
144
|
+
return this.readWorkspaceUnlocked();
|
|
145
|
+
}
|
|
146
|
+
async writeWorkspace(workspace) {
|
|
147
|
+
const parsed = WorkspaceFileSchema.parse(workspace);
|
|
148
|
+
return this.withLock(async () => {
|
|
149
|
+
await this.ensureDirsUnlocked();
|
|
150
|
+
await writeJsonAtomic(this.workspacePath, parsed);
|
|
151
|
+
return parsed;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async addViewRequest(input) {
|
|
155
|
+
return this.withLock(async () => {
|
|
156
|
+
const ws = await this.ensureWorkspaceUnlocked();
|
|
157
|
+
const id = input.id
|
|
158
|
+
? idSlugSchema("view_request.id").parse(input.id)
|
|
159
|
+
: `req_${randomBytes(4).toString("hex")}`;
|
|
160
|
+
if (ws.view_requests.some((r) => r.id === id)) {
|
|
161
|
+
throw new ValidationError(`View request '${id}' already exists`);
|
|
162
|
+
}
|
|
163
|
+
const req = ViewRequestSchemaOrThrow({
|
|
164
|
+
id,
|
|
165
|
+
title: input.title,
|
|
166
|
+
prompt: input.prompt,
|
|
167
|
+
created_at: new Date().toISOString(),
|
|
168
|
+
});
|
|
169
|
+
ws.view_requests.push(req);
|
|
170
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
171
|
+
return req;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async deleteViewRequest(requestId) {
|
|
175
|
+
const validId = idSlugSchema("view_request.id").parse(requestId);
|
|
176
|
+
await this.withLock(async () => {
|
|
177
|
+
const ws = await this.readWorkspaceUnlocked();
|
|
178
|
+
const next = ws.view_requests.filter((r) => r.id !== validId);
|
|
179
|
+
if (next.length === ws.view_requests.length) {
|
|
180
|
+
throw new NotFoundError(`View request '${validId}' not found`);
|
|
181
|
+
}
|
|
182
|
+
ws.view_requests = next;
|
|
183
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async listViewIdsUnlocked() {
|
|
187
|
+
let entries;
|
|
188
|
+
try {
|
|
189
|
+
entries = await fs.readdir(this.viewsDir);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
if (err.code === "ENOENT") {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
throw err;
|
|
196
|
+
}
|
|
197
|
+
const ids = [];
|
|
198
|
+
for (const entry of entries) {
|
|
199
|
+
if (!entry.endsWith(".json") || entry.startsWith(".tmp-"))
|
|
200
|
+
continue;
|
|
201
|
+
const base = entry.slice(0, -5);
|
|
202
|
+
const parsed = idSlugSchema("view_id").safeParse(base);
|
|
203
|
+
if (parsed.success) {
|
|
204
|
+
ids.push(parsed.data);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return ids.sort((a, b) => a.localeCompare(b));
|
|
208
|
+
}
|
|
209
|
+
async listViewIds() {
|
|
210
|
+
return this.listViewIdsUnlocked();
|
|
211
|
+
}
|
|
212
|
+
async readViewUnlocked(viewId) {
|
|
213
|
+
const filePath = this.viewPath(viewId);
|
|
214
|
+
const view = await readJsonFile(filePath, DesignViewSchema, `view '${viewId}'`);
|
|
215
|
+
return { view, view_hash: computeViewHash(view) };
|
|
216
|
+
}
|
|
217
|
+
async readView(viewId) {
|
|
218
|
+
return this.readViewUnlocked(viewId);
|
|
219
|
+
}
|
|
220
|
+
async readCheckpoint(viewId) {
|
|
221
|
+
const filePath = this.checkpointPath(viewId);
|
|
222
|
+
if (!(await pathExists(filePath)))
|
|
223
|
+
return null;
|
|
224
|
+
return readJsonFile(filePath, DesignViewSchema, `checkpoint '${viewId}'`);
|
|
225
|
+
}
|
|
226
|
+
async resolveCheckpointBaselineUnlocked(viewId, currentView) {
|
|
227
|
+
const cpPath = this.checkpointPath(viewId);
|
|
228
|
+
if (await pathExists(cpPath)) {
|
|
229
|
+
return readJsonFile(cpPath, DesignViewSchema, `checkpoint '${viewId}'`);
|
|
230
|
+
}
|
|
231
|
+
if (currentView.created_by === "human") {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
// Missing checkpoint for an agent/repo-tracked view (e.g. fresh git clone):
|
|
235
|
+
// try HEAD version from git before falling back to current view.
|
|
236
|
+
try {
|
|
237
|
+
const { stdout } = await execFileAsync("git", ["show", `HEAD:${DESIGN_DIR_NAME}/views/${viewId}.json`], { cwd: this.rootDir, timeout: 3000 });
|
|
238
|
+
const parsedHead = DesignViewSchema.safeParse(JSON.parse(stdout));
|
|
239
|
+
if (parsedHead.success) {
|
|
240
|
+
await writeJsonAtomic(cpPath, parsedHead.data);
|
|
241
|
+
return parsedHead.data;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Not in a git repo, no HEAD commit, or view is untracked
|
|
246
|
+
}
|
|
247
|
+
await writeJsonAtomic(cpPath, currentView);
|
|
248
|
+
return currentView;
|
|
249
|
+
}
|
|
250
|
+
async resolveCheckpointBaseline(viewId, currentView) {
|
|
251
|
+
return this.withLock(async () => this.resolveCheckpointBaselineUnlocked(viewId, currentView));
|
|
252
|
+
}
|
|
253
|
+
async upsertView(input) {
|
|
254
|
+
let parsedView;
|
|
255
|
+
try {
|
|
256
|
+
parsedView = DesignViewSchema.parse(input.view);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
if (err instanceof ZodError) {
|
|
260
|
+
throw new ValidationError(`Invalid view schema: ${err.message}`, err.issues);
|
|
261
|
+
}
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
264
|
+
return this.withLock(async () => {
|
|
265
|
+
await this.ensureDirsUnlocked();
|
|
266
|
+
const filePath = this.viewPath(parsedView.id);
|
|
267
|
+
const exists = await pathExists(filePath);
|
|
268
|
+
const existingView = exists
|
|
269
|
+
? await readJsonFile(filePath, DesignViewSchema, `view '${parsedView.id}'`)
|
|
270
|
+
: null;
|
|
271
|
+
if (existingView) {
|
|
272
|
+
const existingHash = computeViewHash(existingView);
|
|
273
|
+
const requireHash = (input.actor === "agent" && !input.force) ||
|
|
274
|
+
input.base_hash !== undefined;
|
|
275
|
+
if (requireHash) {
|
|
276
|
+
if (!input.base_hash) {
|
|
277
|
+
throw new ConcurrencyConflictError(parsedView.id, null, existingHash, `base_hash is required when updating existing view '${parsedView.id}'`);
|
|
278
|
+
}
|
|
279
|
+
if (input.base_hash !== existingHash) {
|
|
280
|
+
throw new ConcurrencyConflictError(parsedView.id, input.base_hash, existingHash);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
let nextView = input.actor === "agent"
|
|
285
|
+
? mergePreservedCodeRefs(existingView, parsedView)
|
|
286
|
+
: structuredClone(parsedView);
|
|
287
|
+
if (!existingView && nextView.created_by === undefined) {
|
|
288
|
+
nextView = { ...nextView, created_by: input.actor };
|
|
289
|
+
}
|
|
290
|
+
else if (existingView &&
|
|
291
|
+
nextView.created_by === undefined &&
|
|
292
|
+
existingView.created_by !== undefined) {
|
|
293
|
+
nextView = { ...nextView, created_by: existingView.created_by };
|
|
294
|
+
}
|
|
295
|
+
if (existingView && input.actor === "agent") {
|
|
296
|
+
const violations = checkLockViolations(existingView, nextView);
|
|
297
|
+
if (violations.length > 0) {
|
|
298
|
+
throw new LockViolationError(violations);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
await writeJsonAtomic(filePath, nextView);
|
|
302
|
+
const ws = await this.ensureWorkspaceUnlocked();
|
|
303
|
+
const existingTab = ws.tabs.find((t) => t.view_id === nextView.id);
|
|
304
|
+
if (existingTab) {
|
|
305
|
+
existingTab.title = nextView.title;
|
|
306
|
+
existingTab.diagram_type = nextView.diagram_type;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
const maxOrder = ws.tabs.reduce((max, t) => Math.max(max, t.order), -1);
|
|
310
|
+
ws.tabs.push({
|
|
311
|
+
view_id: nextView.id,
|
|
312
|
+
title: nextView.title,
|
|
313
|
+
diagram_type: nextView.diagram_type,
|
|
314
|
+
order: maxOrder + 1,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (input.fulfill_request_id) {
|
|
318
|
+
ws.view_requests = ws.view_requests.filter((r) => r.id !== input.fulfill_request_id);
|
|
319
|
+
}
|
|
320
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
321
|
+
if (input.actor === "agent") {
|
|
322
|
+
await writeJsonAtomic(this.checkpointPath(nextView.id), nextView);
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
view: nextView,
|
|
326
|
+
view_hash: computeViewHash(nextView),
|
|
327
|
+
created: !existingView,
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
async patchView(input) {
|
|
332
|
+
const validId = idSlugSchema("view_id").parse(input.view_id);
|
|
333
|
+
return this.withLock(async () => {
|
|
334
|
+
await this.ensureDirsUnlocked();
|
|
335
|
+
const { view: existingView, view_hash: existingHash } = await this.readViewUnlocked(validId);
|
|
336
|
+
if (input.base_hash !== existingHash) {
|
|
337
|
+
throw new ConcurrencyConflictError(validId, input.base_hash, existingHash);
|
|
338
|
+
}
|
|
339
|
+
const nextView = applyViewPatch(existingView, input.patch);
|
|
340
|
+
if (input.actor === "agent") {
|
|
341
|
+
const violations = checkLockViolations(existingView, nextView);
|
|
342
|
+
if (violations.length > 0) {
|
|
343
|
+
throw new LockViolationError(violations);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
await writeJsonAtomic(this.viewPath(validId), nextView);
|
|
347
|
+
if ((nextView.title !== existingView.title ||
|
|
348
|
+
nextView.diagram_type !== existingView.diagram_type) &&
|
|
349
|
+
(await pathExists(this.workspacePath))) {
|
|
350
|
+
const ws = await this.readWorkspaceUnlocked();
|
|
351
|
+
const tab = ws.tabs.find((t) => t.view_id === validId);
|
|
352
|
+
if (tab) {
|
|
353
|
+
tab.title = nextView.title;
|
|
354
|
+
tab.diagram_type = nextView.diagram_type;
|
|
355
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (input.actor === "agent") {
|
|
359
|
+
await writeJsonAtomic(this.checkpointPath(validId), nextView);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
view: nextView,
|
|
363
|
+
view_hash: computeViewHash(nextView),
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
async deleteView(viewId) {
|
|
368
|
+
const validId = idSlugSchema("view_id").parse(viewId);
|
|
369
|
+
return this.withLock(async () => {
|
|
370
|
+
const filePath = this.viewPath(validId);
|
|
371
|
+
if (!(await pathExists(filePath))) {
|
|
372
|
+
throw new NotFoundError(`View '${validId}' not found`);
|
|
373
|
+
}
|
|
374
|
+
await fs.unlink(filePath);
|
|
375
|
+
await fs.unlink(this.layoutPath(validId)).catch((err) => {
|
|
376
|
+
if (err.code !== "ENOENT")
|
|
377
|
+
throw err;
|
|
378
|
+
});
|
|
379
|
+
await fs.unlink(this.checkpointPath(validId)).catch((err) => {
|
|
380
|
+
if (err.code !== "ENOENT")
|
|
381
|
+
throw err;
|
|
382
|
+
});
|
|
383
|
+
if (await pathExists(this.workspacePath)) {
|
|
384
|
+
const ws = await this.readWorkspaceUnlocked();
|
|
385
|
+
ws.tabs = ws.tabs
|
|
386
|
+
.filter((t) => t.view_id !== validId)
|
|
387
|
+
.sort((a, b) => a.order - b.order)
|
|
388
|
+
.map((t, idx) => ({ ...t, order: idx }));
|
|
389
|
+
await writeJsonAtomic(this.workspacePath, ws);
|
|
390
|
+
}
|
|
391
|
+
return { deleted: true, view_id: validId };
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
async acknowledgeFeedback(entries) {
|
|
395
|
+
return this.withLock(async () => {
|
|
396
|
+
await this.ensureDirsUnlocked();
|
|
397
|
+
const verified = [];
|
|
398
|
+
for (const entry of entries) {
|
|
399
|
+
const validId = idSlugSchema("view_id").parse(entry.view_id);
|
|
400
|
+
const { view, view_hash } = await this.readViewUnlocked(validId);
|
|
401
|
+
if (entry.base_hash !== view_hash) {
|
|
402
|
+
throw new ConcurrencyConflictError(validId, entry.base_hash, view_hash);
|
|
403
|
+
}
|
|
404
|
+
verified.push({ view_id: validId, view, hash: view_hash });
|
|
405
|
+
}
|
|
406
|
+
for (const item of verified) {
|
|
407
|
+
await writeJsonAtomic(this.checkpointPath(item.view_id), item.view);
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
acknowledged: verified.map((v) => ({
|
|
411
|
+
view_id: v.view_id,
|
|
412
|
+
view_hash: v.hash,
|
|
413
|
+
})),
|
|
414
|
+
};
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async syncCodeRefs(input) {
|
|
418
|
+
const validId = idSlugSchema("view_id").parse(input.view_id);
|
|
419
|
+
const parsedUpdates = input.updates.map((u) => {
|
|
420
|
+
try {
|
|
421
|
+
return CodeRefUpdateSchema.parse(u);
|
|
422
|
+
}
|
|
423
|
+
catch (err) {
|
|
424
|
+
if (err instanceof ZodError) {
|
|
425
|
+
throw new ValidationError(`Invalid code_ref update: ${err.message}`, err.issues);
|
|
426
|
+
}
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
return this.withLock(async () => {
|
|
431
|
+
await this.ensureDirsUnlocked();
|
|
432
|
+
const { view: currentView } = await this.readViewUnlocked(validId);
|
|
433
|
+
const nodeIds = new Set(currentView.nodes.map((n) => n.id));
|
|
434
|
+
for (const upd of parsedUpdates) {
|
|
435
|
+
if (!nodeIds.has(upd.node_id)) {
|
|
436
|
+
throw new NotFoundError(`Node '${upd.node_id}' not found in view '${validId}'`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// Resolve baseline before modifying disk view so missing-checkpoint fallback
|
|
440
|
+
// captures the pre-sync state without inventing unrelated diffs.
|
|
441
|
+
const baseline = await this.resolveCheckpointBaselineUnlocked(validId, currentView);
|
|
442
|
+
const updateMap = new Map(parsedUpdates.map((u) => [u.node_id, u]));
|
|
443
|
+
const nextView = {
|
|
444
|
+
...currentView,
|
|
445
|
+
nodes: currentView.nodes.map((node) => {
|
|
446
|
+
const upd = updateMap.get(node.id);
|
|
447
|
+
if (!upd)
|
|
448
|
+
return node;
|
|
449
|
+
return {
|
|
450
|
+
...node,
|
|
451
|
+
status: upd.status,
|
|
452
|
+
code_refs: structuredClone(upd.code_refs),
|
|
453
|
+
};
|
|
454
|
+
}),
|
|
455
|
+
};
|
|
456
|
+
await writeJsonAtomic(this.viewPath(validId), nextView);
|
|
457
|
+
if (baseline) {
|
|
458
|
+
const nextCheckpoint = {
|
|
459
|
+
...baseline,
|
|
460
|
+
nodes: baseline.nodes.map((node) => {
|
|
461
|
+
const upd = updateMap.get(node.id);
|
|
462
|
+
if (!upd)
|
|
463
|
+
return node;
|
|
464
|
+
return {
|
|
465
|
+
...node,
|
|
466
|
+
status: upd.status,
|
|
467
|
+
code_refs: structuredClone(upd.code_refs),
|
|
468
|
+
};
|
|
469
|
+
}),
|
|
470
|
+
};
|
|
471
|
+
await writeJsonAtomic(this.checkpointPath(validId), nextCheckpoint);
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
view: nextView,
|
|
475
|
+
view_hash: computeViewHash(nextView),
|
|
476
|
+
updated_node_ids: parsedUpdates.map((u) => u.node_id),
|
|
477
|
+
};
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
async listThreadsUnlocked(filter) {
|
|
481
|
+
let entries;
|
|
482
|
+
try {
|
|
483
|
+
entries = await fs.readdir(this.threadsDir);
|
|
484
|
+
}
|
|
485
|
+
catch (err) {
|
|
486
|
+
if (err.code === "ENOENT") {
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
throw err;
|
|
490
|
+
}
|
|
491
|
+
const threads = [];
|
|
492
|
+
for (const entry of entries) {
|
|
493
|
+
if (!entry.endsWith(".json") || entry.startsWith(".tmp-"))
|
|
494
|
+
continue;
|
|
495
|
+
const filePath = path.join(this.threadsDir, entry);
|
|
496
|
+
const thread = await readJsonFile(filePath, DesignThreadSchema, `thread '${entry}'`);
|
|
497
|
+
threads.push(thread);
|
|
498
|
+
}
|
|
499
|
+
const queryLower = filter?.query?.trim().toLowerCase();
|
|
500
|
+
const filtered = threads.filter((thread) => {
|
|
501
|
+
if (filter?.view_id && thread.view_id !== filter.view_id)
|
|
502
|
+
return false;
|
|
503
|
+
if (filter?.target_type && thread.target_type !== filter.target_type)
|
|
504
|
+
return false;
|
|
505
|
+
if (filter?.target_id && thread.target_id !== filter.target_id)
|
|
506
|
+
return false;
|
|
507
|
+
if (filter?.entity_ref && thread.entity_ref !== filter.entity_ref)
|
|
508
|
+
return false;
|
|
509
|
+
if (filter?.status && thread.status !== filter.status)
|
|
510
|
+
return false;
|
|
511
|
+
if (queryLower) {
|
|
512
|
+
const inSummary = thread.resolution_summary?.toLowerCase().includes(queryLower) ?? false;
|
|
513
|
+
const inMessages = thread.messages.some((m) => m.body.toLowerCase().includes(queryLower));
|
|
514
|
+
if (!inSummary && !inMessages)
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
});
|
|
519
|
+
filtered.sort((a, b) => {
|
|
520
|
+
const aTime = a.messages[0]?.created_at ?? "";
|
|
521
|
+
const bTime = b.messages[0]?.created_at ?? "";
|
|
522
|
+
if (aTime !== bTime)
|
|
523
|
+
return aTime.localeCompare(bTime);
|
|
524
|
+
return a.id.localeCompare(b.id);
|
|
525
|
+
});
|
|
526
|
+
return filtered;
|
|
527
|
+
}
|
|
528
|
+
async listThreads(filter) {
|
|
529
|
+
return this.listThreadsUnlocked(filter);
|
|
530
|
+
}
|
|
531
|
+
async readThread(threadId) {
|
|
532
|
+
return readJsonFile(this.threadPath(threadId), DesignThreadSchema, `thread '${threadId}'`);
|
|
533
|
+
}
|
|
534
|
+
async postThreadMessage(input) {
|
|
535
|
+
const body = input.body.trim();
|
|
536
|
+
if (!body) {
|
|
537
|
+
throw new ValidationError("Thread message body cannot be empty");
|
|
538
|
+
}
|
|
539
|
+
return this.withLock(async () => {
|
|
540
|
+
await this.ensureDirsUnlocked();
|
|
541
|
+
const now = new Date().toISOString();
|
|
542
|
+
const msgId = `msg_${randomBytes(6).toString("hex")}`;
|
|
543
|
+
if (input.thread_id) {
|
|
544
|
+
const existing = await readJsonFile(this.threadPath(input.thread_id), DesignThreadSchema, `thread '${input.thread_id}'`);
|
|
545
|
+
const updated = {
|
|
546
|
+
...existing,
|
|
547
|
+
messages: [
|
|
548
|
+
...existing.messages,
|
|
549
|
+
{ id: msgId, author: input.author, body, created_at: now },
|
|
550
|
+
],
|
|
551
|
+
};
|
|
552
|
+
if (input.resolve) {
|
|
553
|
+
const summary = input.resolution_summary?.trim();
|
|
554
|
+
if (input.author === "agent" && !summary) {
|
|
555
|
+
throw new ValidationError("resolution_summary is required when an agent resolves a thread");
|
|
556
|
+
}
|
|
557
|
+
updated.status = "resolved";
|
|
558
|
+
if (summary) {
|
|
559
|
+
updated.resolution_summary = summary;
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
delete updated.resolution_summary;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else if (input.reopen) {
|
|
566
|
+
updated.status = "open";
|
|
567
|
+
delete updated.resolution_summary;
|
|
568
|
+
}
|
|
569
|
+
const validated = DesignThreadSchema.parse(updated);
|
|
570
|
+
await writeJsonAtomic(this.threadPath(validated.id), validated);
|
|
571
|
+
return validated;
|
|
572
|
+
}
|
|
573
|
+
if (!input.target_type || !input.kind) {
|
|
574
|
+
throw new ValidationError("target_type and kind are required when creating a new thread");
|
|
575
|
+
}
|
|
576
|
+
let entityRef = input.entity_ref;
|
|
577
|
+
if (!entityRef &&
|
|
578
|
+
input.target_type === "node" &&
|
|
579
|
+
input.view_id &&
|
|
580
|
+
input.target_id) {
|
|
581
|
+
const vPath = this.viewPath(input.view_id);
|
|
582
|
+
if (await pathExists(vPath)) {
|
|
583
|
+
const view = await readJsonFile(vPath, DesignViewSchema, `view '${input.view_id}'`);
|
|
584
|
+
const node = view.nodes.find((n) => n.id === input.target_id);
|
|
585
|
+
if (node?.entity_ref) {
|
|
586
|
+
entityRef = node.entity_ref;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
let status = "open";
|
|
591
|
+
let resolutionSummary;
|
|
592
|
+
if (input.resolve) {
|
|
593
|
+
const summary = input.resolution_summary?.trim();
|
|
594
|
+
if (input.author === "agent" && !summary) {
|
|
595
|
+
throw new ValidationError("resolution_summary is required when an agent resolves a thread");
|
|
596
|
+
}
|
|
597
|
+
status = "resolved";
|
|
598
|
+
if (summary) {
|
|
599
|
+
resolutionSummary = summary;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const threadId = `thr_${randomBytes(6).toString("hex")}`;
|
|
603
|
+
let created;
|
|
604
|
+
try {
|
|
605
|
+
created = DesignThreadSchema.parse({
|
|
606
|
+
id: threadId,
|
|
607
|
+
target_type: input.target_type,
|
|
608
|
+
...(input.view_id ? { view_id: input.view_id } : {}),
|
|
609
|
+
...(input.target_id ? { target_id: input.target_id } : {}),
|
|
610
|
+
...(entityRef ? { entity_ref: entityRef } : {}),
|
|
611
|
+
kind: input.kind,
|
|
612
|
+
status,
|
|
613
|
+
...(resolutionSummary
|
|
614
|
+
? { resolution_summary: resolutionSummary }
|
|
615
|
+
: {}),
|
|
616
|
+
messages: [{ id: msgId, author: input.author, body, created_at: now }],
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
catch (err) {
|
|
620
|
+
if (err instanceof ZodError) {
|
|
621
|
+
throw new ValidationError(`Invalid thread fields: ${err.message}`, err.issues);
|
|
622
|
+
}
|
|
623
|
+
throw err;
|
|
624
|
+
}
|
|
625
|
+
await writeJsonAtomic(this.threadPath(created.id), created);
|
|
626
|
+
return created;
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
async readLayout(viewId) {
|
|
630
|
+
const filePath = this.layoutPath(viewId);
|
|
631
|
+
if (!(await pathExists(filePath))) {
|
|
632
|
+
return { positions: {} };
|
|
633
|
+
}
|
|
634
|
+
return readJsonFile(filePath, ViewLayoutSchema, `layout '${viewId}'`);
|
|
635
|
+
}
|
|
636
|
+
async writeLayout(viewId, layout) {
|
|
637
|
+
const validId = idSlugSchema("view_id").parse(viewId);
|
|
638
|
+
const parsed = ViewLayoutSchema.parse(layout);
|
|
639
|
+
return this.withLock(async () => {
|
|
640
|
+
await this.ensureDirsUnlocked();
|
|
641
|
+
await writeJsonAtomic(this.layoutPath(validId), parsed);
|
|
642
|
+
return parsed;
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
async clearLayout(viewId) {
|
|
646
|
+
const validId = idSlugSchema("view_id").parse(viewId);
|
|
647
|
+
await this.withLock(async () => {
|
|
648
|
+
await fs.unlink(this.layoutPath(validId)).catch((err) => {
|
|
649
|
+
if (err.code !== "ENOENT") {
|
|
650
|
+
throw err;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
async getEntityRefRegistryUnlocked() {
|
|
656
|
+
const viewIds = await this.listViewIdsUnlocked();
|
|
657
|
+
const map = new Map();
|
|
658
|
+
for (const viewId of viewIds) {
|
|
659
|
+
const { view } = await this.readViewUnlocked(viewId);
|
|
660
|
+
for (const node of view.nodes) {
|
|
661
|
+
if (!node.entity_ref)
|
|
662
|
+
continue;
|
|
663
|
+
let views = map.get(node.entity_ref);
|
|
664
|
+
if (!views) {
|
|
665
|
+
views = new Set();
|
|
666
|
+
map.set(node.entity_ref, views);
|
|
667
|
+
}
|
|
668
|
+
views.add(viewId);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const registry = {};
|
|
672
|
+
for (const ref of [...map.keys()].sort((a, b) => a.localeCompare(b))) {
|
|
673
|
+
registry[ref] = [...map.get(ref)].sort((a, b) => a.localeCompare(b));
|
|
674
|
+
}
|
|
675
|
+
return registry;
|
|
676
|
+
}
|
|
677
|
+
async getEntityRefRegistry() {
|
|
678
|
+
return this.getEntityRefRegistryUnlocked();
|
|
679
|
+
}
|
|
680
|
+
async getPendingFeedback(viewId) {
|
|
681
|
+
const targetViewId = viewId
|
|
682
|
+
? idSlugSchema("view_id").parse(viewId)
|
|
683
|
+
: undefined;
|
|
684
|
+
return this.withLock(async () => {
|
|
685
|
+
const viewIds = targetViewId
|
|
686
|
+
? [targetViewId]
|
|
687
|
+
: await this.listViewIdsUnlocked();
|
|
688
|
+
const view_hashes = {};
|
|
689
|
+
const view_diffs = [];
|
|
690
|
+
for (const id of viewIds) {
|
|
691
|
+
const { view, view_hash } = await this.readViewUnlocked(id);
|
|
692
|
+
view_hashes[id] = view_hash;
|
|
693
|
+
const baseline = await this.resolveCheckpointBaselineUnlocked(id, view);
|
|
694
|
+
const diff = computeSemanticDiff(baseline, view);
|
|
695
|
+
if (diff.has_changes) {
|
|
696
|
+
view_diffs.push({ view_id: id, view_hash, diff });
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const openThreads = await this.listThreadsUnlocked({
|
|
700
|
+
status: "open",
|
|
701
|
+
...(targetViewId ? { view_id: targetViewId } : {}),
|
|
702
|
+
});
|
|
703
|
+
const pending_threads = openThreads.filter(isThreadPendingForAgent);
|
|
704
|
+
let view_requests = [];
|
|
705
|
+
if (await pathExists(this.workspacePath)) {
|
|
706
|
+
const ws = await this.readWorkspaceUnlocked();
|
|
707
|
+
view_requests = ws.view_requests;
|
|
708
|
+
}
|
|
709
|
+
return {
|
|
710
|
+
view_hashes,
|
|
711
|
+
view_diffs,
|
|
712
|
+
pending_threads,
|
|
713
|
+
view_requests,
|
|
714
|
+
};
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
async getWorkspaceStatus() {
|
|
718
|
+
return this.withLock(async () => {
|
|
719
|
+
if (!(await pathExists(this.workspacePath))) {
|
|
720
|
+
return {
|
|
721
|
+
initialized: false,
|
|
722
|
+
project_name: path.basename(this.rootDir) || "redlinify-project",
|
|
723
|
+
tabs: [],
|
|
724
|
+
workspace_threads_waiting_on_agent: 0,
|
|
725
|
+
workspace_threads_waiting_on_human: 0,
|
|
726
|
+
view_requests: [],
|
|
727
|
+
entity_refs: {},
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
const ws = await this.readWorkspaceUnlocked();
|
|
731
|
+
const threads = await this.listThreadsUnlocked({ status: "open" });
|
|
732
|
+
const entity_refs = await this.getEntityRefRegistryUnlocked();
|
|
733
|
+
const sortedTabs = [...ws.tabs].sort((a, b) => a.order - b.order);
|
|
734
|
+
const tabSummaries = [];
|
|
735
|
+
for (const tab of sortedTabs) {
|
|
736
|
+
const viewThreads = threads.filter((t) => t.view_id === tab.view_id);
|
|
737
|
+
const waiting_on_agent = viewThreads.filter(isThreadWaitingOnAgent).length;
|
|
738
|
+
const waiting_on_human = viewThreads.filter(isThreadWaitingOnHuman).length;
|
|
739
|
+
const vPath = this.viewPath(tab.view_id);
|
|
740
|
+
if (!(await pathExists(vPath))) {
|
|
741
|
+
tabSummaries.push({
|
|
742
|
+
...tab,
|
|
743
|
+
view_hash: null,
|
|
744
|
+
missing_view_file: true,
|
|
745
|
+
waiting_on_agent,
|
|
746
|
+
waiting_on_human,
|
|
747
|
+
drifted_count: 0,
|
|
748
|
+
has_human_edits: false,
|
|
749
|
+
diff_counts: {
|
|
750
|
+
nodes_added: 0,
|
|
751
|
+
nodes_removed: 0,
|
|
752
|
+
nodes_modified: 0,
|
|
753
|
+
edges_added: 0,
|
|
754
|
+
edges_removed: 0,
|
|
755
|
+
edges_modified: 0,
|
|
756
|
+
},
|
|
757
|
+
});
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
const { view, view_hash } = await this.readViewUnlocked(tab.view_id);
|
|
761
|
+
const baseline = await this.resolveCheckpointBaselineUnlocked(tab.view_id, view);
|
|
762
|
+
const diff = computeSemanticDiff(baseline, view);
|
|
763
|
+
const drifted_count = view.nodes.filter((n) => n.status === "drifted").length;
|
|
764
|
+
tabSummaries.push({
|
|
765
|
+
...tab,
|
|
766
|
+
view_hash,
|
|
767
|
+
waiting_on_agent,
|
|
768
|
+
waiting_on_human,
|
|
769
|
+
drifted_count,
|
|
770
|
+
has_human_edits: diff.has_changes,
|
|
771
|
+
diff_counts: {
|
|
772
|
+
nodes_added: diff.nodes_added.length,
|
|
773
|
+
nodes_removed: diff.nodes_removed.length,
|
|
774
|
+
nodes_modified: diff.nodes_modified.length,
|
|
775
|
+
edges_added: diff.edges_added.length,
|
|
776
|
+
edges_removed: diff.edges_removed.length,
|
|
777
|
+
edges_modified: diff.edges_modified.length,
|
|
778
|
+
},
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
const workspaceThreads = threads.filter((t) => t.target_type === "workspace");
|
|
782
|
+
return {
|
|
783
|
+
initialized: true,
|
|
784
|
+
project_name: ws.project_name,
|
|
785
|
+
tabs: tabSummaries,
|
|
786
|
+
workspace_threads_waiting_on_agent: workspaceThreads.filter(isThreadWaitingOnAgent).length,
|
|
787
|
+
workspace_threads_waiting_on_human: workspaceThreads.filter(isThreadWaitingOnHuman).length,
|
|
788
|
+
view_requests: ws.view_requests,
|
|
789
|
+
entity_refs,
|
|
790
|
+
};
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function ViewRequestSchemaOrThrow(data) {
|
|
795
|
+
const result = ViewRequestSchema.safeParse(data);
|
|
796
|
+
if (!result.success) {
|
|
797
|
+
throw new ValidationError(`Invalid view_request: ${result.error.message}`, result.error.issues);
|
|
798
|
+
}
|
|
799
|
+
return result.data;
|
|
800
|
+
}
|
|
801
|
+
//# sourceMappingURL=storage.js.map
|