clay-server 4.0.1-beta.1 → 4.1.0-beta.10
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 +661 -21
- package/LICENSES/MIT-legacy.txt +21 -0
- package/LICENSES/README.md +7 -0
- package/README.md +2 -2
- package/bin/cli.js +1 -3
- package/lib/ask-user-request-identity.js +23 -0
- package/lib/autonomous-run-record.js +32 -0
- package/lib/autonomous-run-scheduler.js +92 -0
- package/lib/context-usage.js +47 -0
- package/lib/daemon-project-access.js +118 -0
- package/lib/daemon-projects.js +19 -5
- package/lib/daemon.js +19 -20
- package/lib/default-ai-runtime.js +117 -0
- package/lib/durable-scheduler-record.js +61 -0
- package/lib/durable-scheduler-store.js +185 -0
- package/lib/durable-scheduler.js +495 -0
- package/lib/git-cli.js +1 -0
- package/lib/issue-work-session.js +10 -0
- package/lib/issues-comments.js +40 -0
- package/lib/issues-commit-verification.js +30 -0
- package/lib/issues-mcp-server.js +27 -0
- package/lib/issues-schema.js +119 -0
- package/lib/issues-service.js +339 -0
- package/lib/issues-store.js +210 -0
- package/lib/loop-cron.js +47 -0
- package/lib/loop-durable-schedule.js +159 -0
- package/lib/loop-guidance.js +35 -0
- package/lib/loop-registry-occurrence.js +76 -0
- package/lib/model-entry.js +15 -0
- package/lib/project-ask-user.js +4 -1
- package/lib/project-autonomous-run.js +498 -0
- package/lib/project-capsule-turn.js +1 -0
- package/lib/project-connection.js +8 -1
- package/lib/project-delegated-session.js +1 -0
- package/lib/project-filesystem.js +10 -10
- package/lib/project-full-access.js +86 -0
- package/lib/project-http.js +3 -1
- package/lib/project-issue-launch.js +154 -0
- package/lib/project-issues.js +58 -0
- package/lib/project-logs-access-scope.js +94 -0
- package/lib/project-logs-mcp-server.js +8 -12
- package/lib/project-logs-query.js +3 -0
- package/lib/project-logs-service.js +86 -84
- package/lib/project-logs-store.js +5 -3
- package/lib/project-loop-interview.js +163 -0
- package/lib/project-loop.js +150 -64
- package/lib/project-message-delivery.js +4 -2
- package/lib/project-models.js +71 -3
- package/lib/project-notifications.js +1 -1
- package/lib/project-pair-autonomous-stop.js +16 -0
- package/lib/project-pair-lifecycle.js +140 -102
- package/lib/project-pair-message.js +50 -0
- package/lib/project-pair-owned-stop.js +18 -0
- package/lib/project-pair-replacement-state.js +72 -0
- package/lib/project-pair-task-control.js +277 -0
- package/lib/project-pair-usage.js +76 -0
- package/lib/project-pending-message-queue.js +328 -0
- package/lib/project-scheduled-messages.js +499 -0
- package/lib/project-scheduled-task-execution.js +236 -0
- package/lib/project-scheduled-tasks.js +481 -0
- package/lib/project-session-notes.js +11 -4
- package/lib/project-session-pair.js +123 -127
- package/lib/project-sessions.js +143 -32
- package/lib/project-tool-llm-runtime.js +48 -0
- package/lib/project-user-message.js +224 -62
- package/lib/project-worker-proposal.js +69 -58
- package/lib/project-workspace-query.js +25 -0
- package/lib/project.js +396 -73
- package/lib/public/app.js +96 -26
- package/lib/public/css/default-ai.css +33 -0
- package/lib/public/css/home-hub.css +15 -2
- package/lib/public/css/home-sidebar.css +50 -2
- package/lib/public/css/icon-strip.css +40 -0
- package/lib/public/css/input.css +160 -114
- package/lib/public/css/issues.css +101 -0
- package/lib/public/css/mates.css +0 -1
- package/lib/public/css/messages.css +19 -0
- package/lib/public/css/pane.css +98 -2
- package/lib/public/css/pending-message-queue.css +190 -0
- package/lib/public/css/rewind.css +11 -2
- package/lib/public/css/scheduled-tasks.css +122 -0
- package/lib/public/css/sticky-notes.css +24 -4
- package/lib/public/index.html +43 -150
- package/lib/public/modules/app-connection.js +3 -0
- package/lib/public/modules/app-cursors.js +29 -12
- package/lib/public/modules/app-loop-ui.js +4 -8
- package/lib/public/modules/app-message-router.js +8 -0
- package/lib/public/modules/app-messages.js +38 -22
- package/lib/public/modules/app-notifications.js +2 -0
- package/lib/public/modules/app-panels.js +9 -1
- package/lib/public/modules/app-projects.js +3 -0
- package/lib/public/modules/app-rate-limit.js +0 -179
- package/lib/public/modules/ask-user-state.js +66 -0
- package/lib/public/modules/autonomous-run.js +285 -0
- package/lib/public/modules/chat-render-runtime.js +0 -2
- package/lib/public/modules/clay-file-links.js +111 -0
- package/lib/public/modules/clay-issue-links.js +131 -0
- package/lib/public/modules/clay-log-links.js +2 -0
- package/lib/public/modules/cursor-sharing-preference.js +38 -0
- package/lib/public/modules/default-ai.js +377 -0
- package/lib/public/modules/filebrowser.js +43 -2
- package/lib/public/modules/home-sidebar.js +16 -8
- package/lib/public/modules/home-surface.js +5 -0
- package/lib/public/modules/input.js +92 -40
- package/lib/public/modules/issues-context.js +117 -0
- package/lib/public/modules/issues-render.js +29 -0
- package/lib/public/modules/issues.js +270 -0
- package/lib/public/modules/loop-interview.js +151 -0
- package/lib/public/modules/markdown.js +4 -0
- package/lib/public/modules/message-delivery.js +5 -3
- package/lib/public/modules/pending-message-image-editor.js +143 -0
- package/lib/public/modules/pending-message-queue-model.js +22 -0
- package/lib/public/modules/pending-message-queue.js +491 -0
- package/lib/public/modules/permission-hints.js +13 -0
- package/lib/public/modules/project-access.js +141 -0
- package/lib/public/modules/project-grouping.js +22 -0
- package/lib/public/modules/project-logs.js +2 -2
- package/lib/public/modules/scheduled-message-state.js +22 -0
- package/lib/public/modules/scheduled-task-edit-state.js +7 -0
- package/lib/public/modules/scheduled-task-engine.js +48 -0
- package/lib/public/modules/scheduled-task-form.js +122 -0
- package/lib/public/modules/scheduled-task-recurrence.js +46 -0
- package/lib/public/modules/scheduled-task-schedule-rule.js +115 -0
- package/lib/public/modules/scheduled-tasks.js +459 -0
- package/lib/public/modules/scheduler-config.js +6 -52
- package/lib/public/modules/scheduler.js +9 -21
- package/lib/public/modules/sidebar-mobile.js +3 -0
- package/lib/public/modules/sidebar-projects.js +14 -171
- package/lib/public/modules/sidebar.js +0 -11
- package/lib/public/modules/split-pair-ui.js +5 -0
- package/lib/public/modules/split-view.js +3 -0
- package/lib/public/modules/sticky-note-markdown.js +1 -0
- package/lib/public/modules/sticky-notes-browser.js +1 -1
- package/lib/public/modules/sticky-notes.js +117 -4
- package/lib/public/modules/terminal.js +2 -0
- package/lib/public/modules/tool-palette-order.js +3 -3
- package/lib/public/modules/tools.js +26 -5
- package/lib/public/modules/worker-proposal.js +4 -0
- package/lib/public/style.css +3 -0
- package/lib/record-revision.js +11 -0
- package/lib/schedule-rule.js +151 -0
- package/lib/schedule-validation.js +124 -0
- package/lib/scheduled-run-state.js +87 -0
- package/lib/scheduled-task-records.js +127 -0
- package/lib/scheduler.js +179 -196
- package/lib/sdk-bridge.js +191 -22
- package/lib/sdk-message-processor.js +32 -2
- package/lib/sdk-turn-queue.js +14 -0
- package/lib/server-admin.js +3 -3
- package/lib/server-cursor-sharing.js +65 -0
- package/lib/server-default-ai.js +265 -0
- package/lib/server-durable-scheduler.js +26 -0
- package/lib/server-global-ws.js +10 -0
- package/lib/server-home-chat.js +29 -9
- package/lib/server-home-clay-entry.js +4 -1
- package/lib/server-home-debate-planning.js +32 -14
- package/lib/server-home-mate-creation.js +30 -11
- package/lib/server-home-models.js +14 -6
- package/lib/server-issue-links.js +18 -0
- package/lib/server-mates.js +4 -3
- package/lib/server-palette.js +17 -14
- package/lib/server.js +247 -102
- package/lib/session-notes-mcp-server.js +2 -2
- package/lib/session-pair-factory.js +45 -4
- package/lib/session-pair-history.js +40 -0
- package/lib/session-pair-mcp-server.js +22 -4
- package/lib/session-pair-operation.js +11 -0
- package/lib/session-pair-prompts.js +31 -2
- package/lib/session-pair-query-start.js +22 -0
- package/lib/session-pair-turn-control.js +8 -3
- package/lib/session-provenance.js +1 -0
- package/lib/session-query-tool-bridge.js +52 -0
- package/lib/session-search.js +4 -1
- package/lib/session-spawn-mcp-server.js +2 -1
- package/lib/session-split-groups.js +35 -1
- package/lib/sessions.js +53 -3
- package/lib/tool-llm.js +1 -0
- package/lib/users-default-ai-preferences.js +80 -0
- package/lib/users-home-surface-preferences.js +2 -1
- package/lib/users-preferences.js +35 -0
- package/lib/users-scheduled-task-preferences.js +44 -0
- package/lib/users.js +16 -0
- package/lib/worker-proposal-control.js +69 -0
- package/lib/worker-proposal-decision.js +7 -0
- package/lib/worker-runtime-catalog.js +52 -0
- package/lib/workspace-query-access.js +3 -2
- package/lib/workspace-query-projection.js +29 -0
- package/lib/workspace-query-service.js +20 -30
- package/lib/worktree.js +8 -4
- package/lib/ws-schema.js +62 -1
- package/lib/yoke/adapters/antigravity.js +1 -0
- package/lib/yoke/adapters/claude-worker.js +22 -18
- package/lib/yoke/adapters/claude.js +85 -16
- package/lib/yoke/adapters/codex.js +28 -7
- 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/claude-user-input.js +2 -0
- package/lib/yoke/index.js +2 -0
- package/lib/yoke/mcp-bridge-server.js +7 -1
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/session-tool-transport.js +53 -0
- package/lib/yoke/user-input.js +21 -7
- package/package.json +9 -10
- package/bin/claude-relay.js +0 -6
- package/lib/public/modules/app-loop-wizard.js +0 -439
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
var builtinMates = require("./builtin-mates");
|
|
23
23
|
var logsStore = require("./project-logs-store");
|
|
24
|
+
var attachProjectLogsAccessScope = require("./project-logs-access-scope").attachProjectLogsAccessScope;
|
|
24
25
|
var LOG_REF_PATTERN = /^log:[A-Za-z0-9_-]{24}$/;
|
|
25
26
|
|
|
26
27
|
function readOnly() {
|
|
@@ -52,7 +53,6 @@ function attachProjectLogsService(ctx) {
|
|
|
52
53
|
var getProjects = context.getProjects;
|
|
53
54
|
var isMultiUser = context.isMultiUser;
|
|
54
55
|
var resolveMate = context.resolveMate;
|
|
55
|
-
var canAccessProject = context.canAccessProject;
|
|
56
56
|
var findUserById = context.findUserById || function () { return null; };
|
|
57
57
|
var storeCache = new Map();
|
|
58
58
|
|
|
@@ -75,61 +75,21 @@ function attachProjectLogsService(ctx) {
|
|
|
75
75
|
return (projects && projects.get(slug)) || null;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
function authorizedProject(principal, status) {
|
|
95
|
-
if (!status) return false;
|
|
96
|
-
if (status.isMate === true) return false;
|
|
97
|
-
var governing = effectiveStatus(status);
|
|
98
|
-
if (ownsProject(principal, governing)) return true;
|
|
99
|
-
if (isMultiUser() && principal.userId && typeof canAccessProject === "function") {
|
|
100
|
-
return canAccessProject(principal.userId, governing) === true;
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Open the store for the governing project. When a worktree's parent is
|
|
106
|
-
// registered, its path is authoritative, so worktree Logs are shared without
|
|
107
|
-
// depending on a Git subprocess. The store's own root resolution remains the
|
|
108
|
-
// fallback for unregistered parents and for subdirectories of a checkout.
|
|
109
|
-
function storeForStatus(status) {
|
|
110
|
-
var governing = effectiveStatus(status);
|
|
111
|
-
if (!governing || !governing.path) throw new Error("Project Logs are unavailable for this project.");
|
|
112
|
-
return openStore(governing.path, { projectKnowledgeId: governing.projectKnowledgeId || null });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function recordContext(status) {
|
|
116
|
-
if (!status || status.isWorktree !== true || !status.changeSetId) return null;
|
|
117
|
-
return {
|
|
118
|
-
kind: "worktree",
|
|
119
|
-
changeSetId: status.changeSetId,
|
|
120
|
-
branch: status.branch || null,
|
|
121
|
-
baseCommit: status.baseCommit || null,
|
|
122
|
-
headCommit: status.headCommit || null,
|
|
123
|
-
status: "active",
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function scopedArgs(args, status) {
|
|
128
|
-
var out = Object.assign({}, args || {});
|
|
129
|
-
if (!out.contextMode) out.contextMode = status && status.isWorktree ? "current" : "project";
|
|
130
|
-
out.currentChangeSetId = status && status.changeSetId || null;
|
|
131
|
-
return out;
|
|
132
|
-
}
|
|
78
|
+
var logScope = attachProjectLogsAccessScope({
|
|
79
|
+
projectFor: projectFor,
|
|
80
|
+
isMultiUser: isMultiUser,
|
|
81
|
+
canAccessProject: context.canAccessProject,
|
|
82
|
+
hasFullProjectAccess: context.hasFullProjectAccess,
|
|
83
|
+
openStore: openStore,
|
|
84
|
+
});
|
|
85
|
+
var effectiveStatus = logScope.effectiveStatus;
|
|
86
|
+
var ownsProject = logScope.ownsProject;
|
|
87
|
+
var projectAuthorization = logScope.projectAuthorization;
|
|
88
|
+
var authorizedProject = logScope.authorizedProject;
|
|
89
|
+
var storeForStatus = logScope.storeForStatus;
|
|
90
|
+
var recordContext = logScope.recordContext;
|
|
91
|
+
var scopedArgs = logScope.scopedArgs;
|
|
92
|
+
var visibleEntry = logScope.visibleEntry;
|
|
133
93
|
|
|
134
94
|
function statusFor(principal, slug) {
|
|
135
95
|
var project = projectFor(slug);
|
|
@@ -317,6 +277,20 @@ function attachProjectLogsService(ctx) {
|
|
|
317
277
|
return project.getStatus();
|
|
318
278
|
}
|
|
319
279
|
|
|
280
|
+
function currentScope() {
|
|
281
|
+
var current = revalidate();
|
|
282
|
+
var project = projectFor(current.principal.projectSlug);
|
|
283
|
+
var status = project && project.getStatus();
|
|
284
|
+
var decision = projectAuthorization(current.principal, status);
|
|
285
|
+
if (!decision.allowed) throw new Error("Project Logs are not available for this project.");
|
|
286
|
+
return { status: status, worktreeOnly: decision.worktreeOnly };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function scopedEntry(args) {
|
|
290
|
+
var scope = currentScope();
|
|
291
|
+
return visibleEntry(live(), args && args.ref, scope.status, scope.worktreeOnly);
|
|
292
|
+
}
|
|
293
|
+
|
|
320
294
|
function mutationContext() {
|
|
321
295
|
return recordContext(currentStatus());
|
|
322
296
|
}
|
|
@@ -336,8 +310,9 @@ function attachProjectLogsService(ctx) {
|
|
|
336
310
|
root: store.root,
|
|
337
311
|
author: initial.author,
|
|
338
312
|
listLogs: function (args) {
|
|
339
|
-
var
|
|
340
|
-
var
|
|
313
|
+
var scope = currentScope();
|
|
314
|
+
var status = scope.status;
|
|
315
|
+
var options = scopedArgs(args, status, scope.worktreeOnly);
|
|
341
316
|
var result = live().list(options);
|
|
342
317
|
result.contextMode = options.contextMode;
|
|
343
318
|
result.currentChangeSetId = status.changeSetId || null;
|
|
@@ -345,8 +320,9 @@ function attachProjectLogsService(ctx) {
|
|
|
345
320
|
return result;
|
|
346
321
|
},
|
|
347
322
|
searchLogs: function (args) {
|
|
348
|
-
var
|
|
349
|
-
var
|
|
323
|
+
var scope = currentScope();
|
|
324
|
+
var status = scope.status;
|
|
325
|
+
var options = scopedArgs(args, status, scope.worktreeOnly);
|
|
350
326
|
var result = live().search(options);
|
|
351
327
|
result.contextMode = options.contextMode;
|
|
352
328
|
result.currentChangeSetId = status.changeSetId || null;
|
|
@@ -354,21 +330,22 @@ function attachProjectLogsService(ctx) {
|
|
|
354
330
|
return result;
|
|
355
331
|
},
|
|
356
332
|
readLog: function (args) {
|
|
357
|
-
|
|
358
|
-
if (!entry) throw new Error("Log entry not found.");
|
|
359
|
-
return entry;
|
|
333
|
+
return scopedEntry(args);
|
|
360
334
|
},
|
|
361
|
-
logHistory: function (args) { return live().history(args && args.ref, args || {}); },
|
|
362
|
-
commentLog: function (args) { return live().comment(args && args.ref, args || {}, author(), mutationContext()); },
|
|
363
|
-
readLogRevision: function (args) { return live().readRevision(args && args.ref, args && args.revision); },
|
|
364
|
-
listLogFeedback: canonical ? function (args) {
|
|
365
|
-
|
|
335
|
+
logHistory: function (args) { scopedEntry(args); return live().history(args && args.ref, args || {}); },
|
|
336
|
+
commentLog: function (args) { scopedEntry(args); return live().comment(args && args.ref, args || {}, author(), mutationContext()); },
|
|
337
|
+
readLogRevision: function (args) { scopedEntry(args); return live().readRevision(args && args.ref, args && args.revision); },
|
|
338
|
+
listLogFeedback: canonical ? function (args) {
|
|
339
|
+
var scope = currentScope();
|
|
340
|
+
return live().feedback(scopedArgs(args, scope.status, scope.worktreeOnly));
|
|
341
|
+
} : driverOnly,
|
|
342
|
+
reviewLogComment: canonical ? function (args) { scopedEntry(args); return live().review(args && args.ref, args || {}, author(), mutationContext()); } : driverOnly,
|
|
366
343
|
revertLog: canonical
|
|
367
|
-
? function (args) { return live().revert(args && args.ref, args && args.revision, args && args.reason, author(), mutationContext()); }
|
|
344
|
+
? function (args) { scopedEntry(args); return live().revert(args && args.ref, args && args.revision, args && args.reason, author(), mutationContext()); }
|
|
368
345
|
: driverOnly,
|
|
369
346
|
createLog: canonical ? function (args) { return live().create(args || {}, author(), mutationContext()); } : agentOnly,
|
|
370
|
-
updateLog: canonical ? function (args) { return live().update(args && args.ref, args || {}, author(), mutationContext()); } : agentOnly,
|
|
371
|
-
linkLog: canonical ? function (args) { return live().link(args && args.ref, args && args.links, author(), mutationContext()); } : agentOnly,
|
|
347
|
+
updateLog: canonical ? function (args) { scopedEntry(args); return live().update(args && args.ref, args || {}, author(), mutationContext()); } : agentOnly,
|
|
348
|
+
linkLog: canonical ? function (args) { scopedEntry(args); return live().link(args && args.ref, args && args.links, author(), mutationContext()); } : agentOnly,
|
|
372
349
|
removeLog: canDelete ? function (args) {
|
|
373
350
|
var current = revalidate();
|
|
374
351
|
var project = projectFor(current.principal.projectSlug);
|
|
@@ -376,6 +353,7 @@ function attachProjectLogsService(ctx) {
|
|
|
376
353
|
if (!project || !authorizedProject(current.principal, currentStatus)) {
|
|
377
354
|
throw new Error("Project Logs are not available for this project.");
|
|
378
355
|
}
|
|
356
|
+
visibleEntry(storeForStatus(currentStatus), args && args.ref, currentStatus, projectAuthorization(current.principal, currentStatus).worktreeOnly);
|
|
379
357
|
if (current.principal.kind !== "session" && !ownsProject(current.principal, currentStatus)) ownerOnly();
|
|
380
358
|
return storeForStatus(currentStatus).remove(args && args.ref, current.author, recordContext(currentStatus));
|
|
381
359
|
} : ownerOnly,
|
|
@@ -394,7 +372,17 @@ function attachProjectLogsService(ctx) {
|
|
|
394
372
|
var principal = revalidate();
|
|
395
373
|
var slug = args && args.projectSlug;
|
|
396
374
|
if (!slug) throw new Error("An exact project slug is required.");
|
|
397
|
-
|
|
375
|
+
var status = statusFor(principal, slug);
|
|
376
|
+
var decision = projectAuthorization(principal, status);
|
|
377
|
+
return { store: storeForStatus(status), status: status, worktreeOnly: decision.worktreeOnly };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function targetEntry(args) {
|
|
381
|
+
var selected = target(args);
|
|
382
|
+
return {
|
|
383
|
+
selected: selected,
|
|
384
|
+
entry: visibleEntry(selected.store, args && args.ref, selected.status, selected.worktreeOnly),
|
|
385
|
+
};
|
|
398
386
|
}
|
|
399
387
|
|
|
400
388
|
function resolveLogNavigation(args) {
|
|
@@ -408,15 +396,19 @@ function attachProjectLogsService(ctx) {
|
|
|
408
396
|
projects.forEach(function (project, slug) {
|
|
409
397
|
if (!project || typeof project.getStatus !== "function") return;
|
|
410
398
|
var status = project.getStatus();
|
|
411
|
-
|
|
399
|
+
var decision = projectAuthorization(principal, status);
|
|
400
|
+
if (!decision.allowed) return;
|
|
412
401
|
var governing = effectiveStatus(status);
|
|
413
402
|
var scope = governing && (governing.projectKnowledgeId || governing.path);
|
|
414
|
-
|
|
415
|
-
seenScopes.
|
|
403
|
+
var scopeKey = decision.worktreeOnly ? scope + ":" + (status.changeSetId || slug) : scope;
|
|
404
|
+
if (!scope || seenScopes.has(scopeKey)) return;
|
|
405
|
+
seenScopes.add(scopeKey);
|
|
416
406
|
var entry = null;
|
|
417
|
-
try { entry = storeForStatus(status)
|
|
407
|
+
try { entry = visibleEntry(storeForStatus(status), ref, status, decision.worktreeOnly); } catch (e) { return; }
|
|
418
408
|
if (!entry) return;
|
|
419
|
-
var targetSlug =
|
|
409
|
+
var targetSlug = decision.worktreeOnly
|
|
410
|
+
? slug
|
|
411
|
+
: (status.isWorktree && status.parentSlug && projectFor(status.parentSlug) ? status.parentSlug : slug);
|
|
420
412
|
if (match && match.projectSlug !== targetSlug) throw new Error("Log reference is ambiguous.");
|
|
421
413
|
match = { projectSlug: targetSlug, ref: ref };
|
|
422
414
|
});
|
|
@@ -431,16 +423,26 @@ function attachProjectLogsService(ctx) {
|
|
|
431
423
|
canDelete: false,
|
|
432
424
|
projectSlug: null,
|
|
433
425
|
author: null,
|
|
434
|
-
listLogs: function (args) {
|
|
435
|
-
|
|
426
|
+
listLogs: function (args) {
|
|
427
|
+
var selected = target(args);
|
|
428
|
+
return selected.store.list(scopedArgs(args, selected.status, selected.worktreeOnly));
|
|
429
|
+
},
|
|
430
|
+
searchLogs: function (args) {
|
|
431
|
+
var selected = target(args);
|
|
432
|
+
return selected.store.search(scopedArgs(args, selected.status, selected.worktreeOnly));
|
|
433
|
+
},
|
|
436
434
|
readLog: function (args) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
435
|
+
return targetEntry(args).entry;
|
|
436
|
+
},
|
|
437
|
+
logHistory: function (args) {
|
|
438
|
+
var selected = targetEntry(args).selected;
|
|
439
|
+
return selected.store.history(args && args.ref, args || {});
|
|
440
440
|
},
|
|
441
|
-
logHistory: function (args) { return target(args).history(args && args.ref, args || {}); },
|
|
442
441
|
commentLog: readOnly,
|
|
443
|
-
readLogRevision: function (args) {
|
|
442
|
+
readLogRevision: function (args) {
|
|
443
|
+
var selected = targetEntry(args).selected;
|
|
444
|
+
return selected.store.readRevision(args && args.ref, args && args.revision);
|
|
445
|
+
},
|
|
444
446
|
resolveLogNavigation: resolveLogNavigation,
|
|
445
447
|
listLogFeedback: readOnly,
|
|
446
448
|
reviewLogComment: readOnly,
|
|
@@ -341,11 +341,12 @@ function createProjectLogsStore(opts) {
|
|
|
341
341
|
// revision that changes category updates the vocabulary without rewriting a
|
|
342
342
|
// single historical record. A shared project shares this list because it
|
|
343
343
|
// shares this store.
|
|
344
|
-
function categories() {
|
|
344
|
+
function categories(options) {
|
|
345
345
|
var seen = {};
|
|
346
346
|
var out = [];
|
|
347
347
|
var live = entries(false);
|
|
348
348
|
for (var i = 0; i < live.length; i++) {
|
|
349
|
+
if (!logsQuery.matchesContext(live[i], options || {})) continue;
|
|
349
350
|
var value = live[i].category;
|
|
350
351
|
if (!value || seen[value]) continue;
|
|
351
352
|
seen[value] = true;
|
|
@@ -382,6 +383,7 @@ function createProjectLogsStore(opts) {
|
|
|
382
383
|
var out = [];
|
|
383
384
|
var total = 0;
|
|
384
385
|
for (var i = 0; i < live.length; i++) {
|
|
386
|
+
if (!logsQuery.matchesContext(live[i], options2)) continue;
|
|
385
387
|
var awaiting = logsComments.pendingReviewComments(live[i].comments);
|
|
386
388
|
for (var j = 0; j < awaiting.length; j++) {
|
|
387
389
|
total++;
|
|
@@ -408,13 +410,13 @@ function createProjectLogsStore(opts) {
|
|
|
408
410
|
function list(args) {
|
|
409
411
|
var options2 = args || {};
|
|
410
412
|
var result = logsQuery.listEntries(entries(options2.includeDeleted === true), options2, cleanLine, validateKind);
|
|
411
|
-
result.categories = categories();
|
|
413
|
+
result.categories = categories(options2);
|
|
412
414
|
return result;
|
|
413
415
|
}
|
|
414
416
|
|
|
415
417
|
function search(args) {
|
|
416
418
|
var result = logsQuery.searchEntries(entries(false), args || {}, cleanLine, validateKind);
|
|
417
|
-
result.categories = categories();
|
|
419
|
+
result.categories = categories(args || {});
|
|
418
420
|
return result;
|
|
419
421
|
}
|
|
420
422
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var crypto = require("crypto");
|
|
2
|
+
var driverEligibility = require("./session-driver-eligibility");
|
|
3
|
+
var loopGuidance = require("./loop-guidance");
|
|
4
|
+
|
|
5
|
+
var MAX_OBJECTIVE = 20000;
|
|
6
|
+
var MAX_CRITERIA = 10;
|
|
7
|
+
var MAX_CRITERION = 1000;
|
|
8
|
+
|
|
9
|
+
function text(value, max) { return typeof value === "string" ? value.trim().substring(0, max) : ""; }
|
|
10
|
+
function criteria(value) { return (Array.isArray(value) ? value : []).slice(0, MAX_CRITERIA).map(function (item) { return text(item, MAX_CRITERION); }).filter(Boolean); }
|
|
11
|
+
function activeInterviewId(session) {
|
|
12
|
+
var history = Array.isArray(session && session.history) ? session.history : [];
|
|
13
|
+
var current = null;
|
|
14
|
+
for (var i = 0; i < history.length; i++) {
|
|
15
|
+
var entry = history[i];
|
|
16
|
+
if (entry && entry.source === "loop_interview") current = entry.interviewId || null;
|
|
17
|
+
if (entry && (entry.source === "loop_interview_cancel" || entry.source === "loop_interview_close") && entry.interviewId === current) current = null;
|
|
18
|
+
}
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
function brief(value) {
|
|
22
|
+
if (!value || typeof value !== "object") return null;
|
|
23
|
+
var objective = text(value.objective, MAX_OBJECTIVE);
|
|
24
|
+
var successCriteria = criteria(value.successCriteria);
|
|
25
|
+
if (!objective || successCriteria.length === 0) return null;
|
|
26
|
+
return { version: 1, id: text(value.id, 200) || crypto.randomUUID(), objective: objective,
|
|
27
|
+
successCriteria: successCriteria, maxContinuations: Math.max(1, Math.min(100, Math.floor(Number(value.maxContinuations) || 10))),
|
|
28
|
+
maxMinutes: Math.max(1, Math.min(1440, Math.floor(Number(value.maxMinutes) || 60))), createdAt: Number(value.createdAt) || Date.now() };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function attachLoopInterview(ctx) {
|
|
32
|
+
var sm = ctx.sm;
|
|
33
|
+
var sendTo = ctx.sendTo;
|
|
34
|
+
var autonomousRun = ctx.autonomousRun;
|
|
35
|
+
function eligible(session) { return !!(session && !ctx.isMate && (session.runtimeMode || session.mode) === "gui" && driverEligibility.isEligibleDriverSession(session) && !ctx.isDriverOperatedSession(session)); }
|
|
36
|
+
function runActive(session) { return !!(session && session.autonomousRun && ["armed", "running", "reviewing", "waiting-worker", "waiting-user", "paused"].indexOf(session.autonomousRun.state) !== -1); }
|
|
37
|
+
function hasInterview(session, requestId) {
|
|
38
|
+
var history = Array.isArray(session && session.history) ? session.history : [];
|
|
39
|
+
for (var i = history.length - 1; i >= 0; i--) if (history[i] && history[i].source === "loop_interview" && history[i].requestId === requestId) return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function currentInterview(session) {
|
|
43
|
+
return activeInterviewId(session);
|
|
44
|
+
}
|
|
45
|
+
function interviewActive(session) {
|
|
46
|
+
return !!currentInterview(session);
|
|
47
|
+
}
|
|
48
|
+
function startInterview(ws, msg) {
|
|
49
|
+
var session = ctx.getSessionForWs(ws);
|
|
50
|
+
var requestId = text(msg.requestId, 200);
|
|
51
|
+
var result = { type: "loop_interview_start_result", sessionId: session && session.localId || msg.sessionId || null, requestId: requestId, ok: false };
|
|
52
|
+
if (!session || !requestId || Number(msg.sessionId) !== Number(session.localId) || (ctx.canAccess && !ctx.canAccess(ws, session))) result.error = "This session is no longer available.";
|
|
53
|
+
else if (hasInterview(session, requestId)) { result.ok = true; result.duplicate = true; }
|
|
54
|
+
else if (!eligible(session)) result.error = "Loop interviews are available only in a Driver project chat.";
|
|
55
|
+
else if (runActive(session)) result.error = "Finish the active Loop run before starting another interview.";
|
|
56
|
+
else if (session.isProcessing || session._queryStarting) result.error = "Wait for the current task to finish before starting a Loop interview.";
|
|
57
|
+
else {
|
|
58
|
+
session.loopInterviewBrief = null;
|
|
59
|
+
var prompt = loopGuidance.interviewPrompt();
|
|
60
|
+
var interviewId = crypto.randomUUID();
|
|
61
|
+
var entry = { type: "user_message", text: "[Loop interview started]", source: "loop_interview", interviewId: interviewId, requestId: requestId, _ts: Date.now() };
|
|
62
|
+
session.history.push(entry);
|
|
63
|
+
sm.appendToSessionFile(session, entry);
|
|
64
|
+
sm.saveSessionFile(session);
|
|
65
|
+
publish(session);
|
|
66
|
+
ctx.sendToSession(session.localId, entry);
|
|
67
|
+
session.isProcessing = true;
|
|
68
|
+
ctx.onProcessingChanged();
|
|
69
|
+
ctx.sendToSession(session.localId, { type: "status", status: "processing" });
|
|
70
|
+
try {
|
|
71
|
+
var started = ctx.sdk.startQuery(session, prompt, null, ctx.ensureProjectAccessForSession(session));
|
|
72
|
+
ctx.sendTo(ws, Object.assign({}, result, { ok: true }));
|
|
73
|
+
Promise.resolve(started).catch(function (error) {
|
|
74
|
+
var stillCurrent = ctx.getSessionForWs(ws) === session && currentInterview(session) === interviewId && hasInterview(session, requestId);
|
|
75
|
+
if (!stillCurrent) return;
|
|
76
|
+
session.isProcessing = false;
|
|
77
|
+
ctx.onProcessingChanged();
|
|
78
|
+
ctx.sendToSession(session.localId, { type: "status", status: "idle" });
|
|
79
|
+
sm.saveSessionFile(session);
|
|
80
|
+
ctx.sendTo(ws, Object.assign({}, result, { ok: false, error: "Loop interview could not start: " + (error.message || error) }));
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
session.isProcessing = false;
|
|
85
|
+
ctx.onProcessingChanged();
|
|
86
|
+
ctx.sendToSession(session.localId, { type: "status", status: "idle" });
|
|
87
|
+
sm.saveSessionFile(session);
|
|
88
|
+
result.error = "Loop interview could not start: " + (error.message || error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
ctx.sendTo(ws, result);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function publish(session) { sm.sendToSession(session, { type: "loop_interview_brief", sessionId: session.localId, brief: session.loopInterviewBrief || null }); }
|
|
95
|
+
function propose(session, interviewId, args) {
|
|
96
|
+
if (!eligible(session) || runActive(session) || !interviewId || currentInterview(session) !== interviewId) return Promise.resolve({ content: [{ type: "text", text: JSON.stringify({ status: "rejected", reason: "propose_loop is stale or unavailable outside the current Driver Loop interview." }) }] });
|
|
97
|
+
var next = brief(args);
|
|
98
|
+
if (!next) return Promise.resolve({ content: [{ type: "text", text: JSON.stringify({ status: "rejected", reason: "Provide an objective and at least one success criterion." }) }] });
|
|
99
|
+
next.interviewId = interviewId;
|
|
100
|
+
session.loopInterviewBrief = next;
|
|
101
|
+
sm.saveSessionFile(session);
|
|
102
|
+
publish(session);
|
|
103
|
+
return Promise.resolve({ content: [{ type: "text", text: JSON.stringify({ status: "proposed", brief: next }) }] });
|
|
104
|
+
}
|
|
105
|
+
function getToolDefs(session) {
|
|
106
|
+
if (!eligible(session) || runActive(session) || !interviewActive(session) || session.loopInterviewBrief) return [];
|
|
107
|
+
var interviewId = currentInterview(session);
|
|
108
|
+
return [{ name: "propose_loop", description: "Draft a bounded Loop execution brief for human review. This never starts execution or changes permissions.", inputSchema: { type: "object", properties: {
|
|
109
|
+
objective: { type: "string" }, successCriteria: { type: "array", items: { type: "string" }, minItems: 1, maxItems: 10 },
|
|
110
|
+
maxContinuations: { type: "integer", minimum: 1, maximum: 100 }, maxMinutes: { type: "integer", minimum: 1, maximum: 1440 }
|
|
111
|
+
}, required: ["objective", "successCriteria"], additionalProperties: false }, handler: function (args) { return propose(session, interviewId, args || {}); } }];
|
|
112
|
+
}
|
|
113
|
+
function handleMessage(ws, msg) {
|
|
114
|
+
if (msg.type === "loop_interview_state") {
|
|
115
|
+
var stateSession = ctx.getSessionForWs(ws);
|
|
116
|
+
if (stateSession && Number(msg.sessionId) === Number(stateSession.localId) && (!ctx.canAccess || ctx.canAccess(ws, stateSession))) publish(stateSession);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (msg.type === "loop_interview_start") return startInterview(ws, msg);
|
|
120
|
+
if (["loop_interview_start_run", "loop_interview_edit", "loop_interview_cancel"].indexOf(msg.type) === -1) return false;
|
|
121
|
+
var session = ctx.getSessionForWs(ws);
|
|
122
|
+
if (!session || Number(msg.sessionId) !== Number(session.localId) || (ctx.canAccess && !ctx.canAccess(ws, session)) || !eligible(session)) {
|
|
123
|
+
if (msg.type === "loop_interview_start_run") sendTo(ws, { type: "loop_interview_start_run_result", ok: false, sessionId: session && session.localId || msg.sessionId || null, requestId: text(msg.requestId, 200), error: "This session is no longer available." });
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (msg.type === "loop_interview_cancel") {
|
|
127
|
+
if (session.loopInterviewBrief && (text(msg.proposalId, 200) !== session.loopInterviewBrief.id || Number(msg.version) !== Number(session.loopInterviewBrief.version))) return true;
|
|
128
|
+
var cancelEntry = { type: "loop_interview_cancel", source: "loop_interview_cancel", interviewId: currentInterview(session), _ts: Date.now() };
|
|
129
|
+
session.history.push(cancelEntry); sm.appendToSessionFile(session, cancelEntry);
|
|
130
|
+
session.loopInterviewBrief = null; sm.saveSessionFile(session); publish(session); return true;
|
|
131
|
+
}
|
|
132
|
+
if (msg.type === "loop_interview_edit") {
|
|
133
|
+
if (session.loopInterviewBrief && text(msg.proposalId, 200) === session.loopInterviewBrief.id && Number(msg.version) === Number(session.loopInterviewBrief.version) && session.loopInterviewBrief.interviewId === currentInterview(session)) {
|
|
134
|
+
var edited = brief(Object.assign({}, session.loopInterviewBrief, msg.brief || {}));
|
|
135
|
+
if (edited) { edited.interviewId = session.loopInterviewBrief.interviewId; edited.version = session.loopInterviewBrief.version + 1; session.loopInterviewBrief = edited; sm.saveSessionFile(session); publish(session); }
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
var proposal = session.loopInterviewBrief;
|
|
140
|
+
if (!proposal || proposal.interviewId !== currentInterview(session) || text(msg.proposalId, 200) !== proposal.id || Number(msg.version) !== Number(proposal.version)) {
|
|
141
|
+
sendTo(ws, { type: "loop_interview_start_run_result", ok: false, sessionId: session.localId, requestId: text(msg.requestId, 200), error: "This Loop brief is stale or no longer pending." });
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
autonomousRun.startApprovedBrief(ws, session, proposal, text(msg.requestId, 200), function () {
|
|
145
|
+
return !!(session.loopInterviewBrief && session.loopInterviewBrief.id === proposal.id && Number(session.loopInterviewBrief.version) === Number(proposal.version) && session.loopInterviewBrief.interviewId === currentInterview(session));
|
|
146
|
+
}).then(function (ok) {
|
|
147
|
+
if (ok && session.loopInterviewBrief && session.loopInterviewBrief.id === proposal.id) {
|
|
148
|
+
var closeEntry = { type: "loop_interview_close", source: "loop_interview_close", interviewId: proposal.interviewId, proposalId: proposal.id, proposalVersion: proposal.version, _ts: Date.now() };
|
|
149
|
+
session.history.push(closeEntry);
|
|
150
|
+
sm.appendToSessionFile(session, closeEntry);
|
|
151
|
+
session.loopInterviewBrief = null;
|
|
152
|
+
sm.saveSessionFile(session);
|
|
153
|
+
publish(session);
|
|
154
|
+
}
|
|
155
|
+
}).catch(function (error) {
|
|
156
|
+
sendTo(ws, { type: "loop_interview_start_run_result", ok: false, sessionId: session.localId, requestId: text(msg.requestId, 200), error: error.message || String(error) });
|
|
157
|
+
});
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return { getToolDefs: getToolDefs, handleMessage: handleMessage };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { attachLoopInterview: attachLoopInterview, brief: brief, activeInterviewId: activeInterviewId };
|