@clagentic/console 1.6.0 → 1.7.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/bin/cli.js +20 -102
- package/deploy/clagentic-console.service +10 -1
- package/lib/agents-favorites.js +0 -1
- package/lib/agents.js +0 -10
- package/lib/cli-sessions.js +0 -12
- package/lib/codex-defaults.js +4 -1
- package/lib/config.js +0 -8
- package/lib/daemon.js +88 -9
- package/lib/dm.js +0 -1
- package/lib/ipc.js +129 -59
- package/lib/loop-handoff.js +5 -1
- package/lib/memory-limits.js +214 -36
- package/lib/memory-shed.js +207 -0
- package/lib/notes.js +0 -20
- package/lib/os-users.js +0 -3
- package/lib/project-connection.js +31 -5
- package/lib/project-external-trigger.js +2 -1
- package/lib/project-filesystem.js +18 -11
- package/lib/project-knowledge.js +0 -8
- package/lib/project-loop.js +162 -9
- package/lib/project-sessions.js +87 -21
- package/lib/project-user-mention.js +2 -1
- package/lib/project-user-message.js +16 -5
- package/lib/project.js +14 -25
- package/lib/public/app.js +1 -2
- package/lib/public/css/channel-layout.css +25 -158
- package/lib/public/css/diagnostics.css +17 -1
- package/lib/public/css/icon-strip.css +1 -32
- package/lib/public/css/input.css +0 -56
- package/lib/public/css/loop.css +94 -0
- package/lib/public/css/messages.css +23 -4
- package/lib/public/css/mobile-nav.css +0 -124
- package/lib/public/index.html +11 -11
- package/lib/public/modules/app-connection.js +2 -1
- package/lib/public/modules/app-favicon.js +1 -1
- package/lib/public/modules/app-loop-ui.js +140 -4
- package/lib/public/modules/app-messages.js +17 -11
- package/lib/public/modules/app-projects.js +1 -1
- package/lib/public/modules/custom-icons.js +15 -1
- package/lib/public/modules/dom-refs.js +1 -2
- package/lib/public/modules/emoji-picker.js +6 -1
- package/lib/public/modules/filebrowser.js +33 -9
- package/lib/public/modules/input.js +39 -0
- package/lib/public/modules/scheduler.js +20 -6
- package/lib/public/modules/sidebar-mobile.js +0 -64
- package/lib/public/modules/sidebar-projects.js +90 -25
- package/lib/public/modules/sidebar-sessions.js +80 -13
- package/lib/public/modules/stt.js +2 -6
- package/lib/public/modules/tool-palette.js +0 -1
- package/lib/public/modules/tools.js +2 -6
- package/lib/public/style.css +0 -1
- package/lib/scheduler.js +0 -1
- package/lib/sdk-bridge.js +126 -194
- package/lib/sdk-message-processor.js +24 -9
- package/lib/sdk-permission-ownership.js +51 -0
- package/lib/server-auth.js +25 -18
- package/lib/server-dm.js +1 -1
- package/lib/server-skills.js +9 -1
- package/lib/server.js +18 -3
- package/lib/session-search.js +4 -299
- package/lib/sessions.js +467 -82
- package/lib/smtp.js +0 -15
- package/lib/user-presence.js +0 -12
- package/lib/users-preferences.js +2 -2
- package/lib/users.js +0 -5
- package/lib/utils.js +56 -0
- package/lib/ws-schema.js +3 -14
- package/lib/yoke/adapters/codex.js +96 -10
- package/lib/yoke/codex-local-image.js +79 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +16 -11
- package/lib/ask-user-mcp-server.js +0 -121
- package/lib/project-memory.js +0 -39
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/debate.css +0 -1610
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-dark.svg +0 -32
- package/lib/public/favicon.svg +0 -32
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icons/email/gmail.svg +0 -7
- package/lib/public/icons/email/outlook.svg +0 -35
- package/lib/public/icons/email/yahoo.svg +0 -1
- package/lib/public/modules/events.js +0 -21
- package/lib/public/modules/state.js +0 -3
- package/lib/sdk-worker.js +0 -730
package/lib/smtp.js
CHANGED
|
@@ -73,17 +73,6 @@ function resetTransporter() {
|
|
|
73
73
|
|
|
74
74
|
// --- Test connection ---
|
|
75
75
|
|
|
76
|
-
function testConnection(cfg) {
|
|
77
|
-
var t = createTransporter(cfg);
|
|
78
|
-
return t.verify().then(function () {
|
|
79
|
-
try { t.close(); } catch (e) {}
|
|
80
|
-
return { ok: true };
|
|
81
|
-
}).catch(function (err) {
|
|
82
|
-
try { t.close(); } catch (e) {}
|
|
83
|
-
return { ok: false, error: err.message || "Connection failed" };
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
76
|
function sendTestEmail(cfg, toEmail) {
|
|
88
77
|
var t = createTransporter(cfg);
|
|
89
78
|
return t.sendMail({
|
|
@@ -209,11 +198,7 @@ module.exports = {
|
|
|
209
198
|
saveSmtpConfig: saveSmtpConfig,
|
|
210
199
|
isSmtpConfigured: isSmtpConfigured,
|
|
211
200
|
isEmailLoginEnabled: isEmailLoginEnabled,
|
|
212
|
-
testConnection: testConnection,
|
|
213
201
|
sendTestEmail: sendTestEmail,
|
|
214
|
-
sendMail: sendMail,
|
|
215
|
-
resetTransporter: resetTransporter,
|
|
216
|
-
generateOtp: generateOtp,
|
|
217
202
|
requestOtp: requestOtp,
|
|
218
203
|
verifyOtp: verifyOtp,
|
|
219
204
|
sendOtpEmail: sendOtpEmail,
|
package/lib/user-presence.js
CHANGED
|
@@ -49,17 +49,6 @@ function getPresence(slug, userId) {
|
|
|
49
49
|
return store[slug][userId] || null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function setMateDm(slug, userId, mateDm) {
|
|
53
|
-
if (!slug || !userId) return;
|
|
54
|
-
if (!store[slug]) store[slug] = {};
|
|
55
|
-
var existing = store[slug][userId] || {};
|
|
56
|
-
store[slug][userId] = {
|
|
57
|
-
sessionId: existing.sessionId || null,
|
|
58
|
-
mateDm: mateDm !== undefined ? mateDm : null,
|
|
59
|
-
};
|
|
60
|
-
scheduleSave();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
52
|
function clearPresence(slug, userId) {
|
|
64
53
|
if (!slug || !userId) return;
|
|
65
54
|
if (store[slug]) {
|
|
@@ -86,7 +75,6 @@ load();
|
|
|
86
75
|
module.exports = {
|
|
87
76
|
setPresence: setPresence,
|
|
88
77
|
getPresence: getPresence,
|
|
89
|
-
setMateDm: setMateDm,
|
|
90
78
|
clearPresence: clearPresence,
|
|
91
79
|
clearSession: clearSession,
|
|
92
80
|
};
|
package/lib/users-preferences.js
CHANGED
|
@@ -189,12 +189,12 @@ function attachPreferences(deps) {
|
|
|
189
189
|
//
|
|
190
190
|
// Each user can customize the sidebar tool grid by reordering or
|
|
191
191
|
// hiding individual tools. Stored as an object keyed by palette name
|
|
192
|
-
// ("session"
|
|
192
|
+
// ("session"), each holding { order: [...ids], hidden: [...ids] }.
|
|
193
193
|
// Missing ids are treated as "use registry default at the end", so new
|
|
194
194
|
// tools added in future releases show up for existing users without a
|
|
195
195
|
// migration.
|
|
196
196
|
|
|
197
|
-
var VALID_PALETTES = { session: true
|
|
197
|
+
var VALID_PALETTES = { session: true };
|
|
198
198
|
|
|
199
199
|
function getToolPalettes(userId) {
|
|
200
200
|
var data = loadUsers();
|
package/lib/users.js
CHANGED
|
@@ -423,7 +423,6 @@ module.exports = {
|
|
|
423
423
|
getSetupCode: getSetupCode,
|
|
424
424
|
clearSetupCode: clearSetupCode,
|
|
425
425
|
validateSetupCode: validateSetupCode,
|
|
426
|
-
generateUserId: generateUserId,
|
|
427
426
|
hashPin: hashPin,
|
|
428
427
|
verifyPin: verifyPin,
|
|
429
428
|
createUser: createUser,
|
|
@@ -431,7 +430,6 @@ module.exports = {
|
|
|
431
430
|
findAdmin: findAdmin,
|
|
432
431
|
hasAdmin: hasAdmin,
|
|
433
432
|
findUserById: findUserById,
|
|
434
|
-
findUserByUsername: findUserByUsername,
|
|
435
433
|
findUserByEmail: findUserByEmail,
|
|
436
434
|
authenticateUser: authenticateUser,
|
|
437
435
|
getAllUsers: getAllUsers,
|
|
@@ -442,16 +440,13 @@ module.exports = {
|
|
|
442
440
|
parseAuthCookie: parseAuthCookie,
|
|
443
441
|
createUserWithoutPin: createUserWithoutPin,
|
|
444
442
|
createInvite: createInvite,
|
|
445
|
-
findInvite: findInvite,
|
|
446
443
|
validateInvite: validateInvite,
|
|
447
444
|
markInviteUsed: markInviteUsed,
|
|
448
445
|
revokeInvite: revokeInvite,
|
|
449
446
|
getInvites: getInvites,
|
|
450
|
-
removeExpiredInvites: removeExpiredInvites,
|
|
451
447
|
canAccessProject: canAccessProject,
|
|
452
448
|
getAccessibleProjects: getAccessibleProjects,
|
|
453
449
|
canAccessSession: canAccessSession,
|
|
454
|
-
getOtherUsers: getOtherUsers,
|
|
455
450
|
updateLinuxUser: updateLinuxUser,
|
|
456
451
|
generatePin: generatePin,
|
|
457
452
|
createUserByAdmin: createUserByAdmin,
|
package/lib/utils.js
CHANGED
|
@@ -79,9 +79,65 @@ function sanitizeAllowedTools(value) {
|
|
|
79
79
|
return out;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Default hard cap for readCappedBody() call sites that don't pass their own
|
|
84
|
+
* maxBytes: these are small JSON-only pre-auth endpoints (login, PIN
|
|
85
|
+
* recovery, OTP, invite registration, push-subscribe) — legitimate bodies are
|
|
86
|
+
* well under a few KB, but the accumulator has no cap at all today (lr-f940
|
|
87
|
+
* N2), so an unauthenticated client can stream an arbitrarily large body into
|
|
88
|
+
* a growing string, and N parallel requests multiply the cost.
|
|
89
|
+
*/
|
|
90
|
+
var DEFAULT_BODY_CAP_BYTES = 1 * 1024 * 1024; // 1 MB
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accumulate an HTTP request body with a hard byte cap, destroying the
|
|
94
|
+
* connection and rejecting once the cap is exceeded instead of buffering an
|
|
95
|
+
* unbounded string (lr-f940 N2). Mirrors the existing hardCap + req.destroy()
|
|
96
|
+
* pattern in lib/project-http.js's parseJsonBody(), generalized so the
|
|
97
|
+
* pre-auth endpoints in lib/server-auth.js and lib/server.js (which have no
|
|
98
|
+
* upload-sized payloads and were accumulating via a bare `body += chunk`
|
|
99
|
+
* with no limit at all) can reuse the same defense instead of each
|
|
100
|
+
* hand-rolling it.
|
|
101
|
+
*
|
|
102
|
+
* @param {http.IncomingMessage} req
|
|
103
|
+
* @param {number} [maxBytes] - hard cap in bytes; defaults to DEFAULT_BODY_CAP_BYTES.
|
|
104
|
+
* @returns {Promise<string>} resolves with the accumulated body (utf8), or
|
|
105
|
+
* rejects with an Error if the cap is exceeded or the request errors.
|
|
106
|
+
*/
|
|
107
|
+
function readCappedBody(req, maxBytes) {
|
|
108
|
+
var cap = typeof maxBytes === "number" && maxBytes > 0 ? maxBytes : DEFAULT_BODY_CAP_BYTES;
|
|
109
|
+
return new Promise(function (resolve, reject) {
|
|
110
|
+
var chunks = [];
|
|
111
|
+
var bodyBytes = 0;
|
|
112
|
+
var rejected = false;
|
|
113
|
+
req.on("data", function (chunk) {
|
|
114
|
+
if (rejected) return;
|
|
115
|
+
bodyBytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
|
|
116
|
+
if (bodyBytes > cap) {
|
|
117
|
+
rejected = true;
|
|
118
|
+
req.destroy();
|
|
119
|
+
reject(new Error("Request body too large"));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
chunks.push(chunk);
|
|
123
|
+
});
|
|
124
|
+
req.on("end", function () {
|
|
125
|
+
if (rejected) return;
|
|
126
|
+
resolve(Buffer.concat(chunks.map(function (c) { return Buffer.isBuffer(c) ? c : Buffer.from(c); })).toString("utf8"));
|
|
127
|
+
});
|
|
128
|
+
req.on("error", function (err) {
|
|
129
|
+
if (rejected) return;
|
|
130
|
+
rejected = true;
|
|
131
|
+
reject(err);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
82
136
|
module.exports = {
|
|
83
137
|
encodeCwd: encodeCwd,
|
|
84
138
|
resolveEncodedDir: resolveEncodedDir,
|
|
85
139
|
resolveEncodedFile: resolveEncodedFile,
|
|
86
140
|
sanitizeAllowedTools: sanitizeAllowedTools,
|
|
141
|
+
readCappedBody: readCappedBody,
|
|
142
|
+
DEFAULT_BODY_CAP_BYTES: DEFAULT_BODY_CAP_BYTES,
|
|
87
143
|
};
|
package/lib/ws-schema.js
CHANGED
|
@@ -395,7 +395,6 @@ var schema = {
|
|
|
395
395
|
"dm_add_favorite": { direction: "c2s", handler: "lib/server-dm.js", description: "Add a user to DM favorites" },
|
|
396
396
|
"dm_remove_favorite": { direction: "c2s", handler: "lib/server-dm.js", description: "Remove a user from DM favorites" },
|
|
397
397
|
"dm_favorites_updated": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "DM favorites list updated" },
|
|
398
|
-
"set_mate_dm": { direction: "c2s", handler: "lib/project-sessions.js", description: "No-op stub (mates removed, lr-316f)" },
|
|
399
398
|
|
|
400
399
|
// -----------------------------------------------------------------------
|
|
401
400
|
// Knowledge (project knowledge files)
|
|
@@ -407,19 +406,6 @@ var schema = {
|
|
|
407
406
|
"knowledge_saved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Knowledge file was saved" },
|
|
408
407
|
"knowledge_delete": { direction: "c2s", handler: "lib/project-knowledge.js", description: "Delete a knowledge file" },
|
|
409
408
|
"knowledge_deleted": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Knowledge file was deleted" },
|
|
410
|
-
"knowledge_promote": { direction: "c2s", handler: "lib/project-knowledge.js", description: "Promote a knowledge file to always-active" },
|
|
411
|
-
"knowledge_promoted": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Knowledge file was promoted" },
|
|
412
|
-
"knowledge_depromote": { direction: "c2s", handler: "lib/project-knowledge.js", description: "Depromote a knowledge file from always-active" },
|
|
413
|
-
"knowledge_depromoted": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Knowledge file was depromoted" },
|
|
414
|
-
|
|
415
|
-
// -----------------------------------------------------------------------
|
|
416
|
-
// Memory (stub — mates removed, lr-316f)
|
|
417
|
-
// -----------------------------------------------------------------------
|
|
418
|
-
"memory_list": { direction: "both", handler: "lib/project.js", description: "Request (c2s) or receive (s2c) memory entries" },
|
|
419
|
-
"memory_search": { direction: "c2s", handler: "lib/project.js", description: "Search memory entries" },
|
|
420
|
-
"memory_search_results": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Memory search results" },
|
|
421
|
-
"memory_delete": { direction: "c2s", handler: "lib/project.js", description: "Delete a memory entry by index" },
|
|
422
|
-
"memory_deleted": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Memory entry was deleted" },
|
|
423
409
|
|
|
424
410
|
// -----------------------------------------------------------------------
|
|
425
411
|
// Loop (automated task runner)
|
|
@@ -436,6 +422,9 @@ var schema = {
|
|
|
436
422
|
"loop_error": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Loop error" },
|
|
437
423
|
"loop_scheduled": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Loop was scheduled via cron" },
|
|
438
424
|
"loop_rerun_started": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A loop registry entry re-run has started" },
|
|
425
|
+
"loop_message": { direction: "c2s", handler: "lib/project-loop.js", description: "Queue a human message for delivery at the next loop iteration boundary" },
|
|
426
|
+
"loop_message_error": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Loop message could not be queued (e.g. no loop running)" },
|
|
427
|
+
"loop_pending_messages": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Current list of human messages queued for the next loop iteration" },
|
|
439
428
|
|
|
440
429
|
// -----------------------------------------------------------------------
|
|
441
430
|
// Loop registry (task schedule management)
|
|
@@ -8,6 +8,7 @@ var fs = require("fs");
|
|
|
8
8
|
var { CodexAppServer } = require("../codex-app-server");
|
|
9
9
|
var { discoverWorkflows } = require("../../sdk-workflow-discovery");
|
|
10
10
|
var { discoverSkillsWithMeta } = require("../../sdk-skill-discovery");
|
|
11
|
+
var codexLocalImage = require("../codex-local-image");
|
|
11
12
|
|
|
12
13
|
// --- Claude skill discovery ---
|
|
13
14
|
// Finds Claude skills in ~/.claude/skills/ and <cwd>/.claude/skills/
|
|
@@ -598,6 +599,13 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
598
599
|
aborted: false,
|
|
599
600
|
loopStarted: false,
|
|
600
601
|
model: _test_resolveModel(queryOpts),
|
|
602
|
+
// lr-79ee — live model/effort, mutable via handle.setModel()/setEffort().
|
|
603
|
+
// The app-server has no thread-level "change model" RPC, but turn/start
|
|
604
|
+
// accepts a per-turn model/effort override (see docs/guides/codex-reference/
|
|
605
|
+
// llms-full.txt around "Start a turn"), so mutating these here and passing
|
|
606
|
+
// them into every turn/start call switches the active thread's model on
|
|
607
|
+
// its next turn — no thread recreation required.
|
|
608
|
+
modelReasoningEffort: queryOpts.modelReasoningEffort || null,
|
|
601
609
|
// Track incremental text deltas
|
|
602
610
|
textBlocks: {}, // itemId -> true (text_start sent)
|
|
603
611
|
textLengths: {}, // itemId -> last sent length
|
|
@@ -606,6 +614,17 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
606
614
|
toolBlocks: {}, // itemId -> blockId (for tool_start dedup)
|
|
607
615
|
commandInputs: {}, // itemId -> command captured from approval/start events
|
|
608
616
|
planTexts: {}, // itemId -> streamed plan text
|
|
617
|
+
// lr-f7a4 — live tool policy, mutable via handle.setToolPolicy(). The
|
|
618
|
+
// app-server's own approvalPolicy is fixed at thread creation, but every
|
|
619
|
+
// requestApproval/requestUserInput notification is resolved here in JS
|
|
620
|
+
// via canUseTool, so a mid-thread policy change genuinely takes effect
|
|
621
|
+
// on the next approval request even though the underlying thread was
|
|
622
|
+
// started with a different approvalPolicy.
|
|
623
|
+
toolPolicy: queryOpts.toolPolicy || null,
|
|
624
|
+
// lr-de04 — absolute paths of localImage temp files written for the turn
|
|
625
|
+
// currently in flight. Cleared (and files deleted) once that turn's
|
|
626
|
+
// input has been sent, since the app-server has read the file by then.
|
|
627
|
+
pendingImagePaths: [],
|
|
609
628
|
};
|
|
610
629
|
|
|
611
630
|
// Internal event buffer for async iterator
|
|
@@ -692,13 +711,23 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
692
711
|
return false;
|
|
693
712
|
}
|
|
694
713
|
|
|
714
|
+
// lr-f7a4 — live "allow-all" tool policy, settable mid-thread via
|
|
715
|
+
// handle.setToolPolicy("allow-all"). Bypasses the canUseTool round-trip
|
|
716
|
+
// entirely so an operator-triggered full-auto toggle takes effect on the
|
|
717
|
+
// very next approval request, without waiting for a new thread.
|
|
718
|
+
function isAllowAll() {
|
|
719
|
+
return state.toolPolicy === "allow-all";
|
|
720
|
+
}
|
|
721
|
+
|
|
695
722
|
// Command approval request
|
|
696
723
|
if (method === "item/commandExecution/requestApproval") {
|
|
697
724
|
var cmdParams = msg.params || {};
|
|
698
725
|
if (cmdParams.itemId && cmdParams.command) {
|
|
699
726
|
state.commandInputs[cmdParams.itemId] = cmdParams.command;
|
|
700
727
|
}
|
|
701
|
-
if (
|
|
728
|
+
if (isAllowAll()) {
|
|
729
|
+
appServer.respond(msg.id, { decision: "accept" });
|
|
730
|
+
} else if (canUseTool) {
|
|
702
731
|
canUseTool("Bash", { command: cmdParams.command }, {}).then(function(decision) {
|
|
703
732
|
var approved = isApproved(decision);
|
|
704
733
|
// Response must be wrapped in { decision: ... } object per app-server protocol
|
|
@@ -716,7 +745,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
716
745
|
// File change approval request
|
|
717
746
|
if (method === "item/fileChange/requestApproval") {
|
|
718
747
|
var fcParams = msg.params || {};
|
|
719
|
-
if (
|
|
748
|
+
if (isAllowAll()) {
|
|
749
|
+
appServer.respond(msg.id, { decision: "accept" });
|
|
750
|
+
} else if (canUseTool) {
|
|
720
751
|
var changeInfo = (fcParams.changes || []).map(function(c) { return c.kind + " " + c.path; }).join(", ");
|
|
721
752
|
canUseTool("Edit", { changes: changeInfo, path: fcParams.path }, {}).then(function(decision) {
|
|
722
753
|
appServer.respond(msg.id, { decision: isApproved(decision) ? "accept" : "decline" });
|
|
@@ -919,14 +950,27 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
919
950
|
input = input.concat(skillItemsToInject);
|
|
920
951
|
}
|
|
921
952
|
|
|
922
|
-
|
|
953
|
+
var turnParams = {
|
|
923
954
|
threadId: state.threadId,
|
|
924
955
|
input: input,
|
|
925
|
-
|
|
956
|
+
model: state.model,
|
|
957
|
+
};
|
|
958
|
+
if (state.modelReasoningEffort) {
|
|
959
|
+
turnParams.effort = state.modelReasoningEffort;
|
|
960
|
+
}
|
|
961
|
+
await appServer.send("turn/start", turnParams, 60000);
|
|
926
962
|
|
|
927
963
|
// Wait for turn to complete
|
|
928
964
|
await turnPromise;
|
|
929
965
|
|
|
966
|
+
// lr-de04 — the app-server has finished reading any localImage temp
|
|
967
|
+
// files for this turn (whether it completed or failed), so they can
|
|
968
|
+
// be removed now rather than lingering until process exit.
|
|
969
|
+
if (state.pendingImagePaths.length > 0) {
|
|
970
|
+
codexLocalImage.removeTempImages(state.pendingImagePaths);
|
|
971
|
+
state.pendingImagePaths = [];
|
|
972
|
+
}
|
|
973
|
+
|
|
930
974
|
if (isCancelled()) break;
|
|
931
975
|
|
|
932
976
|
// Wait for next message (multi-turn)
|
|
@@ -948,6 +992,12 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
948
992
|
// Always deregister this query's handler so it doesn't receive stale events
|
|
949
993
|
// from a future query on the same app-server thread ID.
|
|
950
994
|
appServer.removeEventHandler(_handlerEntry);
|
|
995
|
+
// lr-de04 — catch-all for images belonging to a turn that never
|
|
996
|
+
// reached the post-turnPromise cleanup above (abort/error mid-turn).
|
|
997
|
+
if (state.pendingImagePaths.length > 0) {
|
|
998
|
+
codexLocalImage.removeTempImages(state.pendingImagePaths);
|
|
999
|
+
state.pendingImagePaths = [];
|
|
1000
|
+
}
|
|
951
1001
|
}
|
|
952
1002
|
|
|
953
1003
|
state.done = true;
|
|
@@ -973,9 +1023,27 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
973
1023
|
var input;
|
|
974
1024
|
if (images && images.length > 0) {
|
|
975
1025
|
input = [];
|
|
1026
|
+
var failedCount = 0;
|
|
976
1027
|
for (var i = 0; i < images.length; i++) {
|
|
977
|
-
|
|
978
|
-
|
|
1028
|
+
var img = images[i];
|
|
1029
|
+
var imgPath = codexLocalImage.writeTempImage(img.mediaType, img.data);
|
|
1030
|
+
if (imgPath) {
|
|
1031
|
+
state.pendingImagePaths.push(imgPath);
|
|
1032
|
+
input.push({ type: "localImage", path: imgPath });
|
|
1033
|
+
} else {
|
|
1034
|
+
failedCount++;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
if (failedCount > 0) {
|
|
1038
|
+
// Acceptance criterion (lr-de04): an image must never be dropped
|
|
1039
|
+
// silently. Surface a visible error event so the UI shows it,
|
|
1040
|
+
// matching the shape flattenEvent already produces for turn/failed.
|
|
1041
|
+
pushEvent({
|
|
1042
|
+
yokeType: "error",
|
|
1043
|
+
text: failedCount === 1
|
|
1044
|
+
? "1 image could not be sent to Codex (failed to write temp file) and was not included in this message."
|
|
1045
|
+
: failedCount + " images could not be sent to Codex (failed to write temp file) and were not included in this message.",
|
|
1046
|
+
});
|
|
979
1047
|
}
|
|
980
1048
|
input.push({ type: "text", text: text || "" });
|
|
981
1049
|
} else {
|
|
@@ -991,17 +1059,27 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
991
1059
|
},
|
|
992
1060
|
|
|
993
1061
|
setModel: function(model) {
|
|
994
|
-
//
|
|
1062
|
+
// lr-79ee — genuinely live: turn/start (see runQueryLoop above) sends
|
|
1063
|
+
// state.model on every turn, so this takes effect starting with the
|
|
1064
|
+
// next turn on the current thread. No thread recreation needed.
|
|
1065
|
+
if (model) state.model = model;
|
|
995
1066
|
return Promise.resolve();
|
|
996
1067
|
},
|
|
997
1068
|
|
|
998
1069
|
setEffort: function(effort) {
|
|
999
|
-
//
|
|
1070
|
+
// lr-79ee — same live mechanism as setModel: state.modelReasoningEffort
|
|
1071
|
+
// is read by turn/start on every turn.
|
|
1072
|
+
state.modelReasoningEffort = effort || null;
|
|
1000
1073
|
return Promise.resolve();
|
|
1001
1074
|
},
|
|
1002
1075
|
|
|
1003
1076
|
setToolPolicy: function(policy) {
|
|
1004
|
-
//
|
|
1077
|
+
// lr-f7a4 — the app-server's approvalPolicy is fixed at thread
|
|
1078
|
+
// creation (no known live-update RPC), but every approval
|
|
1079
|
+
// notification is resolved here in JS via canUseTool, so mutating
|
|
1080
|
+
// state.toolPolicy genuinely changes behavior for the next approval
|
|
1081
|
+
// request on this thread (see isAllowAll() in handleServerEvent).
|
|
1082
|
+
state.toolPolicy = policy || null;
|
|
1005
1083
|
return Promise.resolve();
|
|
1006
1084
|
},
|
|
1007
1085
|
|
|
@@ -1576,7 +1654,11 @@ function createCodexAdapter(opts) {
|
|
|
1576
1654
|
handleOpts.modelReasoningEffort = codexOpts.modelReasoningEffort || queryOpts.effort || "medium";
|
|
1577
1655
|
}
|
|
1578
1656
|
|
|
1579
|
-
// Tool policy -> approval mode
|
|
1657
|
+
// Tool policy -> approval mode. handleOpts.toolPolicy seeds
|
|
1658
|
+
// state.toolPolicy in createCodexQueryHandle so isAllowAll() (lr-f7a4)
|
|
1659
|
+
// is already correct on the very first approval request, not just
|
|
1660
|
+
// after a later setToolPolicy() call.
|
|
1661
|
+
handleOpts.toolPolicy = queryOpts.toolPolicy || null;
|
|
1580
1662
|
if (queryOpts.toolPolicy === "allow-all") {
|
|
1581
1663
|
handleOpts.approvalPolicy = "never";
|
|
1582
1664
|
} else {
|
|
@@ -1708,4 +1790,8 @@ function createCodexAdapter(opts) {
|
|
|
1708
1790
|
module.exports = {
|
|
1709
1791
|
createCodexAdapter: createCodexAdapter,
|
|
1710
1792
|
_test_resolveModel: _test_resolveModel,
|
|
1793
|
+
// lr-f7a4 — exported so tests can drive the real approval-routing and
|
|
1794
|
+
// setToolPolicy logic against a fake appServer, rather than reimplementing
|
|
1795
|
+
// a copy of handleServerEvent's approval branches inline.
|
|
1796
|
+
_test_createCodexQueryHandle: createCodexQueryHandle,
|
|
1711
1797
|
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Codex local_image temp-file helper (lr-de04)
|
|
2
|
+
// ---------------------------------------------
|
|
3
|
+
// The Codex app-server protocol accepts image input only as a `localImage`
|
|
4
|
+
// turn item (`{ type: "localImage", path: "..." }`) — it does not accept
|
|
5
|
+
// inline base64 data the way the Claude adapter does. This module writes an
|
|
6
|
+
// incoming base64 image to an unpredictably-named temp file so the codex.js
|
|
7
|
+
// adapter can reference it by path, and removes those files once the codex
|
|
8
|
+
// process no longer needs them (end of turn / end of query).
|
|
9
|
+
//
|
|
10
|
+
// Kept separate from codex.js (which is already large) so the write/cleanup
|
|
11
|
+
// logic is independently testable without spinning up an app-server.
|
|
12
|
+
|
|
13
|
+
var fs = require("fs");
|
|
14
|
+
var path = require("path");
|
|
15
|
+
var os = require("os");
|
|
16
|
+
var crypto = require("crypto");
|
|
17
|
+
|
|
18
|
+
var EXT_BY_MEDIA_TYPE = {
|
|
19
|
+
"image/png": ".png",
|
|
20
|
+
"image/jpeg": ".jpg",
|
|
21
|
+
"image/gif": ".gif",
|
|
22
|
+
"image/webp": ".webp",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function extForMediaType(mediaType) {
|
|
26
|
+
return EXT_BY_MEDIA_TYPE[mediaType] || ".png";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Per-process scratch dir for Codex local_image temp files. Deliberately not
|
|
30
|
+
// the persistent, HTTP-served chat-images dir (lib/project-image.js) — these
|
|
31
|
+
// files exist only for the lifetime of a single turn/query and are never
|
|
32
|
+
// served to the browser.
|
|
33
|
+
function defaultTempDir() {
|
|
34
|
+
return path.join(os.tmpdir(), "clagentic-codex-images-" + process.pid);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Writes one base64 image to an unpredictably-named temp file.
|
|
38
|
+
// Returns the absolute path, or null if the write failed (caller decides
|
|
39
|
+
// how to surface that — see codex.js pushMessage, which must not silently
|
|
40
|
+
// drop the image on write failure either).
|
|
41
|
+
function writeTempImage(mediaType, base64Data, tempDir) {
|
|
42
|
+
var dir = tempDir || defaultTempDir();
|
|
43
|
+
try {
|
|
44
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var randomName = crypto.randomBytes(16).toString("hex") + extForMediaType(mediaType);
|
|
49
|
+
var filePath = path.join(dir, randomName);
|
|
50
|
+
try {
|
|
51
|
+
fs.writeFileSync(filePath, Buffer.from(base64Data, "base64"), { mode: 0o600 });
|
|
52
|
+
return filePath;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Best-effort delete; never throws. Missing files are not an error (the
|
|
59
|
+
// caller may race a cleanup against process teardown).
|
|
60
|
+
function removeTempImage(filePath) {
|
|
61
|
+
if (!filePath) return;
|
|
62
|
+
try {
|
|
63
|
+
fs.unlinkSync(filePath);
|
|
64
|
+
} catch (e) {}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function removeTempImages(filePaths) {
|
|
68
|
+
if (!filePaths) return;
|
|
69
|
+
for (var i = 0; i < filePaths.length; i++) {
|
|
70
|
+
removeTempImage(filePaths[i]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
defaultTempDir: defaultTempDir,
|
|
76
|
+
writeTempImage: writeTempImage,
|
|
77
|
+
removeTempImage: removeTempImage,
|
|
78
|
+
removeTempImages: removeTempImages,
|
|
79
|
+
};
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -148,16 +148,23 @@ if (selfUpdate) {
|
|
|
148
148
|
log(`skipping start (daemon was not running or is already running — operator controls restarts)`);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
// Step 6: Apply memory-limit drop-in
|
|
152
|
-
// When
|
|
153
|
-
//
|
|
151
|
+
// Step 6: Apply the memory-limit drop-in (lr-c10f6d).
|
|
152
|
+
// When the operator has NOT set memoryHigh/memoryMax in daemon.json, the
|
|
153
|
+
// drop-in is still written — with ABSOLUTE byte values computed from
|
|
154
|
+
// /proc/meminfo MemTotal (floor(60%) / floor(75%)) — because a `%` directive
|
|
155
|
+
// in the shipped unit file is resolved by systemd against the wrong MemTotal
|
|
156
|
+
// inside an LXC container; only userspace sees the lxcfs-corrected value.
|
|
157
|
+
// Recomputed on every postinstall so it tracks RAM changes. Operator
|
|
158
|
+
// overrides in daemon.json always keep precedence (unchanged from lr-de07).
|
|
154
159
|
(function applyMemoryDropIn() {
|
|
155
160
|
const { loadConfig } = require('../lib/config');
|
|
156
161
|
const cfg = loadConfig();
|
|
157
162
|
const memoryHigh = cfg && cfg.memoryHigh ? String(cfg.memoryHigh) : null;
|
|
158
163
|
const memoryMax = cfg && cfg.memoryMax ? String(cfg.memoryMax) : null;
|
|
159
164
|
|
|
160
|
-
// Validate before writing — reject garbage
|
|
165
|
+
// Validate operator-supplied values before writing — reject garbage early.
|
|
166
|
+
// (Computed defaults are always well-formed bare-byte strings, so no
|
|
167
|
+
// validation is needed for that path.)
|
|
161
168
|
if (memoryHigh) {
|
|
162
169
|
const vr = parseMemoryLimit(memoryHigh);
|
|
163
170
|
if (!vr.ok) {
|
|
@@ -175,13 +182,11 @@ if (selfUpdate) {
|
|
|
175
182
|
|
|
176
183
|
try {
|
|
177
184
|
applyDropIn({ memoryHigh, memoryMax }, (msg) => log(msg.replace(/^\[memory-limits\] /, '')));
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
log(`WARNING: daemon-reload (memory drop-in) failed: ${errMsg(err)}`);
|
|
184
|
-
}
|
|
185
|
+
log('running systemctl daemon-reload (memory drop-in updated)');
|
|
186
|
+
try {
|
|
187
|
+
runCmd('systemctl', ['daemon-reload']);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
log(`WARNING: daemon-reload (memory drop-in) failed: ${errMsg(err)}`);
|
|
185
190
|
}
|
|
186
191
|
} catch (err) {
|
|
187
192
|
log(`WARNING: memory drop-in apply failed: ${err.message}`);
|