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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Licensing scope
|
|
2
|
+
|
|
3
|
+
Clay Studio as a whole is licensed under the GNU Affero General Public License, version 3 only (AGPL-3.0-only), under the terms in the root [LICENSE](../LICENSE). This project-wide license does not narrow the grants that apply to preexisting portions previously covered by the project’s MIT license.
|
|
4
|
+
|
|
5
|
+
Preexisting MIT-covered portions retain the grants and applicable copyright and permission notices from the MIT license. The byte-for-byte prior license text is preserved in [MIT-legacy.txt](MIT-legacy.txt), and this notice does not revoke or alter those earlier grants or notices.
|
|
6
|
+
|
|
7
|
+
Third-party components and assets retain their own licenses and notices. In particular, the bundled Source Serif 4 font remains under the [SIL Open Font License 1.1](../lib/public/fonts/source-serif-4/LICENSE.md).
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<a href="https://www.npmjs.com/package/clay-server"><img src="https://img.shields.io/npm/v/clay-server" alt="npm version" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/clay-server"><img src="https://img.shields.io/npm/dw/clay-server" alt="npm downloads" /></a>
|
|
16
16
|
<a href="https://github.com/chadbyte/clay"><img src="https://img.shields.io/github/stars/chadbyte/clay" alt="GitHub stars" /></a>
|
|
17
|
-
<a href="https://github.com/chadbyte/clay/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-
|
|
17
|
+
<a href="https://github.com/chadbyte/clay/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-AGPL--3.0--only-blue.svg" alt="License: AGPL-3.0-only" /></a>
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
20
|
Clay Studio turns local coding agents into a shared, persistent team. Run different agents from one browser workspace, join a teammate's live session, keep project knowledge between conversations, and automate work without handing your workspace to another cloud.
|
|
@@ -105,4 +105,4 @@ Clay Studio is not affiliated with the providers of the coding agents it support
|
|
|
105
105
|
|
|
106
106
|
## License
|
|
107
107
|
|
|
108
|
-
[
|
|
108
|
+
Clay Studio as a whole is licensed under the [GNU Affero General Public License, version 3 only](LICENSE) (AGPL-3.0-only). Preexisting portions previously covered by the project’s MIT license retain the grants and applicable notices from that license; see [LICENSES/MIT-legacy.txt](LICENSES/MIT-legacy.txt) and the [licensing scope notice](LICENSES/README.md). Third-party components remain under their respective licenses.
|
package/bin/cli.js
CHANGED
|
@@ -6,10 +6,8 @@ if (_nodeMajor < 20) {
|
|
|
6
6
|
console.error("");
|
|
7
7
|
console.error("\x1b[31m[clay] Node.js 20+ is required (current: " + process.version + ")\x1b[0m");
|
|
8
8
|
console.error("[clay] The Claude Agent SDK 0.2.40+ requires Node 20 for Symbol.dispose support.");
|
|
9
|
-
console.error("[clay] If you cannot upgrade Node, use claude-relay@2.4.3 which supports Node 18.");
|
|
10
9
|
console.error("");
|
|
11
10
|
console.error(" Upgrade Node: nvm install 22 && nvm use 22");
|
|
12
|
-
console.error(" Or use older: npx claude-relay@2.4.3");
|
|
13
11
|
console.error("");
|
|
14
12
|
process.exit(78);
|
|
15
13
|
}
|
|
@@ -1270,7 +1268,7 @@ function setup(callback) {
|
|
|
1270
1268
|
console.clear();
|
|
1271
1269
|
printLogo();
|
|
1272
1270
|
log("");
|
|
1273
|
-
log(sym.pointer + " " + a.bold + "Clay" + a.reset + a.dim + " ·
|
|
1271
|
+
log(sym.pointer + " " + a.bold + "Clay Studio" + a.reset + a.dim + " · Official open-source distribution" + a.reset);
|
|
1274
1272
|
log(sym.bar);
|
|
1275
1273
|
log(sym.bar + " " + a.yellow + sym.warn + " Disclaimer" + a.reset);
|
|
1276
1274
|
log(sym.bar);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function canonicalize(value) {
|
|
2
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
3
|
+
if (!value || typeof value !== "object") return value;
|
|
4
|
+
var keys = Object.keys(value).sort();
|
|
5
|
+
var result = {};
|
|
6
|
+
for (var i = 0; i < keys.length; i++) result[keys[i]] = canonicalize(value[keys[i]]);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function sameAskUserRequest(event, id, input) {
|
|
11
|
+
return !!(event && event.type === "tool_executing" && event.name === "AskUserQuestion"
|
|
12
|
+
&& event.id === id && JSON.stringify(canonicalize(event.input || {})) === JSON.stringify(canonicalize(input || {})));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hasRecordedAskUserRequest(history, id, input) {
|
|
16
|
+
if (!Array.isArray(history) || !id) return false;
|
|
17
|
+
for (var i = history.length - 1; i >= 0; i--) {
|
|
18
|
+
if (sameAskUserRequest(history[i], id, input)) return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { canonicalize: canonicalize, sameAskUserRequest: sameAskUserRequest, hasRecordedAskUserRequest: hasRecordedAskUserRequest };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var crypto = require("crypto");
|
|
2
|
+
var ACTIVE_STATES = ["armed", "running", "reviewing", "waiting-worker", "waiting-user", "paused"];
|
|
3
|
+
var TERMINAL_STATES = ["completed", "stopped", "limit", "error"];
|
|
4
|
+
function clean(value, max) { return typeof value === "string" ? value.trim().substring(0, max) : ""; }
|
|
5
|
+
function integer(value, fallback, max) { var number = Number(value); return Number.isFinite(number) ? Math.max(1, Math.min(max, Math.floor(number))) : fallback; }
|
|
6
|
+
function criteria(value) { return (Array.isArray(value) ? value : []).slice(0, 10).map(function (item) { return clean(item, 1000); }).filter(Boolean); }
|
|
7
|
+
function project(run) {
|
|
8
|
+
if (!run) return null;
|
|
9
|
+
return { id: run.id, state: run.state, objective: run.objective || "", successCriteria: run.successCriteria || [], continuationCount: run.continuationCount || 0,
|
|
10
|
+
maxContinuations: run.maxContinuations, startedAt: run.startedAt || null, deadlineAt: run.deadlineAt || null, maxMinutes: run.maxMinutes,
|
|
11
|
+
waitingReason: run.waitingReason || "", terminalReason: run.terminalReason || "", outcome: run.outcome || null, pausedAfterRestart: !!run.pausedAfterRestart,
|
|
12
|
+
armToken: run.state === "armed" ? run.armToken : undefined };
|
|
13
|
+
}
|
|
14
|
+
function restore(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || ACTIVE_STATES.concat(TERMINAL_STATES).indexOf(value.state) === -1) return null;
|
|
16
|
+
var evidence = value.outcome && Array.isArray(value.outcome.evidence) ? value.outcome.evidence.slice(0, 20).map(function (item) { return clean(item, 2000); }).filter(Boolean) : [];
|
|
17
|
+
var assessments = value.outcome && Array.isArray(value.outcome.criteria) ? value.outcome.criteria.slice(0, 10).map(function (item) {
|
|
18
|
+
return item && { criterion: clean(item.criterion, 1000), met: item.met === true, evidence: clean(item.evidence, 2000) };
|
|
19
|
+
}).filter(function (item) { return item && item.criterion && item.evidence; }) : [];
|
|
20
|
+
var snapshot = value.permissionSnapshot && typeof value.permissionSnapshot === "object" ? value.permissionSnapshot : {};
|
|
21
|
+
var run = { version: 1, id: clean(value.id, 200) || crypto.randomUUID(), state: value.state, objective: clean(value.objective, 20000), successCriteria: criteria(value.successCriteria),
|
|
22
|
+
continuationCount: Math.max(0, Math.min(100, Math.floor(Number(value.continuationCount) || 0))), maxContinuations: integer(value.maxContinuations, 10, 100), maxMinutes: integer(value.maxMinutes, 60, 1440),
|
|
23
|
+
createdAt: Number.isFinite(value.createdAt) ? value.createdAt : Date.now(), startedAt: Number.isFinite(value.startedAt) ? value.startedAt : null, deadlineAt: Number.isFinite(value.deadlineAt) ? value.deadlineAt : null,
|
|
24
|
+
finishedAt: Number.isFinite(value.finishedAt) ? value.finishedAt : null, waitingReason: clean(value.waitingReason, 2000), terminalReason: clean(value.terminalReason, 2000), pausedAfterRestart: !!value.pausedAfterRestart,
|
|
25
|
+
cancellationEpoch: Math.max(0, Math.floor(Number(value.cancellationEpoch) || 0)), rateLimitUntil: Number.isFinite(value.rateLimitUntil) ? value.rateLimitUntil : null, continuationPending: false,
|
|
26
|
+
wakeSequence: Math.max(0, Math.floor(Number(value.wakeSequence) || 0)), completionRequested: !!value.completionRequested,
|
|
27
|
+
permissionSnapshot: { permissionMode: clean(snapshot.permissionMode, 100) || null, permissionModeBeforeFullAccess: clean(snapshot.permissionModeBeforeFullAccess, 100) || null, enabled: snapshot.enabled === true } };
|
|
28
|
+
if (value.state === "armed") run.armToken = clean(value.armToken, 200) || crypto.randomUUID();
|
|
29
|
+
if (value.outcome && typeof value.outcome === "object") run.outcome = { assessment: clean(value.outcome.assessment, 40), summary: clean(value.outcome.summary, 4000), evidence: evidence, criteria: assessments, reportedAt: Number.isFinite(value.outcome.reportedAt) ? value.outcome.reportedAt : null };
|
|
30
|
+
return run;
|
|
31
|
+
}
|
|
32
|
+
module.exports = { project: project, restore: restore };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var sessionProvenance = require("./session-provenance");
|
|
2
|
+
|
|
3
|
+
function attachAutonomousRunScheduler(ctx) {
|
|
4
|
+
var scheduler = ctx.scheduler;
|
|
5
|
+
var type = "autonomous-wake:" + ctx.projectId;
|
|
6
|
+
var unregister = null;
|
|
7
|
+
function isMultiUser() { return typeof ctx.isMultiUser === "function" ? ctx.isMultiUser() : !!ctx.isMultiUser; }
|
|
8
|
+
|
|
9
|
+
function origin(session) {
|
|
10
|
+
var existing = session.sessionOriginId;
|
|
11
|
+
var value = sessionProvenance.ensureOrigin(session);
|
|
12
|
+
if (!existing) ctx.sm.saveSessionFile(session);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function owner(session) {
|
|
16
|
+
if (isMultiUser()) {
|
|
17
|
+
if (!session.ownerId) throw new Error("Until complete requires an explicit session owner.");
|
|
18
|
+
return session.ownerId;
|
|
19
|
+
}
|
|
20
|
+
return "local-user";
|
|
21
|
+
}
|
|
22
|
+
function matching(job, session, run, kind) {
|
|
23
|
+
return job.type === type && job.projectId === ctx.projectId && job.target.id === origin(session) &&
|
|
24
|
+
job.payload.runId === run.id && (!kind || job.payload.kind === kind);
|
|
25
|
+
}
|
|
26
|
+
function queued(session, run, kind) {
|
|
27
|
+
var jobs = scheduler.listJobs();
|
|
28
|
+
for (var i = jobs.length - 1; i >= 0; i--) if (jobs[i].state === "queued" && matching(jobs[i], session, run, kind)) return jobs[i];
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function schedule(session, run, kind, runAt) {
|
|
32
|
+
var sessionOrigin = origin(session);
|
|
33
|
+
run.wakeSequence = Math.max(0, Math.floor(Number(run.wakeSequence) || 0)) + 1;
|
|
34
|
+
if (ctx.sm && typeof ctx.sm.saveSessionFile === "function") ctx.sm.saveSessionFile(session);
|
|
35
|
+
var spec = {
|
|
36
|
+
type: type,
|
|
37
|
+
idempotencyKey: "autonomous:" + sessionOrigin + ":" + run.id + ":" + kind + ":" + run.cancellationEpoch + ":" + run.wakeSequence,
|
|
38
|
+
ownerId: owner(session),
|
|
39
|
+
projectId: ctx.projectId,
|
|
40
|
+
target: { kind: "project-session-origin", id: sessionOrigin },
|
|
41
|
+
payload: { kind: kind, runId: run.id, epoch: run.cancellationEpoch, wakeSequence: run.wakeSequence, sessionOrigin: sessionOrigin, cliSessionId: session.cliSessionId || null },
|
|
42
|
+
runAt: Number(runAt),
|
|
43
|
+
};
|
|
44
|
+
var current = queued(session, run, kind);
|
|
45
|
+
return current ? scheduler.replaceQueued(current.id, spec) : scheduler.enqueue(spec);
|
|
46
|
+
}
|
|
47
|
+
function cancel(session, run, kinds) {
|
|
48
|
+
if (!run) return;
|
|
49
|
+
var jobs = scheduler.listJobs();
|
|
50
|
+
for (var i = 0; i < jobs.length; i++) {
|
|
51
|
+
if (jobs[i].state !== "queued" || !matching(jobs[i], session, run)) continue;
|
|
52
|
+
if (kinds && kinds.indexOf(jobs[i].payload.kind) === -1) continue;
|
|
53
|
+
scheduler.cancel(jobs[i].id, "autonomous_run_cancelled_or_replaced");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function findSession(job) {
|
|
57
|
+
var found = null;
|
|
58
|
+
ctx.sm.sessions.forEach(function (session) {
|
|
59
|
+
if (!found && session.sessionOriginId === job.target.id) found = session;
|
|
60
|
+
});
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
function exact(job) {
|
|
64
|
+
var session = findSession(job);
|
|
65
|
+
var run = session && session.autonomousRun;
|
|
66
|
+
if (!session || !run || run.id !== job.payload.runId) return null;
|
|
67
|
+
if (job.payload.kind !== "deadline" && owner(session) !== job.ownerId) return null;
|
|
68
|
+
if (Number(run.cancellationEpoch || 0) !== Number(job.payload.epoch)) return null;
|
|
69
|
+
if (run.state === "armed" || run.state === "paused" || ["completed", "stopped", "limit", "error"].indexOf(run.state) !== -1) return null;
|
|
70
|
+
if (job.payload.kind !== "deadline" && ctx.authorize && !ctx.authorize(session)) return null;
|
|
71
|
+
return { session: session, run: run };
|
|
72
|
+
}
|
|
73
|
+
function canRun(job) {
|
|
74
|
+
var current;
|
|
75
|
+
try { current = exact(job); } catch (error) { return true; }
|
|
76
|
+
if (!current) return true;
|
|
77
|
+
return job.payload.kind !== "continuation" || (!current.session.isProcessing && !current.session._queryStarting);
|
|
78
|
+
}
|
|
79
|
+
function dispatch(job, execution) {
|
|
80
|
+
var current = exact(job);
|
|
81
|
+
if (!current) throw new Error("The Until complete wake no longer belongs to an authorized active run.");
|
|
82
|
+
execution.recordMetadata({ projectId: ctx.projectId, runId: current.run.id, kind: job.payload.kind, sessionOrigin: job.target.id, epoch: job.payload.epoch });
|
|
83
|
+
execution.recordReceipt({ state: "dispatching", runId: current.run.id, kind: job.payload.kind, sessionOrigin: job.target.id, recordedAt: Date.now() });
|
|
84
|
+
return ctx.onWake(job.payload.kind, current.session, current.run);
|
|
85
|
+
}
|
|
86
|
+
function start() {
|
|
87
|
+
if (!unregister) unregister = scheduler.registerHandler(type, dispatch, { canRun: canRun });
|
|
88
|
+
}
|
|
89
|
+
return { schedule: schedule, cancel: cancel, start: start, shutdown: function () { if (unregister) { unregister(); unregister = null; } } };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { attachAutonomousRunScheduler: attachAutonomousRunScheduler };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Shared request ordering for routine estimates and user-requested details.
|
|
2
|
+
var requests = new WeakMap();
|
|
3
|
+
|
|
4
|
+
function readUsage(session, detail) {
|
|
5
|
+
var query = session.queryInstance;
|
|
6
|
+
if (!query || typeof query.getContextUsage !== "function") return Promise.resolve(null);
|
|
7
|
+
var state = requests.get(session);
|
|
8
|
+
if (!state || state.query !== query || state.turn !== session.turnCount) {
|
|
9
|
+
state = { query: query, turn: session.turnCount, sequence: 0, pending: {} };
|
|
10
|
+
requests.set(session, state);
|
|
11
|
+
}
|
|
12
|
+
var level = detail === "full" ? "full" : "summary";
|
|
13
|
+
if (state.pending[level]) return state.pending[level];
|
|
14
|
+
var sequence = ++state.sequence;
|
|
15
|
+
var request = Promise.resolve().then(function() {
|
|
16
|
+
return query.getContextUsage({ detail: level });
|
|
17
|
+
}).then(function(data) {
|
|
18
|
+
if (!data || session.queryInstance !== query || requests.get(session) !== state || state.sequence !== sequence) return null;
|
|
19
|
+
session.lastContextUsage = data;
|
|
20
|
+
return data;
|
|
21
|
+
}).finally(function() { delete state.pending[level]; });
|
|
22
|
+
state.pending[level] = request;
|
|
23
|
+
return request;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function attachContextUsage(ctx) {
|
|
27
|
+
function allowed(ws, session) {
|
|
28
|
+
if (!session || ctx.getSessionForWs(ws) !== session) return false;
|
|
29
|
+
if (!ctx.usersModule || !ctx.usersModule.isMultiUser()) return true;
|
|
30
|
+
return !!(ws._clayUser && ctx.usersModule.canAccessSession(ws._clayUser.id, session, ctx.getProjectAccess ? ctx.getProjectAccess() : { visibility: "public" }));
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
handleMessage: function(ws, message) {
|
|
34
|
+
if (message.type !== "context_usage_request") return false;
|
|
35
|
+
var session = ctx.getSessionForWs(ws);
|
|
36
|
+
if (!allowed(ws, session) || message.sessionId !== session.localId) return true;
|
|
37
|
+
readUsage(session, "full").then(function(data) {
|
|
38
|
+
if (data && allowed(ws, session) && ctx.sm.sessions.get(session.localId) === session) {
|
|
39
|
+
ctx.sendTo(ws, { type: "context_usage", sessionId: session.localId, data: data });
|
|
40
|
+
}
|
|
41
|
+
}).catch(function(error) { console.error("[context-usage] Detail request failed:", error.message); });
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { readUsage: readUsage, attachContextUsage: attachContextUsage };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Persisted Clay-level access rules for parent projects and exact worktrees.
|
|
2
|
+
// Filesystem and Git permissions are deliberately outside this module.
|
|
3
|
+
|
|
4
|
+
function parentSlugFor(slug) {
|
|
5
|
+
if (typeof slug !== "string") return null;
|
|
6
|
+
var marker = slug.indexOf("--");
|
|
7
|
+
return marker > 0 ? slug.substring(0, marker) : null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function findProject(config, slug) {
|
|
11
|
+
var projects = config && Array.isArray(config.projects) ? config.projects : [];
|
|
12
|
+
for (var i = 0; i < projects.length; i++) {
|
|
13
|
+
if (projects[i].slug === slug) return projects[i];
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function uniqueUsers(values) {
|
|
19
|
+
var source = Array.isArray(values) ? values : [];
|
|
20
|
+
var seen = {};
|
|
21
|
+
var out = [];
|
|
22
|
+
for (var i = 0; i < source.length; i++) {
|
|
23
|
+
if (typeof source[i] !== "string" || !source[i] || seen[source[i]]) continue;
|
|
24
|
+
seen[source[i]] = true;
|
|
25
|
+
out.push(source[i]);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getProjectAccess(config, slug, osUsers) {
|
|
31
|
+
var parentSlug = parentSlugFor(slug);
|
|
32
|
+
var project = findProject(config, parentSlug || slug);
|
|
33
|
+
if (!project) return { error: "Project not found" };
|
|
34
|
+
|
|
35
|
+
var isMateProject = project.slug.indexOf("mate-") === 0;
|
|
36
|
+
var visibility = isMateProject ? "private" : (project.visibility || (osUsers ? "private" : "public"));
|
|
37
|
+
var parentAllowedUsers = uniqueUsers(project.allowedUsers);
|
|
38
|
+
if (!parentSlug) {
|
|
39
|
+
return {
|
|
40
|
+
slug: slug,
|
|
41
|
+
visibility: visibility,
|
|
42
|
+
allowedUsers: parentAllowedUsers,
|
|
43
|
+
ownerId: project.ownerId || null,
|
|
44
|
+
isWorktree: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var grants = project.worktreeAllowedUsers && project.worktreeAllowedUsers[slug];
|
|
49
|
+
var worktreeAllowedUsers = uniqueUsers(grants);
|
|
50
|
+
return {
|
|
51
|
+
slug: slug,
|
|
52
|
+
visibility: visibility,
|
|
53
|
+
allowedUsers: uniqueUsers(parentAllowedUsers.concat(worktreeAllowedUsers)),
|
|
54
|
+
ownerId: project.ownerId || null,
|
|
55
|
+
isWorktree: true,
|
|
56
|
+
parentSlug: parentSlug,
|
|
57
|
+
parentAllowedUsers: parentAllowedUsers,
|
|
58
|
+
worktreeAllowedUsers: worktreeAllowedUsers,
|
|
59
|
+
parentAccess: {
|
|
60
|
+
slug: parentSlug,
|
|
61
|
+
visibility: visibility,
|
|
62
|
+
allowedUsers: parentAllowedUsers,
|
|
63
|
+
ownerId: project.ownerId || null,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function setAllowedUsers(config, slug, allowedUsers) {
|
|
69
|
+
var parentSlug = parentSlugFor(slug);
|
|
70
|
+
var project = findProject(config, parentSlug || slug);
|
|
71
|
+
if (!project) return { error: "Project not found" };
|
|
72
|
+
var clean = uniqueUsers(allowedUsers);
|
|
73
|
+
if (!parentSlug) {
|
|
74
|
+
project.allowedUsers = clean;
|
|
75
|
+
return { ok: true, isWorktree: false, allowedUsers: clean };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!project.worktreeAllowedUsers || typeof project.worktreeAllowedUsers !== "object" || Array.isArray(project.worktreeAllowedUsers)) {
|
|
79
|
+
project.worktreeAllowedUsers = {};
|
|
80
|
+
}
|
|
81
|
+
if (clean.length > 0) project.worktreeAllowedUsers[slug] = clean;
|
|
82
|
+
else delete project.worktreeAllowedUsers[slug];
|
|
83
|
+
if (Object.keys(project.worktreeAllowedUsers).length === 0) delete project.worktreeAllowedUsers;
|
|
84
|
+
return { ok: true, isWorktree: true, allowedUsers: clean };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function clearWorktreeGrant(config, slug) {
|
|
88
|
+
var parentSlug = parentSlugFor(slug);
|
|
89
|
+
var project = parentSlug ? findProject(config, parentSlug) : null;
|
|
90
|
+
if (!project || !project.worktreeAllowedUsers || !Object.prototype.hasOwnProperty.call(project.worktreeAllowedUsers, slug)) return false;
|
|
91
|
+
delete project.worktreeAllowedUsers[slug];
|
|
92
|
+
if (Object.keys(project.worktreeAllowedUsers).length === 0) delete project.worktreeAllowedUsers;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function reconcileWorktreeGrants(config, parentSlug, existingSlugs) {
|
|
97
|
+
var project = findProject(config, parentSlug);
|
|
98
|
+
if (!project || !project.worktreeAllowedUsers) return false;
|
|
99
|
+
var existing = {};
|
|
100
|
+
for (var i = 0; i < existingSlugs.length; i++) existing[existingSlugs[i]] = true;
|
|
101
|
+
var changed = false;
|
|
102
|
+
var granted = Object.keys(project.worktreeAllowedUsers);
|
|
103
|
+
for (var j = 0; j < granted.length; j++) {
|
|
104
|
+
if (existing[granted[j]]) continue;
|
|
105
|
+
delete project.worktreeAllowedUsers[granted[j]];
|
|
106
|
+
changed = true;
|
|
107
|
+
}
|
|
108
|
+
if (Object.keys(project.worktreeAllowedUsers).length === 0) delete project.worktreeAllowedUsers;
|
|
109
|
+
return changed;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
parentSlugFor: parentSlugFor,
|
|
114
|
+
getProjectAccess: getProjectAccess,
|
|
115
|
+
setAllowedUsers: setAllowedUsers,
|
|
116
|
+
clearWorktreeGrant: clearWorktreeGrant,
|
|
117
|
+
reconcileWorktreeGrants: reconcileWorktreeGrants,
|
|
118
|
+
};
|
package/lib/daemon-projects.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var fs = require("fs");
|
|
8
|
-
var {
|
|
8
|
+
var { scanWorktreesResult, isWorktree } = require("./worktree");
|
|
9
9
|
var { daemonSync } = require("./daemon-sync");
|
|
10
10
|
var logContext = require("./project-log-context");
|
|
11
|
+
var daemonProjectAccess = require("./daemon-project-access");
|
|
12
|
+
var saveConfig = require("./config").saveConfig;
|
|
11
13
|
|
|
12
14
|
// --- Worktree tracking state ---
|
|
13
15
|
var worktreeRegistry = {}; // parentSlug -> [wtSlug, ...]
|
|
@@ -29,9 +31,13 @@ function isWorktreeSlug(slug) {
|
|
|
29
31
|
* @param {string} parentIcon - icon of parent project
|
|
30
32
|
* @param {string} parentOwnerId - owner user ID
|
|
31
33
|
*/
|
|
32
|
-
function scanAndRegisterWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId, projectKnowledgeId, osUserInfo) {
|
|
34
|
+
function scanAndRegisterWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId, projectKnowledgeId, osUserInfo, config) {
|
|
33
35
|
if (isWorktree(parentPath, osUserInfo)) return;
|
|
34
|
-
var
|
|
36
|
+
var scan = scanWorktreesResult(parentPath, osUserInfo);
|
|
37
|
+
if (!scan.ok) return;
|
|
38
|
+
var worktrees = scan.worktrees;
|
|
39
|
+
var currentSlugs = worktrees.map(function (worktree) { return parentSlug + "--" + worktree.dirName; });
|
|
40
|
+
if (config && daemonProjectAccess.reconcileWorktreeGrants(config, parentSlug, currentSlugs)) saveConfig(config);
|
|
35
41
|
if (worktrees.length === 0) return;
|
|
36
42
|
if (!worktreeRegistry[parentSlug]) worktreeRegistry[parentSlug] = [];
|
|
37
43
|
for (var i = 0; i < worktrees.length; i++) {
|
|
@@ -49,7 +55,7 @@ function scanAndRegisterWorktrees(relay, parentPath, parentSlug, parentIcon, par
|
|
|
49
55
|
console.log("[daemon] Registered worktree:", wtSlug, "->", wt.path, wt.external ? "(external)" : "(inside project folder)");
|
|
50
56
|
}
|
|
51
57
|
daemonSync.register(getWorktreeSyncKey(parentSlug), function () {
|
|
52
|
-
rescanWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId,
|
|
58
|
+
rescanWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerId, config, projectKnowledgeId, osUserInfo);
|
|
53
59
|
});
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -66,8 +72,15 @@ function rescanWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerI
|
|
|
66
72
|
if (worktreeScanning[parentSlug]) return;
|
|
67
73
|
worktreeScanning[parentSlug] = true;
|
|
68
74
|
try {
|
|
69
|
-
var
|
|
75
|
+
var scan = scanWorktreesResult(parentPath, osUserInfo);
|
|
76
|
+
if (!scan.ok) return;
|
|
77
|
+
var discovered = scan.worktrees;
|
|
70
78
|
var changed = false;
|
|
79
|
+
var discoveredSlugs = discovered.map(function (worktree) { return parentSlug + "--" + worktree.dirName; });
|
|
80
|
+
if (config && daemonProjectAccess.reconcileWorktreeGrants(config, parentSlug, discoveredSlugs)) {
|
|
81
|
+
saveConfig(config);
|
|
82
|
+
changed = true;
|
|
83
|
+
}
|
|
71
84
|
var existingSlugs = worktreeRegistry[parentSlug] || [];
|
|
72
85
|
var discoveredNames = {};
|
|
73
86
|
for (var i = 0; i < discovered.length; i++) {
|
|
@@ -96,6 +109,7 @@ function rescanWorktrees(relay, parentPath, parentSlug, parentIcon, parentOwnerI
|
|
|
96
109
|
if (!discoveredNames[dirName]) {
|
|
97
110
|
if (relay.setProjectLogContextState) relay.setProjectLogContextState(sSlug, "archived");
|
|
98
111
|
relay.removeProject(sSlug);
|
|
112
|
+
if (config && daemonProjectAccess.clearWorktreeGrant(config, sSlug)) saveConfig(config);
|
|
99
113
|
existingSlugs.splice(si, 1);
|
|
100
114
|
console.log("[daemon] Rescan: removed stale worktree:", sSlug);
|
|
101
115
|
changed = true;
|
package/lib/daemon.js
CHANGED
|
@@ -5,10 +5,8 @@ var nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
|
|
|
5
5
|
if (nodeMajor < 20) {
|
|
6
6
|
console.error("\x1b[31m[clay] Node.js 20+ is required (current: " + process.version + ")\x1b[0m");
|
|
7
7
|
console.error("[clay] The Claude Agent SDK 0.2.40+ requires Node 20 for Symbol.dispose support.");
|
|
8
|
-
console.error("[clay] If you cannot upgrade Node, use claude-relay@2.4.3 which supports Node 18.");
|
|
9
8
|
console.error("");
|
|
10
9
|
console.error(" Upgrade Node: nvm install 22 && nvm use 22");
|
|
11
|
-
console.error(" Or use older: npx claude-relay@2.4.3");
|
|
12
10
|
process.exit(78); // EX_CONFIG — fatal config error, don't auto-restart
|
|
13
11
|
}
|
|
14
12
|
|
|
@@ -36,6 +34,7 @@ var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
|
|
|
36
34
|
var mates = require("./mates");
|
|
37
35
|
var mateKnowledgeMigration = require("./mate-knowledge-migration");
|
|
38
36
|
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
|
|
37
|
+
var daemonProjectAccess = require("./daemon-project-access");
|
|
39
38
|
var projectLogContext = require("./project-log-context");
|
|
40
39
|
|
|
41
40
|
var daemonVersion = require("../package.json").version;
|
|
@@ -186,7 +185,7 @@ function worktreeOsUserInfo(project, requestUser) {
|
|
|
186
185
|
function registerProjectWorktrees(project, requestUser) {
|
|
187
186
|
try {
|
|
188
187
|
var osUserInfo = worktreeOsUserInfo(project, requestUser);
|
|
189
|
-
scanAndRegisterWorktrees(relay, project.path, project.slug, project.icon, project.ownerId, project.projectKnowledgeId, osUserInfo);
|
|
188
|
+
scanAndRegisterWorktrees(relay, project.path, project.slug, project.icon, project.ownerId, project.projectKnowledgeId, osUserInfo, config);
|
|
190
189
|
} catch (e) {
|
|
191
190
|
console.error("[daemon] Failed to scan worktrees for " + project.slug + ": " + e.message);
|
|
192
191
|
}
|
|
@@ -440,6 +439,7 @@ var relay = createServer({
|
|
|
440
439
|
}
|
|
441
440
|
relay.removeProject(slug);
|
|
442
441
|
unregisterWorktreeSlug(wtParent, slug);
|
|
442
|
+
if (daemonProjectAccess.clearWorktreeGrant(config, slug)) saveConfig(config);
|
|
443
443
|
console.log("[daemon] Removed worktree (web):", slug);
|
|
444
444
|
relay.broadcastAll({
|
|
445
445
|
type: "projects_updated",
|
|
@@ -599,6 +599,7 @@ var relay = createServer({
|
|
|
599
599
|
projects: relay.getProjects(),
|
|
600
600
|
projectCount: config.projects.length,
|
|
601
601
|
});
|
|
602
|
+
if (relay.refreshProjectAccess) relay.refreshProjectAccess();
|
|
602
603
|
return { ok: true };
|
|
603
604
|
},
|
|
604
605
|
onGetProjectEnv: function (slug) {
|
|
@@ -960,20 +961,27 @@ var relay = createServer({
|
|
|
960
961
|
}
|
|
961
962
|
}
|
|
962
963
|
}
|
|
964
|
+
if (relay.refreshProjectAccess) relay.refreshProjectAccess();
|
|
963
965
|
return { ok: true };
|
|
964
966
|
}
|
|
965
967
|
}
|
|
966
968
|
return { error: "Project not found" };
|
|
967
969
|
},
|
|
968
970
|
onSetProjectAllowedUsers: function (slug, allowedUsers) {
|
|
971
|
+
var accessBefore = daemonProjectAccess.getProjectAccess(config, slug, config.osUsers);
|
|
972
|
+
var result = daemonProjectAccess.setAllowedUsers(config, slug, allowedUsers);
|
|
973
|
+
if (result.error) return result;
|
|
974
|
+
var parentSlug = daemonProjectAccess.parentSlugFor(slug);
|
|
969
975
|
for (var i = 0; i < config.projects.length; i++) {
|
|
970
|
-
if (config.projects[i].slug === slug) {
|
|
971
|
-
var prev =
|
|
972
|
-
|
|
976
|
+
if (config.projects[i].slug === (parentSlug || slug)) {
|
|
977
|
+
var prev = accessBefore && !accessBefore.error
|
|
978
|
+
? (parentSlug ? accessBefore.worktreeAllowedUsers : accessBefore.allowedUsers)
|
|
979
|
+
: [];
|
|
973
980
|
saveConfig(config);
|
|
974
|
-
console.log("[daemon] Set project allowed users:", slug, "→", allowedUsers.length, "users");
|
|
981
|
+
console.log("[daemon] Set project allowed users:", slug, "→", result.allowedUsers.length, "users");
|
|
975
982
|
// OS users mode: sync ACLs for added/removed users
|
|
976
|
-
|
|
983
|
+
// Exact-worktree grants are Clay-only and never change filesystem ACLs.
|
|
984
|
+
if (config.osUsers && !parentSlug) {
|
|
977
985
|
var projectPath = config.projects[i].path;
|
|
978
986
|
// Grant access to newly added users
|
|
979
987
|
for (var a = 0; a < allowedUsers.length; a++) {
|
|
@@ -994,24 +1002,14 @@ var relay = createServer({
|
|
|
994
1002
|
}
|
|
995
1003
|
}
|
|
996
1004
|
}
|
|
1005
|
+
if (relay.refreshProjectAccess) relay.refreshProjectAccess();
|
|
997
1006
|
return { ok: true };
|
|
998
1007
|
}
|
|
999
1008
|
}
|
|
1000
1009
|
return { error: "Project not found" };
|
|
1001
1010
|
},
|
|
1002
1011
|
onGetProjectAccess: function (slug) {
|
|
1003
|
-
|
|
1004
|
-
if (config.projects[i].slug === slug) {
|
|
1005
|
-
var isMateProject = slug.indexOf("mate-") === 0;
|
|
1006
|
-
return {
|
|
1007
|
-
slug: slug,
|
|
1008
|
-
visibility: isMateProject ? "private" : (config.projects[i].visibility || (config.osUsers ? "private" : "public")),
|
|
1009
|
-
allowedUsers: config.projects[i].allowedUsers || [],
|
|
1010
|
-
ownerId: config.projects[i].ownerId || null,
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
return { error: "Project not found" };
|
|
1012
|
+
return daemonProjectAccess.getProjectAccess(config, slug, config.osUsers);
|
|
1015
1013
|
},
|
|
1016
1014
|
onUserProvisioned: function (userId, linuxUser) {
|
|
1017
1015
|
// Grant ACL on all public projects to the newly provisioned user
|
|
@@ -1048,6 +1046,7 @@ var relay = createServer({
|
|
|
1048
1046
|
if (!result.ok) return result;
|
|
1049
1047
|
// Register the new worktree as ephemeral project
|
|
1050
1048
|
var wtSlug = parentSlug + "--" + dirName;
|
|
1049
|
+
if (daemonProjectAccess.clearWorktreeGrant(config, wtSlug)) saveConfig(config);
|
|
1051
1050
|
var context = projectLogContext.resolveWorktreeContext(result.path, parent.projectKnowledgeId, {
|
|
1052
1051
|
branch: branchName,
|
|
1053
1052
|
baseCommit: baseCommit,
|