@clagentic/console 1.10.0 → 1.11.0-beta.1
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/README.md +14 -0
- package/bin/cli.js +15 -3
- package/lib/agents.js +1 -55
- package/lib/bash-auto-approve.js +133 -0
- package/lib/build-identity.js +23 -5
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +0 -62
- package/lib/build-update-offer.js +23 -13
- package/lib/build-update-restart.js +59 -43
- package/lib/cli/schedule-input-subcommands.js +327 -0
- package/lib/cli/session-subcommands.js +100 -17
- package/lib/client-build-id.js +56 -0
- package/lib/daemon.js +20 -5
- package/lib/injected-sender.js +225 -0
- package/lib/message-sender-record.js +133 -0
- package/lib/pending-prompts.js +55 -0
- package/lib/permission-mode-policy.js +63 -0
- package/lib/permission-summary.js +67 -0
- package/lib/project-connection.js +2 -1
- package/lib/project-external-trigger.js +9 -1
- package/lib/project-loop.js +26 -20
- package/lib/project-prompt-responses.js +20 -14
- package/lib/project-sessions.js +73 -21
- package/lib/project-user-message.js +18 -47
- package/lib/project.js +36 -62
- package/lib/public/app.js +3 -5
- package/lib/public/css/channel-layout.css +20 -0
- package/lib/public/css/diagnostics.css +7 -0
- package/lib/public/css/input.css +78 -0
- package/lib/public/css/menus.css +17 -0
- package/lib/public/modules/app-connection.js +18 -1
- package/lib/public/modules/app-messages.js +19 -17
- package/lib/public/modules/app-panels.js +9 -2
- package/lib/public/modules/app-rate-limit.js +63 -87
- package/lib/public/modules/app-rendering.js +37 -6
- package/lib/public/modules/at-agents.js +8 -0
- package/lib/public/modules/build-guard.js +61 -0
- package/lib/public/modules/build-update-detail.js +1 -4
- package/lib/public/modules/diagnostics.js +98 -9
- package/lib/public/modules/injected-identity.js +78 -0
- package/lib/public/modules/injected-label.js +62 -0
- package/lib/public/modules/input.js +64 -114
- package/lib/public/modules/mode-options.js +19 -16
- package/lib/public/modules/rate-limit-state.js +47 -22
- package/lib/public/modules/schedule-panel.js +234 -0
- package/lib/public/modules/schedule-time.js +193 -0
- package/lib/public/modules/scheduled-input-actions.js +19 -0
- package/lib/runtime-env.js +4 -0
- package/lib/scheduled-input/ipc.js +92 -0
- package/lib/scheduled-input/rate-limit-resume.js +53 -0
- package/lib/scheduled-input/records.js +350 -0
- package/lib/scheduled-input/service.js +743 -0
- package/lib/scheduled-input/store.js +132 -0
- package/lib/scheduled-input/ws.js +194 -0
- package/lib/sdk-bridge.js +137 -152
- package/lib/sdk-message-processor.js +13 -5
- package/lib/sdk-skill-discovery.js +17 -0
- package/lib/sender-ref.js +109 -0
- package/lib/server.js +28 -8
- package/lib/session-directory.js +224 -0
- package/lib/session-file-scan.js +55 -0
- package/lib/session-input-ipc.js +20 -0
- package/lib/session-input.js +355 -19
- package/lib/session-name-holder.js +82 -0
- package/lib/session-resume.js +1 -0
- package/lib/sessions.js +44 -0
- package/lib/turn-initiator.js +6 -2
- package/lib/ws-schema.js +15 -7
- package/lib/yoke/adapters/claude-worker.js +3 -1
- package/lib/yoke/adapters/claude.js +13 -7
- package/lib/yoke/adapters/codex.js +18 -5
- package/lib/yoke/adapters/permission-relay.js +9 -0
- package/lib/yoke/interface.js +7 -1
- package/package.json +1 -1
- package/scripts/check-test-count.js +1 -1
- package/scripts/install-local-test.js +45 -1
- package/scripts/postinstall.js +1 -0
package/lib/project-loop.js
CHANGED
|
@@ -8,6 +8,7 @@ var usersModule = require("./users");
|
|
|
8
8
|
var { writeHandoff, buildHandoffPreamble } = require("./loop-handoff");
|
|
9
9
|
var { authOf } = require("./project-access");
|
|
10
10
|
var { INITIATORS } = require("./turn-initiator");
|
|
11
|
+
var { consoleTurnEntry, stampRecord } = require("./injected-sender");
|
|
11
12
|
|
|
12
13
|
var LOOP_ID_RE = /^loop_[A-Za-z0-9_-]+$/;
|
|
13
14
|
|
|
@@ -20,6 +21,12 @@ var LOOP_ID_RE = /^loop_[A-Za-z0-9_-]+$/;
|
|
|
20
21
|
var LOOP_MESSAGE_MAX_QUEUE_LENGTH = 20;
|
|
21
22
|
var LOOP_MESSAGE_MAX_TEXT_LENGTH = 4000;
|
|
22
23
|
|
|
24
|
+
// The detail a loop turn's chat label carries after "loop": the loop's name, when
|
|
25
|
+
// it has one, then what this turn is.
|
|
26
|
+
function loopNote(name, what) {
|
|
27
|
+
return name ? name + " · " + what : what;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
/**
|
|
24
31
|
* Validate a loop ID before using it as a path component.
|
|
25
32
|
*
|
|
@@ -574,36 +581,35 @@ function attachLoop(ctx) {
|
|
|
574
581
|
|
|
575
582
|
// lr-e31b: Deliver human messages queued during the prior iteration at this
|
|
576
583
|
// boundary. Ephemeral loop-iteration sessions are single-turn (their SDK
|
|
577
|
-
// input stream is closed
|
|
584
|
+
// input stream is closed right after the messages are pushed - see
|
|
578
585
|
// yoke/adapters/claude.js endInput()), so mid-flight injection into a live
|
|
579
|
-
// iteration is not viable without a broader architecture change.
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
//
|
|
586
|
+
// iteration is not viable without a broader architecture change.
|
|
587
|
+
//
|
|
588
|
+
// Each queued message is the operator's own words, so it is sent to the
|
|
589
|
+
// vendor as a user message of its own, ahead of the iteration message: it
|
|
590
|
+
// carries the human initiator (the vendor's per-turn origin and the
|
|
591
|
+
// published sender record) and its own message id, and is never merged into
|
|
592
|
+
// or recorded under the iteration message, which keeps the loop initiator.
|
|
583
593
|
var _queuedMsgs = loopState.pendingUserMessages || [];
|
|
594
|
+
var _leadMessages = [];
|
|
584
595
|
if (_queuedMsgs.length > 0) {
|
|
585
|
-
var _queuedBlock = ["## Message from user (sent during the previous iteration)", ""];
|
|
586
596
|
for (var _qi = 0; _qi < _queuedMsgs.length; _qi++) {
|
|
587
597
|
var _qm = _queuedMsgs[_qi];
|
|
588
|
-
|
|
589
|
-
// Record as its own history entry so the transcript shows exactly what
|
|
590
|
-
// the human sent and when, distinct from the coder's own prompt text.
|
|
591
|
-
var _qUserMsg = { type: "user_message", text: _qm.text, _ts: _qm.ts || Date.now() };
|
|
598
|
+
var _qUserMsg = stampRecord({ type: "user_message", text: _qm.text, _ts: _qm.ts || Date.now(), initiator: INITIATORS.HUMAN });
|
|
592
599
|
if (_qm.from) { _qUserMsg.from = _qm.from; _qUserMsg.fromName = _qm.fromName || ""; }
|
|
593
600
|
// lr-2ea2a7: routes through the shared history-cap helper (see
|
|
594
601
|
// grep-guard test) — Ralph/crew loop sessions are exactly the
|
|
595
602
|
// long-running isProcessing sessions this fix bounds.
|
|
596
603
|
sm.recordHistoryEntry(session, _qUserMsg, true);
|
|
597
604
|
sm.appendToSessionFile(session, _qUserMsg);
|
|
605
|
+
_leadMessages.push({ text: _qm.text, initiator: INITIATORS.HUMAN, messageId: _qUserMsg.messageId });
|
|
598
606
|
}
|
|
599
|
-
_queuedBlock.push("", "---", "");
|
|
600
|
-
_iterationPrompt = _queuedBlock.join("\n") + _iterationPrompt;
|
|
601
607
|
loopState.pendingUserMessages = [];
|
|
602
608
|
saveLoopState();
|
|
603
609
|
send({ type: "loop_pending_messages", messages: [] });
|
|
604
610
|
}
|
|
605
611
|
|
|
606
|
-
var userMsg =
|
|
612
|
+
var userMsg = consoleTurnEntry(INITIATORS.LOOP, _iterationPrompt, loopNote(loopName, "iteration " + loopState.iteration));
|
|
607
613
|
sm.recordHistoryEntry(session, userMsg, true);
|
|
608
614
|
sm.appendToSessionFile(session, userMsg);
|
|
609
615
|
|
|
@@ -614,7 +620,7 @@ function attachLoop(ctx) {
|
|
|
614
620
|
session.acceptEditsAfterStart = true;
|
|
615
621
|
session.singleTurn = true;
|
|
616
622
|
if (loopState.settings) session.loopSettings = loopState.settings;
|
|
617
|
-
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session), INITIATORS.LOOP);
|
|
623
|
+
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session), INITIATORS.LOOP, userMsg.messageId, _leadMessages);
|
|
618
624
|
}
|
|
619
625
|
|
|
620
626
|
function runJudge() {
|
|
@@ -726,7 +732,7 @@ function attachLoop(ctx) {
|
|
|
726
732
|
}
|
|
727
733
|
}, 10 * 60 * 1000);
|
|
728
734
|
|
|
729
|
-
var userMsg =
|
|
735
|
+
var userMsg = consoleTurnEntry(INITIATORS.LOOP, judgePrompt, loopNote(judgeName, "judge, iteration " + loopState.iteration));
|
|
730
736
|
// lr-2ea2a7: routes through the shared history-cap helper (see grep-guard test).
|
|
731
737
|
sm.recordHistoryEntry(judgeSession, userMsg, true);
|
|
732
738
|
sm.appendToSessionFile(judgeSession, userMsg);
|
|
@@ -737,7 +743,7 @@ function attachLoop(ctx) {
|
|
|
737
743
|
judgeSession.acceptEditsAfterStart = true;
|
|
738
744
|
judgeSession.singleTurn = true;
|
|
739
745
|
if (loopState.settings) judgeSession.loopSettings = loopState.settings;
|
|
740
|
-
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession), INITIATORS.LOOP);
|
|
746
|
+
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession), INITIATORS.LOOP, userMsg.messageId);
|
|
741
747
|
}
|
|
742
748
|
|
|
743
749
|
// lr-2ea2a7: forward-accumulates delta/text across the FULL heap array —
|
|
@@ -1155,7 +1161,7 @@ function attachLoop(ctx) {
|
|
|
1155
1161
|
// heap entry and the durable append (previously two separate
|
|
1156
1162
|
// literals — harmless before, but recordHistoryEntry mutates the
|
|
1157
1163
|
// object it's given, so a shared reference is the correct shape).
|
|
1158
|
-
var judgeCraftUserMsg =
|
|
1164
|
+
var judgeCraftUserMsg = consoleTurnEntry(INITIATORS.LOOP, judgeCraftPrompt, loopNote(craftName, "writing the judge"));
|
|
1159
1165
|
sm.recordHistoryEntry(judgeCraftSession, judgeCraftUserMsg, true);
|
|
1160
1166
|
sm.appendToSessionFile(judgeCraftSession, judgeCraftUserMsg);
|
|
1161
1167
|
sendToSession(judgeCraftSession.localId, judgeCraftUserMsg);
|
|
@@ -1163,7 +1169,7 @@ function attachLoop(ctx) {
|
|
|
1163
1169
|
onProcessingChanged();
|
|
1164
1170
|
judgeCraftSession.sentToolResults = {};
|
|
1165
1171
|
sendToSession(judgeCraftSession.localId, { type: "status", status: "processing" });
|
|
1166
|
-
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession), INITIATORS.LOOP);
|
|
1172
|
+
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession), INITIATORS.LOOP, judgeCraftUserMsg.messageId);
|
|
1167
1173
|
|
|
1168
1174
|
send({ type: "ralph_crafting_started", sessionId: judgeCraftSession.localId, taskId: newLoopId, source: recordSource });
|
|
1169
1175
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: judgeCraftSession.localId });
|
|
@@ -1232,7 +1238,7 @@ function attachLoop(ctx) {
|
|
|
1232
1238
|
// lr-2ea2a7: routes through the shared history-cap helper (see
|
|
1233
1239
|
// grep-guard test); single object instance shared across the heap
|
|
1234
1240
|
// entry, the durable append, and the client send.
|
|
1235
|
-
var craftingUserMsg =
|
|
1241
|
+
var craftingUserMsg = consoleTurnEntry(INITIATORS.LOOP, craftingPrompt, loopNote(craftName, "crafting the loop files"));
|
|
1236
1242
|
sm.recordHistoryEntry(craftingSession, craftingUserMsg, true);
|
|
1237
1243
|
sm.appendToSessionFile(craftingSession, craftingUserMsg);
|
|
1238
1244
|
sendToSession(craftingSession.localId, craftingUserMsg);
|
|
@@ -1240,7 +1246,7 @@ function attachLoop(ctx) {
|
|
|
1240
1246
|
onProcessingChanged();
|
|
1241
1247
|
craftingSession.sentToolResults = {};
|
|
1242
1248
|
sendToSession(craftingSession.localId, { type: "status", status: "processing" });
|
|
1243
|
-
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession), INITIATORS.LOOP);
|
|
1249
|
+
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession), INITIATORS.LOOP, craftingUserMsg.messageId);
|
|
1244
1250
|
|
|
1245
1251
|
send({ type: "ralph_crafting_started", sessionId: craftingSession.localId, taskId: newLoopId, source: recordSource });
|
|
1246
1252
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: craftingSession.localId });
|
|
@@ -16,6 +16,7 @@ var promptKinds = require("./prompt-kinds");
|
|
|
16
16
|
var { mayAnswerPrompt } = require("./prompt-access");
|
|
17
17
|
var { ownValue } = require("./prompt-kinds/codecs");
|
|
18
18
|
var { INITIATORS } = require("./turn-initiator");
|
|
19
|
+
var { stampRecord } = require("./injected-sender");
|
|
19
20
|
var promptSource = require("./prompt-source");
|
|
20
21
|
|
|
21
22
|
// alias type -> { toPrompt(msg), kinds it may answer, stale reply type }
|
|
@@ -57,11 +58,13 @@ function attachPromptResponses(ctx) {
|
|
|
57
58
|
var onProcessingChanged = ctx.onProcessingChanged || function () {};
|
|
58
59
|
var ensureProjectAccessForSession = ctx.ensureProjectAccessForSession;
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
// The config card for ONE session, with that session's own mode. A plan
|
|
62
|
+
// answer changes the answering session only, so only its viewers hear it.
|
|
63
|
+
function sendConfigState(session) {
|
|
64
|
+
sendToSession(session.localId, {
|
|
62
65
|
type: "config_state",
|
|
63
|
-
model: sm.currentModel || "",
|
|
64
|
-
mode: sm.currentPermissionMode,
|
|
66
|
+
model: sm.effectiveSessionModel ? sm.effectiveSessionModel(session) : (sm.currentModel || ""),
|
|
67
|
+
mode: session.permissionMode || sm.currentPermissionMode || "default",
|
|
65
68
|
effort: sm.currentEffort || CONFIG_STATE_DEFAULTS.effort,
|
|
66
69
|
betas: sm.currentBetas || [],
|
|
67
70
|
thinking: sm.currentThinking || CONFIG_STATE_DEFAULTS.thinking,
|
|
@@ -72,12 +75,12 @@ function attachPromptResponses(ctx) {
|
|
|
72
75
|
// A user message delivered to the session as if typed, starting a query
|
|
73
76
|
// when none is running.
|
|
74
77
|
function deliverUserMessage(session, text) {
|
|
75
|
-
var userMsg = { type: "user_message", text: text };
|
|
78
|
+
var userMsg = stampRecord({ type: "user_message", text: text, initiator: INITIATORS.HUMAN });
|
|
76
79
|
sm.recordHistoryEntry(session, userMsg, true);
|
|
77
80
|
sm.appendToSessionFile(session, userMsg);
|
|
78
81
|
sendToSession(session.localId, userMsg);
|
|
79
82
|
if (session.isProcessing) {
|
|
80
|
-
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN);
|
|
83
|
+
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN, userMsg.messageId);
|
|
81
84
|
return;
|
|
82
85
|
}
|
|
83
86
|
session.isProcessing = true;
|
|
@@ -85,9 +88,9 @@ function attachPromptResponses(ctx) {
|
|
|
85
88
|
session.sentToolResults = {};
|
|
86
89
|
sendToSession(session.localId, { type: "status", status: "processing" });
|
|
87
90
|
if (!session.queryInstance && !session.worker) {
|
|
88
|
-
sdk.startQuery(session, text, undefined, ensureProjectAccessForSession(session), INITIATORS.HUMAN);
|
|
91
|
+
sdk.startQuery(session, text, undefined, ensureProjectAccessForSession(session), INITIATORS.HUMAN, userMsg.messageId);
|
|
89
92
|
} else {
|
|
90
|
-
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN);
|
|
93
|
+
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN, userMsg.messageId);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
|
|
@@ -106,8 +109,10 @@ function attachPromptResponses(ctx) {
|
|
|
106
109
|
if (session.abortController) session.abortController.abort();
|
|
107
110
|
});
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
// Only the answering session's mode changes (the new session's is set
|
|
113
|
+
// below); the project default and every other session are untouched.
|
|
114
|
+
session.permissionMode = "acceptEdits";
|
|
115
|
+
sendConfigState(session);
|
|
111
116
|
|
|
112
117
|
var planPrompt;
|
|
113
118
|
if (planContent) {
|
|
@@ -125,7 +130,7 @@ function attachPromptResponses(ctx) {
|
|
|
125
130
|
]).then(function () {
|
|
126
131
|
try {
|
|
127
132
|
var newSession = sm.createSession(null, ws);
|
|
128
|
-
var userMsg = { type: "user_message", text: planPrompt, planContent: planContent || null };
|
|
133
|
+
var userMsg = stampRecord({ type: "user_message", text: planPrompt, planContent: planContent || null, initiator: INITIATORS.HUMAN });
|
|
129
134
|
sm.recordHistoryEntry(newSession, userMsg, true);
|
|
130
135
|
sm.appendToSessionFile(newSession, userMsg);
|
|
131
136
|
newSession.title = "Plan execution (cleared context)";
|
|
@@ -138,7 +143,8 @@ function attachPromptResponses(ctx) {
|
|
|
138
143
|
newSession.sentToolResults = {};
|
|
139
144
|
sendToSession(newSession.localId, { type: "status", status: "processing" });
|
|
140
145
|
newSession.acceptEditsAfterStart = true;
|
|
141
|
-
|
|
146
|
+
newSession.permissionMode = "acceptEdits";
|
|
147
|
+
sdk.startQuery(newSession, planPrompt, undefined, ensureProjectAccessForSession(newSession), INITIATORS.HUMAN, userMsg.messageId);
|
|
142
148
|
} catch (e) {
|
|
143
149
|
console.error("[project] Error starting plan execution:", e);
|
|
144
150
|
if (ws) sendTo(ws, { type: "error", text: "Failed to start plan execution: " + (e.message || e) });
|
|
@@ -151,8 +157,8 @@ function attachPromptResponses(ctx) {
|
|
|
151
157
|
function applyPlanDecision(ws, session, prompt, response) {
|
|
152
158
|
if (response.decision === "allow_accept_edits") {
|
|
153
159
|
sdk.setPermissionMode(session, "acceptEdits");
|
|
154
|
-
|
|
155
|
-
sendConfigState();
|
|
160
|
+
session.permissionMode = "acceptEdits";
|
|
161
|
+
sendConfigState(session);
|
|
156
162
|
} else if (response.decision === "allow_clear_context") {
|
|
157
163
|
executePlanInFreshContext(ws, session, prompt, response.planContent || "");
|
|
158
164
|
} else if (response.decision === "deny_with_feedback" && response.feedback) {
|
package/lib/project-sessions.js
CHANGED
|
@@ -16,6 +16,8 @@ var { ownValue } = require("./prompt-kinds/codecs");
|
|
|
16
16
|
var { logField, logText } = require("./log-field");
|
|
17
17
|
var { isKnownVendor } = require("./yoke");
|
|
18
18
|
var sessionCapabilities = require("./session-capabilities");
|
|
19
|
+
var { checkPermissionMode } = require("./permission-mode-policy");
|
|
20
|
+
var { composeRestartingNotice } = require("./build-update-offer");
|
|
19
21
|
// Kick off SDK agent discovery in the background at module load.
|
|
20
22
|
// Errors are swallowed inside refresh(); the cache starts empty and fills
|
|
21
23
|
// when the SDK subprocess completes initialization (~9s on this box).
|
|
@@ -53,7 +55,6 @@ if (!process.env.NODE_TEST_CONTEXT) {
|
|
|
53
55
|
* adapter, getProjectList, getProjectCount, getScheduleCount,
|
|
54
56
|
* moveScheduleToProject, moveAllSchedulesToProject, getHubSchedules,
|
|
55
57
|
* fetchVersion, isNewer, onCreateWorktree, IGNORED_DIRS,
|
|
56
|
-
* scheduleMessage, cancelScheduledMessage,
|
|
57
58
|
* getProjectOwnerId, setProjectOwnerId,
|
|
58
59
|
* getUpdateChannel, setUpdateChannel,
|
|
59
60
|
* getLatestVersion, setLatestVersion
|
|
@@ -80,13 +81,6 @@ var PROCESS_STATS_BASE_FIELD_KEYS = [
|
|
|
80
81
|
"memAvailableMB",
|
|
81
82
|
];
|
|
82
83
|
|
|
83
|
-
// auto and dontAsk are permission modes only a vendor that lists them in
|
|
84
|
-
// capabilities.permissionModes can run. A session whose vendor does not
|
|
85
|
-
// declare them (or whose capabilities are not known yet) cannot, so a request
|
|
86
|
-
// for one is refused rather than handed to a vendor that would reject or
|
|
87
|
-
// ignore it.
|
|
88
|
-
var CAPABILITY_GATED_MODES = { auto: true, dontAsk: true };
|
|
89
|
-
|
|
90
84
|
function attachSessions(ctx) {
|
|
91
85
|
var cwd = ctx.cwd;
|
|
92
86
|
var slug = ctx.slug;
|
|
@@ -131,8 +125,6 @@ function attachSessions(ctx) {
|
|
|
131
125
|
var isNewer = ctx.isNewer;
|
|
132
126
|
var onCreateWorktree = ctx.onCreateWorktree;
|
|
133
127
|
var IGNORED_DIRS = ctx.IGNORED_DIRS;
|
|
134
|
-
var scheduleMessage = ctx.scheduleMessage;
|
|
135
|
-
var cancelScheduledMessage = ctx.cancelScheduledMessage;
|
|
136
128
|
var getProjectOwnerId = ctx.getProjectOwnerId;
|
|
137
129
|
var setProjectOwnerId = ctx.setProjectOwnerId;
|
|
138
130
|
var getUpdateChannel = ctx.getUpdateChannel;
|
|
@@ -158,10 +150,56 @@ function attachSessions(ctx) {
|
|
|
158
150
|
getSessionForWs: getSessionForWs,
|
|
159
151
|
});
|
|
160
152
|
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
// The shared mode check (lib/permission-mode-policy.js) for a mode that a
|
|
154
|
+
// client asks for. `session` is the session it would run in, or null for a
|
|
155
|
+
// default that applies to whatever vendor a session later uses (the project's
|
|
156
|
+
// default vendor stands in for it). A refusal is logged and returned as
|
|
157
|
+
// { ok: false, error }.
|
|
158
|
+
function checkRequestedMode(session, mode, what) {
|
|
163
159
|
var vendor = sessionCapabilities.effectiveVendorId(sm, session, adapter && adapter.vendor);
|
|
164
|
-
|
|
160
|
+
var verdict = checkPermissionMode(mode, {
|
|
161
|
+
skipPermissionsAllowed: ctx.dangerouslySkipPermissions === true,
|
|
162
|
+
supportedModes: sessionCapabilities.capabilitiesFor(sm, vendor).permissionModes,
|
|
163
|
+
});
|
|
164
|
+
if (!verdict.ok) {
|
|
165
|
+
console.warn("[project-sessions] refused " + what + " " + logField(mode) + " in " + slug + ": " + verdict.error);
|
|
166
|
+
}
|
|
167
|
+
return verdict;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Changing a default that every session of the project (or of the server)
|
|
171
|
+
// starts from takes the same standing as changing project settings: an
|
|
172
|
+
// administrator, or the project owner in multi-user mode; in single-user
|
|
173
|
+
// mode the connection is the implicit owner (projectAccess.isAdmin).
|
|
174
|
+
// The server-wide default reaches every project, so it is the administrator's
|
|
175
|
+
// alone (ownerAllowed false); the project default also accepts the owner.
|
|
176
|
+
function maySetDefaultMode(ws, ownerAllowed) {
|
|
177
|
+
if (!projectAccess || typeof projectAccess.isAdmin !== "function") return false;
|
|
178
|
+
var user = ws._clagenticUser;
|
|
179
|
+
if (projectAccess.isAdmin(user, projectAccess.authOf(ws))) return true;
|
|
180
|
+
if (!ownerAllowed) return false;
|
|
181
|
+
var ownerId = getProjectOwnerId ? getProjectOwnerId() : null;
|
|
182
|
+
return !!(user && ownerId && user.id === ownerId);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Both default setters share this gate. Returns true when the request was
|
|
186
|
+
// refused (and answered), false when the caller may go on.
|
|
187
|
+
function refuseDefaultMode(ws, msg) {
|
|
188
|
+
var what = msg.type;
|
|
189
|
+
var serverWide = what === "set_server_default_mode";
|
|
190
|
+
if (!maySetDefaultMode(ws, !serverWide)) {
|
|
191
|
+
console.warn("[project-sessions] refused " + what + " in " + slug + ": caller is not " + (serverWide ? "an admin" : "an admin or the project owner"));
|
|
192
|
+
sendTo(ws, { type: "error", text: serverWide
|
|
193
|
+
? "Only admins can change the server default permission mode."
|
|
194
|
+
: "Only project owners or admins can change the default permission mode." });
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
var verdict = checkRequestedMode(null, msg.mode, what);
|
|
198
|
+
if (!verdict.ok) {
|
|
199
|
+
sendTo(ws, { type: "error", text: verdict.error });
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
165
203
|
}
|
|
166
204
|
|
|
167
205
|
function handleSessionsMessage(ws, msg) {
|
|
@@ -955,8 +993,10 @@ function attachSessions(ctx) {
|
|
|
955
993
|
|
|
956
994
|
if (msg.type === "set_permission_mode" && msg.mode) {
|
|
957
995
|
var session = getSessionForWs(ws);
|
|
958
|
-
|
|
959
|
-
|
|
996
|
+
var modeVerdict = checkRequestedMode(session, msg.mode, "set_permission_mode");
|
|
997
|
+
if (!modeVerdict.ok) {
|
|
998
|
+
sendTo(ws, { type: "error", text: modeVerdict.error });
|
|
999
|
+
if (!session) return true;
|
|
960
1000
|
sendTo(ws, { type: "config_state", model: sm.effectiveSessionModel(session), mode: session.permissionMode || sm.currentPermissionMode || "default", effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
961
1001
|
return true;
|
|
962
1002
|
}
|
|
@@ -971,6 +1011,7 @@ function attachSessions(ctx) {
|
|
|
971
1011
|
}
|
|
972
1012
|
|
|
973
1013
|
if (msg.type === "set_server_default_mode" && msg.mode) {
|
|
1014
|
+
if (refuseDefaultMode(ws, msg)) return true;
|
|
974
1015
|
if (typeof opts.onSetServerDefaultMode === "function") {
|
|
975
1016
|
opts.onSetServerDefaultMode(msg.mode);
|
|
976
1017
|
}
|
|
@@ -984,6 +1025,7 @@ function attachSessions(ctx) {
|
|
|
984
1025
|
}
|
|
985
1026
|
|
|
986
1027
|
if (msg.type === "set_project_default_mode" && msg.mode) {
|
|
1028
|
+
if (refuseDefaultMode(ws, msg)) return true;
|
|
987
1029
|
if (typeof opts.onSetProjectDefaultMode === "function") {
|
|
988
1030
|
opts.onSetProjectDefaultMode(slug, msg.mode);
|
|
989
1031
|
}
|
|
@@ -1815,18 +1857,23 @@ function attachSessions(ctx) {
|
|
|
1815
1857
|
// issued, and only if that offer is still true (lib/build-update-restart.js).
|
|
1816
1858
|
if (msg.type === "restart_for_build_update") {
|
|
1817
1859
|
if (typeof opts.onRestartForBuildUpdate !== "function") {
|
|
1818
|
-
sendTo(ws, { type: "restart_for_build_update_result", ok: false, error: "Restart not supported" });
|
|
1860
|
+
sendTo(ws, { type: "restart_for_build_update_result", requestId: typeof msg.requestId === "string" ? msg.requestId : undefined, ok: false, error: "Restart not supported" });
|
|
1819
1861
|
return true;
|
|
1820
1862
|
}
|
|
1821
1863
|
var buildToken = typeof msg.confirmToken === "string" ? msg.confirmToken : null;
|
|
1864
|
+
// Echoed in every result so the client releases only the button that asked.
|
|
1865
|
+
var buildRequestId = typeof msg.requestId === "string" && msg.requestId.length <= 64 ? msg.requestId : undefined;
|
|
1866
|
+
var buildResult = function (fields) {
|
|
1867
|
+
return Object.assign({ type: "restart_for_build_update_result", requestId: buildRequestId }, fields);
|
|
1868
|
+
};
|
|
1822
1869
|
Promise.resolve(opts.onRestartForBuildUpdate(buildToken)).then(function (outcome) {
|
|
1823
1870
|
if (outcome.status === "not_stale") {
|
|
1824
1871
|
var nothingToApply = "No newer build is installed, so there is nothing to apply.";
|
|
1825
|
-
sendTo(ws, {
|
|
1872
|
+
sendTo(ws, buildResult({ ok: false, error: nothingToApply }));
|
|
1826
1873
|
sendTo(ws, { type: "error", text: nothingToApply });
|
|
1827
1874
|
} else if (outcome.status === "confirm") {
|
|
1828
1875
|
var offer = outcome.offer;
|
|
1829
|
-
sendTo(ws, {
|
|
1876
|
+
sendTo(ws, buildResult({ ok: false, needsConfirmation: true }));
|
|
1830
1877
|
sendTo(ws, {
|
|
1831
1878
|
type: "diagnostic",
|
|
1832
1879
|
severity: "warning",
|
|
@@ -1836,12 +1883,17 @@ function attachSessions(ctx) {
|
|
|
1836
1883
|
actionable: { label: "Restart now", action: "confirm_build_update_restart" },
|
|
1837
1884
|
});
|
|
1838
1885
|
} else {
|
|
1839
|
-
|
|
1840
|
-
|
|
1886
|
+
// The requester always gets the pending state, including on a repeat
|
|
1887
|
+
// request: the offer is withdrawn and one card that does not close on a
|
|
1888
|
+
// timer takes its place. A timed toast here vanished before it could be
|
|
1889
|
+
// read and left the offer card clickable.
|
|
1890
|
+
sendTo(ws, buildResult({ ok: true }));
|
|
1891
|
+
sendTo(ws, { type: "diagnostic_retract", source: "build-update" });
|
|
1892
|
+
sendTo(ws, composeRestartingNotice());
|
|
1841
1893
|
}
|
|
1842
1894
|
}).catch(function (e) {
|
|
1843
1895
|
console.error("[project] restart_for_build_update failed:", e && e.message ? e.message : e);
|
|
1844
|
-
sendTo(ws, {
|
|
1896
|
+
sendTo(ws, buildResult({ ok: false, error: "Could not prepare the restart offer" }));
|
|
1845
1897
|
sendTo(ws, { type: "error", text: "Could not prepare the restart offer. Nothing was restarted." });
|
|
1846
1898
|
});
|
|
1847
1899
|
return true;
|
|
@@ -4,6 +4,8 @@ var { promptsFor } = require("./prompt-registry");
|
|
|
4
4
|
var { putOwn } = require("./prompt-kinds/codecs");
|
|
5
5
|
var { isKnownVendor } = require("./yoke");
|
|
6
6
|
var { INITIATORS } = require("./turn-initiator");
|
|
7
|
+
var { createWsHandlers: createScheduledInputHandlers } = require("./scheduled-input/ws");
|
|
8
|
+
var { stampRecord } = require("./injected-sender");
|
|
7
9
|
var promptSource = require("./prompt-source");
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -25,7 +27,7 @@ var promptSource = require("./prompt-source");
|
|
|
25
27
|
* browserState - { _browserTabList, _extensionWs } (mutable refs)
|
|
26
28
|
* sendExtensionCommandAny, requestTabContext,
|
|
27
29
|
* startFileWatch, stopFileWatch,
|
|
28
|
-
*
|
|
30
|
+
* scheduledInput - the scheduled-input service (null in a bare harness)
|
|
29
31
|
* loadContextSources, saveContextSources,
|
|
30
32
|
* digestDmTurn,
|
|
31
33
|
* adapter - YOKE adapter instance
|
|
@@ -120,14 +122,18 @@ function attachUserMessage(ctx) {
|
|
|
120
122
|
var sendExtensionCommandAny = ctx.sendExtensionCommandAny;
|
|
121
123
|
var requestTabContext = ctx.requestTabContext;
|
|
122
124
|
|
|
123
|
-
var scheduleMessage = ctx.scheduleMessage;
|
|
124
|
-
var cancelScheduledMessage = ctx.cancelScheduledMessage;
|
|
125
|
-
|
|
126
125
|
var loadContextSources = ctx.loadContextSources;
|
|
127
126
|
var saveContextSources = ctx.saveContextSources;
|
|
128
127
|
|
|
129
128
|
var adapter = ctx.adapter;
|
|
130
129
|
|
|
130
|
+
var scheduledInput = createScheduledInputHandlers({
|
|
131
|
+
slug: slug,
|
|
132
|
+
service: ctx.scheduledInput || null,
|
|
133
|
+
getSessionForWs: getSessionForWs,
|
|
134
|
+
sendTo: sendTo,
|
|
135
|
+
});
|
|
136
|
+
|
|
131
137
|
// --------------- Terminal list broadcast ---------------
|
|
132
138
|
|
|
133
139
|
// Each client only sees their own terminals — send filtered term_list messages individually.
|
|
@@ -322,45 +328,8 @@ function attachUserMessage(ctx) {
|
|
|
322
328
|
// --- Loop message delegation (project-loop.js) ---
|
|
323
329
|
if (_loop.handleLoopMessage(ws, msg)) return true;
|
|
324
330
|
|
|
325
|
-
// ---
|
|
326
|
-
if (
|
|
327
|
-
var schedSession = getSessionForWs(ws);
|
|
328
|
-
if (!schedSession || !msg.text || !msg.resetsAt) return true;
|
|
329
|
-
scheduleMessage(schedSession, msg.text, msg.resetsAt);
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (msg.type === "cancel_scheduled_message") {
|
|
334
|
-
var cancelSession = getSessionForWs(ws);
|
|
335
|
-
if (!cancelSession) return true;
|
|
336
|
-
cancelScheduledMessage(cancelSession);
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (msg.type === "send_scheduled_now") {
|
|
341
|
-
var nowSession = getSessionForWs(ws);
|
|
342
|
-
if (!nowSession || !nowSession.scheduledMessage) return true;
|
|
343
|
-
var schedText = nowSession.scheduledMessage.text;
|
|
344
|
-
clearTimeout(nowSession.scheduledMessage.timer);
|
|
345
|
-
nowSession.scheduledMessage = null;
|
|
346
|
-
console.log("[project] Scheduled message sent immediately for session " + nowSession.localId);
|
|
347
|
-
sm.sendAndRecord(nowSession, { type: "scheduled_message_sent" });
|
|
348
|
-
var userMsg = { type: "user_message", text: schedText, _ts: Date.now() };
|
|
349
|
-
// lr-2ea2a7: routes through the shared history-cap helper (see grep-guard
|
|
350
|
-
// test) instead of pushing directly, so a long-running session's heap
|
|
351
|
-
// history stays bounded even for scheduled-message injection.
|
|
352
|
-
sm.recordHistoryEntry(nowSession, userMsg, true);
|
|
353
|
-
sm.appendToSessionFile(nowSession, userMsg);
|
|
354
|
-
sendToSession(nowSession.localId, userMsg);
|
|
355
|
-
nowSession.isProcessing = true;
|
|
356
|
-
onProcessingChanged();
|
|
357
|
-
sendToSession(nowSession.localId, { type: "status", status: "processing" });
|
|
358
|
-
// A person forced the send, but the text is the one scheduled earlier:
|
|
359
|
-
// it is a scheduled turn that fired manually, not typed text.
|
|
360
|
-
sdk.startQuery(nowSession, schedText, null, ensureProjectAccessForSession(nowSession), INITIATORS.SCHEDULED_NOW);
|
|
361
|
-
sm.broadcastSessionList();
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
331
|
+
// --- Scheduled input: the clock button and the scheduled-message bubble ---
|
|
332
|
+
if (scheduledInput.handle(ws, msg)) return true;
|
|
364
333
|
|
|
365
334
|
if (msg.type !== "message") return false;
|
|
366
335
|
if (!msg.text && (!msg.images || msg.images.length === 0) && (!msg.pastes || msg.pastes.length === 0)) return true;
|
|
@@ -395,7 +364,9 @@ function attachUserMessage(ctx) {
|
|
|
395
364
|
|
|
396
365
|
// Keep any pending scheduled message alive when user sends a regular message
|
|
397
366
|
|
|
398
|
-
|
|
367
|
+
// The human initiator is what marks an entry as the operator's own: this is
|
|
368
|
+
// the one place the authenticated browser composer's text is recorded.
|
|
369
|
+
var userMsg2 = stampRecord({ type: "user_message", text: msg.text || "", initiator: INITIATORS.HUMAN });
|
|
399
370
|
// Attach sender info for multi-user attribution (backward-compatible: old clients ignore these)
|
|
400
371
|
if (ws._clagenticUser) {
|
|
401
372
|
userMsg2.from = ws._clagenticUser.id;
|
|
@@ -568,12 +539,12 @@ function attachUserMessage(ctx) {
|
|
|
568
539
|
// No active query (or worker idle between queries): start a new query
|
|
569
540
|
session._queryStartTs = Date.now();
|
|
570
541
|
console.log("[PERF] project.js: startQuery called, localId=" + session.localId + " t=0ms");
|
|
571
|
-
sdk.startQuery(session, finalText, msg.images, ensureProjectAccessForSession(session), INITIATORS.HUMAN);
|
|
542
|
+
sdk.startQuery(session, finalText, msg.images, ensureProjectAccessForSession(session), INITIATORS.HUMAN, userMsg2.messageId);
|
|
572
543
|
} else {
|
|
573
|
-
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN);
|
|
544
|
+
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN, userMsg2.messageId);
|
|
574
545
|
}
|
|
575
546
|
} else {
|
|
576
|
-
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN);
|
|
547
|
+
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN, userMsg2.messageId);
|
|
577
548
|
}
|
|
578
549
|
sm.broadcastSessionList();
|
|
579
550
|
}
|