@clagentic/console 1.10.0-beta.1 → 1.10.0-beta.2
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 +1 -1
- package/bin/cli.js +10 -0
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +8 -5
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/daemon-projects.js +19 -0
- package/lib/daemon.js +166 -127
- package/lib/memory-shed.js +13 -32
- package/lib/project-connection.js +14 -0
- package/lib/project-external-trigger.js +91 -123
- package/lib/project-loop.js +5 -4
- package/lib/project-prompt-responses.js +5 -4
- package/lib/project-sessions.js +43 -68
- package/lib/project-user-message.js +7 -20
- package/lib/project.js +23 -5
- package/lib/prompt-registry.js +7 -0
- package/lib/public/css/diagnostics.css +30 -0
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-messages.js +7 -2
- package/lib/public/modules/app-panels.js +0 -1
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +126 -20
- package/lib/public/modules/tools.js +14 -2
- package/lib/public/modules/vendor-picker.js +2 -2
- package/lib/public/modules/vendor-registry.js +11 -2
- package/lib/sdk-bridge.js +62 -15
- package/lib/sdk-message-processor.js +11 -20
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server.js +15 -2
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +16 -2
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/vendor-registry-message.js +1 -0
- package/lib/ws-schema.js +3 -1
- package/lib/yoke/adapters/claude-vendor.js +0 -1
- package/lib/yoke/adapters/claude-worker.js +6 -4
- package/lib/yoke/adapters/claude.js +34 -34
- package/lib/yoke/adapters/codex-capabilities.js +9 -6
- package/lib/yoke/adapters/codex-vendor.js +15 -15
- package/lib/yoke/adapters/codex.js +121 -61
- package/lib/yoke/auth-checks.js +8 -21
- package/lib/yoke/codex-app-server.js +27 -71
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/index.js +20 -4
- package/lib/yoke/install-probe.js +21 -6
- package/lib/yoke/interface.js +11 -5
- package/lib/yoke/registry.js +41 -4
- package/package.json +1 -2
- package/scripts/verify-installed-build.js +59 -17
- package/lib/lore-attestation.js +0 -73
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
var fs = require("fs");
|
|
2
2
|
var path = require("path");
|
|
3
|
+
var { createSessionInput, settle, RESULT } = require("./session-input");
|
|
3
4
|
|
|
4
5
|
// How long (ms) to keep processed trigger files before pruning on startup.
|
|
5
6
|
var PROCESSED_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; // 30 days (processed/ and expired/)
|
|
6
7
|
// Default grace period before an unprocessed trigger is moved to expired/.
|
|
7
8
|
var DEFAULT_UNPROCESSED_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
|
8
9
|
var CLOCK_SKEW_TOLERANCE_MS = 5 * 60 * 1000; // future createdAt beyond this is ignored
|
|
9
|
-
var POLL_INTERVAL_MS = 30 * 1000;
|
|
10
|
+
var POLL_INTERVAL_MS = 30 * 1000; // 30 s backstop scan
|
|
10
11
|
var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -19,23 +20,44 @@ var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
|
|
|
19
20
|
* processed/ on success.
|
|
20
21
|
*
|
|
21
22
|
* Schema v1 (all fields except * are required):
|
|
22
|
-
* { version: 1, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt
|
|
23
|
-
*
|
|
23
|
+
* { version: 1, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt*,
|
|
24
|
+
* vendor*, agentName*, sessionVisibility*, initiator* }
|
|
25
|
+
* -> always opens a new session (backward-compatible, v1 files remain valid)
|
|
24
26
|
*
|
|
25
27
|
* Schema v2 (all fields except * are required):
|
|
26
|
-
* { version: 2, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt*,
|
|
27
|
-
*
|
|
28
|
-
* -> if sessionId
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* { version: 2, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt*,
|
|
29
|
+
* sessionId*, vendor*, agentName*, sessionVisibility*, initiator* }
|
|
30
|
+
* -> if sessionId present: send initialPrompt as that session's next turn,
|
|
31
|
+
* resuming the session first when its runtime has ended (vendor, agentName
|
|
32
|
+
* and sessionVisibility are ignored: the session keeps its own)
|
|
33
|
+
* -> if sessionId absent: open a new session (same as v1)
|
|
31
34
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
* vendor, agentName and sessionVisibility choose the kind of session an open
|
|
36
|
+
* creates; absent means the default vendor, no named agent, shared. initiator
|
|
37
|
+
* names who started the turn: trigger (default), scheduled, scheduled-now or
|
|
38
|
+
* loop. human and anything unknown are refused: a file is never a human turn.
|
|
39
|
+
*
|
|
40
|
+
* Every file is acted on by lib/session-input.js, the same code the daemon IPC
|
|
41
|
+
* verbs run. A file whose outcome is final (delivered, resumed-and-delivered,
|
|
42
|
+
* opened, not-found, refused) moves to processed/ with the outcome written into
|
|
43
|
+
* it under "result". A session id that exists nowhere is not-found, never
|
|
44
|
+
* retried. Only a delivery failure ("error") or memory pressure keeps the file
|
|
45
|
+
* in place, until it expires. A query that fails to start is such a failure:
|
|
46
|
+
* "error" is reported only then, never "delivered".
|
|
47
|
+
*
|
|
48
|
+
* Archiving is one rename into processed/ after the request is handled, then
|
|
49
|
+
* the result is written into the processed record. Delivery is therefore
|
|
50
|
+
* at-least-once across a daemon crash: a crash between delivery and the rename
|
|
51
|
+
* leaves the trigger pending, and it is dispatched again on restart. A crash (or
|
|
52
|
+
* a write failure) between the rename and the result write leaves a processed
|
|
53
|
+
* record without a "result": the request was handled, its outcome was not kept,
|
|
54
|
+
* and nothing retries it.
|
|
55
|
+
*
|
|
56
|
+
* contextNote on the send path: the prompt text delivered to the agent is
|
|
57
|
+
* unchanged; a user_message entry carrying { source: "external-trigger",
|
|
58
|
+
* triggerId, initiator, contextNote } is recorded in the session history and
|
|
59
|
+
* session file so the agent-origin is distinguishable from operator-typed
|
|
60
|
+
* input. The entry is recorded only after the delivery succeeds.
|
|
39
61
|
*
|
|
40
62
|
* Trigger lifecycle directories under triggersDir:
|
|
41
63
|
* (triggersDir) — pending / retrying
|
|
@@ -52,6 +74,7 @@ var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
|
|
|
52
74
|
* triggersDir — absolute path to ~/.clagentic/external-triggers/
|
|
53
75
|
* getProject — function(slug) -> project context | null
|
|
54
76
|
* unprocessedTtlMs — optional grace period before expiry (default 7 days)
|
|
77
|
+
* sessionInput — optional createSessionInput() instance shared with the IPC verbs
|
|
55
78
|
*
|
|
56
79
|
* Security: triggers dir is under the user's home. Any process running as
|
|
57
80
|
* the same OS user can write files. Acceptable for single-user self-hosted
|
|
@@ -72,6 +95,7 @@ var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
|
|
|
72
95
|
function attachExternalTrigger(ctx) {
|
|
73
96
|
var triggersDir = ctx.triggersDir;
|
|
74
97
|
var getProject = ctx.getProject;
|
|
98
|
+
var sessionInput = ctx.sessionInput || createSessionInput({ getProject: getProject });
|
|
75
99
|
|
|
76
100
|
var triggersRoot = path.dirname(path.join(triggersDir, "x"));
|
|
77
101
|
var processedDir = path.join(triggersDir, "processed");
|
|
@@ -109,110 +133,43 @@ function attachExternalTrigger(ctx) {
|
|
|
109
133
|
if (obj.sessionId !== undefined && (typeof obj.sessionId !== "string" || !obj.sessionId)) {
|
|
110
134
|
return "sessionId must be a non-empty string when present";
|
|
111
135
|
}
|
|
136
|
+
// vendor, agentName, sessionVisibility and initiator are not checked here:
|
|
137
|
+
// session-input.js refuses a bad one by name, and that refusal is recorded
|
|
138
|
+
// in processed/ where the writer can read it.
|
|
112
139
|
return null; // valid
|
|
113
140
|
}
|
|
114
141
|
|
|
115
|
-
// ---
|
|
116
|
-
|
|
117
|
-
function spawnSession(project, trigger) {
|
|
118
|
-
var sm = project.sm;
|
|
119
|
-
var sdk = project.sdk;
|
|
120
|
-
var send = project.send;
|
|
121
|
-
var onProcessingChanged = project.onProcessingChanged;
|
|
122
|
-
var getLinuxUserForSession = project.getLinuxUserForSession;
|
|
123
|
-
|
|
124
|
-
if (!sm || !sdk || !send || !onProcessingChanged || !getLinuxUserForSession) {
|
|
125
|
-
console.error("[external-trigger] Project context missing required fields for slug:", trigger.projectSlug);
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var sess = sm.createSession({});
|
|
130
|
-
sess.title = (trigger.contextNote || "External trigger") + " — " + trigger.id.substring(0, 12);
|
|
131
|
-
if (trigger.cwd) sess.cwd = trigger.cwd;
|
|
132
|
-
sm.saveSessionFile(sess);
|
|
133
|
-
sm.broadcastSessionList();
|
|
134
|
-
|
|
135
|
-
var userMsg = { type: "user_message", text: trigger.initialPrompt };
|
|
136
|
-
// lr-2ea2a7: routes through the shared history-cap helper (see grep-guard test).
|
|
137
|
-
sm.recordHistoryEntry(sess, userMsg, true);
|
|
138
|
-
sm.appendToSessionFile(sess, userMsg);
|
|
139
|
-
|
|
140
|
-
sess.isProcessing = true;
|
|
141
|
-
onProcessingChanged();
|
|
142
|
-
sess.sentToolResults = {};
|
|
143
|
-
// singleTurn=false (default): session stays open for human follow-up.
|
|
144
|
-
// The trigger JSON can set singleTurn:true for fire-and-forget agentic
|
|
145
|
-
// dispatches (not part of v1 schema, reserved for future use).
|
|
146
|
-
sess.acceptEditsAfterStart = true;
|
|
142
|
+
// --- Dispatch ---
|
|
147
143
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.log("[external-trigger] Session spawned: project=" + trigger.projectSlug + " session=" + sess.localId + " trigger=" + trigger.id);
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// --- Mid-session inject ---
|
|
160
|
-
|
|
161
|
-
// Marks the pushed message as agent-origin in history/session file. Failure
|
|
162
|
-
// here must not turn a delivered message into a retry (double delivery).
|
|
163
|
-
function recordPushedMessage(sm, sess, trigger) {
|
|
164
|
-
var entry = {
|
|
165
|
-
type: "user_message",
|
|
166
|
-
text: trigger.initialPrompt,
|
|
167
|
-
source: "external-trigger",
|
|
144
|
+
// Hands a validated trigger to session-input.js: send to the named session
|
|
145
|
+
// (v2 with sessionId) or open a new one. Returns a result or a Promise of one.
|
|
146
|
+
function dispatchTrigger(trigger) {
|
|
147
|
+
var request = {
|
|
148
|
+
projectSlug: trigger.projectSlug,
|
|
149
|
+
prompt: trigger.initialPrompt,
|
|
150
|
+
contextNote: trigger.contextNote,
|
|
168
151
|
triggerId: trigger.id,
|
|
152
|
+
initiator: trigger.initiator,
|
|
169
153
|
};
|
|
170
|
-
if (trigger.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
sm.appendToSessionFile(sess, entry);
|
|
174
|
-
} catch (e) {
|
|
175
|
-
console.error("[external-trigger] Failed to record pushed message for trigger " + trigger.id + ":", e.message || e);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function pushMessageToSession(project, trigger) {
|
|
180
|
-
var sm = project.sm;
|
|
181
|
-
var sdk = project.sdk;
|
|
182
|
-
|
|
183
|
-
if (!sm || !sdk) {
|
|
184
|
-
console.error("[external-trigger] Project context missing sm/sdk for push_message, slug:", trigger.projectSlug);
|
|
185
|
-
return "error";
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
var found = null;
|
|
189
|
-
sm.sessions.forEach(function (s) {
|
|
190
|
-
if (!found && s.cliSessionId === trigger.sessionId) {
|
|
191
|
-
found = s;
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
if (!found) {
|
|
196
|
-
console.warn("[external-trigger] push_message: session not found: " + trigger.sessionId + " (trigger " + trigger.id + " not archived — will retry)");
|
|
197
|
-
return "not_found";
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
// Third argument is images, not metadata: contextNote travels via the
|
|
202
|
-
// recorded history entry below.
|
|
203
|
-
sdk.pushMessage(found, trigger.initialPrompt, null);
|
|
204
|
-
console.log("[external-trigger] push_message delivered to session " + trigger.sessionId + " (trigger " + trigger.id + ")");
|
|
205
|
-
recordPushedMessage(sm, found, trigger);
|
|
206
|
-
return "ok";
|
|
207
|
-
} catch (e) {
|
|
208
|
-
console.error("[external-trigger] push_message failed for trigger " + trigger.id + ":", e.message || e);
|
|
209
|
-
return "error";
|
|
154
|
+
if (trigger.sessionId) {
|
|
155
|
+
request.sessionId = trigger.sessionId;
|
|
156
|
+
return sessionInput.sendInput(request);
|
|
210
157
|
}
|
|
158
|
+
request.cwd = trigger.cwd;
|
|
159
|
+
request.vendor = trigger.vendor;
|
|
160
|
+
request.agentName = trigger.agentName;
|
|
161
|
+
request.sessionVisibility = trigger.sessionVisibility;
|
|
162
|
+
return sessionInput.openSession(request);
|
|
211
163
|
}
|
|
212
164
|
|
|
213
165
|
// --- Archive ---
|
|
214
166
|
|
|
215
|
-
|
|
167
|
+
// Moves the trigger to processed/ in one rename once the request is handled,
|
|
168
|
+
// then writes the outcome into the processed record so the writer can read
|
|
169
|
+
// what happened to its request. Delivery is at-least-once across a daemon
|
|
170
|
+
// crash: a crash after the input is delivered and before the rename leaves
|
|
171
|
+
// the trigger pending, and it is dispatched again on restart.
|
|
172
|
+
function archiveTrigger(triggerPath, id, obj, result) {
|
|
216
173
|
var dest = path.join(processedDir, id + ".json");
|
|
217
174
|
try {
|
|
218
175
|
fs.renameSync(triggerPath, dest);
|
|
@@ -223,10 +180,18 @@ function attachExternalTrigger(ctx) {
|
|
|
223
180
|
fs.unlinkSync(triggerPath);
|
|
224
181
|
} catch (e2) {
|
|
225
182
|
console.error("[external-trigger] Failed to archive trigger " + id + ":", e2.message || e2);
|
|
183
|
+
return;
|
|
226
184
|
}
|
|
227
185
|
}
|
|
186
|
+
var record = Object.assign({}, obj, { result: result, processedAt: new Date().toISOString() });
|
|
187
|
+
try {
|
|
188
|
+
fs.writeFileSync(dest, JSON.stringify(record, null, 2) + "\n");
|
|
189
|
+
} catch (e) {
|
|
190
|
+
console.error("[external-trigger] Failed to record the result of trigger " + id + ":", e.message || e);
|
|
191
|
+
}
|
|
228
192
|
}
|
|
229
193
|
|
|
194
|
+
|
|
230
195
|
// --- Expiry ---
|
|
231
196
|
|
|
232
197
|
function triggerAgeMs(filePath, obj) {
|
|
@@ -302,23 +267,26 @@ function attachExternalTrigger(ctx) {
|
|
|
302
267
|
return;
|
|
303
268
|
}
|
|
304
269
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
|
|
270
|
+
settle(dispatchTrigger(obj), function (result) {
|
|
271
|
+
if (result.result === RESULT.ERROR && result.retryable !== false) {
|
|
272
|
+
// Delivery was attempted and failed in a way trying again can help, and
|
|
273
|
+
// the failure is reported as one (never archived as done): leave the
|
|
274
|
+
// file and keep dispatched[id] set to avoid a rapid retry loop. A
|
|
275
|
+
// restart tries it again; it expires by TTL otherwise. An error marked
|
|
276
|
+
// not retryable (a failed open, which removed its session) is archived
|
|
277
|
+
// below with that result.
|
|
278
|
+
console.error("[external-trigger] Trigger " + id + " failed: " + result.reason);
|
|
279
|
+
return;
|
|
314
280
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
281
|
+
if (result.retryable) {
|
|
282
|
+
// The daemon is shedding work: keep the file and let the next scan retry.
|
|
283
|
+
delete dispatched[id];
|
|
284
|
+
console.warn("[external-trigger] Trigger " + id + " deferred: " + result.reason);
|
|
285
|
+
return;
|
|
320
286
|
}
|
|
321
|
-
|
|
287
|
+
console.log("[external-trigger] Trigger " + id + " " + result.result + (result.reason ? ": " + result.reason : ""));
|
|
288
|
+
archiveTrigger(filePath, id, obj, result);
|
|
289
|
+
});
|
|
322
290
|
}
|
|
323
291
|
|
|
324
292
|
// --- Watcher ---
|
package/lib/project-loop.js
CHANGED
|
@@ -7,6 +7,7 @@ var store = require("./store");
|
|
|
7
7
|
var usersModule = require("./users");
|
|
8
8
|
var { writeHandoff, buildHandoffPreamble } = require("./loop-handoff");
|
|
9
9
|
var { authOf } = require("./project-access");
|
|
10
|
+
var { INITIATORS } = require("./turn-initiator");
|
|
10
11
|
|
|
11
12
|
var LOOP_ID_RE = /^loop_[A-Za-z0-9_-]+$/;
|
|
12
13
|
|
|
@@ -613,7 +614,7 @@ function attachLoop(ctx) {
|
|
|
613
614
|
session.acceptEditsAfterStart = true;
|
|
614
615
|
session.singleTurn = true;
|
|
615
616
|
if (loopState.settings) session.loopSettings = loopState.settings;
|
|
616
|
-
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session));
|
|
617
|
+
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session), INITIATORS.LOOP);
|
|
617
618
|
}
|
|
618
619
|
|
|
619
620
|
function runJudge() {
|
|
@@ -736,7 +737,7 @@ function attachLoop(ctx) {
|
|
|
736
737
|
judgeSession.acceptEditsAfterStart = true;
|
|
737
738
|
judgeSession.singleTurn = true;
|
|
738
739
|
if (loopState.settings) judgeSession.loopSettings = loopState.settings;
|
|
739
|
-
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession));
|
|
740
|
+
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession), INITIATORS.LOOP);
|
|
740
741
|
}
|
|
741
742
|
|
|
742
743
|
// lr-2ea2a7: forward-accumulates delta/text across the FULL heap array —
|
|
@@ -1162,7 +1163,7 @@ function attachLoop(ctx) {
|
|
|
1162
1163
|
onProcessingChanged();
|
|
1163
1164
|
judgeCraftSession.sentToolResults = {};
|
|
1164
1165
|
sendToSession(judgeCraftSession.localId, { type: "status", status: "processing" });
|
|
1165
|
-
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession));
|
|
1166
|
+
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession), INITIATORS.LOOP);
|
|
1166
1167
|
|
|
1167
1168
|
send({ type: "ralph_crafting_started", sessionId: judgeCraftSession.localId, taskId: newLoopId, source: recordSource });
|
|
1168
1169
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: judgeCraftSession.localId });
|
|
@@ -1239,7 +1240,7 @@ function attachLoop(ctx) {
|
|
|
1239
1240
|
onProcessingChanged();
|
|
1240
1241
|
craftingSession.sentToolResults = {};
|
|
1241
1242
|
sendToSession(craftingSession.localId, { type: "status", status: "processing" });
|
|
1242
|
-
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession));
|
|
1243
|
+
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession), INITIATORS.LOOP);
|
|
1243
1244
|
|
|
1244
1245
|
send({ type: "ralph_crafting_started", sessionId: craftingSession.localId, taskId: newLoopId, source: recordSource });
|
|
1245
1246
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: craftingSession.localId });
|
|
@@ -15,6 +15,7 @@ var { promptsFor } = require("./prompt-registry");
|
|
|
15
15
|
var promptKinds = require("./prompt-kinds");
|
|
16
16
|
var { mayAnswerPrompt } = require("./prompt-access");
|
|
17
17
|
var { ownValue } = require("./prompt-kinds/codecs");
|
|
18
|
+
var { INITIATORS } = require("./turn-initiator");
|
|
18
19
|
|
|
19
20
|
// alias type -> { toPrompt(msg), kinds it may answer, stale reply type }
|
|
20
21
|
var LEGACY_RESPONSES = {
|
|
@@ -75,7 +76,7 @@ function attachPromptResponses(ctx) {
|
|
|
75
76
|
sm.appendToSessionFile(session, userMsg);
|
|
76
77
|
sendToSession(session.localId, userMsg);
|
|
77
78
|
if (session.isProcessing) {
|
|
78
|
-
sdk.pushMessage(session, text);
|
|
79
|
+
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN);
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
session.isProcessing = true;
|
|
@@ -83,9 +84,9 @@ function attachPromptResponses(ctx) {
|
|
|
83
84
|
session.sentToolResults = {};
|
|
84
85
|
sendToSession(session.localId, { type: "status", status: "processing" });
|
|
85
86
|
if (!session.queryInstance && !session.worker) {
|
|
86
|
-
sdk.startQuery(session, text, undefined, ensureProjectAccessForSession(session));
|
|
87
|
+
sdk.startQuery(session, text, undefined, ensureProjectAccessForSession(session), INITIATORS.HUMAN);
|
|
87
88
|
} else {
|
|
88
|
-
sdk.pushMessage(session, text);
|
|
89
|
+
sdk.pushMessage(session, text, undefined, INITIATORS.HUMAN);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -136,7 +137,7 @@ function attachPromptResponses(ctx) {
|
|
|
136
137
|
newSession.sentToolResults = {};
|
|
137
138
|
sendToSession(newSession.localId, { type: "status", status: "processing" });
|
|
138
139
|
newSession.acceptEditsAfterStart = true;
|
|
139
|
-
sdk.startQuery(newSession, planPrompt, undefined, ensureProjectAccessForSession(newSession));
|
|
140
|
+
sdk.startQuery(newSession, planPrompt, undefined, ensureProjectAccessForSession(newSession), INITIATORS.HUMAN);
|
|
140
141
|
} catch (e) {
|
|
141
142
|
console.error("[project] Error starting plan execution:", e);
|
|
142
143
|
if (ws) sendTo(ws, { type: "error", text: "Failed to start plan execution: " + (e.message || e) });
|
package/lib/project-sessions.js
CHANGED
|
@@ -488,60 +488,13 @@ function attachSessions(ctx) {
|
|
|
488
488
|
|
|
489
489
|
if (msg.type === "resume_session") {
|
|
490
490
|
if (!msg.cliSessionId) return true;
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
//
|
|
494
|
-
|
|
495
|
-
// primary vendor (which would break codex sessions after server restart).
|
|
496
|
-
// Also read allowedTools (lr-8b2e) so a previously-granted "allow for
|
|
497
|
-
// session" decision survives this rehydration path instead of
|
|
498
|
-
// re-prompting — resumeSession() itself defaults to {} when absent.
|
|
499
|
-
var persistedVendor = null;
|
|
500
|
-
var persistedAllowedTools = null;
|
|
501
|
-
try {
|
|
502
|
-
var _fsResume = require("fs");
|
|
503
|
-
var _pathResume = require("path");
|
|
504
|
-
var metaPath = _pathResume.join(sm.sessionsDir, msg.cliSessionId + ".jsonl");
|
|
505
|
-
if (_fsResume.existsSync(metaPath)) {
|
|
506
|
-
var firstLine = _fsResume.readFileSync(metaPath, "utf8").split("\n", 1)[0];
|
|
507
|
-
try {
|
|
508
|
-
var metaObj = JSON.parse(firstLine);
|
|
509
|
-
if (metaObj && metaObj.type === "meta" && metaObj.vendor) persistedVendor = metaObj.vendor;
|
|
510
|
-
// Sanitize before it ever reaches resumeSession() (lr-8b2e
|
|
511
|
-
// hardening) — a crafted meta record must not be able to
|
|
512
|
-
// auto-approve a tool with no operator click.
|
|
513
|
-
if (metaObj && metaObj.type === "meta" && metaObj.allowedTools) {
|
|
514
|
-
persistedAllowedTools = utils.sanitizeAllowedTools(metaObj.allowedTools);
|
|
515
|
-
}
|
|
516
|
-
} catch (e) {}
|
|
517
|
-
}
|
|
518
|
-
} catch (e) {}
|
|
519
|
-
|
|
520
|
-
// Try SDK for title first, then fall back to manual parsing
|
|
521
|
-
var titlePromise = adapter.getSessionInfo(msg.cliSessionId, { dir: cwd }).then(function(info) {
|
|
522
|
-
return (info && info.summary) ? info.summary.substring(0, 100) : null;
|
|
523
|
-
}).catch(function() { return null; });
|
|
524
|
-
|
|
525
|
-
Promise.all([
|
|
526
|
-
cliSess.readCliSessionHistory(cwd, msg.cliSessionId),
|
|
527
|
-
titlePromise
|
|
528
|
-
]).then(function(results) {
|
|
529
|
-
var history = results[0];
|
|
530
|
-
var sdkTitle = results[1];
|
|
531
|
-
var title = sdkTitle || "Resumed session";
|
|
532
|
-
if (!sdkTitle) {
|
|
533
|
-
for (var i = 0; i < history.length; i++) {
|
|
534
|
-
if (history[i].type === "user_message" && history[i].text) {
|
|
535
|
-
title = history[i].text.substring(0, 50);
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
var resumed = sm.resumeSession(msg.cliSessionId, { history: history, title: title, vendor: persistedVendor || undefined, allowedTools: persistedAllowedTools || undefined }, ws);
|
|
541
|
-
if (resumed) ws._clagenticActiveSession = resumed.localId;
|
|
542
|
-
}).catch(function() {
|
|
543
|
-
var resumed = sm.resumeSession(msg.cliSessionId, (persistedVendor || persistedAllowedTools) ? { vendor: persistedVendor, allowedTools: persistedAllowedTools } : undefined, ws);
|
|
491
|
+
// The resume that injected input uses too (session-resume.js): vendor,
|
|
492
|
+
// agent and granted tools come from the stored meta record, so a resume
|
|
493
|
+
// never silently falls back to the project's default vendor.
|
|
494
|
+
require("./session-resume").resumeStoredSession({ sm: sm, adapter: adapter, cwd: cwd }, msg.cliSessionId, { ws: ws }).then(function (resumed) {
|
|
544
495
|
if (resumed) ws._clagenticActiveSession = resumed.localId;
|
|
496
|
+
}, function (err) {
|
|
497
|
+
sendTo(ws, { type: "error", text: "Could not resume this session: " + (err && err.message ? err.message : err) });
|
|
545
498
|
});
|
|
546
499
|
return true;
|
|
547
500
|
}
|
|
@@ -1182,7 +1135,7 @@ function attachSessions(ctx) {
|
|
|
1182
1135
|
}
|
|
1183
1136
|
}
|
|
1184
1137
|
|
|
1185
|
-
// Notify adapter of conversation rollback (e.g. Codex
|
|
1138
|
+
// Notify adapter of conversation rollback (e.g. Codex, which refuses)
|
|
1186
1139
|
// BEFORE trimming: when the adapter cannot roll its thread back, the
|
|
1187
1140
|
// rewind fails (the catch below reports it) and the local history is
|
|
1188
1141
|
// left as it was, so the two never disagree.
|
|
@@ -1840,23 +1793,45 @@ function attachSessions(ctx) {
|
|
|
1840
1793
|
return true;
|
|
1841
1794
|
}
|
|
1842
1795
|
|
|
1843
|
-
//
|
|
1844
|
-
//
|
|
1845
|
-
//
|
|
1846
|
-
//
|
|
1847
|
-
//
|
|
1848
|
-
//
|
|
1849
|
-
//
|
|
1796
|
+
// Operator-initiated adoption of an installed-but-not-yet-running build.
|
|
1797
|
+
// Same admin gate as restart_server above, but two steps, because this
|
|
1798
|
+
// restart ends sessions the operator may not be thinking about. A message
|
|
1799
|
+
// without confirmToken only asks for the offer: the reply names both
|
|
1800
|
+
// builds, the commits between them and the live sessions and background
|
|
1801
|
+
// agents a restart would end, and nothing restarts. The restart is
|
|
1802
|
+
// scheduled only by a message carrying the token of an offer the daemon
|
|
1803
|
+
// issued, and only if that offer is still true (lib/build-update-restart.js).
|
|
1850
1804
|
if (msg.type === "restart_for_build_update") {
|
|
1851
|
-
if (typeof opts.onRestartForBuildUpdate
|
|
1852
|
-
sendTo(ws, { type: "restart_for_build_update_result", ok: true });
|
|
1853
|
-
send({ type: "toast", level: "info", message: "Restarting to apply the installed update..." });
|
|
1854
|
-
setTimeout(function () {
|
|
1855
|
-
opts.onRestartForBuildUpdate();
|
|
1856
|
-
}, 500);
|
|
1857
|
-
} else {
|
|
1805
|
+
if (typeof opts.onRestartForBuildUpdate !== "function") {
|
|
1858
1806
|
sendTo(ws, { type: "restart_for_build_update_result", ok: false, error: "Restart not supported" });
|
|
1807
|
+
return true;
|
|
1859
1808
|
}
|
|
1809
|
+
var buildToken = typeof msg.confirmToken === "string" ? msg.confirmToken : null;
|
|
1810
|
+
Promise.resolve(opts.onRestartForBuildUpdate(buildToken)).then(function (outcome) {
|
|
1811
|
+
if (outcome.status === "not_stale") {
|
|
1812
|
+
var nothingToApply = "No newer build is installed, so there is nothing to apply.";
|
|
1813
|
+
sendTo(ws, { type: "restart_for_build_update_result", ok: false, error: nothingToApply });
|
|
1814
|
+
sendTo(ws, { type: "error", text: nothingToApply });
|
|
1815
|
+
} else if (outcome.status === "confirm") {
|
|
1816
|
+
var offer = outcome.offer;
|
|
1817
|
+
sendTo(ws, { type: "restart_for_build_update_result", ok: false, needsConfirmation: true });
|
|
1818
|
+
sendTo(ws, {
|
|
1819
|
+
type: "diagnostic",
|
|
1820
|
+
severity: "warning",
|
|
1821
|
+
source: "build-update",
|
|
1822
|
+
message: (outcome.note ? outcome.note + "\n" : "") + offer.interruptionText,
|
|
1823
|
+
buildUpdate: offer,
|
|
1824
|
+
actionable: { label: "Restart now", action: "confirm_build_update_restart" },
|
|
1825
|
+
});
|
|
1826
|
+
} else {
|
|
1827
|
+
sendTo(ws, { type: "restart_for_build_update_result", ok: true });
|
|
1828
|
+
send({ type: "toast", level: "info", message: "Restarting to apply the installed update. Running turns get up to " + (outcome.waitSeconds || 60) + " seconds to finish first." });
|
|
1829
|
+
}
|
|
1830
|
+
}).catch(function (e) {
|
|
1831
|
+
console.error("[project] restart_for_build_update failed:", e && e.message ? e.message : e);
|
|
1832
|
+
sendTo(ws, { type: "restart_for_build_update_result", ok: false, error: "Could not prepare the restart offer" });
|
|
1833
|
+
sendTo(ws, { type: "error", text: "Could not prepare the restart offer. Nothing was restarted." });
|
|
1834
|
+
});
|
|
1860
1835
|
return true;
|
|
1861
1836
|
}
|
|
1862
1837
|
|
|
@@ -3,6 +3,7 @@ var fs = require("fs");
|
|
|
3
3
|
var { promptsFor } = require("./prompt-registry");
|
|
4
4
|
var { putOwn } = require("./prompt-kinds/codecs");
|
|
5
5
|
var { isKnownVendor } = require("./yoke");
|
|
6
|
+
var { INITIATORS } = require("./turn-initiator");
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Attach user-message handler and remaining small handlers
|
|
@@ -338,10 +339,6 @@ function attachUserMessage(ctx) {
|
|
|
338
339
|
if (msg.type === "send_scheduled_now") {
|
|
339
340
|
var nowSession = getSessionForWs(ws);
|
|
340
341
|
if (!nowSession || !nowSession.scheduledMessage) return true;
|
|
341
|
-
// lr-f7c100: reachable only via a live WS client explicitly forcing a
|
|
342
|
-
// scheduled send — same human-presence rationale as the "message"
|
|
343
|
-
// handler above.
|
|
344
|
-
nowSession.humanOriginated = true;
|
|
345
342
|
var schedText = nowSession.scheduledMessage.text;
|
|
346
343
|
clearTimeout(nowSession.scheduledMessage.timer);
|
|
347
344
|
nowSession.scheduledMessage = null;
|
|
@@ -357,7 +354,9 @@ function attachUserMessage(ctx) {
|
|
|
357
354
|
nowSession.isProcessing = true;
|
|
358
355
|
onProcessingChanged();
|
|
359
356
|
sendToSession(nowSession.localId, { type: "status", status: "processing" });
|
|
360
|
-
|
|
357
|
+
// A person forced the send, but the text is the one scheduled earlier:
|
|
358
|
+
// it is a scheduled turn that fired manually, not typed text.
|
|
359
|
+
sdk.startQuery(nowSession, schedText, null, ensureProjectAccessForSession(nowSession), INITIATORS.SCHEDULED_NOW);
|
|
361
360
|
sm.broadcastSessionList();
|
|
362
361
|
return true;
|
|
363
362
|
}
|
|
@@ -380,18 +379,6 @@ function attachUserMessage(ctx) {
|
|
|
380
379
|
return true;
|
|
381
380
|
}
|
|
382
381
|
|
|
383
|
-
// lr-f7c100: this handler is reachable ONLY via a live WebSocket client
|
|
384
|
-
// sending a {type:"message"} frame — headless session drivers
|
|
385
|
-
// (project-loop.js's Ralph Loop iterations, project-external-trigger.js,
|
|
386
|
-
// scheduler.js) build their own history entries and call sdk.startQuery
|
|
387
|
-
// directly, never through here. That makes this the one structural (not
|
|
388
|
-
// heuristic) point in the codebase where "a human is in this session" is
|
|
389
|
-
// true by construction, independent of session state that a headless
|
|
390
|
-
// caller could otherwise set. Sticky once set — later processing (e.g. a
|
|
391
|
-
// scheduled message firing for the same session) never has a chance to
|
|
392
|
-
// clear it, matching the "a session mints iff a human is in it" rule.
|
|
393
|
-
session.humanOriginated = true;
|
|
394
|
-
|
|
395
382
|
// Bind vendor to session on first message (if not already set)
|
|
396
383
|
if (!session.vendor && isKnownVendor(msg.vendor)) {
|
|
397
384
|
session.vendor = msg.vendor;
|
|
@@ -580,12 +567,12 @@ function attachUserMessage(ctx) {
|
|
|
580
567
|
// No active query (or worker idle between queries): start a new query
|
|
581
568
|
session._queryStartTs = Date.now();
|
|
582
569
|
console.log("[PERF] project.js: startQuery called, localId=" + session.localId + " t=0ms");
|
|
583
|
-
sdk.startQuery(session, finalText, msg.images, ensureProjectAccessForSession(session));
|
|
570
|
+
sdk.startQuery(session, finalText, msg.images, ensureProjectAccessForSession(session), INITIATORS.HUMAN);
|
|
584
571
|
} else {
|
|
585
|
-
sdk.pushMessage(session, finalText, msg.images);
|
|
572
|
+
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN);
|
|
586
573
|
}
|
|
587
574
|
} else {
|
|
588
|
-
sdk.pushMessage(session, finalText, msg.images);
|
|
575
|
+
sdk.pushMessage(session, finalText, msg.images, INITIATORS.HUMAN);
|
|
589
576
|
}
|
|
590
577
|
sm.broadcastSessionList();
|
|
591
578
|
}
|