clay-server 4.1.0-beta.9 → 4.1.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/lib/context-usage.js +47 -0
- package/lib/issues-mcp-server.js +1 -1
- package/lib/issues-service.js +3 -1
- package/lib/loop-registry-occurrence.js +1 -0
- package/lib/notes.js +20 -3
- package/lib/os-users.js +6 -0
- package/lib/project-connection.js +14 -3
- package/lib/project-file-path.js +13 -0
- package/lib/project-file-watch.js +19 -8
- package/lib/project-filesystem.js +10 -16
- package/lib/project-http.js +53 -48
- package/lib/project-logs-mcp-server.js +8 -8
- package/lib/project-logs-schema.js +1 -1
- package/lib/project-logs-service.js +46 -13
- package/lib/project-logs-store.js +17 -15
- package/lib/project-logs.js +70 -0
- package/lib/project-loop.js +1 -0
- package/lib/project-notifications.js +1 -1
- package/lib/project-scheduled-result-store.js +131 -0
- package/lib/project-scheduled-task-execution.js +35 -2
- package/lib/project-session-notes.js +11 -4
- package/lib/project-sessions.js +7 -0
- package/lib/project-user-message.js +47 -0
- package/lib/project.js +53 -3
- package/lib/public/app.js +26 -9
- package/lib/public/css/avatar-imprints.css +1 -1
- package/lib/public/css/command-palette.css +20 -0
- package/lib/public/css/git-panel.css +13 -12
- package/lib/public/css/git-placard.css +4 -4
- package/lib/public/css/issues.css +78 -31
- package/lib/public/css/mobile-nav.css +7 -0
- package/lib/public/css/notifications-center.css +3 -3
- package/lib/public/css/project-logs.css +15 -0
- package/lib/public/css/sidebar.css +7 -0
- package/lib/public/css/sticky-notes.css +29 -0
- package/lib/public/modules/app-connection.js +9 -1
- package/lib/public/modules/app-favicon.js +10 -0
- package/lib/public/modules/app-messages.js +43 -12
- package/lib/public/modules/app-notifications.js +2 -0
- package/lib/public/modules/app-panels.js +77 -23
- package/lib/public/modules/app-projects.js +2 -0
- package/lib/public/modules/app-rate-limit.js +148 -61
- package/lib/public/modules/avatar-imprint.js +25 -70
- package/lib/public/modules/avatar.js +12 -4
- package/lib/public/modules/chat-render-runtime.js +20 -0
- package/lib/public/modules/clay-issue-links.js +23 -2
- package/lib/public/modules/clay-log-links.js +11 -1
- package/lib/public/modules/context-view-preference.js +143 -0
- package/lib/public/modules/default-vendor.js +116 -0
- package/lib/public/modules/filebrowser-tabs.js +1 -0
- package/lib/public/modules/filebrowser.js +45 -18
- package/lib/public/modules/issues-render.js +36 -10
- package/lib/public/modules/issues.js +95 -13
- package/lib/public/modules/markdown.js +3 -1
- package/lib/public/modules/pane-bridge.js +14 -8
- package/lib/public/modules/pane-issue-bridge.js +27 -0
- package/lib/public/modules/permission-hints.js +13 -0
- package/lib/public/modules/profile.js +9 -9
- package/lib/public/modules/project-activation.js +49 -0
- package/lib/public/modules/project-logs-render.js +13 -3
- package/lib/public/modules/project-logs.js +45 -15
- package/lib/public/modules/right-workbench.js +44 -0
- package/lib/public/modules/scheduled-result-client.js +33 -0
- package/lib/public/modules/scheduled-result-display.js +50 -0
- package/lib/public/modules/scheduled-result-notification.js +31 -0
- package/lib/public/modules/scheduled-task-presentation.js +15 -0
- package/lib/public/modules/scheduled-tasks.js +9 -21
- package/lib/public/modules/sidebar-mobile.js +51 -3
- package/lib/public/modules/sidebar-sessions.js +65 -5
- package/lib/public/modules/split-session-boundary.js +28 -0
- package/lib/public/modules/split-view.js +42 -7
- package/lib/public/modules/sticky-notes-browser.js +130 -18
- package/lib/public/modules/sticky-notes.js +2 -3
- package/lib/public/modules/terminal.js +4 -4
- package/lib/public/modules/thinking-lifecycle.js +4 -1
- package/lib/public/modules/tools.js +5 -1
- package/lib/scheduled-run-state.js +10 -2
- package/lib/scheduler.js +1 -0
- package/lib/sdk-bridge.js +97 -61
- package/lib/sdk-message-processor.js +44 -13
- package/lib/sdk-skill-discovery.js +6 -28
- package/lib/sdk-turn-queue.js +14 -0
- package/lib/server-context-view.js +53 -0
- package/lib/server-default-vendor.js +60 -0
- package/lib/server.js +23 -6
- package/lib/session-notes-mcp-server.js +3 -5
- package/lib/session-pair-factory.js +2 -2
- package/lib/session-title-generator.js +89 -0
- package/lib/session-title-policy.js +8 -2
- package/lib/sessions.js +26 -1
- package/lib/user-presence.js +6 -0
- package/lib/users-context-view-preferences.js +65 -0
- package/lib/users-default-vendor-preferences.js +80 -0
- package/lib/users.js +12 -0
- package/lib/ws-schema.js +11 -0
- package/lib/yoke/acp-agent-profiles.js +15 -2
- package/lib/yoke/adapters/acp.js +3 -2
- package/lib/yoke/adapters/antigravity.js +2 -2
- package/lib/yoke/adapters/claude-worker.js +11 -12
- package/lib/yoke/adapters/claude.js +75 -22
- package/lib/yoke/adapters/codex.js +216 -29
- package/lib/yoke/adapters/kiro.js +6 -5
- package/lib/yoke/claude-context-usage.js +57 -0
- package/lib/yoke/claude-message-correlation.js +31 -0
- package/lib/yoke/claude-model-switch.js +15 -0
- package/lib/yoke/index.js +5 -1
- package/lib/yoke/mcp-bridge-server.js +18 -5
- package/lib/yoke/session-skill-catalog.js +45 -0
- package/lib/yoke/skill-discovery.js +60 -20
- package/lib/yoke/vendor-registry.js +1 -1
- package/package.json +5 -7
|
@@ -253,6 +253,11 @@ function attachProjectLogsService(ctx) {
|
|
|
253
253
|
|
|
254
254
|
function createProjectBound(initial, revalidate) {
|
|
255
255
|
var store = storeForStatus(initial.status);
|
|
256
|
+
var scheduledResultViewerId = initial.principal.userId || null;
|
|
257
|
+
|
|
258
|
+
function withScheduledResultViewer(args) {
|
|
259
|
+
return Object.assign({}, args || {}, { scheduledResultOwnerId: scheduledResultViewerId });
|
|
260
|
+
}
|
|
256
261
|
|
|
257
262
|
// Identity, authorization, and the target store are all re-derived per
|
|
258
263
|
// call. revalidate() re-checks exact session identity where there is one;
|
|
@@ -288,7 +293,15 @@ function attachProjectLogsService(ctx) {
|
|
|
288
293
|
|
|
289
294
|
function scopedEntry(args) {
|
|
290
295
|
var scope = currentScope();
|
|
291
|
-
|
|
296
|
+
var entry = visibleEntry(live(), args && args.ref, scope.status, scope.worktreeOnly);
|
|
297
|
+
if (entry.scheduledResult && (entry.scheduledResult.ownerId || null) !== scheduledResultViewerId) throw new Error("Log entry not found.");
|
|
298
|
+
return entry;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function mutableEntry(args) {
|
|
302
|
+
var entry = scopedEntry(args);
|
|
303
|
+
if (entry.scheduledResult) throw new Error("Scheduled results are server-owned records.");
|
|
304
|
+
return entry;
|
|
292
305
|
}
|
|
293
306
|
|
|
294
307
|
function mutationContext() {
|
|
@@ -312,7 +325,7 @@ function attachProjectLogsService(ctx) {
|
|
|
312
325
|
listLogs: function (args) {
|
|
313
326
|
var scope = currentScope();
|
|
314
327
|
var status = scope.status;
|
|
315
|
-
var options = scopedArgs(args, status, scope.worktreeOnly);
|
|
328
|
+
var options = withScheduledResultViewer(scopedArgs(args, status, scope.worktreeOnly));
|
|
316
329
|
var result = live().list(options);
|
|
317
330
|
result.contextMode = options.contextMode;
|
|
318
331
|
result.currentChangeSetId = status.changeSetId || null;
|
|
@@ -322,7 +335,7 @@ function attachProjectLogsService(ctx) {
|
|
|
322
335
|
searchLogs: function (args) {
|
|
323
336
|
var scope = currentScope();
|
|
324
337
|
var status = scope.status;
|
|
325
|
-
var options = scopedArgs(args, status, scope.worktreeOnly);
|
|
338
|
+
var options = withScheduledResultViewer(scopedArgs(args, status, scope.worktreeOnly));
|
|
326
339
|
var result = live().search(options);
|
|
327
340
|
result.contextMode = options.contextMode;
|
|
328
341
|
result.currentChangeSetId = status.changeSetId || null;
|
|
@@ -334,18 +347,20 @@ function attachProjectLogsService(ctx) {
|
|
|
334
347
|
},
|
|
335
348
|
logHistory: function (args) { scopedEntry(args); return live().history(args && args.ref, args || {}); },
|
|
336
349
|
commentLog: function (args) { scopedEntry(args); return live().comment(args && args.ref, args || {}, author(), mutationContext()); },
|
|
350
|
+
scheduledResultsState: function () { var scope = currentScope(); return live().unreadScheduledResults(scheduledResultViewerId, scopedArgs({}, scope.status, scope.worktreeOnly)); },
|
|
351
|
+
markScheduledResultRead: function (args) { var scope = currentScope(); scopedEntry(args); return live().markScheduledResultRead(args && args.ref, scheduledResultViewerId, scopedArgs({}, scope.status, scope.worktreeOnly)); },
|
|
337
352
|
readLogRevision: function (args) { scopedEntry(args); return live().readRevision(args && args.ref, args && args.revision); },
|
|
338
353
|
listLogFeedback: canonical ? function (args) {
|
|
339
354
|
var scope = currentScope();
|
|
340
|
-
return live().feedback(scopedArgs(args, scope.status, scope.worktreeOnly));
|
|
355
|
+
return live().feedback(withScheduledResultViewer(scopedArgs(args, scope.status, scope.worktreeOnly)));
|
|
341
356
|
} : driverOnly,
|
|
342
|
-
reviewLogComment: canonical ? function (args) { scopedEntry(args); return live().review(args && args.ref, args || {}, author(), mutationContext()); } : driverOnly,
|
|
357
|
+
reviewLogComment: canonical ? function (args) { if (args && args.action === "incorporate") mutableEntry(args); else scopedEntry(args); return live().review(args && args.ref, args || {}, author(), mutationContext()); } : driverOnly,
|
|
343
358
|
revertLog: canonical
|
|
344
|
-
? function (args) {
|
|
359
|
+
? function (args) { mutableEntry(args); return live().revert(args && args.ref, args && args.revision, args && args.reason, author(), mutationContext()); }
|
|
345
360
|
: driverOnly,
|
|
346
361
|
createLog: canonical ? function (args) { return live().create(args || {}, author(), mutationContext()); } : agentOnly,
|
|
347
|
-
updateLog: canonical ? function (args) {
|
|
348
|
-
linkLog: canonical ? function (args) {
|
|
362
|
+
updateLog: canonical ? function (args) { mutableEntry(args); return live().update(args && args.ref, args || {}, author(), mutationContext()); } : agentOnly,
|
|
363
|
+
linkLog: canonical ? function (args) { mutableEntry(args); return live().link(args && args.ref, args && args.links, author(), mutationContext()); } : agentOnly,
|
|
349
364
|
removeLog: canDelete ? function (args) {
|
|
350
365
|
var current = revalidate();
|
|
351
366
|
var project = projectFor(current.principal.projectSlug);
|
|
@@ -353,7 +368,7 @@ function attachProjectLogsService(ctx) {
|
|
|
353
368
|
if (!project || !authorizedProject(current.principal, currentStatus)) {
|
|
354
369
|
throw new Error("Project Logs are not available for this project.");
|
|
355
370
|
}
|
|
356
|
-
|
|
371
|
+
mutableEntry(args);
|
|
357
372
|
if (current.principal.kind !== "session" && !ownsProject(current.principal, currentStatus)) ownerOnly();
|
|
358
373
|
return storeForStatus(currentStatus).remove(args && args.ref, current.author, recordContext(currentStatus));
|
|
359
374
|
} : ownerOnly,
|
|
@@ -367,6 +382,20 @@ function attachProjectLogsService(ctx) {
|
|
|
367
382
|
return storeForStatus(projectStatus).setContextState(recordContext(projectStatus), status);
|
|
368
383
|
}
|
|
369
384
|
|
|
385
|
+
// Trusted server lifecycle path. It is deliberately not part of any bound
|
|
386
|
+
// human or MCP write capability, so system results cannot be impersonated.
|
|
387
|
+
function recordScheduledResult(source) {
|
|
388
|
+
var data = source || {};
|
|
389
|
+
var project = projectFor(data.projectSlug);
|
|
390
|
+
if (!project) throw new Error("Project not found.");
|
|
391
|
+
var status = project.getStatus();
|
|
392
|
+
if (!status || status.isMate === true) throw new Error("Scheduled results require a project.");
|
|
393
|
+
if (isMultiUser()) {
|
|
394
|
+
if (!data.ownerId || !findUserById(data.ownerId)) throw new Error("Scheduled result owner is unavailable.");
|
|
395
|
+
}
|
|
396
|
+
return storeForStatus(status).createScheduledResult(data, recordContext(status));
|
|
397
|
+
}
|
|
398
|
+
|
|
370
399
|
function createClayBound(revalidate) {
|
|
371
400
|
function target(args) {
|
|
372
401
|
var principal = revalidate();
|
|
@@ -374,14 +403,16 @@ function attachProjectLogsService(ctx) {
|
|
|
374
403
|
if (!slug) throw new Error("An exact project slug is required.");
|
|
375
404
|
var status = statusFor(principal, slug);
|
|
376
405
|
var decision = projectAuthorization(principal, status);
|
|
377
|
-
return { store: storeForStatus(status), status: status, worktreeOnly: decision.worktreeOnly };
|
|
406
|
+
return { store: storeForStatus(status), status: status, worktreeOnly: decision.worktreeOnly, viewerId: principal.userId || null };
|
|
378
407
|
}
|
|
379
408
|
|
|
380
409
|
function targetEntry(args) {
|
|
381
410
|
var selected = target(args);
|
|
411
|
+
var entry = visibleEntry(selected.store, args && args.ref, selected.status, selected.worktreeOnly);
|
|
412
|
+
if (entry.scheduledResult && (entry.scheduledResult.ownerId || null) !== selected.viewerId) throw new Error("Log entry not found.");
|
|
382
413
|
return {
|
|
383
414
|
selected: selected,
|
|
384
|
-
entry:
|
|
415
|
+
entry: entry,
|
|
385
416
|
};
|
|
386
417
|
}
|
|
387
418
|
|
|
@@ -405,6 +436,7 @@ function attachProjectLogsService(ctx) {
|
|
|
405
436
|
seenScopes.add(scopeKey);
|
|
406
437
|
var entry = null;
|
|
407
438
|
try { entry = visibleEntry(storeForStatus(status), ref, status, decision.worktreeOnly); } catch (e) { return; }
|
|
439
|
+
if (entry && entry.scheduledResult && (entry.scheduledResult.ownerId || null) !== (principal.userId || null)) return;
|
|
408
440
|
if (!entry) return;
|
|
409
441
|
var targetSlug = decision.worktreeOnly
|
|
410
442
|
? slug
|
|
@@ -425,11 +457,11 @@ function attachProjectLogsService(ctx) {
|
|
|
425
457
|
author: null,
|
|
426
458
|
listLogs: function (args) {
|
|
427
459
|
var selected = target(args);
|
|
428
|
-
return selected.store.list(scopedArgs(args, selected.status, selected.worktreeOnly));
|
|
460
|
+
return selected.store.list(Object.assign({}, scopedArgs(args, selected.status, selected.worktreeOnly), { scheduledResultOwnerId: selected.viewerId }));
|
|
429
461
|
},
|
|
430
462
|
searchLogs: function (args) {
|
|
431
463
|
var selected = target(args);
|
|
432
|
-
return selected.store.search(scopedArgs(args, selected.status, selected.worktreeOnly));
|
|
464
|
+
return selected.store.search(Object.assign({}, scopedArgs(args, selected.status, selected.worktreeOnly), { scheduledResultOwnerId: selected.viewerId }));
|
|
433
465
|
},
|
|
434
466
|
readLog: function (args) {
|
|
435
467
|
return targetEntry(args).entry;
|
|
@@ -458,6 +490,7 @@ function attachProjectLogsService(ctx) {
|
|
|
458
490
|
bindProjectSession: bindProjectSession,
|
|
459
491
|
bindUser: bindUser,
|
|
460
492
|
bindMate: bindMate,
|
|
493
|
+
recordScheduledResult: recordScheduledResult,
|
|
461
494
|
setContextState: setContextState,
|
|
462
495
|
};
|
|
463
496
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Project Logs projection over the Clay-wide knowledge record backend.
|
|
2
|
-
|
|
3
2
|
var fs = require("fs");
|
|
4
3
|
var path = require("path");
|
|
5
4
|
var crypto = require("crypto");
|
|
@@ -12,6 +11,7 @@ var logsVersioning = require("./project-logs-versioning");
|
|
|
12
11
|
var logsRoot = require("./project-logs-root");
|
|
13
12
|
var logContext = require("./project-log-context");
|
|
14
13
|
var contextState = require("./project-logs-context-state");
|
|
14
|
+
var scheduledResultStore = require("./project-scheduled-result-store");
|
|
15
15
|
|
|
16
16
|
var MAX_SUMMARY_CHARS = logsSchema.MAX_SUMMARY_CHARS;
|
|
17
17
|
var MAX_COMMENT_CHARS = 4000;
|
|
@@ -34,7 +34,6 @@ var normalizeTags = logsSchema.normalizeTags;
|
|
|
34
34
|
var normalizeLinks = logsSchema.normalizeLinks;
|
|
35
35
|
|
|
36
36
|
var page = logsQuery.page;
|
|
37
|
-
|
|
38
37
|
// Filters accept any well-formed category. An unknown but valid one matches
|
|
39
38
|
// nothing, which is a real answer. A supplied malformed one is an error:
|
|
40
39
|
// silently dropping it would widen the result set to everything the caller is
|
|
@@ -45,7 +44,6 @@ function validateKind(kind, fallback) {
|
|
|
45
44
|
return logsSchema.normalizeCategory(kind);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
49
47
|
function createProjectLogsStore(opts) {
|
|
50
48
|
var options = opts || {};
|
|
51
49
|
var root = options.root ? path.resolve(options.root) : logsRoot.resolveProjectRoot(options.cwd, options.runGit);
|
|
@@ -116,6 +114,7 @@ function createProjectLogsStore(opts) {
|
|
|
116
114
|
deletedAt: history.deleted ? history.deleted.at : null,
|
|
117
115
|
deletedBy: history.deleted ? history.deleted.author : null,
|
|
118
116
|
context: logContext.normalizeRecordContext(originRecord && originRecord.context),
|
|
117
|
+
scheduledResult: scheduledResultStore.normalizeMetadata(originRecord && originRecord.scheduledResult),
|
|
119
118
|
};
|
|
120
119
|
if (entry.context.changeSetId) {
|
|
121
120
|
var states = knownContextStates || contexts.states();
|
|
@@ -132,13 +131,14 @@ function createProjectLogsStore(opts) {
|
|
|
132
131
|
return entry;
|
|
133
132
|
}
|
|
134
133
|
|
|
135
|
-
function entries(includeDeleted) {
|
|
134
|
+
function entries(includeDeleted, scheduledResultOwnerId) {
|
|
136
135
|
var out = [];
|
|
137
136
|
var states = contexts.states();
|
|
138
137
|
chains().forEach(function (chain, rootId) {
|
|
139
138
|
var entry = fold(rootId, chain, states);
|
|
140
139
|
if (!entry) return;
|
|
141
140
|
if (entry.deleted && !includeDeleted) return;
|
|
141
|
+
if (!scheduledResultStore.visibleTo(entry.scheduledResult, scheduledResultOwnerId)) return;
|
|
142
142
|
out.push(entry);
|
|
143
143
|
});
|
|
144
144
|
// Latest canonical update first, ref as a deterministic tie-break. Only a
|
|
@@ -157,12 +157,13 @@ function createProjectLogsStore(opts) {
|
|
|
157
157
|
return found;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
function read(ref, includeDeleted) {
|
|
160
|
+
function read(ref, includeDeleted, scheduledResultOwnerId) {
|
|
161
161
|
var located = findChain(ref);
|
|
162
162
|
if (!located) return null;
|
|
163
163
|
var entry = fold(located.rootId, located.chain);
|
|
164
164
|
if (!entry) return null;
|
|
165
165
|
if (entry.deleted && !includeDeleted) return null;
|
|
166
|
+
if (!scheduledResultStore.visibleTo(entry.scheduledResult, scheduledResultOwnerId)) return null;
|
|
166
167
|
return entry;
|
|
167
168
|
}
|
|
168
169
|
|
|
@@ -212,8 +213,7 @@ function createProjectLogsStore(opts) {
|
|
|
212
213
|
return read(refFor(id), false);
|
|
213
214
|
}
|
|
214
215
|
|
|
215
|
-
// Build the complete snapshot a revision will store
|
|
216
|
-
// plus the requested changes. Every new canonical edit is self-contained.
|
|
216
|
+
// Build the complete snapshot a revision will store from current state.
|
|
217
217
|
function nextSnapshot(current, validated, data) {
|
|
218
218
|
var snapshot = logsSnapshot.cloneSnapshot(current);
|
|
219
219
|
if (validated.category !== undefined) snapshot.category = validated.category;
|
|
@@ -251,7 +251,6 @@ function createProjectLogsStore(opts) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
// One append per canonical revision, always carrying a complete snapshot.
|
|
254
|
-
// Legacy field names ride along so an older build can still read the record.
|
|
255
254
|
function appendRevision(rootId, op, snapshot, author, extra) {
|
|
256
255
|
var record = {
|
|
257
256
|
id: recordStore.newRecordId(),
|
|
@@ -275,9 +274,7 @@ function createProjectLogsStore(opts) {
|
|
|
275
274
|
return record;
|
|
276
275
|
}
|
|
277
276
|
|
|
278
|
-
// Human participation
|
|
279
|
-
// never a canonical revision. The author is supplied by the authorization
|
|
280
|
-
// layer, never by the caller's payload.
|
|
277
|
+
// Human participation is append-only and never a canonical revision.
|
|
281
278
|
function comment(ref, input, author, context) {
|
|
282
279
|
var located = requireLive(ref);
|
|
283
280
|
var data = input || {};
|
|
@@ -344,7 +341,7 @@ function createProjectLogsStore(opts) {
|
|
|
344
341
|
function categories(options) {
|
|
345
342
|
var seen = {};
|
|
346
343
|
var out = [];
|
|
347
|
-
var live = entries(false);
|
|
344
|
+
var live = entries(false, options && options.scheduledResultOwnerId);
|
|
348
345
|
for (var i = 0; i < live.length; i++) {
|
|
349
346
|
if (!logsQuery.matchesContext(live[i], options || {})) continue;
|
|
350
347
|
var value = live[i].category;
|
|
@@ -379,7 +376,7 @@ function createProjectLogsStore(opts) {
|
|
|
379
376
|
var limit = Number(options2.limit);
|
|
380
377
|
if (!Number.isFinite(limit)) limit = MAX_FEEDBACK_ITEMS;
|
|
381
378
|
limit = Math.max(1, Math.min(MAX_FEEDBACK_ITEMS, Math.floor(limit)));
|
|
382
|
-
var live = entries(false);
|
|
379
|
+
var live = entries(false, options2.scheduledResultOwnerId);
|
|
383
380
|
var out = [];
|
|
384
381
|
var total = 0;
|
|
385
382
|
for (var i = 0; i < live.length; i++) {
|
|
@@ -409,13 +406,13 @@ function createProjectLogsStore(opts) {
|
|
|
409
406
|
|
|
410
407
|
function list(args) {
|
|
411
408
|
var options2 = args || {};
|
|
412
|
-
var result = logsQuery.listEntries(entries(options2.includeDeleted === true), options2, cleanLine, validateKind);
|
|
409
|
+
var result = logsQuery.listEntries(entries(options2.includeDeleted === true, options2.scheduledResultOwnerId), options2, cleanLine, validateKind);
|
|
413
410
|
result.categories = categories(options2);
|
|
414
411
|
return result;
|
|
415
412
|
}
|
|
416
413
|
|
|
417
414
|
function search(args) {
|
|
418
|
-
var result = logsQuery.searchEntries(entries(false), args || {}, cleanLine, validateKind);
|
|
415
|
+
var result = logsQuery.searchEntries(entries(false, args && args.scheduledResultOwnerId), args || {}, cleanLine, validateKind);
|
|
419
416
|
result.categories = categories(args || {});
|
|
420
417
|
return result;
|
|
421
418
|
}
|
|
@@ -457,6 +454,8 @@ function createProjectLogsStore(opts) {
|
|
|
457
454
|
};
|
|
458
455
|
}
|
|
459
456
|
|
|
457
|
+
var scheduledResults = scheduledResultStore.attachScheduledResultStore({ store: store, scopeId: scopeId, refFor: refFor, read: read, entries: entries, findChain: findChain, matchesContext: logsQuery.matchesContext });
|
|
458
|
+
|
|
460
459
|
return {
|
|
461
460
|
root: root,
|
|
462
461
|
scopeId: scopeId,
|
|
@@ -477,6 +476,9 @@ function createProjectLogsStore(opts) {
|
|
|
477
476
|
search: search,
|
|
478
477
|
history: history,
|
|
479
478
|
stats: stats,
|
|
479
|
+
createScheduledResult: scheduledResults.create,
|
|
480
|
+
unreadScheduledResults: scheduledResults.unread,
|
|
481
|
+
markScheduledResultRead: scheduledResults.markRead,
|
|
480
482
|
};
|
|
481
483
|
}
|
|
482
484
|
|
package/lib/project-logs.js
CHANGED
|
@@ -72,6 +72,8 @@ var HANDLED_TYPES = [
|
|
|
72
72
|
"project_log_read",
|
|
73
73
|
"project_log_comment",
|
|
74
74
|
"project_log_delete",
|
|
75
|
+
"scheduled_task_result_mark_read",
|
|
76
|
+
"scheduled_task_result_open_session",
|
|
75
77
|
// Retired human mutations. Still claimed so an older client gets an
|
|
76
78
|
// explicit refusal rather than silence.
|
|
77
79
|
"project_log_create",
|
|
@@ -155,6 +157,31 @@ function attachProjectLogs(ctx) {
|
|
|
155
157
|
return service.bindUser({ projectSlug: slug, user: (ws && ws._clayUser) || null });
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
function scheduledResultState(bound, autoFocus) {
|
|
161
|
+
var state = bound.scheduledResultsState();
|
|
162
|
+
return { type: "scheduled_task_results_state", unreadCount: state.count, newestUnreadRef: state.newestRef, autoFocus: autoFocus === true };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function sendScheduledResultState(ws) {
|
|
166
|
+
if (!ws || ws._clayPane) return false;
|
|
167
|
+
var bound = userBinding(ws);
|
|
168
|
+
if (!bound) return false;
|
|
169
|
+
try { sendTo(ws, scheduledResultState(bound, true)); return true; } catch (e) { return false; }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function broadcastScheduledResultState(sourceWs) {
|
|
173
|
+
var sourceUserId = sourceWs && sourceWs._clayUser ? sourceWs._clayUser.id : null;
|
|
174
|
+
var clients = getClients();
|
|
175
|
+
for (var client of clients) {
|
|
176
|
+
if (!client || client.readyState !== 1 || client._clayPane) continue;
|
|
177
|
+
var clientUserId = client._clayUser ? client._clayUser.id : null;
|
|
178
|
+
if (clientUserId !== sourceUserId) continue;
|
|
179
|
+
var bound = userBinding(client);
|
|
180
|
+
if (!bound) continue;
|
|
181
|
+
try { sendTo(client, scheduledResultState(bound)); } catch (e) {}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
158
185
|
// --- WebSocket surface -----------------------------------------------
|
|
159
186
|
|
|
160
187
|
function fail(ws, requestId, message) {
|
|
@@ -253,6 +280,27 @@ function attachProjectLogs(ctx) {
|
|
|
253
280
|
sendTo(ws, { type: "project_log_commented", requestId: requestId, entry: commented, reviewQueued: reviewQueued });
|
|
254
281
|
return true;
|
|
255
282
|
}
|
|
283
|
+
|
|
284
|
+
if (msg.type === "scheduled_task_result_mark_read") {
|
|
285
|
+
bound.markScheduledResultRead({ ref: msg.ref });
|
|
286
|
+
broadcastScheduledResultState(ws);
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (msg.type === "scheduled_task_result_open_session") {
|
|
291
|
+
var resultEntry = bound.readLog({ ref: msg.ref });
|
|
292
|
+
var resultMeta = resultEntry && resultEntry.scheduledResult;
|
|
293
|
+
if (!resultMeta) throw new Error("Scheduled result not found.");
|
|
294
|
+
var target = null;
|
|
295
|
+
sm.sessions.forEach(function (session) {
|
|
296
|
+
if (target || !session || session.sessionOriginId !== resultMeta.driverOriginId) return;
|
|
297
|
+
var marker = session.scheduledTaskRun;
|
|
298
|
+
if ((session.ownerId || null) === (resultMeta.ownerId || null) && marker && marker.role === "driver" && marker.runId === resultMeta.runId && marker.scheduleId === resultMeta.scheduleId) target = session;
|
|
299
|
+
});
|
|
300
|
+
if (!target) throw new Error("This scheduled session is no longer available.");
|
|
301
|
+
sendTo(ws, { type: "scheduled_task_result_session", requestId: requestId, ref: resultEntry.ref, sessionId: target.localId });
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
256
304
|
} catch (e) {
|
|
257
305
|
fail(ws, requestId, (e && e.message) || "Project Logs could not complete the request.");
|
|
258
306
|
return true;
|
|
@@ -378,6 +426,26 @@ function attachProjectLogs(ctx) {
|
|
|
378
426
|
"\n" + logsMcp.REVIEW_CONTRACT + pendingFeedbackSignal(session);
|
|
379
427
|
}
|
|
380
428
|
|
|
429
|
+
function recordScheduledResult(data) {
|
|
430
|
+
if (!service || isMate) return null;
|
|
431
|
+
var result = service.recordScheduledResult(Object.assign({}, data || {}, { projectSlug: slug }));
|
|
432
|
+
if (!result || !result.entry || !result.created) return result;
|
|
433
|
+
var clients = getClients();
|
|
434
|
+
for (var client of clients) {
|
|
435
|
+
if (!client || client.readyState !== 1 || client._clayPane) continue;
|
|
436
|
+
if (result.entry.scheduledResult.ownerId && (!client._clayUser || client._clayUser.id !== result.entry.scheduledResult.ownerId)) continue;
|
|
437
|
+
var bound = userBinding(client);
|
|
438
|
+
if (!bound) continue;
|
|
439
|
+
try { bound.readLog({ ref: result.entry.ref }); } catch (e) { continue; }
|
|
440
|
+
sendTo(client, {
|
|
441
|
+
type: "scheduled_task_result_created", ref: result.entry.ref,
|
|
442
|
+
title: result.entry.title, summary: result.entry.summary,
|
|
443
|
+
outcome: result.entry.scheduledResult.outcome,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
|
|
381
449
|
return {
|
|
382
450
|
handleLogsMessage: handleLogsMessage,
|
|
383
451
|
createMcpServer: createMcpServer,
|
|
@@ -386,6 +454,8 @@ function attachProjectLogs(ctx) {
|
|
|
386
454
|
getBridgeTools: getBridgeTools,
|
|
387
455
|
callBridgeTool: callBridgeTool,
|
|
388
456
|
getSystemPrompt: getSystemPrompt,
|
|
457
|
+
recordScheduledResult: recordScheduledResult,
|
|
458
|
+
sendScheduledResultState: sendScheduledResultState,
|
|
389
459
|
};
|
|
390
460
|
}
|
|
391
461
|
|
package/lib/project-loop.js
CHANGED
|
@@ -373,6 +373,7 @@ function attachLoop(ctx) {
|
|
|
373
373
|
if (durableSchedule) durableSchedule.sync();
|
|
374
374
|
send({ type: "loop_registry_updated", records: getHubSchedules() });
|
|
375
375
|
},
|
|
376
|
+
onRunTerminal: ctx.onScheduledRunTerminal,
|
|
376
377
|
});
|
|
377
378
|
loopRegistry.load();
|
|
378
379
|
if (ctx.durableScheduler) {
|
|
@@ -67,7 +67,7 @@ var formatters = {
|
|
|
67
67
|
type: "permission_request",
|
|
68
68
|
title: data.title || "Permission requested",
|
|
69
69
|
body: data.body || "",
|
|
70
|
-
meta: { requestId: data.requestId, toolName: data.toolName, toolInput: data.toolInput || null },
|
|
70
|
+
meta: { requestId: data.requestId, toolName: data.toolName, toolInput: data.toolInput || null, defaultToNo: data.defaultToNo === true, suppressAlwaysAllowRule: data.suppressAlwaysAllowRule === true },
|
|
71
71
|
};
|
|
72
72
|
},
|
|
73
73
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Server-owned Scheduled Tasks results inside the Project Logs record stream.
|
|
2
|
+
// This capability is never exposed through the human or agent write surfaces.
|
|
3
|
+
|
|
4
|
+
var crypto = require("crypto");
|
|
5
|
+
var recordStore = require("./knowledge-record-store");
|
|
6
|
+
var logsSchema = require("./project-logs-schema");
|
|
7
|
+
var logsSnapshot = require("./project-logs-snapshot");
|
|
8
|
+
|
|
9
|
+
var ID_PATTERN = /^[A-Za-z0-9_-]{1,200}$/;
|
|
10
|
+
var OUTCOMES = ["completed", "failed", "needs-input", "interrupted", "skipped-busy"];
|
|
11
|
+
|
|
12
|
+
function clean(value, max) {
|
|
13
|
+
return logsSchema.cleanLine(typeof value === "string" ? value : "", max);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function normalizeMetadata(value) {
|
|
17
|
+
var source = value || {};
|
|
18
|
+
if (!ID_PATTERN.test(source.runId || "") || !ID_PATTERN.test(source.scheduleId || "")) return null;
|
|
19
|
+
if (OUTCOMES.indexOf(source.outcome) === -1) return null;
|
|
20
|
+
return {
|
|
21
|
+
runId: source.runId,
|
|
22
|
+
scheduleId: source.scheduleId,
|
|
23
|
+
outcome: source.outcome,
|
|
24
|
+
ownerId: source.ownerId ? clean(String(source.ownerId), 120) : null,
|
|
25
|
+
driverOriginId: clean(source.driverOriginId || "", 200) || null,
|
|
26
|
+
workerOriginId: clean(source.workerOriginId || "", 200) || null,
|
|
27
|
+
driverProviderSessionId: clean(source.driverProviderSessionId || "", 200) || null,
|
|
28
|
+
workerProviderSessionId: clean(source.workerProviderSessionId || "", 200) || null,
|
|
29
|
+
startedAt: Number(source.startedAt) || null,
|
|
30
|
+
finishedAt: Number(source.finishedAt) || null,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function visibleTo(metadata, viewerId) {
|
|
35
|
+
if (!metadata || viewerId === undefined) return true;
|
|
36
|
+
return (metadata.ownerId || null) === (viewerId || null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function outcomeLabel(outcome) {
|
|
40
|
+
if (outcome === "completed") return "Completed";
|
|
41
|
+
if (outcome === "needs-input") return "Needs input";
|
|
42
|
+
if (outcome === "interrupted") return "Interrupted";
|
|
43
|
+
if (outcome === "skipped-busy") return "Skipped";
|
|
44
|
+
return "Failed";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fallbackSummary(outcome) {
|
|
48
|
+
if (outcome === "completed") return "The scheduled task completed successfully.";
|
|
49
|
+
if (outcome === "needs-input") return "The scheduled task is waiting for user input or permission.";
|
|
50
|
+
if (outcome === "interrupted") return "The scheduled task was interrupted before completion.";
|
|
51
|
+
if (outcome === "skipped-busy") return "The scheduled occurrence was skipped because an earlier run was still active.";
|
|
52
|
+
return "The scheduled task failed.";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function rootId(scopeId, runId) {
|
|
56
|
+
var digest = crypto.createHash("sha256").update(scopeId + "\u0000scheduled-result\u0000" + runId).digest("base64url");
|
|
57
|
+
return "sresult-" + digest.substring(0, 24);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function attachScheduledResultStore(ctx) {
|
|
61
|
+
function resultRecord(runId) {
|
|
62
|
+
var records = ctx.store.all();
|
|
63
|
+
for (var i = 0; i < records.length; i++) {
|
|
64
|
+
if (records[i].op === "create" && records[i].scheduledResult && records[i].scheduledResult.runId === runId) return records[i];
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function create(input, context) {
|
|
70
|
+
var data = input || {};
|
|
71
|
+
var metadata = normalizeMetadata(data);
|
|
72
|
+
if (!metadata) throw new Error("Scheduled result identity is invalid.");
|
|
73
|
+
var existing = resultRecord(metadata.runId);
|
|
74
|
+
if (existing) return { entry: ctx.read(ctx.refFor(existing.rootId || existing.id), false), created: false };
|
|
75
|
+
var name = clean(data.name || "Scheduled task", 160) || "Scheduled task";
|
|
76
|
+
var reason = clean(data.summary || data.reason || "", 400);
|
|
77
|
+
var summary = reason || fallbackSummary(metadata.outcome);
|
|
78
|
+
var title = name + " · " + outcomeLabel(metadata.outcome);
|
|
79
|
+
var body = "## Scheduled result\n\n" + summary + "\n\n" +
|
|
80
|
+
"- Outcome: " + outcomeLabel(metadata.outcome) + "\n" +
|
|
81
|
+
"- Run: `" + metadata.runId + "`\n" +
|
|
82
|
+
(metadata.startedAt ? "- Started: " + new Date(metadata.startedAt).toISOString() + "\n" : "") +
|
|
83
|
+
(metadata.finishedAt ? "- Finished: " + new Date(metadata.finishedAt).toISOString() + "\n" : "");
|
|
84
|
+
var id = rootId(ctx.scopeId, metadata.runId);
|
|
85
|
+
var snapshot = logsSnapshot.cloneSnapshot({ category: "scheduled-result", priority: metadata.outcome === "failed" ? "important" : "normal", title: title, summary: summary, body: body, tags: ["scheduled-task", metadata.outcome], links: [] });
|
|
86
|
+
ctx.store.append({
|
|
87
|
+
id: id, rootId: id, op: "create", scope: ctx.scopeId,
|
|
88
|
+
kind: snapshot.category, priority: snapshot.priority, title: snapshot.title,
|
|
89
|
+
summary: snapshot.summary, body: snapshot.body, tags: snapshot.tags,
|
|
90
|
+
links: snapshot.links, snapshot: snapshot,
|
|
91
|
+
author: logsSchema.normalizeAuthor({ type: "system", displayName: "Scheduled Tasks" }),
|
|
92
|
+
context: context || null, scheduledResult: metadata, at: metadata.finishedAt || Date.now(),
|
|
93
|
+
});
|
|
94
|
+
return { entry: ctx.read(ctx.refFor(id), false), created: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function hasRead(root, readerId) {
|
|
98
|
+
var records = ctx.store.all();
|
|
99
|
+
for (var i = 0; i < records.length; i++) {
|
|
100
|
+
if (records[i].rootId === root && records[i].op === "scheduled-result-read" && (records[i].readerId || null) === (readerId || null)) return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function unread(viewerId, options) {
|
|
106
|
+
var entries = ctx.entries(false, viewerId);
|
|
107
|
+
var refs = [];
|
|
108
|
+
for (var i = 0; i < entries.length; i++) {
|
|
109
|
+
if (!entries[i].scheduledResult) continue;
|
|
110
|
+
if (ctx.matchesContext && !ctx.matchesContext(entries[i], options || {})) continue;
|
|
111
|
+
var located = ctx.findChain(entries[i].ref);
|
|
112
|
+
if (located && !hasRead(located.rootId, viewerId)) refs.push(entries[i].ref);
|
|
113
|
+
}
|
|
114
|
+
return { count: refs.length, newestRef: refs.length ? refs[0] : null, refs: refs };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function markRead(ref, viewerId, options) {
|
|
118
|
+
var entry = ctx.read(ref, false, viewerId);
|
|
119
|
+
if (!entry || !entry.scheduledResult) throw new Error("Scheduled result not found.");
|
|
120
|
+
var located = ctx.findChain(ref);
|
|
121
|
+
if (!located) throw new Error("Scheduled result not found.");
|
|
122
|
+
if (!hasRead(located.rootId, viewerId)) {
|
|
123
|
+
ctx.store.append({ id: recordStore.newRecordId(), rootId: located.rootId, op: "scheduled-result-read", scope: ctx.scopeId, readerId: viewerId || null, at: Date.now() });
|
|
124
|
+
}
|
|
125
|
+
return unread(viewerId, options);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { create: create, markRead: markRead, unread: unread };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = { attachScheduledResultStore: attachScheduledResultStore, normalizeMetadata: normalizeMetadata, visibleTo: visibleTo };
|
|
@@ -50,8 +50,9 @@ function attachScheduledTaskExecution(ctx) {
|
|
|
50
50
|
var active = record.activeRun;
|
|
51
51
|
var driver = sm.sessions.get(active.driverSessionId);
|
|
52
52
|
var worker = sm.sessions.get(active.workerSessionId);
|
|
53
|
+
var finalSummary = clean(reason, 1000) || null;
|
|
53
54
|
var saved = registry.completeRun(recordId, runId, {
|
|
54
|
-
outcome: outcome,
|
|
55
|
+
outcome: outcome, summary: finalSummary, reason: finalSummary,
|
|
55
56
|
driverProviderSessionId: driver && driver.cliSessionId || active.driverProviderSessionId || null,
|
|
56
57
|
workerProviderSessionId: worker && worker.cliSessionId || active.workerProviderSessionId || null,
|
|
57
58
|
});
|
|
@@ -65,6 +66,37 @@ function attachScheduledTaskExecution(ctx) {
|
|
|
65
66
|
return true;
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function recordTerminal(record, run, attempt) {
|
|
70
|
+
if (!record || !run || !run.runId || !run.outcome || typeof ctx.recordResult !== "function") return false;
|
|
71
|
+
try {
|
|
72
|
+
ctx.recordResult({
|
|
73
|
+
scheduleId: record.id, runId: run.runId, name: record.name || "Scheduled task",
|
|
74
|
+
ownerId: record.ownerId || null, outcome: run.outcome,
|
|
75
|
+
summary: run.summary || run.reason || null, startedAt: run.startedAt || null,
|
|
76
|
+
finishedAt: run.finishedAt || Date.now(), driverOriginId: run.driverOriginId || null,
|
|
77
|
+
workerOriginId: run.workerOriginId || null,
|
|
78
|
+
driverProviderSessionId: run.driverProviderSessionId || null,
|
|
79
|
+
workerProviderSessionId: run.workerProviderSessionId || null,
|
|
80
|
+
});
|
|
81
|
+
return true;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error("[scheduled-task] Failed to record result for " + run.runId + ":", error.message || error);
|
|
84
|
+
if (Number(attempt || 0) < 2) setTimeout(function () { recordTerminal(record, run, Number(attempt || 0) + 1); }, 1000);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function syncTerminalResults() {
|
|
90
|
+
var records = registry.getAll ? registry.getAll() : [];
|
|
91
|
+
for (var i = 0; i < records.length; i++) {
|
|
92
|
+
if (records[i].createdViaScheduledTasks !== true && records[i].source !== "schedule") continue;
|
|
93
|
+
var runs = Array.isArray(records[i].runs) ? records[i].runs : [];
|
|
94
|
+
for (var j = 0; j < runs.length; j++) {
|
|
95
|
+
if (runs[j] && runs[j].runId && runs[j].outcome) recordTerminal(records[i], runs[j]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
68
100
|
function failStart(recordId, runId, created, error, preDispatch) {
|
|
69
101
|
if (preDispatch) rollbackPair(created);
|
|
70
102
|
else if (created) {
|
|
@@ -110,6 +142,7 @@ function attachScheduledTaskExecution(ctx) {
|
|
|
110
142
|
name: record.name || "Scheduled task",
|
|
111
143
|
driver: record.execution.driver,
|
|
112
144
|
worker: record.execution.worker,
|
|
145
|
+
hidden: true,
|
|
113
146
|
});
|
|
114
147
|
var runState = {
|
|
115
148
|
status: "running", groupId: created.group.id,
|
|
@@ -230,7 +263,7 @@ function attachScheduledTaskExecution(ctx) {
|
|
|
230
263
|
return driver ? stopForSession(driver, reason) : finish(record.id, record.activeRun.runId, "interrupted", reason, false);
|
|
231
264
|
}
|
|
232
265
|
|
|
233
|
-
return { getToolDefs: getToolDefs, onPartnerResult: onPartnerResult, onTurnDone: onTurnDone, prepare: prepare, runnable: runnable, stopForSession: stopForSession, stopRecord: stopRecord, trigger: trigger };
|
|
266
|
+
return { getToolDefs: getToolDefs, onPartnerResult: onPartnerResult, onTurnDone: onTurnDone, prepare: prepare, recordTerminal: recordTerminal, runnable: runnable, stopForSession: stopForSession, stopRecord: stopRecord, syncTerminalResults: syncTerminalResults, trigger: trigger };
|
|
234
267
|
}
|
|
235
268
|
|
|
236
269
|
module.exports = { attachScheduledTaskExecution: attachScheduledTaskExecution, validRuntime: validRuntime };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var sessionNotesMcp = require("./session-notes-mcp-server");
|
|
2
2
|
var lifecycle = require("./notes-lifecycle");
|
|
3
|
+
var driverEligibility = require("./session-driver-eligibility");
|
|
3
4
|
|
|
4
5
|
var MAX_NOTE_TEXT_CHARS = 20000;
|
|
5
6
|
var MAX_ACTIVE_NOTES = 20;
|
|
@@ -172,13 +173,19 @@ function attachSessionNotes(ctx) {
|
|
|
172
173
|
return toolResult(publicNote(created));
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
// in the arguments.
|
|
176
|
+
// Cross-session closure requires a live, authorized Project Driver.
|
|
177
|
+
// Reopening retains the existing creator-only permission.
|
|
178
178
|
function ownedNote(args, caller, verb) {
|
|
179
|
+
var authorized = typeof ctx.canUseSession === "function" && ctx.canUseSession(caller);
|
|
180
|
+
if (ctx.canUseSession && !authorized) {
|
|
181
|
+
return { error: "this session no longer has access to project notes" };
|
|
182
|
+
}
|
|
179
183
|
var note = findNote(nm.list() || [], args && args.id);
|
|
180
184
|
if (!note) return { error: "note not found: " + ((args && args.id) || "unknown") };
|
|
181
|
-
|
|
185
|
+
var driverCanClose = verb === "close" && !ctx.isMate &&
|
|
186
|
+
driverEligibility.isEligibleDriverSession(caller) &&
|
|
187
|
+
authorized;
|
|
188
|
+
if (!driverCanClose && (!note.origin || note.origin.sessionId !== caller.localId)) {
|
|
182
189
|
return { error: "this session can only " + verb + " notes it created" };
|
|
183
190
|
}
|
|
184
191
|
return { note: note };
|