@clagentic/console 1.10.0 → 1.11.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 +14 -1
- package/bin/cli.js +38 -16
- 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/arg-validation.js +50 -0
- package/lib/cli/daemon-launch.js +5 -4
- package/lib/cli/menus.js +2 -2
- package/lib/cli/schedule-input-subcommands.js +327 -0
- package/lib/cli/session-subcommands.js +101 -17
- package/lib/client-build-id.js +56 -0
- package/lib/daemon.js +38 -6
- package/lib/identity/index.js +9 -4
- 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-settings.js +96 -0
- package/lib/permission-summary.js +67 -0
- package/lib/project-connection.js +10 -11
- package/lib/project-external-trigger.js +9 -1
- package/lib/project-loop.js +50 -23
- package/lib/project-permission-settings.js +59 -0
- package/lib/project-prompt-responses.js +25 -15
- package/lib/project-sessions.js +164 -60
- package/lib/project-user-message.js +18 -47
- package/lib/project.js +46 -74
- package/lib/public/app.js +4 -7
- 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/css/overlays.css +0 -3
- package/lib/public/css/scheduler-modal.css +5 -0
- package/lib/public/index.html +44 -8
- package/lib/public/modules/app-connection.js +18 -1
- package/lib/public/modules/app-loop-ui.js +11 -1
- package/lib/public/modules/app-messages.js +23 -30
- package/lib/public/modules/app-panels.js +10 -3
- package/lib/public/modules/app-rate-limit.js +64 -88
- package/lib/public/modules/app-rendering.js +37 -6
- package/lib/public/modules/approve-tools-toggle.js +33 -0
- 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/loop-hooks-warning.js +20 -0
- package/lib/public/modules/mode-options.js +35 -16
- package/lib/public/modules/permission-settings.js +56 -0
- package/lib/public/modules/project-settings.js +3 -0
- 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/public/modules/scheduler-config.js +12 -0
- package/lib/public/modules/scheduler.js +8 -0
- package/lib/public/modules/server-settings.js +5 -9
- package/lib/public/modules/settings-defaults.js +18 -4
- 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/scheduler.js +4 -0
- package/lib/sdk-bridge.js +194 -175
- 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 +37 -11
- package/lib/session-directory.js +224 -0
- package/lib/session-file-scan.js +55 -0
- package/lib/session-input-ipc.js +21 -0
- package/lib/session-input.js +396 -23
- package/lib/session-name-holder.js +82 -0
- package/lib/session-resume.js +3 -0
- package/lib/sessions.js +111 -2
- package/lib/turn-initiator.js +6 -2
- package/lib/updater.js +8 -2
- package/lib/ws-schema.js +20 -9
- package/lib/yoke/adapters/claude-worker.js +3 -1
- package/lib/yoke/adapters/claude.js +13 -17
- 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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// message-sender-record.js - the per-message sender record the console publishes
|
|
2
|
+
// for any tool that reads a vendor session.
|
|
3
|
+
//
|
|
4
|
+
// A vendor transcript says what was said, not always who sent it. For every user
|
|
5
|
+
// message the console sends into a vendor session this module appends one line
|
|
6
|
+
// to a file an outside tool can find from the vendor session id alone, with no
|
|
7
|
+
// console running. The format is versioned and documented in
|
|
8
|
+
// docs/guides/architecture.md ("Integrating other tools"); change it only by
|
|
9
|
+
// bumping FORMAT_VERSION.
|
|
10
|
+
//
|
|
11
|
+
// Location: <console data dir>/message-senders/<vendor>/<vendor session id>.jsonl
|
|
12
|
+
// Lines (JSON, one per line, appended with a single write):
|
|
13
|
+
// kind "message" one per user message the console sent
|
|
14
|
+
// kind "turn" added when a vendor reports the turn id of a message (Codex)
|
|
15
|
+
//
|
|
16
|
+
// This is not a second history writer: the entries come from the history
|
|
17
|
+
// entries the existing writers already build (injected-sender.js stampRecord and
|
|
18
|
+
// consoleTurnEntry, session-input.js recordInjected), observed at the one place
|
|
19
|
+
// they all pass through (sessions.js recordHistoryEntry).
|
|
20
|
+
|
|
21
|
+
var fs = require("fs");
|
|
22
|
+
var path = require("path");
|
|
23
|
+
var { isSafeSessionId } = require("./session-id");
|
|
24
|
+
|
|
25
|
+
var FORMAT_VERSION = 1;
|
|
26
|
+
var DIR_NAME = "message-senders";
|
|
27
|
+
var KIND = Object.freeze({ MESSAGE: "message", TURN: "turn" });
|
|
28
|
+
|
|
29
|
+
// A session whose vendor session id is not known yet (its first turn has not
|
|
30
|
+
// answered) holds its records on the session object itself, uncapped: one
|
|
31
|
+
// record per user message must hold, so none is dropped. Memory stays bounded
|
|
32
|
+
// because the list belongs to one session, is emptied the moment the vendor
|
|
33
|
+
// names the session (flush), and goes away with the session object when it
|
|
34
|
+
// closes; each record is a few hundred bytes.
|
|
35
|
+
var PENDING_FIELD = "_senderRecordsPending";
|
|
36
|
+
|
|
37
|
+
function isoOf(ms) {
|
|
38
|
+
return new Date(typeof ms === "number" && isFinite(ms) ? ms : Date.now()).toISOString();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The record fields a history entry yields. vendor and vendorSessionId are filled
|
|
42
|
+
// in when the record is written.
|
|
43
|
+
function fieldsFromEntry(entry) {
|
|
44
|
+
var rec = {
|
|
45
|
+
formatVersion: FORMAT_VERSION,
|
|
46
|
+
kind: KIND.MESSAGE,
|
|
47
|
+
messageId: entry.messageId,
|
|
48
|
+
initiator: entry.initiator || null,
|
|
49
|
+
senderName: typeof entry.fromName === "string" && entry.fromName ? entry.fromName : null,
|
|
50
|
+
senderKind: entry.senderKind || null,
|
|
51
|
+
fromSession: typeof entry.fromSession === "string" && entry.fromSession ? entry.fromSession : null,
|
|
52
|
+
timestamp: isoOf(entry._ts),
|
|
53
|
+
};
|
|
54
|
+
return rec;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function recordPath(baseDir, vendor, vendorSessionId) {
|
|
58
|
+
if (typeof vendor !== "string" || !isSafeSessionId(vendor)) throw new Error("unsafe vendor " + JSON.stringify(String(vendor).slice(0, 32)));
|
|
59
|
+
if (!isSafeSessionId(vendorSessionId)) throw new Error("unsafe vendor session id " + JSON.stringify(String(vendorSessionId).slice(0, 64)));
|
|
60
|
+
return path.join(baseDir, DIR_NAME, vendor, vendorSessionId + ".jsonl");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// getBaseDir() is read at write time so a recorder built before the data
|
|
64
|
+
// directory exists still writes to it.
|
|
65
|
+
function createSenderRecorder(opts) {
|
|
66
|
+
var getBaseDir = opts.getBaseDir;
|
|
67
|
+
var log = opts.log || console;
|
|
68
|
+
|
|
69
|
+
function append(vendor, vendorSessionId, rec) {
|
|
70
|
+
var file = recordPath(getBaseDir(), vendor, vendorSessionId);
|
|
71
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
72
|
+
var out = Object.assign({}, rec, { vendor: vendor, vendorSessionId: vendorSessionId });
|
|
73
|
+
// One write of one line: a reader sees whole lines, and tolerates an
|
|
74
|
+
// unparsable final one.
|
|
75
|
+
fs.appendFileSync(file, JSON.stringify(out) + "\n", { mode: 0o600 });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function attempt(vendor, vendorSessionId, rec) {
|
|
79
|
+
try { append(vendor, vendorSessionId, rec); }
|
|
80
|
+
catch (e) {
|
|
81
|
+
// Publishing the record never breaks or delays the turn it describes.
|
|
82
|
+
log.error("[message-sender-record] could not write the record:", e && e.message ? e.message : String(e));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function vendorOf(session, defaultVendor) {
|
|
87
|
+
return session.vendor || defaultVendor || null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function pendingOf(session) {
|
|
91
|
+
if (!session[PENDING_FIELD]) session[PENDING_FIELD] = [];
|
|
92
|
+
return session[PENDING_FIELD];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Called for each history entry as it is recorded. Entries that are not a
|
|
96
|
+
// user message the console sent (no message id) are ignored.
|
|
97
|
+
function note(session, entry, defaultVendor) {
|
|
98
|
+
if (!entry || entry.type !== "user_message" || !entry.messageId) return;
|
|
99
|
+
var rec = fieldsFromEntry(entry);
|
|
100
|
+
var vendor = vendorOf(session, defaultVendor);
|
|
101
|
+
if (vendor && session.cliSessionId) return attempt(vendor, session.cliSessionId, rec);
|
|
102
|
+
pendingOf(session).push(rec);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Writes what was held for a session whose vendor session id is now known.
|
|
106
|
+
function flush(session, defaultVendor) {
|
|
107
|
+
var pending = session[PENDING_FIELD];
|
|
108
|
+
var vendor = vendorOf(session, defaultVendor);
|
|
109
|
+
if (!pending || !pending.length || !vendor || !session.cliSessionId) return;
|
|
110
|
+
session[PENDING_FIELD] = [];
|
|
111
|
+
for (var i = 0; i < pending.length; i++) attempt(vendor, session.cliSessionId, pending[i]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// A vendor that assigns its own id to the turn a message started (Codex)
|
|
115
|
+
// reports it here; the id joins the message to the vendor transcript.
|
|
116
|
+
function bindTurn(session, messageId, turnId, defaultVendor) {
|
|
117
|
+
if (!messageId || !turnId) return;
|
|
118
|
+
var rec = { formatVersion: FORMAT_VERSION, kind: KIND.TURN, messageId: messageId, turnId: String(turnId), timestamp: isoOf() };
|
|
119
|
+
var vendor = vendorOf(session, defaultVendor);
|
|
120
|
+
if (vendor && session.cliSessionId) return attempt(vendor, session.cliSessionId, rec);
|
|
121
|
+
pendingOf(session).push(rec);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { note: note, flush: flush, bindTurn: bindTurn };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
FORMAT_VERSION: FORMAT_VERSION,
|
|
129
|
+
DIR_NAME: DIR_NAME,
|
|
130
|
+
KIND: KIND,
|
|
131
|
+
recordPath: recordPath,
|
|
132
|
+
createSenderRecorder: createSenderRecorder,
|
|
133
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// A read-only view of the prompts a session is waiting on, for the session
|
|
4
|
+
// directory (list-sessions). The source is the live registry state on the
|
|
5
|
+
// session objects in the daemon's memory (the maps lib/prompt-registry.js owns),
|
|
6
|
+
// the same state the operator's banner is raised from; no file is read.
|
|
7
|
+
//
|
|
8
|
+
// A prompt is shown by its identifiers and the one-line summary the banner
|
|
9
|
+
// already shows for a tool call. Excluded: tool input beyond that summary, the
|
|
10
|
+
// decision reason, a question's or an elicitation's text and schema, a plan's
|
|
11
|
+
// content and anything a client would answer with.
|
|
12
|
+
|
|
13
|
+
var promptKinds = require("./prompt-kinds");
|
|
14
|
+
var { ownValue } = require("./prompt-kinds/codecs");
|
|
15
|
+
var { summarize } = require("./permission-summary");
|
|
16
|
+
|
|
17
|
+
var STORES = promptKinds.sessionStores();
|
|
18
|
+
|
|
19
|
+
// Kinds whose summary is a tool call; any other kind reports none.
|
|
20
|
+
var TOOL_KINDS = { permission: true, plan: true };
|
|
21
|
+
|
|
22
|
+
function ageSeconds(createdAt, now) {
|
|
23
|
+
if (typeof createdAt !== "number" || !isFinite(createdAt)) return 0;
|
|
24
|
+
return Math.max(0, Math.floor((now - createdAt) / 1000));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Returns [{ requestId, kind, tool, summary, ageSeconds }], oldest first;
|
|
28
|
+
// empty when the session waits on nothing. Only operator-facing prompts count
|
|
29
|
+
// (kind.journal), the ones a banner is raised for.
|
|
30
|
+
function pendingPrompts(session, now) {
|
|
31
|
+
var out = [];
|
|
32
|
+
STORES.forEach(function (store) {
|
|
33
|
+
var map = session && session[store];
|
|
34
|
+
if (!map) return;
|
|
35
|
+
Object.keys(map).forEach(function (id) {
|
|
36
|
+
var record = ownValue(map, id);
|
|
37
|
+
if (!record) return;
|
|
38
|
+
var kind = promptKinds.kindOfRecord(record, store);
|
|
39
|
+
if (!kind || !kind.journal) return;
|
|
40
|
+
out.push({
|
|
41
|
+
createdAt: typeof record.createdAt === "number" ? record.createdAt : 0,
|
|
42
|
+
view: {
|
|
43
|
+
requestId: id,
|
|
44
|
+
kind: kind.name,
|
|
45
|
+
tool: typeof record.toolName === "string" ? record.toolName : null,
|
|
46
|
+
summary: TOOL_KINDS[kind.name] ? summarize(record.toolName, record.toolInput) : "",
|
|
47
|
+
ageSeconds: ageSeconds(record.createdAt, now),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
return out.sort(function (a, b) { return a.createdAt - b.createdAt; }).map(function (e) { return e.view; });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { pendingPrompts: pendingPrompts };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The one answer to "may this permission mode be applied?", shared by every
|
|
4
|
+
// place a mode enters the server: the per-session, project-default and
|
|
5
|
+
// server-default setters, a loop's mode at query start, and a saved default
|
|
6
|
+
// read at load. A mode is accepted only when the vendor can run it AND the
|
|
7
|
+
// server allows it; bypassPermissions is accepted only when a caller passes
|
|
8
|
+
// skipPermissionsAllowed: true, and no caller in the server does.
|
|
9
|
+
|
|
10
|
+
var { ownValue } = require("./prompt-kinds/codecs");
|
|
11
|
+
|
|
12
|
+
// Every mode the console knows. Anything else is refused outright.
|
|
13
|
+
var KNOWN_MODES = {
|
|
14
|
+
default: true,
|
|
15
|
+
plan: true,
|
|
16
|
+
acceptEdits: true,
|
|
17
|
+
dontAsk: true,
|
|
18
|
+
auto: true,
|
|
19
|
+
bypassPermissions: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Modes only a vendor that lists them in capabilities.permissionModes can run.
|
|
23
|
+
var CAPABILITY_GATED_MODES = { auto: true, dontAsk: true };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {*} mode - the requested mode, unchecked client or file input.
|
|
27
|
+
* @param {object} [opts]
|
|
28
|
+
* @param {boolean} [opts.skipPermissionsAllowed] - the server's skip-permissions setting.
|
|
29
|
+
* @param {?string[]} [opts.supportedModes] - the vendor's capabilities.permissionModes;
|
|
30
|
+
* null or absent skips the vendor check (used where no vendor is known yet, e.g. at load).
|
|
31
|
+
* @returns {{ok: true}|{ok: false, error: string}}
|
|
32
|
+
*/
|
|
33
|
+
function checkPermissionMode(mode, opts) {
|
|
34
|
+
opts = opts || {};
|
|
35
|
+
if (typeof mode !== "string" || ownValue(KNOWN_MODES, mode) !== true) {
|
|
36
|
+
return { ok: false, error: "Unknown permission mode" };
|
|
37
|
+
}
|
|
38
|
+
if (mode === "bypassPermissions" && opts.skipPermissionsAllowed !== true) {
|
|
39
|
+
return { ok: false, error: "The bypassPermissions mode is not enabled on this server" };
|
|
40
|
+
}
|
|
41
|
+
if (ownValue(CAPABILITY_GATED_MODES, mode) === true && Array.isArray(opts.supportedModes)
|
|
42
|
+
&& opts.supportedModes.indexOf(mode) === -1) {
|
|
43
|
+
return { ok: false, error: "This session's agent does not support the " + mode + " permission mode" };
|
|
44
|
+
}
|
|
45
|
+
return { ok: true };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A mode read from storage (daemon.json defaults): the mode itself when it
|
|
50
|
+
* passes, "default" otherwise, with the refusal so the caller can log it. The
|
|
51
|
+
* vendor check is skipped: no vendor has reported its capabilities at load.
|
|
52
|
+
* @returns {{mode: string, error: ?string}}
|
|
53
|
+
*/
|
|
54
|
+
function savedModeOrDefault(mode, opts) {
|
|
55
|
+
var verdict = checkPermissionMode(mode, { skipPermissionsAllowed: !!(opts && opts.skipPermissionsAllowed) });
|
|
56
|
+
return verdict.ok ? { mode: mode, error: null } : { mode: "default", error: verdict.error };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
checkPermissionMode: checkPermissionMode,
|
|
61
|
+
savedModeOrDefault: savedModeOrDefault,
|
|
62
|
+
CAPABILITY_GATED_MODES: CAPABILITY_GATED_MODES,
|
|
63
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The server-wide permission settings an administrator may change. Each default
|
|
4
|
+
// equals the behaviour before the setting existed, so nothing changes until a
|
|
5
|
+
// person changes it. Stored in daemon.json beside the other server settings;
|
|
6
|
+
// read at decision time, so a change needs no restart.
|
|
7
|
+
|
|
8
|
+
var { ownValue } = require("./prompt-kinds/codecs");
|
|
9
|
+
|
|
10
|
+
var DEFAULT_OPENED_SESSION_MODE = "acceptEdits";
|
|
11
|
+
|
|
12
|
+
// The setting names a client may send, each with its type check. Anything else
|
|
13
|
+
// in a request is refused rather than stored.
|
|
14
|
+
var SETTING_TYPES = {
|
|
15
|
+
autoApproveReadOnly: function (v) { return typeof v === "boolean"; },
|
|
16
|
+
openedSessionMode: function (v) { return typeof v === "string" && v.length > 0; },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {?object} config - the daemon configuration (daemon.json contents).
|
|
21
|
+
* @returns {{autoApproveReadOnly: boolean, openedSessionMode: string}}
|
|
22
|
+
*/
|
|
23
|
+
function readPermissionSettings(config) {
|
|
24
|
+
var cfg = config || {};
|
|
25
|
+
return {
|
|
26
|
+
// Only an explicit false turns it off: an absent field is today's behaviour.
|
|
27
|
+
autoApproveReadOnly: cfg.autoApproveReadOnly !== false,
|
|
28
|
+
openedSessionMode: typeof cfg.openedSessionMode === "string" && cfg.openedSessionMode
|
|
29
|
+
? cfg.openedSessionMode
|
|
30
|
+
: DEFAULT_OPENED_SESSION_MODE,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The fields of a change request that name a known setting with a value of the
|
|
36
|
+
* right type; nothing else passes. `rejected` lists the names that did not.
|
|
37
|
+
* @returns {{values: object, rejected: string[]}}
|
|
38
|
+
*/
|
|
39
|
+
function pickSettingChanges(request) {
|
|
40
|
+
var values = {};
|
|
41
|
+
var rejected = [];
|
|
42
|
+
Object.keys(request || {}).forEach(function (name) {
|
|
43
|
+
if (name === "type") return;
|
|
44
|
+
var check = ownValue(SETTING_TYPES, name);
|
|
45
|
+
if (typeof check === "function" && check(request[name])) values[name] = request[name];
|
|
46
|
+
else rejected.push(name);
|
|
47
|
+
});
|
|
48
|
+
return { values: values, rejected: rejected };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The mode a session opened by the CLI or a trigger starts in. Precedence: the
|
|
53
|
+
* open request's own mode, then the server setting, then accept edits.
|
|
54
|
+
*
|
|
55
|
+
* A mode the request names that fails the check refuses the open (the caller
|
|
56
|
+
* asked for it by name). A stored setting that fails it falls back to accept
|
|
57
|
+
* edits: it was valid when saved and may have stopped being so (a vendor
|
|
58
|
+
* change).
|
|
59
|
+
*
|
|
60
|
+
* @param {object} args
|
|
61
|
+
* @param {*} args.requested - the open request's mode, or undefined/null.
|
|
62
|
+
* @param {string} args.setting - the server setting's value.
|
|
63
|
+
* @param {function(string): {ok: boolean, error: ?string}} args.check - the shared mode check
|
|
64
|
+
* for the vendor the session will run on.
|
|
65
|
+
* @param {function(string): void} [args.onFallback] - told why the stored setting was not used.
|
|
66
|
+
* @returns {{mode: string}|{error: string}}
|
|
67
|
+
*/
|
|
68
|
+
function resolveOpenedSessionMode(args) {
|
|
69
|
+
if (args.requested !== undefined && args.requested !== null) {
|
|
70
|
+
var asked = args.check(args.requested);
|
|
71
|
+
return asked.ok ? { mode: args.requested } : { error: asked.error };
|
|
72
|
+
}
|
|
73
|
+
if (args.setting && args.setting !== DEFAULT_OPENED_SESSION_MODE) {
|
|
74
|
+
var stored = args.check(args.setting);
|
|
75
|
+
if (stored.ok) return { mode: args.setting };
|
|
76
|
+
if (args.onFallback) args.onFallback(stored.error);
|
|
77
|
+
}
|
|
78
|
+
return { mode: DEFAULT_OPENED_SESSION_MODE };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The wire message that tells a client the current settings. */
|
|
82
|
+
function settingsMessage(settings) {
|
|
83
|
+
return {
|
|
84
|
+
type: "permission_settings",
|
|
85
|
+
autoApproveReadOnly: settings.autoApproveReadOnly,
|
|
86
|
+
openedSessionMode: settings.openedSessionMode,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
DEFAULT_OPENED_SESSION_MODE: DEFAULT_OPENED_SESSION_MODE,
|
|
92
|
+
readPermissionSettings: readPermissionSettings,
|
|
93
|
+
pickSettingChanges: pickSettingChanges,
|
|
94
|
+
resolveOpenedSessionMode: resolveOpenedSessionMode,
|
|
95
|
+
settingsMessage: settingsMessage,
|
|
96
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The short text that identifies a tool call to the operator: the body of a
|
|
4
|
+
// permission banner and push, and the summary list-sessions reports for a
|
|
5
|
+
// pending prompt. One source, so no surface shows more of a call than the
|
|
6
|
+
// banner does.
|
|
7
|
+
|
|
8
|
+
// Summary bound, in characters, ellipsis included.
|
|
9
|
+
var SUMMARY_MAX = 120;
|
|
10
|
+
|
|
11
|
+
// C0 and C1 controls (ESC, CR, LF, NUL, ...) and the Unicode line and
|
|
12
|
+
// paragraph separators. A summary is printed by a tool that may reach a
|
|
13
|
+
// terminal, so none of these may pass.
|
|
14
|
+
function isControl(code) {
|
|
15
|
+
return code <= 0x1f || (code >= 0x7f && code <= 0x9f) || code === 0x2028 || code === 0x2029;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function pushBody(toolName, input) {
|
|
19
|
+
if (!input) return "";
|
|
20
|
+
var text = "";
|
|
21
|
+
if (toolName === "Bash" && input.command) {
|
|
22
|
+
text = input.command;
|
|
23
|
+
} else if (toolName === "Edit" && input.file_path) {
|
|
24
|
+
text = input.file_path.split(/[/\\]/).pop() + ": " + (input.old_string || "").substring(0, 40) + " " + String.fromCharCode(0x2192) + " " + (input.new_string || "").substring(0, 40);
|
|
25
|
+
} else if (toolName === "Write" && input.file_path) {
|
|
26
|
+
text = input.file_path;
|
|
27
|
+
} else if (input.file_path) {
|
|
28
|
+
text = input.file_path;
|
|
29
|
+
} else if (input.command) {
|
|
30
|
+
text = input.command;
|
|
31
|
+
} else if (input.url) {
|
|
32
|
+
text = input.url;
|
|
33
|
+
} else if (input.query) {
|
|
34
|
+
text = input.query;
|
|
35
|
+
} else if (input.pattern) {
|
|
36
|
+
text = input.pattern;
|
|
37
|
+
} else if (input.description) {
|
|
38
|
+
text = input.description;
|
|
39
|
+
}
|
|
40
|
+
if (text.length > 120) text = text.substring(0, 120) + "...";
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function oneLine(text) {
|
|
45
|
+
var out = "";
|
|
46
|
+
for (var i = 0; i < text.length; i++) {
|
|
47
|
+
out += isControl(text.charCodeAt(i)) ? " " : text.charAt(i);
|
|
48
|
+
}
|
|
49
|
+
return out.replace(/ {2,}/g, " ").trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A single printable line of at most SUMMARY_MAX characters. A non-string
|
|
53
|
+
// field of a hostile input is not a summary.
|
|
54
|
+
function summarize(toolName, input) {
|
|
55
|
+
var body;
|
|
56
|
+
try {
|
|
57
|
+
body = pushBody(toolName, input);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
if (typeof body !== "string") return "";
|
|
62
|
+
var line = oneLine(body);
|
|
63
|
+
if (line.length > SUMMARY_MAX) line = line.slice(0, SUMMARY_MAX - 3) + "...";
|
|
64
|
+
return line;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { pushBody: pushBody, summarize: summarize, SUMMARY_MAX: SUMMARY_MAX };
|
|
@@ -5,7 +5,10 @@ var userPresence = require("./user-presence");
|
|
|
5
5
|
var { authOf } = require("./project-access");
|
|
6
6
|
var { getCodexConfig } = require("./codex-defaults");
|
|
7
7
|
var { promptsFor } = require("./prompt-registry");
|
|
8
|
+
var { settingsMessage } = require("./permission-settings");
|
|
9
|
+
var { effectiveSessionMode } = require("./sessions");
|
|
8
10
|
var sessionReclaim = require("./session-reclaim");
|
|
11
|
+
var clientBuildId = require("./client-build-id");
|
|
9
12
|
var { buildVendorRegistryMessage } = require("./vendor-registry-message");
|
|
10
13
|
// detectLite is cached per-project in project.js and passed via ctx.liteStatus.
|
|
11
14
|
// This import is retained only for backward compat if ctx.liteStatus is absent.
|
|
@@ -15,7 +18,7 @@ var { detectLite } = require("./lite-detect");
|
|
|
15
18
|
* Attach connection/disconnection handlers to a project context.
|
|
16
19
|
*
|
|
17
20
|
* ctx fields:
|
|
18
|
-
* cwd, slug, isMate, osUsers, debug,
|
|
21
|
+
* cwd, slug, isMate, osUsers, debug,
|
|
19
22
|
* currentVersion, lanHost, sm, tm, nm, clients, send, sendTo,
|
|
20
23
|
* opts, loopState, loopRegistry, _loop, pushModule,
|
|
21
24
|
* hydrateImageRefs, broadcastClientCount, broadcastPresence,
|
|
@@ -30,8 +33,6 @@ function attachConnection(ctx) {
|
|
|
30
33
|
var slug = ctx.slug;
|
|
31
34
|
var osUsers = ctx.osUsers;
|
|
32
35
|
var debug = ctx.debug;
|
|
33
|
-
var dangerouslySkipPermissions = ctx.dangerouslySkipPermissions;
|
|
34
|
-
var dangerouslySkipPermissionsConfigured = ctx.dangerouslySkipPermissionsConfigured || false;
|
|
35
36
|
var currentVersion = ctx.currentVersion;
|
|
36
37
|
var lanHost = ctx.lanHost;
|
|
37
38
|
var sm = ctx.sm;
|
|
@@ -141,12 +142,7 @@ function attachConnection(ctx) {
|
|
|
141
142
|
// Use the liteStatus cached at project-context creation time (project.js) to
|
|
142
143
|
// avoid a synchronous execFileSync("which",...) on every WS connect.
|
|
143
144
|
var _liteStatus = ctx.liteStatus || detectLite();
|
|
144
|
-
var infoMsg = { type: "info", cwd: cwd, slug: slug, project: title || project, version: currentVersion,
|
|
145
|
-
// When dangerouslySkipPermissions is set in config but suppressed because
|
|
146
|
-
// multi-user mode is active, tell the client so it can surface a warning.
|
|
147
|
-
if (dangerouslySkipPermissionsConfigured && !dangerouslySkipPermissions) {
|
|
148
|
-
infoMsg.dangerouslySkipPermissionsBlocked = true;
|
|
149
|
-
}
|
|
145
|
+
var infoMsg = { type: "info", cwd: cwd, slug: slug, project: title || project, version: currentVersion, buildId: clientBuildId.get(), debug: !!debug, osUsers: osUsers, lanHost: lanHost, projectCount: _filteredProjects.length, projects: _filteredProjects, projectOwnerId: projectOwnerId, ownerLocked: ownerLocked, liteInstalled: _liteStatus.installed, liteHome: _liteStatus.liteHome };
|
|
150
146
|
sendTo(ws, infoMsg);
|
|
151
147
|
// Background agents the last shutdown interrupted: nobody was connected
|
|
152
148
|
// to be told then.
|
|
@@ -174,8 +170,11 @@ function attachConnection(ctx) {
|
|
|
174
170
|
sendTo(ws, { type: "model_info", model: _initialModel, models: initialModels, vendor: initialVendor, availableVendors: sm.availableVendors || [] });
|
|
175
171
|
}
|
|
176
172
|
sendTo(ws, buildVendorRegistryMessage(sm, _osIdentity));
|
|
177
|
-
sendTo(ws, { type: "config_state", model: _initialModel, mode: sm
|
|
173
|
+
sendTo(ws, { type: "config_state", model: _initialModel, mode: effectiveSessionMode(restoredActive, sm), effort: sm.currentEffort || "medium", betas: sm.currentBetas || [], thinking: sm.currentThinking || "adaptive", thinkingBudget: sm.currentThinkingBudget || 10000 });
|
|
178
174
|
sendTo(ws, Object.assign({ type: "codex_config" }, getCodexConfig(sm)));
|
|
175
|
+
if (typeof opts.onGetPermissionSettings === "function") {
|
|
176
|
+
sendTo(ws, settingsMessage(opts.onGetPermissionSettings()));
|
|
177
|
+
}
|
|
179
178
|
sendTo(ws, { type: "term_list", terminals: tm.list(ws) });
|
|
180
179
|
// Context sources sent after session is resolved (per-session storage)
|
|
181
180
|
sendTo(ws, { type: "notes_list", notes: nm.list() });
|
|
@@ -265,7 +264,7 @@ function attachConnection(ctx) {
|
|
|
265
264
|
// server truth across a reconnect. Carrying it directly on
|
|
266
265
|
// session_switched matches switchSession() and gives the client a
|
|
267
266
|
// single authoritative snapshot value to reconcile the footer against.
|
|
268
|
-
sendTo(ws, { type: "session_switched", id: active.localId, cliSessionId: active.cliSessionId || null, loop: active.loop || null, vendor: active.vendor || null, model: sm.effectiveSessionModel(active), hasHistory: _hasHistory, capabilities: _vendorCaps, isProcessing: !!active.isProcessing, agentName: active.agentName || null });
|
|
267
|
+
sendTo(ws, { type: "session_switched", id: active.localId, cliSessionId: active.cliSessionId || null, loop: active.loop || null, vendor: active.vendor || null, model: sm.effectiveSessionModel(active), mode: effectiveSessionMode(active, sm), hasHistory: _hasHistory, capabilities: _vendorCaps, isProcessing: !!active.isProcessing, agentName: active.agentName || null });
|
|
269
268
|
// Send per-session context sources
|
|
270
269
|
var sessionSources = loadContextSources(slug, active.localId);
|
|
271
270
|
sendTo(ws, { type: "context_sources_state", active: sessionSources });
|
|
@@ -21,7 +21,11 @@ var WATCHER_REARM_INTERVAL_MS = 5 * 60 * 1000; // 5 min inotify rebind
|
|
|
21
21
|
*
|
|
22
22
|
* Schema v1 (all fields except * are required):
|
|
23
23
|
* { version: 1, id, projectSlug, initialPrompt, contextNote*, cwd*, createdAt*,
|
|
24
|
-
* vendor*, agentName*, sessionVisibility*, initiator
|
|
24
|
+
* vendor*, agentName*, sessionVisibility*, initiator*, from*,
|
|
25
|
+
* senderProject*, senderSessionId* }
|
|
26
|
+
* senderProject and senderSessionId are the values of CLAGENTIC_CONSOLE_PROJECT
|
|
27
|
+
* and CLAGENTIC_CONSOLE_SESSION_ID in a writer running inside a console session
|
|
28
|
+
* (lib/sender-ref.js); a writer outside one omits them.
|
|
25
29
|
* -> always opens a new session (backward-compatible, v1 files remain valid)
|
|
26
30
|
*
|
|
27
31
|
* Schema v2 (all fields except * are required):
|
|
@@ -148,6 +152,10 @@ function attachExternalTrigger(ctx) {
|
|
|
148
152
|
projectSlug: trigger.projectSlug,
|
|
149
153
|
prompt: trigger.initialPrompt,
|
|
150
154
|
contextNote: trigger.contextNote,
|
|
155
|
+
from: trigger.from,
|
|
156
|
+
fromSession: trigger.fromSession,
|
|
157
|
+
senderProject: trigger.senderProject,
|
|
158
|
+
senderSessionId: trigger.senderSessionId,
|
|
151
159
|
triggerId: trigger.id,
|
|
152
160
|
initiator: trigger.initiator,
|
|
153
161
|
};
|