@clagentic/console 1.12.0 → 1.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/bin/cli.js +18 -15
- package/lib/agent-roster-ws.js +38 -13
- package/lib/agent-roster.js +111 -12
- package/lib/agents.js +68 -33
- package/lib/atomic-install.js +334 -0
- package/lib/build-changes.js +33 -4
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +12 -0
- package/lib/chat-width.js +31 -0
- package/lib/cli/agent-usage.js +126 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/compact-output.js +69 -0
- package/lib/cli/ipc-subcommands.js +92 -67
- package/lib/cli/output.js +28 -0
- package/lib/cli/restart-verb.js +132 -0
- package/lib/cli/schedule-input-subcommands.js +45 -8
- package/lib/cli/session-subcommands.js +37 -11
- package/lib/cli/settings-subcommands.js +74 -0
- package/lib/cli-transcript-title.js +56 -3
- package/lib/client-files.js +79 -0
- package/lib/daemon.js +100 -28
- package/lib/default-avatar-color.js +4 -0
- package/lib/drain.js +58 -10
- package/lib/mcp-tool-input.js +2 -2
- package/lib/model-families.js +49 -1
- package/lib/notify/type-registry.js +4 -0
- package/lib/notify/types.js +7 -4
- package/lib/pages.js +13 -63
- package/lib/permission-summary.js +12 -16
- package/lib/plan-usage-reader.js +70 -0
- package/lib/project-connection.js +4 -2
- package/lib/project-filesystem.js +6 -7
- package/lib/project-notifications.js +55 -8
- package/lib/project-prompt-expiry-settings.js +42 -0
- package/lib/project-sessions.js +52 -0
- package/lib/project-settings-gate.js +98 -0
- package/lib/project-user-mention.js +3 -2
- package/lib/project.js +1 -1
- package/lib/prompt-expiry-settings.js +49 -0
- package/lib/prompt-expiry.js +24 -3
- package/lib/prompt-kinds/codecs.js +6 -2
- package/lib/public/app.js +36 -36
- package/lib/public/css/admin.css +156 -170
- package/lib/public/css/agent-messages.css +24 -24
- package/lib/public/css/agent-picker.css +90 -38
- package/lib/public/css/agent-roster.css +61 -27
- package/lib/public/css/at-agents.css +10 -10
- package/lib/public/css/base.css +207 -184
- package/lib/public/css/chat-layout.css +228 -0
- package/lib/public/css/command-palette.css +86 -88
- package/lib/public/css/diagnostics.css +78 -204
- package/lib/public/css/diff.css +10 -10
- package/lib/public/css/filebrowser.css +32 -60
- package/lib/public/css/home-hub.css +100 -100
- package/lib/public/css/icon-strip.css +195 -238
- package/lib/public/css/input.css +191 -212
- package/lib/public/css/login-panel.css +16 -16
- package/lib/public/css/loop.css +96 -187
- package/lib/public/css/mention.css +49 -110
- package/lib/public/css/menus.css +162 -169
- package/lib/public/css/messages.css +49 -123
- package/lib/public/css/mobile-nav.css +207 -264
- package/lib/public/css/notifications-center.css +45 -124
- package/lib/public/css/overlay.css +269 -0
- package/lib/public/css/overlays.css +134 -156
- package/lib/public/css/playbook.css +41 -41
- package/lib/public/css/profile.css +43 -112
- package/lib/public/css/rewind.css +112 -112
- package/lib/public/css/scheduler-modal.css +27 -135
- package/lib/public/css/scheduler.css +204 -210
- package/lib/public/css/server-settings.css +173 -239
- package/lib/public/css/session-search.css +20 -20
- package/lib/public/css/settings-nav.css +197 -0
- package/lib/public/css/sidebar.css +213 -304
- package/lib/public/css/skills.css +121 -135
- package/lib/public/css/sticky-notes.css +114 -200
- package/lib/public/css/stt.css +17 -26
- package/lib/public/css/team-panel.css +36 -36
- package/lib/public/css/team-view.css +9 -9
- package/lib/public/css/title-bar.css +83 -100
- package/lib/public/css/tooltip.css +10 -10
- package/lib/public/css/user-settings.css +78 -131
- package/lib/public/css/user-shell.css +125 -29
- package/lib/public/index.html +178 -177
- package/lib/public/manifest.json +0 -2
- package/lib/public/modules/admin.js +54 -92
- package/lib/public/modules/agent-avatar.js +134 -3
- package/lib/public/modules/agent-messages.js +2 -1
- package/lib/public/modules/agent-picker.js +23 -21
- package/lib/public/modules/agent-roster-groups.js +128 -0
- package/lib/public/modules/agent-roster.js +40 -11
- package/lib/public/modules/app-connection.js +13 -1
- package/lib/public/modules/app-cursors.js +9 -9
- package/lib/public/modules/app-favicon.js +8 -16
- package/lib/public/modules/app-header.js +28 -19
- package/lib/public/modules/app-history-replay.js +67 -4
- package/lib/public/modules/app-home-hub.js +15 -0
- package/lib/public/modules/app-loop-ui.js +41 -47
- package/lib/public/modules/app-loop-wizard.js +9 -10
- package/lib/public/modules/app-messages.js +32 -36
- package/lib/public/modules/app-misc.js +22 -92
- package/lib/public/modules/app-modals.js +98 -0
- package/lib/public/modules/app-notifications.js +124 -135
- package/lib/public/modules/app-panels.js +28 -32
- package/lib/public/modules/app-projects.js +30 -40
- package/lib/public/modules/app-rate-limit.js +26 -9
- package/lib/public/modules/app-rendering.js +128 -110
- package/lib/public/modules/app-skills-install.js +6 -4
- package/lib/public/modules/assistant-identity.js +55 -0
- package/lib/public/modules/at-agents.js +3 -0
- package/lib/public/modules/build-guard.js +25 -11
- package/lib/public/modules/chat-width-choice.js +75 -0
- package/lib/public/modules/chat-width-prefs.js +52 -0
- package/lib/public/modules/chat-width.js +102 -0
- package/lib/public/modules/collapsible-text.js +36 -4
- package/lib/public/modules/command-palette.js +28 -34
- package/lib/public/modules/context-sources.js +3 -5
- package/lib/public/modules/diagnostics.js +130 -129
- package/lib/public/modules/info-panel.js +31 -0
- package/lib/public/modules/injected-identity.js +8 -8
- package/lib/public/modules/input-list-menu.js +39 -0
- package/lib/public/modules/input.js +22 -21
- package/lib/public/modules/markdown.js +10 -11
- package/lib/public/modules/mcp-ui.js +4 -14
- package/lib/public/modules/mention.js +100 -229
- package/lib/public/modules/message-header.js +80 -0
- package/lib/public/modules/message-participants.js +39 -0
- package/lib/public/modules/mobile-action-sheet.js +46 -0
- package/lib/public/modules/mobile-nav-sheet.js +104 -0
- package/lib/public/modules/model-families.js +41 -4
- package/lib/public/modules/note-order.js +39 -0
- package/lib/public/modules/notifications.js +35 -52
- package/lib/public/modules/overlay-history.js +73 -19
- package/lib/public/modules/overlay-menu.js +123 -0
- package/lib/public/modules/overlay-modal.js +186 -0
- package/lib/public/modules/overlay-registry.js +392 -0
- package/lib/public/modules/overlay-stack.js +110 -0
- package/lib/public/modules/overlay.js +117 -0
- package/lib/public/modules/popover-position.js +18 -2
- package/lib/public/modules/preference-sync.js +28 -0
- package/lib/public/modules/profile.js +24 -49
- package/lib/public/modules/project-settings.js +27 -172
- package/lib/public/modules/prompt-expiry-controls.js +46 -0
- package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
- package/lib/public/modules/prompt-kinds/permission.js +70 -92
- package/lib/public/modules/prompts.js +1 -2
- package/lib/public/modules/qrcode.js +6 -21
- package/lib/public/modules/queued-button.js +15 -2
- package/lib/public/modules/rewind.js +9 -3
- package/lib/public/modules/schedule-time.js +32 -7
- package/lib/public/modules/scheduled-outbox.js +51 -18
- package/lib/public/modules/scheduler-config.js +87 -127
- package/lib/public/modules/scheduler.js +29 -26
- package/lib/public/modules/serialized-save.js +79 -0
- package/lib/public/modules/server-settings.js +75 -65
- package/lib/public/modules/session-grants.js +16 -19
- package/lib/public/modules/session-list-avatars.js +98 -0
- package/lib/public/modules/session-vendor-state.js +86 -0
- package/lib/public/modules/settings-access.js +35 -0
- package/lib/public/modules/settings-hub.js +125 -0
- package/lib/public/modules/settings-nav.js +182 -0
- package/lib/public/modules/shell-line.js +24 -0
- package/lib/public/modules/sidebar-mobile.js +151 -195
- package/lib/public/modules/sidebar-projects.js +88 -129
- package/lib/public/modules/sidebar-sessions.js +66 -34
- package/lib/public/modules/sidebar.js +2 -2
- package/lib/public/modules/skills.js +11 -26
- package/lib/public/modules/sticky-notes.js +19 -16
- package/lib/public/modules/stt.js +9 -23
- package/lib/public/modules/terminal.js +86 -90
- package/lib/public/modules/theme-choice.js +126 -0
- package/lib/public/modules/theme-colors.js +19 -0
- package/lib/public/modules/theme-prefs.js +121 -0
- package/lib/public/modules/theme.js +227 -605
- package/lib/public/modules/tool-palette.js +7 -17
- package/lib/public/modules/tools.js +8 -10
- package/lib/public/modules/user-settings.js +59 -115
- package/lib/public/modules/user-shell.js +9 -2
- package/lib/public/modules/utils.js +10 -12
- package/lib/public/modules/vendor-picker.js +4 -2
- package/lib/public/modules/vendor-registry.js +1 -2
- package/lib/public/style.css +3 -1
- package/lib/public/sw.js +9 -2
- package/lib/public/theme-core.js +411 -0
- package/lib/request-body.js +70 -0
- package/lib/sdk-bridge.js +227 -88
- package/lib/sdk-message-processor.js +44 -16
- package/lib/server-admin.js +198 -200
- package/lib/server-auth.js +16 -13
- package/lib/server-dm.js +4 -3
- package/lib/server-settings.js +177 -130
- package/lib/server.js +87 -36
- package/lib/session-background-tasks.js +79 -0
- package/lib/session-directory.js +138 -13
- package/lib/session-input-ipc.js +2 -0
- package/lib/session-input.js +39 -5
- package/lib/session-list-avatars.js +16 -0
- package/lib/session-reclaim.js +37 -25
- package/lib/session-vendor.js +37 -0
- package/lib/sessions.js +99 -34
- package/lib/settings-ipc.js +60 -0
- package/lib/settings-registry.js +86 -0
- package/lib/terminal-manager.js +17 -5
- package/lib/theme-files.js +132 -0
- package/lib/theme-seed.js +136 -0
- package/lib/themes/clagentic-dark.json +13 -6
- package/lib/themes/clagentic-light.json +12 -5
- package/lib/updater.js +6 -4
- package/lib/usage-store.js +97 -10
- package/lib/users-preferences.js +118 -19
- package/lib/users.js +19 -10
- package/lib/vendor-catalog.js +130 -0
- package/lib/ws-schema.js +4 -2
- package/lib/yoke/adapters/claude.js +81 -1
- package/lib/yoke/adapters/codex-user-shell.js +87 -23
- package/lib/yoke/adapters/codex.js +89 -5
- package/lib/yoke/codex-binary.js +59 -0
- package/package.json +1 -1
- package/scripts/check-test-count.js +5 -0
- package/scripts/install-local-test.js +50 -9
- package/scripts/write-build-sha.js +18 -2
- package/lib/public/css/channel-layout.css +0 -329
- package/lib/themes/ayu-light.json +0 -9
- package/lib/themes/catppuccin-latte.json +0 -9
- package/lib/themes/catppuccin-mocha.json +0 -9
- package/lib/themes/dracula.json +0 -9
- package/lib/themes/everforest-light.json +0 -9
- package/lib/themes/everforest.json +0 -9
- package/lib/themes/github-light.json +0 -9
- package/lib/themes/gruvbox-dark.json +0 -9
- package/lib/themes/gruvbox-light.json +0 -9
- package/lib/themes/monokai.json +0 -9
- package/lib/themes/nord-light.json +0 -9
- package/lib/themes/nord.json +0 -9
- package/lib/themes/one-dark.json +0 -9
- package/lib/themes/one-light.json +0 -9
- package/lib/themes/rose-pine-dawn.json +0 -9
- package/lib/themes/rose-pine.json +0 -9
- package/lib/themes/solarized-dark.json +0 -9
- package/lib/themes/solarized-light.json +0 -9
- package/lib/themes/tokyo-night-light.json +0 -9
- package/lib/themes/tokyo-night.json +0 -9
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The live background tasks of one session, of any type (Agent, Bash, monitor,
|
|
4
|
+
// workflow...). The idle reaper (lib/sdk-bridge.js) never ends a session while
|
|
5
|
+
// this set is non-empty: a lane waiting on a background command emits nothing
|
|
6
|
+
// until the command's notification, and ending its query would kill the waiter.
|
|
7
|
+
//
|
|
8
|
+
// Two sources feed the set:
|
|
9
|
+
// 1. The SDK's background_tasks_changed, a level signal: replaceAll swaps the
|
|
10
|
+
// whole set for each payload.
|
|
11
|
+
// 2. A fallback for a CLI that never emits it: add() on the tool_result that
|
|
12
|
+
// carries a Bash backgroundTaskId, remove() on the task_notification whose
|
|
13
|
+
// task_id matches, whatever its status.
|
|
14
|
+
// clear() runs when the query ends, so a stale entry cannot pin a session.
|
|
15
|
+
|
|
16
|
+
var LABEL_MAX = 80;
|
|
17
|
+
var FALLBACK_LABEL = "background task";
|
|
18
|
+
var AGENT_TYPE = "local_agent";
|
|
19
|
+
|
|
20
|
+
function table(session) {
|
|
21
|
+
if (!session.liveBackgroundTasks) session.liveBackgroundTasks = Object.create(null);
|
|
22
|
+
return session.liveBackgroundTasks;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function cleanLabel(raw) {
|
|
26
|
+
if (typeof raw !== "string") return FALLBACK_LABEL;
|
|
27
|
+
var one = raw.replace(/\s+/g, " ").trim();
|
|
28
|
+
if (!one) return FALLBACK_LABEL;
|
|
29
|
+
return one.length > LABEL_MAX ? one.slice(0, LABEL_MAX - 3) + "..." : one;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Replace the set with the SDK's full list. Ambient tasks are not activity. */
|
|
33
|
+
function replaceAll(session, tasks) {
|
|
34
|
+
var next = Object.create(null);
|
|
35
|
+
(Array.isArray(tasks) ? tasks : []).forEach(function (t) {
|
|
36
|
+
if (!t || typeof t.id !== "string" || !t.id || t.ambient) return;
|
|
37
|
+
next[t.id] = { type: t.type || null, label: cleanLabel(t.description) };
|
|
38
|
+
});
|
|
39
|
+
session.liveBackgroundTasks = next;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function add(session, id, type, label) {
|
|
43
|
+
if (typeof id !== "string" || !id) return;
|
|
44
|
+
table(session)[id] = { type: type || null, label: cleanLabel(label) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function remove(session, id) {
|
|
48
|
+
if (typeof id !== "string" || !id || !session.liveBackgroundTasks) return;
|
|
49
|
+
delete session.liveBackgroundTasks[id];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function clear(session) {
|
|
53
|
+
session.liveBackgroundTasks = Object.create(null);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function count(session) {
|
|
57
|
+
return session && session.liveBackgroundTasks ? Object.keys(session.liveBackgroundTasks).length : 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Operator-facing labels of the live tasks that are not agents. Agents are
|
|
62
|
+
* named from the prompt registry's own tracking (lib/session-reclaim.js), so
|
|
63
|
+
* listing them here too would name each one twice.
|
|
64
|
+
*/
|
|
65
|
+
function nonAgentLabels(session) {
|
|
66
|
+
var live = session && session.liveBackgroundTasks;
|
|
67
|
+
if (!live) return [];
|
|
68
|
+
return Object.keys(live).filter(function (id) { return live[id].type !== AGENT_TYPE; })
|
|
69
|
+
.map(function (id) { return live[id].label; });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
replaceAll: replaceAll,
|
|
74
|
+
add: add,
|
|
75
|
+
remove: remove,
|
|
76
|
+
clear: clear,
|
|
77
|
+
count: count,
|
|
78
|
+
nonAgentLabels: nonAgentLabels,
|
|
79
|
+
};
|
package/lib/session-directory.js
CHANGED
|
@@ -102,18 +102,65 @@ function describe(slug, project, session, now) {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// The richer fields of a session, for list-sessions --verbose and for the
|
|
106
|
+
// candidates of an ambiguous address. Read from what the daemon already holds:
|
|
107
|
+
// nothing is loaded from disk, so a field that needs history is null when the
|
|
108
|
+
// session's history is not in memory.
|
|
109
|
+
// openedAt when the session was created
|
|
110
|
+
// opener who started it: the first message's sender record
|
|
111
|
+
// (kind, name, project, initiator), from the history held
|
|
112
|
+
// in memory when that history starts at the first message
|
|
113
|
+
// lastInjectedSender who sent the newest injected message held in memory
|
|
114
|
+
// turnCount turns completed
|
|
115
|
+
// midTurn a turn is running now
|
|
116
|
+
// memory.heapEntries history entries held in memory (the console's own
|
|
117
|
+
// per-session memory count)
|
|
118
|
+
function detailOf(session) {
|
|
119
|
+
var history = session.history || [];
|
|
120
|
+
var first = null;
|
|
121
|
+
if (!session._historyBaseIndex) {
|
|
122
|
+
for (var i = 0; i < history.length && !first; i++) {
|
|
123
|
+
if (history[i] && history[i].type === "user_message") first = history[i];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
var last = lastInjectedSender(history);
|
|
127
|
+
return {
|
|
128
|
+
openedAt: isoOrNull(session.createdAt),
|
|
129
|
+
opener: first ? {
|
|
130
|
+
kind: first.senderKind || null,
|
|
131
|
+
name: first.fromName || null,
|
|
132
|
+
project: first.senderProject || null,
|
|
133
|
+
initiator: first.initiator || null,
|
|
134
|
+
} : null,
|
|
135
|
+
lastInjectedSender: last.reason ? null : {
|
|
136
|
+
project: last.project,
|
|
137
|
+
vendor: last.vendor,
|
|
138
|
+
sessionId: last.cliSessionId,
|
|
139
|
+
name: last.name,
|
|
140
|
+
},
|
|
141
|
+
turnCount: typeof session.turnCount === "number" ? session.turnCount : 0,
|
|
142
|
+
midTurn: !!session.isProcessing,
|
|
143
|
+
memory: { heapEntries: history.length },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function withDetail(entry, session) {
|
|
148
|
+
return Object.assign({}, entry, detailOf(session));
|
|
149
|
+
}
|
|
150
|
+
|
|
105
151
|
// Newest first; ties keep the lower console id first so the order is stable.
|
|
106
152
|
function byRecency(a, b) {
|
|
107
|
-
var ta = a.lastActivity || "";
|
|
108
|
-
var tb = b.lastActivity || "";
|
|
153
|
+
var ta = a.entry.lastActivity || "";
|
|
154
|
+
var tb = b.entry.lastActivity || "";
|
|
109
155
|
if (ta !== tb) return ta < tb ? 1 : -1;
|
|
110
|
-
return Number(a.consoleSessionId) - Number(b.consoleSessionId);
|
|
156
|
+
return Number(a.entry.consoleSessionId) - Number(b.entry.consoleSessionId);
|
|
111
157
|
}
|
|
112
158
|
|
|
113
159
|
// projects: [{ slug, project }] with project a context holding sm.sessions.
|
|
114
160
|
// A hidden session (a background helper) is not part of the directory, and a
|
|
115
161
|
// session that has no id from its vendor yet and no runtime was never recorded.
|
|
116
|
-
|
|
162
|
+
// Returns [{ entry, session }], newest first.
|
|
163
|
+
function collectPairs(projects, now) {
|
|
117
164
|
var out = [];
|
|
118
165
|
var at = typeof now === "number" ? now : Date.now();
|
|
119
166
|
(projects || []).forEach(function (p) {
|
|
@@ -121,31 +168,105 @@ function collect(projects, now) {
|
|
|
121
168
|
p.project.sm.sessions.forEach(function (s) {
|
|
122
169
|
if (s.hidden) return;
|
|
123
170
|
if (!s.cliSessionId && !senderRef.isLive(s)) return;
|
|
124
|
-
out.push(describe(p.slug, p.project, s, at));
|
|
171
|
+
out.push({ entry: describe(p.slug, p.project, s, at), session: s });
|
|
125
172
|
});
|
|
126
173
|
});
|
|
127
174
|
return out.sort(byRecency);
|
|
128
175
|
}
|
|
129
176
|
|
|
130
|
-
|
|
131
|
-
|
|
177
|
+
function collect(projects, now) {
|
|
178
|
+
return collectPairs(projects, now).map(function (pair) { return pair.entry; });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// What a list with no state filter shows: sessions that are running or waiting
|
|
182
|
+
// to be used. Reaped sessions pile up (every idle reap and daemon restart leaves
|
|
183
|
+
// one), so they are asked for by name. The one exception is a lane: a (project,
|
|
184
|
+
// agent) pair with a named agent and no live or idle session among the matches
|
|
185
|
+
// would vanish from the default, and a coordinator could not see that it holds
|
|
186
|
+
// work, so its newest reaped session is shown too (withReapedLanes). A plain
|
|
187
|
+
// session with no agent has no lane and keeps this default.
|
|
188
|
+
var DEFAULT_STATES = Object.freeze([STATE.LIVE, STATE.IDLE]);
|
|
189
|
+
|
|
190
|
+
function laneKey(entry) {
|
|
191
|
+
return entry.agent ? entry.project + "\u0000" + slugifyAgentName(entry.agent) : null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// pairs: newest first (collectPairs order). Keeps DEFAULT_STATES pairs plus, per
|
|
195
|
+
// lane with none of them, its newest reaped pair; the order is preserved.
|
|
196
|
+
function withReapedLanes(pairs) {
|
|
197
|
+
var active = {};
|
|
198
|
+
pairs.forEach(function (pair) {
|
|
199
|
+
var key = laneKey(pair.entry);
|
|
200
|
+
if (key && DEFAULT_STATES.indexOf(pair.entry.state) !== -1) active[key] = true;
|
|
201
|
+
});
|
|
202
|
+
var taken = {};
|
|
203
|
+
return pairs.filter(function (pair) {
|
|
204
|
+
if (DEFAULT_STATES.indexOf(pair.entry.state) !== -1) return true;
|
|
205
|
+
var key = laneKey(pair.entry);
|
|
206
|
+
if (!key || active[key] || taken[key]) return false;
|
|
207
|
+
taken[key] = true;
|
|
208
|
+
return true;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// The states a filter names: a comma list ("live,idle"), an array of names, or
|
|
213
|
+
// "any" for every state. Unset is DEFAULT_STATES. Returns { states } (null means
|
|
214
|
+
// every state) or { error } listing the valid names.
|
|
215
|
+
function parseStates(raw) {
|
|
216
|
+
if (raw === undefined || raw === null) return { states: DEFAULT_STATES.slice() };
|
|
217
|
+
var names = Array.isArray(raw) ? raw : String(raw).split(",");
|
|
218
|
+
var states = [];
|
|
219
|
+
for (var i = 0; i < names.length; i++) {
|
|
220
|
+
var name = typeof names[i] === "string" ? names[i].trim() : names[i];
|
|
221
|
+
if (STATE_FILTERS.indexOf(name) === -1) {
|
|
222
|
+
return { error: "unknown state " + JSON.stringify(String(name).slice(0, 32)) + " (accepted: " + STATE_FILTERS.join(", ") + "; several as a comma list)" };
|
|
223
|
+
}
|
|
224
|
+
if (name === ANY_STATE) return { states: null };
|
|
225
|
+
if (states.indexOf(name) === -1) states.push(name);
|
|
226
|
+
}
|
|
227
|
+
return { states: states };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// filter: { project?, agent?, vendor?, state?, limit?, detail?, now? }
|
|
231
|
+
// state a comma list of live, idle, reaped, or "any"; default live and idle
|
|
232
|
+
// plus each agent lane's newest reaped session when it has no live
|
|
233
|
+
// or idle one (see withReapedLanes); an explicit value is exact
|
|
234
|
+
// limit at most this many entries, the newest (a whole number of 1 or more)
|
|
235
|
+
// detail add the richer fields of detailOf() to each entry
|
|
236
|
+
// now ms epoch for the prompt ages, default the current time
|
|
237
|
+
// Returns { entries, total } (total counts the rows shown before the limit) or
|
|
238
|
+
// { error }.
|
|
132
239
|
function list(projects, filter) {
|
|
133
240
|
filter = filter || {};
|
|
134
|
-
var
|
|
135
|
-
if (
|
|
136
|
-
|
|
241
|
+
var parsedStates = parseStates(filter.state);
|
|
242
|
+
if (parsedStates.error) return { error: parsedStates.error };
|
|
243
|
+
var states = parsedStates.states;
|
|
244
|
+
var limit = null;
|
|
245
|
+
if (filter.limit !== undefined && filter.limit !== null) {
|
|
246
|
+
if (typeof filter.limit !== "number" || !isFinite(filter.limit) || filter.limit < 1 || Math.floor(filter.limit) !== filter.limit) {
|
|
247
|
+
return { error: "limit must be a whole number of 1 or more" };
|
|
248
|
+
}
|
|
249
|
+
limit = filter.limit;
|
|
137
250
|
}
|
|
138
251
|
var agentSlug = filter.agent ? slugifyAgentName(filter.agent) : null;
|
|
139
252
|
if (filter.agent && !agentSlug) return { error: "agent must name an agent" };
|
|
140
253
|
var vendor = filter.vendor ? String(filter.vendor).toLowerCase() : null;
|
|
141
|
-
var
|
|
254
|
+
var scoped = collectPairs(projects, filter.now).filter(function (pair) {
|
|
255
|
+
var e = pair.entry;
|
|
142
256
|
if (filter.project && e.project !== filter.project) return false;
|
|
143
257
|
if (agentSlug && slugifyAgentName(e.agent) !== agentSlug) return false;
|
|
144
258
|
if (vendor && String(e.vendor || "").toLowerCase() !== vendor) return false;
|
|
145
|
-
if (state !== ANY_STATE && e.state !== state) return false;
|
|
146
259
|
return true;
|
|
147
260
|
});
|
|
148
|
-
|
|
261
|
+
var matched = filter.state === undefined || filter.state === null
|
|
262
|
+
? withReapedLanes(scoped)
|
|
263
|
+
: scoped.filter(function (pair) { return !states || states.indexOf(pair.entry.state) !== -1; });
|
|
264
|
+
var shown = limit === null ? matched : matched.slice(0, limit);
|
|
265
|
+
// The richer fields are worked out for the rows returned, not for every match.
|
|
266
|
+
return {
|
|
267
|
+
entries: shown.map(function (pair) { return filter.detail ? withDetail(pair.entry, pair.session) : pair.entry; }),
|
|
268
|
+
total: matched.length,
|
|
269
|
+
};
|
|
149
270
|
}
|
|
150
271
|
|
|
151
272
|
// Returns { project, token } (token is "" for @<project>) or { error }, plus
|
|
@@ -242,7 +363,11 @@ module.exports = {
|
|
|
242
363
|
STATE: STATE,
|
|
243
364
|
STATE_FILTERS: STATE_FILTERS,
|
|
244
365
|
stateOf: stateOf,
|
|
366
|
+
DEFAULT_STATES: DEFAULT_STATES,
|
|
367
|
+
parseStates: parseStates,
|
|
245
368
|
collect: collect,
|
|
369
|
+
detailOf: detailOf,
|
|
370
|
+
withDetail: withDetail,
|
|
246
371
|
list: list,
|
|
247
372
|
parseAddress: parseAddress,
|
|
248
373
|
validateName: validateName,
|
package/lib/session-input-ipc.js
CHANGED
package/lib/session-input.js
CHANGED
|
@@ -208,6 +208,8 @@ function present(value) {
|
|
|
208
208
|
// no ledger entry, so a live view hears of it here
|
|
209
209
|
// onAgentSeen(sighting) -> told of each injected sender that names an agent
|
|
210
210
|
// (the agent roster); read-only, its result is unused
|
|
211
|
+
// readMemAvailableMB() -> the host's free memory in MB, or null; shown by
|
|
212
|
+
// list-sessions --verbose (default: not reported)
|
|
211
213
|
function createSessionInput(deps) {
|
|
212
214
|
var getProject = deps.getProject;
|
|
213
215
|
var listProjects = deps.listProjects || function () { return []; };
|
|
@@ -215,6 +217,7 @@ function createSessionInput(deps) {
|
|
|
215
217
|
var onAutomationInjected = deps.onAutomationInjected || null;
|
|
216
218
|
var onAgentSeen = deps.onAgentSeen || null;
|
|
217
219
|
var clock = deps.now || Date.now;
|
|
220
|
+
var readMemAvailableMB = deps.readMemAvailableMB || null;
|
|
218
221
|
|
|
219
222
|
function defaultAgentCatalog(project) {
|
|
220
223
|
// Neither lookup throws: both answer [] when discovery has not run or the
|
|
@@ -223,6 +226,22 @@ function createSessionInput(deps) {
|
|
|
223
226
|
}
|
|
224
227
|
var agentCatalog = deps.agentCatalog || defaultAgentCatalog;
|
|
225
228
|
|
|
229
|
+
// The candidates of an ambiguous address, each with the richer fields of
|
|
230
|
+
// list-sessions --verbose so the caller can choose without another call.
|
|
231
|
+
// Resolution has already happened: this only describes what it found.
|
|
232
|
+
function detailedCandidates(candidates) {
|
|
233
|
+
return candidates.map(function (c) {
|
|
234
|
+
var project = getProject(c.project);
|
|
235
|
+
var held = null;
|
|
236
|
+
if (project && project.sm && project.sm.sessions) {
|
|
237
|
+
project.sm.sessions.forEach(function (s) {
|
|
238
|
+
if (!held && String(s.localId) === c.consoleSessionId) held = s;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return held ? directory.withDetail(c, held) : c;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
226
245
|
function resolveProject(slug) {
|
|
227
246
|
var project = typeof slug === "string" && slug ? getProject(slug) : null;
|
|
228
247
|
if (!project) return { refusal: refused("unknown project " + shown(slug)) };
|
|
@@ -276,7 +295,7 @@ function createSessionInput(deps) {
|
|
|
276
295
|
result: RESULT.AMBIGUOUS,
|
|
277
296
|
reason: "the address " + shown(req.to) + " matches " + found.candidates.length + " sessions; choose one and send again with --project and --session",
|
|
278
297
|
to: req.to,
|
|
279
|
-
candidates: found.candidates,
|
|
298
|
+
candidates: detailedCandidates(found.candidates),
|
|
280
299
|
},
|
|
281
300
|
};
|
|
282
301
|
}
|
|
@@ -338,7 +357,7 @@ function createSessionInput(deps) {
|
|
|
338
357
|
ok: false,
|
|
339
358
|
result: RESULT.AMBIGUOUS,
|
|
340
359
|
reason: "reply refused: the recorded sender matches " + found.candidates.length + " sessions; choose one and send again with --project and --session",
|
|
341
|
-
candidates: found.candidates,
|
|
360
|
+
candidates: detailedCandidates(found.candidates),
|
|
342
361
|
},
|
|
343
362
|
};
|
|
344
363
|
}
|
|
@@ -986,8 +1005,19 @@ function createSessionInput(deps) {
|
|
|
986
1005
|
}, openStartFailure);
|
|
987
1006
|
}
|
|
988
1007
|
|
|
989
|
-
//
|
|
990
|
-
//
|
|
1008
|
+
// The host's load, read at the moment of the call: free memory, and whether the
|
|
1009
|
+
// console is refusing new sessions and agent work (memory pressure or a drain).
|
|
1010
|
+
// It is a read, not a cap: the console's own refusal stays the backstop.
|
|
1011
|
+
function hostLoad() {
|
|
1012
|
+
var available = typeof readMemAvailableMB === "function" ? readMemAvailableMB() : null;
|
|
1013
|
+
return { memAvailableMB: typeof available === "number" ? available : null, newWorkRefused: !!getNewWorkRefusal() };
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// req: { projectSlug?, agentName?, vendor?, state?, limit?, verbose? }.
|
|
1017
|
+
// Read-only: the sessions of the console's own store
|
|
1018
|
+
// (lib/session-directory.js), newest first. state is a comma list or "any"
|
|
1019
|
+
// (default live,idle); limit keeps the newest rows. verbose adds the richer
|
|
1020
|
+
// fields to each row and the host load to the result.
|
|
991
1021
|
function listSessions(req) {
|
|
992
1022
|
req = req || {};
|
|
993
1023
|
if (req.projectSlug && !getProject(req.projectSlug)) {
|
|
@@ -998,9 +1028,13 @@ function createSessionInput(deps) {
|
|
|
998
1028
|
agent: req.agentName,
|
|
999
1029
|
vendor: req.vendor,
|
|
1000
1030
|
state: req.state,
|
|
1031
|
+
limit: req.limit,
|
|
1032
|
+
detail: !!req.verbose,
|
|
1001
1033
|
});
|
|
1002
1034
|
if (found.error) return refused(found.error);
|
|
1003
|
-
|
|
1035
|
+
var out = { ok: true, result: RESULT.LISTED, count: found.entries.length, total: found.total, sessions: found.entries };
|
|
1036
|
+
if (req.verbose) out.host = hostLoad();
|
|
1037
|
+
return out;
|
|
1004
1038
|
}
|
|
1005
1039
|
|
|
1006
1040
|
return {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The "Avatars in session list" setting: a boolean, on by default. The daemon's
|
|
4
|
+
// `sessionListAvatars` setting (`clagentic-console settings`) is the default for a
|
|
5
|
+
// person who has not chosen in Appearance; their own choice always wins.
|
|
6
|
+
|
|
7
|
+
var DEFAULT_SESSION_LIST_AVATARS = true;
|
|
8
|
+
|
|
9
|
+
function isSessionListAvatars(value) {
|
|
10
|
+
return typeof value === "boolean";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
DEFAULT_SESSION_LIST_AVATARS: DEFAULT_SESSION_LIST_AVATARS,
|
|
15
|
+
isSessionListAvatars: isSessionListAvatars,
|
|
16
|
+
};
|
package/lib/session-reclaim.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// announceLiveAgentReclaim: the agents are named, the session is marked as
|
|
8
8
|
// expected to resume, and both UI surfaces are told.
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var backgroundTasks = require("./session-background-tasks");
|
|
11
11
|
|
|
12
12
|
var LABEL_MAX = 80;
|
|
13
13
|
var FALLBACK_LABEL = "background agent";
|
|
@@ -84,23 +84,6 @@ function noteBackgroundLaunch(session, taskId) {
|
|
|
84
84
|
session.backgroundTaskIds[taskId] = true;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
88
|
-
* True when the session is busy only because tracked background agents hold
|
|
89
|
-
* activity tokens: no tool call, thinking block or other live work of its own.
|
|
90
|
-
* The idle reaper reads this so a session waiting on silent agents stays
|
|
91
|
-
* reapable (and announced) instead of looking like a running turn.
|
|
92
|
-
*/
|
|
93
|
-
function onlyBackgroundAgentsActive(session) {
|
|
94
|
-
var tracked = session && session.activeTaskToolIds;
|
|
95
|
-
var marks = session && session.backgroundTaskIds;
|
|
96
|
-
if (!tracked || !marks) return false;
|
|
97
|
-
var has = Object.prototype.hasOwnProperty;
|
|
98
|
-
var sources = sessionActivity.listActiveSources(session);
|
|
99
|
-
return sources.length > 0 && sources.every(function (s) {
|
|
100
|
-
return has.call(tracked, s.token) && !!tracked[s.token] && has.call(marks, s.token);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
87
|
/** Operator-facing names of every Task the session still tracks. */
|
|
105
88
|
function liveAgentLabels(session) {
|
|
106
89
|
return liveAgentTasks(session).map(function (t) { return t.label; });
|
|
@@ -118,8 +101,26 @@ function describeAgents(labels) {
|
|
|
118
101
|
: labels.length + " background agents (" + labels.map(function (l) { return '"' + l + '"'; }).join(", ") + ")";
|
|
119
102
|
}
|
|
120
103
|
|
|
121
|
-
function
|
|
122
|
-
return
|
|
104
|
+
function describeTasks(tasks) {
|
|
105
|
+
return tasks.length === 1
|
|
106
|
+
? 'background task "' + tasks[0] + '"'
|
|
107
|
+
: tasks.length + " background tasks (" + tasks.map(function (l) { return '"' + l + '"'; }).join(", ") + ")";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A foreground query has no Task label. It rides in the same label list under
|
|
111
|
+
// this marker so it survives the session file and the restart notice with no
|
|
112
|
+
// second persisted field.
|
|
113
|
+
var FOREGROUND_QUERY_LABEL = "foreground query";
|
|
114
|
+
|
|
115
|
+
// tasks: live non-agent background tasks (Bash and the like), named after the agents.
|
|
116
|
+
function reclaimMessage(cause, labels, tasks) {
|
|
117
|
+
var parts = [];
|
|
118
|
+
var foreground = labels.indexOf(FOREGROUND_QUERY_LABEL) !== -1;
|
|
119
|
+
var agents = labels.filter(function (l) { return l !== FOREGROUND_QUERY_LABEL; });
|
|
120
|
+
if (foreground) parts.push("its running query");
|
|
121
|
+
if (agents.length) parts.push(describeAgents(agents));
|
|
122
|
+
if (tasks && tasks.length) parts.push(describeTasks(tasks));
|
|
123
|
+
return cause + " Interrupted: " + parts.join(" and ") + ". "
|
|
123
124
|
+ "The session will resume on your next message; if it does not, resume it manually.";
|
|
124
125
|
}
|
|
125
126
|
|
|
@@ -127,7 +128,7 @@ function reclaimMessage(cause, labels) {
|
|
|
127
128
|
// it, so the agents are written to the session file and told to the operator
|
|
128
129
|
// at the next startup (surfaceRestartReclaims / restartNoticeMessages).
|
|
129
130
|
var RESTART_REASON = "daemon_restart";
|
|
130
|
-
var RESTART_CAUSE = "Clagentic: Console shut down or restarted while this session had
|
|
131
|
+
var RESTART_CAUSE = "Clagentic: Console shut down or restarted while this session had agent work running.";
|
|
131
132
|
// Bounds the meta line of the session file, which is read back from a 4 KiB chunk.
|
|
132
133
|
var PERSISTED_AGENTS_MAX = 8;
|
|
133
134
|
|
|
@@ -168,6 +169,8 @@ function logReclaimFailure(what, session, labels, e) {
|
|
|
168
169
|
* @param {string} o.reason - durable marker stored on the session
|
|
169
170
|
* @param {string} o.source - diagnostic source shown in the Diagnostics panel
|
|
170
171
|
* @param {string} o.cause - sentence naming why the session was ended
|
|
172
|
+
* @param {boolean} [o.foreground] - the session's foreground query is running
|
|
173
|
+
* and counts as interrupted work even with no background agent
|
|
171
174
|
* @param {boolean} [o.deferNotice] - persist the marker and the agent names but
|
|
172
175
|
* send nothing now (the process is exiting; the notice goes out at startup)
|
|
173
176
|
*/
|
|
@@ -175,7 +178,10 @@ function announceLiveAgentReclaim(o) {
|
|
|
175
178
|
var session = o.session;
|
|
176
179
|
if (!session) return { labels: [], persisted: true };
|
|
177
180
|
var labels = liveAgentLabels(session);
|
|
178
|
-
if (
|
|
181
|
+
if (o.foreground) labels.unshift(FOREGROUND_QUERY_LABEL);
|
|
182
|
+
// A daemon shutdown persists agent names only; its restart notice is agent-specific.
|
|
183
|
+
var tasks = o.deferNotice ? [] : backgroundTasks.nonAgentLabels(session);
|
|
184
|
+
if (labels.length === 0 && tasks.length === 0) return { labels: labels, persisted: true };
|
|
179
185
|
|
|
180
186
|
var persisted = true;
|
|
181
187
|
try {
|
|
@@ -192,7 +198,7 @@ function announceLiveAgentReclaim(o) {
|
|
|
192
198
|
|
|
193
199
|
if (o.deferNotice) return { labels: labels, persisted: persisted };
|
|
194
200
|
|
|
195
|
-
var message = reclaimMessage(o.cause, labels);
|
|
201
|
+
var message = reclaimMessage(o.cause, labels, tasks);
|
|
196
202
|
if (typeof o.send === "function") {
|
|
197
203
|
try {
|
|
198
204
|
o.send({
|
|
@@ -212,7 +218,11 @@ function announceLiveAgentReclaim(o) {
|
|
|
212
218
|
logReclaimFailure("Could not record the inline reclaim notice", session, labels, e);
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
|
-
|
|
221
|
+
var result = { labels: labels, persisted: persisted };
|
|
222
|
+
// Present only when a non-agent task was named, so the result keeps its
|
|
223
|
+
// shape for every session without one.
|
|
224
|
+
if (tasks.length) result.tasks = tasks;
|
|
225
|
+
return result;
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
/**
|
|
@@ -230,6 +240,9 @@ function announceShutdownReclaim(session, sm) {
|
|
|
230
240
|
source: "daemon-shutdown",
|
|
231
241
|
cause: RESTART_CAUSE,
|
|
232
242
|
deferNotice: true,
|
|
243
|
+
// A query still running at exit is cut off even with no background agent:
|
|
244
|
+
// the SIGTERM drain can end on its bound with a foreground query mid-turn.
|
|
245
|
+
foreground: session.isProcessing === true,
|
|
233
246
|
});
|
|
234
247
|
}
|
|
235
248
|
|
|
@@ -310,7 +323,6 @@ module.exports = {
|
|
|
310
323
|
restartDiagnostics: restartDiagnostics,
|
|
311
324
|
noteTaskLabel: noteTaskLabel,
|
|
312
325
|
noteBackgroundLaunch: noteBackgroundLaunch,
|
|
313
|
-
onlyBackgroundAgentsActive: onlyBackgroundAgentsActive,
|
|
314
326
|
pruneTaskLabels: pruneTaskLabels,
|
|
315
327
|
liveAgentLabels: liveAgentLabels,
|
|
316
328
|
liveAgentTasks: liveAgentTasks,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// One answer to "which vendor does this session run on", shared by the query
|
|
2
|
+
// start, fork/rewind and the session switch so none of them can disagree.
|
|
3
|
+
//
|
|
4
|
+
// Order: the vendor on the session in memory, else the one its stored meta
|
|
5
|
+
// records, else the project's default vendor, else none. `source` says which
|
|
6
|
+
// one answered; only the caller that runs a query acts on "default" (binds it).
|
|
7
|
+
//
|
|
8
|
+
// The meta lookup has three states (see sessions.js lookupMetaVendor): present,
|
|
9
|
+
// absent, error. An error answers `source: "error"` with no vendor and never
|
|
10
|
+
// falls through to the default, because the default would overwrite a vendor
|
|
11
|
+
// that is recorded but could not be read.
|
|
12
|
+
|
|
13
|
+
function resolveVendor(session, deps) {
|
|
14
|
+
if (session && session.vendor) return { vendor: session.vendor, source: "session" };
|
|
15
|
+
var lookup = deps && deps.lookupMetaVendor;
|
|
16
|
+
if (session && typeof lookup === "function") {
|
|
17
|
+
var meta = lookup(session);
|
|
18
|
+
if (meta && meta.state === "present" && meta.vendor) return { vendor: meta.vendor, source: "meta" };
|
|
19
|
+
if (meta && meta.state === "error") return { vendor: null, source: "error" };
|
|
20
|
+
}
|
|
21
|
+
var fallback = deps && deps.defaultVendor;
|
|
22
|
+
if (fallback) return { vendor: fallback, source: "default" };
|
|
23
|
+
return { vendor: null, source: null };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The wire name of a resolution source, for a client that must tell a vendor
|
|
27
|
+
// the session records ("present"), one the project default stands in for
|
|
28
|
+
// ("default-bound"), a meta that could not be read ("error") and no vendor at
|
|
29
|
+
// all ("absent").
|
|
30
|
+
function vendorSourceLabel(source) {
|
|
31
|
+
if (source === "session" || source === "meta") return "present";
|
|
32
|
+
if (source === "default") return "default-bound";
|
|
33
|
+
if (source === "error") return "error";
|
|
34
|
+
return "absent";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { resolveVendor: resolveVendor, vendorSourceLabel: vendorSourceLabel };
|