@clagentic/console 1.10.0-beta.4 → 1.11.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +14 -0
  2. package/bin/cli.js +15 -3
  3. package/lib/agents.js +1 -55
  4. package/lib/bash-auto-approve.js +133 -0
  5. package/lib/build-identity.js +23 -5
  6. package/lib/build-sha.json +2 -2
  7. package/lib/build-update-check.js +0 -62
  8. package/lib/build-update-offer.js +23 -13
  9. package/lib/build-update-restart.js +59 -43
  10. package/lib/cli/schedule-input-subcommands.js +327 -0
  11. package/lib/cli/session-subcommands.js +100 -17
  12. package/lib/client-build-id.js +56 -0
  13. package/lib/daemon.js +20 -5
  14. package/lib/injected-sender.js +225 -0
  15. package/lib/message-sender-record.js +133 -0
  16. package/lib/pending-prompts.js +55 -0
  17. package/lib/permission-mode-policy.js +63 -0
  18. package/lib/permission-summary.js +67 -0
  19. package/lib/project-connection.js +2 -1
  20. package/lib/project-external-trigger.js +9 -1
  21. package/lib/project-loop.js +26 -20
  22. package/lib/project-prompt-responses.js +20 -14
  23. package/lib/project-sessions.js +73 -21
  24. package/lib/project-user-message.js +18 -47
  25. package/lib/project.js +36 -62
  26. package/lib/public/app.js +3 -5
  27. package/lib/public/css/channel-layout.css +20 -0
  28. package/lib/public/css/diagnostics.css +7 -0
  29. package/lib/public/css/input.css +78 -0
  30. package/lib/public/css/menus.css +17 -0
  31. package/lib/public/modules/app-connection.js +18 -1
  32. package/lib/public/modules/app-messages.js +19 -17
  33. package/lib/public/modules/app-panels.js +9 -2
  34. package/lib/public/modules/app-rate-limit.js +63 -87
  35. package/lib/public/modules/app-rendering.js +37 -6
  36. package/lib/public/modules/at-agents.js +8 -0
  37. package/lib/public/modules/build-guard.js +61 -0
  38. package/lib/public/modules/build-update-detail.js +1 -4
  39. package/lib/public/modules/diagnostics.js +98 -9
  40. package/lib/public/modules/injected-identity.js +78 -0
  41. package/lib/public/modules/injected-label.js +62 -0
  42. package/lib/public/modules/input.js +64 -114
  43. package/lib/public/modules/mode-options.js +19 -16
  44. package/lib/public/modules/rate-limit-state.js +47 -22
  45. package/lib/public/modules/schedule-panel.js +234 -0
  46. package/lib/public/modules/schedule-time.js +193 -0
  47. package/lib/public/modules/scheduled-input-actions.js +19 -0
  48. package/lib/runtime-env.js +4 -0
  49. package/lib/scheduled-input/ipc.js +92 -0
  50. package/lib/scheduled-input/rate-limit-resume.js +53 -0
  51. package/lib/scheduled-input/records.js +350 -0
  52. package/lib/scheduled-input/service.js +743 -0
  53. package/lib/scheduled-input/store.js +132 -0
  54. package/lib/scheduled-input/ws.js +194 -0
  55. package/lib/sdk-bridge.js +137 -152
  56. package/lib/sdk-message-processor.js +13 -5
  57. package/lib/sdk-skill-discovery.js +17 -0
  58. package/lib/sender-ref.js +109 -0
  59. package/lib/server.js +28 -8
  60. package/lib/session-directory.js +224 -0
  61. package/lib/session-file-scan.js +55 -0
  62. package/lib/session-input-ipc.js +20 -0
  63. package/lib/session-input.js +355 -19
  64. package/lib/session-name-holder.js +82 -0
  65. package/lib/session-resume.js +1 -0
  66. package/lib/sessions.js +44 -0
  67. package/lib/turn-initiator.js +6 -2
  68. package/lib/ws-schema.js +15 -7
  69. package/lib/yoke/adapters/claude-worker.js +3 -1
  70. package/lib/yoke/adapters/claude.js +13 -7
  71. package/lib/yoke/adapters/codex.js +18 -5
  72. package/lib/yoke/adapters/permission-relay.js +9 -0
  73. package/lib/yoke/interface.js +7 -1
  74. package/package.json +1 -1
  75. package/scripts/check-test-count.js +1 -1
  76. package/scripts/install-local-test.js +45 -1
  77. package/scripts/postinstall.js +1 -0
@@ -0,0 +1,225 @@
1
+ // injected-sender.js - who sent an injected user_message, as the chat shows it.
2
+ //
3
+ // Input that reaches a session through session-input.js is not typed by the
4
+ // person at the browser, so its history entry names a sender instead of
5
+ // borrowing the operator's identity. The sender is recorded at injection time
6
+ // (senderFields) and completed on the way to a client (forClient) so an injected
7
+ // entry never renders as the local user.
8
+ //
9
+ // senderKind:
10
+ // "extracted" derived from the console's own records for a process the console
11
+ // started (lib/sender-ref.js); not proof against a same-user process
12
+ // copying the reference
13
+ // "declared" the caller named itself with --from (self-reported, unverified)
14
+ // "undeclared" the caller named nobody
15
+ // "automation" a turn the console composed itself (a scheduled message, a run-now,
16
+ // a loop iteration, a rate-limit resume); the console is the sender
17
+ // "unrecorded" a new entry (marked, see below) that names no initiator, or an
18
+ // injected entry that names no usable sender
19
+ // ("attested" is reserved for a caller identity the console itself verified;
20
+ // nothing produces it yet.) Precedence: attested > extracted > declared >
21
+ // undeclared.
22
+ //
23
+ // Record-format marker. Every user_message recorded from this format on carries
24
+ // `entryFormat: 1` (stampRecord, called by each writer) and ALWAYS an initiator,
25
+ // the human one included. The marker is what tells a new entry that lost its
26
+ // initiator (a defect: fail closed, never the operator) from a legacy entry that
27
+ // predates initiators (the console cannot tell a legacy typed turn from a legacy
28
+ // automated one, so it renders exactly as it always did). Additive field: older
29
+ // readers ignore it.
30
+ //
31
+ // marked + initiator human operator
32
+ // marked + other initiator the automation or sender it names
33
+ // marked + no initiator not the operator; "sender not recorded"
34
+ // unmarked (legacy) as before: operator, unless it is injected
35
+ // (source external-trigger or a non-human
36
+ // initiator), in which case the sender path
37
+
38
+ var crypto = require("crypto");
39
+ var { INITIATORS } = require("./turn-initiator");
40
+
41
+ var SENDER_KIND = Object.freeze({
42
+ EXTRACTED: "extracted",
43
+ DECLARED: "declared",
44
+ UNDECLARED: "undeclared",
45
+ AUTOMATION: "automation",
46
+ UNRECORDED: "unrecorded",
47
+ });
48
+
49
+ // Sender names of the console's own automations. Run-now shares the scheduled
50
+ // name, so the same schedule keeps one avatar whichever way it fired.
51
+ var AUTOMATION_NAMES = Object.freeze({
52
+ [INITIATORS.SCHEDULED]: "Scheduled message",
53
+ [INITIATORS.SCHEDULED_NOW]: "Scheduled message",
54
+ [INITIATORS.LOOP]: "Loop",
55
+ });
56
+
57
+ var RECORD_FORMAT_FIELD = "entryFormat";
58
+ var RECORD_FORMAT = 1;
59
+
60
+ var MAX_FROM_LENGTH = 64;
61
+ // Vendor session ids are uuids or short opaque ids; this bounds a declared one.
62
+ var MAX_FROM_SESSION_LENGTH = 128;
63
+ // C0 controls, DEL and C1 controls: nothing a sender name needs, and they can
64
+ // disguise or break the one-line label.
65
+ var CONTROL_CHARS = /[\u0000-\u001f\u007f-\u009f]/;
66
+
67
+ // Prefix keeps a sender id from ever equalling a real user id.
68
+ var SENDER_ID_PREFIX = "injected:";
69
+
70
+ var MESSAGE_ID_FIELD = "messageId";
71
+
72
+ // The id one message carries from the console to the vendor and into the
73
+ // published per-message sender record (lib/message-sender-record.js).
74
+ function newMessageId() {
75
+ return crypto.randomUUID();
76
+ }
77
+
78
+ // Marks a new user_message as recorded in the current format and gives it its
79
+ // message id (kept when the writer already minted one, because the same id must
80
+ // reach the vendor with the turn). Returns the entry.
81
+ function stampRecord(entry) {
82
+ entry[RECORD_FORMAT_FIELD] = RECORD_FORMAT;
83
+ if (!entry[MESSAGE_ID_FIELD]) entry[MESSAGE_ID_FIELD] = newMessageId();
84
+ return entry;
85
+ }
86
+
87
+ function isMarked(entry) {
88
+ return typeof entry[RECORD_FORMAT_FIELD] === "number" && entry[RECORD_FORMAT_FIELD] >= RECORD_FORMAT;
89
+ }
90
+
91
+ // Returns { from } (absent when the caller named nobody) or { error }.
92
+ function validateFrom(raw) {
93
+ if (raw === undefined || raw === null) return {};
94
+ if (typeof raw !== "string") return { error: "from must be a string" };
95
+ var name = raw.trim();
96
+ if (!name) return {};
97
+ if (name.length > MAX_FROM_LENGTH) return { error: "from is longer than " + MAX_FROM_LENGTH + " characters" };
98
+ if (CONTROL_CHARS.test(name)) return { error: "from contains control characters" };
99
+ return { from: name };
100
+ }
101
+
102
+ // Returns { fromSession } (absent when the caller named none) or { error }. The
103
+ // id is the sending session's own id at its vendor (the vendor's field is
104
+ // fromSession), written by the sender: a navigation target, never authority.
105
+ function validateFromSession(raw) {
106
+ if (raw === undefined || raw === null) return {};
107
+ if (typeof raw !== "string") return { error: "fromSession must be a string" };
108
+ var id = raw.trim();
109
+ if (!id) return {};
110
+ if (id.length > MAX_FROM_SESSION_LENGTH) return { error: "fromSession is longer than " + MAX_FROM_SESSION_LENGTH + " characters" };
111
+ if (CONTROL_CHARS.test(id)) return { error: "fromSession contains control characters" };
112
+ return { fromSession: id };
113
+ }
114
+
115
+ function senderId(initiator) {
116
+ return SENDER_ID_PREFIX + (initiator || "unknown");
117
+ }
118
+
119
+ // Fields to store on a new injected entry. declaredName is validateFrom().from;
120
+ // extracted is lib/sender-ref.js resolve() or null; declaredSession is
121
+ // validateFromSession().fromSession. An extracted sender wins the display; a
122
+ // --from that names someone else is kept beside it as declaredName. fromSession
123
+ // is the sending session's vendor session id: the console's own record of an
124
+ // extracted sender when it has one, else what the caller declared.
125
+ function senderFields(initiator, declaredName, extracted, declaredSession) {
126
+ var fields = { from: senderId(initiator) };
127
+ if (extracted && extracted.cliSessionId && extracted.vendor) fields.fromSession = extracted.cliSessionId;
128
+ else if (declaredSession) fields.fromSession = declaredSession;
129
+ if (extracted) {
130
+ fields.senderKind = SENDER_KIND.EXTRACTED;
131
+ fields.fromName = extracted.name;
132
+ fields.senderProject = extracted.project;
133
+ fields.senderSessionId = extracted.sessionId;
134
+ if (extracted.agent) fields.senderAgent = extracted.agent;
135
+ if (extracted.agentSlug) fields.senderAgentSlug = extracted.agentSlug;
136
+ if (extracted.vendor) fields.senderVendor = extracted.vendor;
137
+ // Optional history field, and recorded only together with the vendor: a
138
+ // vendor session id means nothing without the vendor that issued it, and
139
+ // --reply routes by the pair. Absent when the sender had no vendor session id
140
+ // yet, and on entries recorded before it existed.
141
+ if (extracted.cliSessionId && extracted.vendor) fields.senderCliSessionId = extracted.cliSessionId;
142
+ var lower = String(declaredName || "").toLowerCase();
143
+ if (declaredName && lower !== extracted.name.toLowerCase()
144
+ && lower !== String(extracted.agent || extracted.vendor || "").toLowerCase()) {
145
+ fields.declaredName = declaredName;
146
+ }
147
+ } else if (declaredName) {
148
+ fields.fromName = declaredName;
149
+ fields.senderKind = SENDER_KIND.DECLARED;
150
+ } else {
151
+ fields.senderKind = SENDER_KIND.UNDECLARED;
152
+ }
153
+ return fields;
154
+ }
155
+
156
+ // The history entry for a turn the console composed itself. `initiator` is the
157
+ // same value the caller passes to startQuery, so the entry and the vendor's
158
+ // origin stamp (turn-initiator.js) cannot name different sources. `note` is the
159
+ // automation's own detail (the schedule or loop name, the iteration).
160
+ function consoleTurnEntry(initiator, text, note) {
161
+ var name = Object.prototype.hasOwnProperty.call(AUTOMATION_NAMES, initiator) ? AUTOMATION_NAMES[initiator] : null;
162
+ if (!name) throw new Error("not a console automation initiator: " + String(initiator));
163
+ var entry = stampRecord({
164
+ type: "user_message",
165
+ text: text,
166
+ _ts: Date.now(),
167
+ initiator: initiator,
168
+ from: senderId(initiator),
169
+ fromName: name,
170
+ senderKind: SENDER_KIND.AUTOMATION,
171
+ });
172
+ if (note) entry.contextNote = note;
173
+ return entry;
174
+ }
175
+
176
+ function isInjected(entry) {
177
+ if (!entry || entry.type !== "user_message") return false;
178
+ return entry.source === "external-trigger" || (!!entry.initiator && entry.initiator !== INITIATORS.HUMAN);
179
+ }
180
+
181
+ // Whether the entry is the operator's own, by the table at the top of the file.
182
+ function isOperatorEntry(entry) {
183
+ if (!entry || entry.type !== "user_message") return false;
184
+ if (entry.source === "external-trigger") return false;
185
+ if (isMarked(entry)) return entry.initiator === INITIATORS.HUMAN;
186
+ return !isInjected(entry);
187
+ }
188
+
189
+ // The entry as a client should receive it. Every user message that is not the
190
+ // operator's leaves with a sender id that is not a user's and a senderKind,
191
+ // whatever was stored, so the client cannot fall back to drawing it as the local
192
+ // user. Operator entries and other entry types are returned untouched.
193
+ function forClient(entry) {
194
+ if (!entry || entry.type !== "user_message" || isOperatorEntry(entry)) return entry;
195
+ var out = {};
196
+ for (var k in entry) out[k] = entry[k];
197
+ out.from = senderId(entry.initiator);
198
+ var known = out.senderKind === SENDER_KIND.DECLARED || out.senderKind === SENDER_KIND.UNDECLARED
199
+ || (out.senderKind === SENDER_KIND.AUTOMATION && Object.prototype.hasOwnProperty.call(AUTOMATION_NAMES, out.initiator)
200
+ && typeof out.fromName === "string" && !!out.fromName)
201
+ || (out.senderKind === SENDER_KIND.EXTRACTED && typeof out.fromName === "string" && !!out.fromName);
202
+ if (!known) {
203
+ out.senderKind = SENDER_KIND.UNRECORDED;
204
+ delete out.fromName;
205
+ }
206
+ return out;
207
+ }
208
+
209
+ module.exports = {
210
+ SENDER_KIND: SENDER_KIND,
211
+ MAX_FROM_LENGTH: MAX_FROM_LENGTH,
212
+ validateFrom: validateFrom,
213
+ validateFromSession: validateFromSession,
214
+ MAX_FROM_SESSION_LENGTH: MAX_FROM_SESSION_LENGTH,
215
+ newMessageId: newMessageId,
216
+ MESSAGE_ID_FIELD: MESSAGE_ID_FIELD,
217
+ senderFields: senderFields,
218
+ stampRecord: stampRecord,
219
+ RECORD_FORMAT_FIELD: RECORD_FORMAT_FIELD,
220
+ consoleTurnEntry: consoleTurnEntry,
221
+ AUTOMATION_NAMES: AUTOMATION_NAMES,
222
+ isInjected: isInjected,
223
+ isOperatorEntry: isOperatorEntry,
224
+ forClient: forClient,
225
+ };
@@ -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 while the server's
8
+ // skip-permissions setting is on.
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,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 };
@@ -6,6 +6,7 @@ var { authOf } = require("./project-access");
6
6
  var { getCodexConfig } = require("./codex-defaults");
7
7
  var { promptsFor } = require("./prompt-registry");
8
8
  var sessionReclaim = require("./session-reclaim");
9
+ var clientBuildId = require("./client-build-id");
9
10
  var { buildVendorRegistryMessage } = require("./vendor-registry-message");
10
11
  // detectLite is cached per-project in project.js and passed via ctx.liteStatus.
11
12
  // This import is retained only for backward compat if ctx.liteStatus is absent.
@@ -141,7 +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, debug: !!debug, dangerouslySkipPermissions: dangerouslySkipPermissions, osUsers: osUsers, lanHost: lanHost, projectCount: _filteredProjects.length, projects: _filteredProjects, projectOwnerId: projectOwnerId, ownerLocked: ownerLocked, liteInstalled: _liteStatus.installed, liteHome: _liteStatus.liteHome };
145
+ var infoMsg = { type: "info", cwd: cwd, slug: slug, project: title || project, version: currentVersion, buildId: clientBuildId.get(), debug: !!debug, dangerouslySkipPermissions: dangerouslySkipPermissions, osUsers: osUsers, lanHost: lanHost, projectCount: _filteredProjects.length, projects: _filteredProjects, projectOwnerId: projectOwnerId, ownerLocked: ownerLocked, liteInstalled: _liteStatus.installed, liteHome: _liteStatus.liteHome };
145
146
  // When dangerouslySkipPermissions is set in config but suppressed because
146
147
  // multi-user mode is active, tell the client so it can surface a warning.
147
148
  if (dangerouslySkipPermissionsConfigured && !dangerouslySkipPermissions) {
@@ -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
  };