@clagentic/console 1.0.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/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Agent favorites — Clay-side list of agents the user has marked as
|
|
2
|
+
// chat-eligible. Surfaces in the "Start agent chat" picker on the project
|
|
3
|
+
// view; everything not on this list is discovered but not promoted.
|
|
4
|
+
//
|
|
5
|
+
// Storage: ~/.clay/agents/chattable.json. Schema:
|
|
6
|
+
// {
|
|
7
|
+
// "version": 1,
|
|
8
|
+
// "favorites": [
|
|
9
|
+
// { "name": "gemini-researcher", "kind": "user", "addedAt": 1735000000000 },
|
|
10
|
+
// { "name": "amos", "kind": "plugin", "pluginName": "amos", "addedAt": 1735000000001 }
|
|
11
|
+
// ],
|
|
12
|
+
// "recents": [
|
|
13
|
+
// { "name": "gemini-researcher", "kind": "user", "lastUsedAt": 1735000000500 }
|
|
14
|
+
// ]
|
|
15
|
+
// }
|
|
16
|
+
//
|
|
17
|
+
// Identity key for an agent across the file is (kind, pluginName, name).
|
|
18
|
+
// Built-in agents are not eligible — they have no source .md and the
|
|
19
|
+
// favorites surface is for user-installed agents.
|
|
20
|
+
//
|
|
21
|
+
// Concurrency: single-process daemon; no locking. Writes are atomic via
|
|
22
|
+
// rename() to avoid torn reads if a reader races with a writer.
|
|
23
|
+
|
|
24
|
+
var fs = require("fs");
|
|
25
|
+
var path = require("path");
|
|
26
|
+
var os = require("os");
|
|
27
|
+
|
|
28
|
+
var REAL_HOME = process.env.SUDO_USER
|
|
29
|
+
? path.join("/home", process.env.SUDO_USER)
|
|
30
|
+
: os.homedir();
|
|
31
|
+
|
|
32
|
+
var FAVORITES_PATH = path.join(REAL_HOME, ".clagentic", "agents", "chattable.json");
|
|
33
|
+
var SCHEMA_VERSION = 1;
|
|
34
|
+
var RECENTS_LIMIT = 8;
|
|
35
|
+
|
|
36
|
+
function ensureDir() {
|
|
37
|
+
fs.mkdirSync(path.dirname(FAVORITES_PATH), { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function emptyStore() {
|
|
41
|
+
return { version: SCHEMA_VERSION, favorites: [], recents: [] };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readStore() {
|
|
45
|
+
var raw;
|
|
46
|
+
try { raw = fs.readFileSync(FAVORITES_PATH, "utf8"); }
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (e.code === "ENOENT") return emptyStore();
|
|
49
|
+
console.error("[agents-favorites] read failed:", e.message);
|
|
50
|
+
return emptyStore();
|
|
51
|
+
}
|
|
52
|
+
var parsed;
|
|
53
|
+
try { parsed = JSON.parse(raw); }
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error("[agents-favorites] corrupt JSON, returning empty store:", e.message);
|
|
56
|
+
return emptyStore();
|
|
57
|
+
}
|
|
58
|
+
if (!parsed || typeof parsed !== "object") return emptyStore();
|
|
59
|
+
if (!Array.isArray(parsed.favorites)) parsed.favorites = [];
|
|
60
|
+
if (!Array.isArray(parsed.recents)) parsed.recents = [];
|
|
61
|
+
if (typeof parsed.version !== "number") parsed.version = SCHEMA_VERSION;
|
|
62
|
+
return parsed;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function writeStore(store) {
|
|
66
|
+
ensureDir();
|
|
67
|
+
var tmp = FAVORITES_PATH + ".tmp";
|
|
68
|
+
fs.writeFileSync(tmp, JSON.stringify(store, null, 2) + "\n");
|
|
69
|
+
fs.renameSync(tmp, FAVORITES_PATH);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Identity match. pluginName is only meaningful for kind="plugin".
|
|
73
|
+
function sameAgent(a, b) {
|
|
74
|
+
if (!a || !b) return false;
|
|
75
|
+
if (a.name !== b.name) return false;
|
|
76
|
+
if (a.kind !== b.kind) return false;
|
|
77
|
+
if (a.kind === "plugin" && (a.pluginName || null) !== (b.pluginName || null)) return false;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function listFavorites() {
|
|
82
|
+
return readStore().favorites.slice();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isFavorite(agent) {
|
|
86
|
+
var favs = readStore().favorites;
|
|
87
|
+
for (var i = 0; i < favs.length; i++) {
|
|
88
|
+
if (sameAgent(favs[i], agent)) return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Add an agent to favorites. No-op if already present. Returns true if added,
|
|
94
|
+
// false if already present or input invalid.
|
|
95
|
+
function addFavorite(agent) {
|
|
96
|
+
if (!agent || !agent.name || !agent.kind) return false;
|
|
97
|
+
if (agent.kind === "builtin") return false;
|
|
98
|
+
var store = readStore();
|
|
99
|
+
for (var i = 0; i < store.favorites.length; i++) {
|
|
100
|
+
if (sameAgent(store.favorites[i], agent)) return false;
|
|
101
|
+
}
|
|
102
|
+
store.favorites.push({
|
|
103
|
+
name: agent.name,
|
|
104
|
+
kind: agent.kind,
|
|
105
|
+
pluginName: agent.kind === "plugin" ? (agent.pluginName || null) : null,
|
|
106
|
+
addedAt: Date.now(),
|
|
107
|
+
});
|
|
108
|
+
writeStore(store);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Remove an agent from favorites. Returns true if removed, false if not present.
|
|
113
|
+
function removeFavorite(agent) {
|
|
114
|
+
if (!agent || !agent.name || !agent.kind) return false;
|
|
115
|
+
var store = readStore();
|
|
116
|
+
var before = store.favorites.length;
|
|
117
|
+
store.favorites = store.favorites.filter(function (f) { return !sameAgent(f, agent); });
|
|
118
|
+
if (store.favorites.length === before) return false;
|
|
119
|
+
writeStore(store);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Idempotent toggle — flips membership and returns the new state.
|
|
124
|
+
function toggleFavorite(agent) {
|
|
125
|
+
if (isFavorite(agent)) {
|
|
126
|
+
removeFavorite(agent);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
addFavorite(agent);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function listRecents() {
|
|
134
|
+
return readStore().recents.slice();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Bump usage. Moves the agent to the head of recents and trims to RECENTS_LIMIT.
|
|
138
|
+
function touchRecent(agent) {
|
|
139
|
+
if (!agent || !agent.name || !agent.kind) return;
|
|
140
|
+
var store = readStore();
|
|
141
|
+
store.recents = store.recents.filter(function (r) { return !sameAgent(r, agent); });
|
|
142
|
+
store.recents.unshift({
|
|
143
|
+
name: agent.name,
|
|
144
|
+
kind: agent.kind,
|
|
145
|
+
pluginName: agent.kind === "plugin" ? (agent.pluginName || null) : null,
|
|
146
|
+
lastUsedAt: Date.now(),
|
|
147
|
+
});
|
|
148
|
+
if (store.recents.length > RECENTS_LIMIT) {
|
|
149
|
+
store.recents = store.recents.slice(0, RECENTS_LIMIT);
|
|
150
|
+
}
|
|
151
|
+
writeStore(store);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = {
|
|
155
|
+
FAVORITES_PATH: FAVORITES_PATH,
|
|
156
|
+
RECENTS_LIMIT: RECENTS_LIMIT,
|
|
157
|
+
listFavorites: listFavorites,
|
|
158
|
+
isFavorite: isFavorite,
|
|
159
|
+
addFavorite: addFavorite,
|
|
160
|
+
removeFavorite: removeFavorite,
|
|
161
|
+
toggleFavorite: toggleFavorite,
|
|
162
|
+
listRecents: listRecents,
|
|
163
|
+
touchRecent: touchRecent,
|
|
164
|
+
};
|
package/lib/agents.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// Named agents — Claude CLI catalog discovery and SDK AgentDefinition lookup.
|
|
2
|
+
//
|
|
3
|
+
// History: an earlier path (chadbyte/clay#332) registered each chat-enabled
|
|
4
|
+
// agent as its own Clay project rooted at ~/.clay/agents/<slug>/, with the
|
|
5
|
+
// agent body materialized as that project's CLAUDE.md so Claude CLI's
|
|
6
|
+
// project-context loader injected it as the system prompt. That path was
|
|
7
|
+
// retired in lr-ea32 once the per-session SDK-`agent`-option path (lr-7db0)
|
|
8
|
+
// proved out — sessions now carry an `agentName` and the SDK applies the
|
|
9
|
+
// agent identity itself.
|
|
10
|
+
//
|
|
11
|
+
// What's left here is the catalog + definition surface the picker and the
|
|
12
|
+
// SDK bridge need:
|
|
13
|
+
// - listClaudeAgents() — parse `claude agents` output
|
|
14
|
+
// - resolveAgentSourcePath() — locate the .md for a catalog entry
|
|
15
|
+
// - discoverAllAgents() — full non-builtin catalog for the picker
|
|
16
|
+
// - getAgentDefinition(name) — build the in-band SDK AgentDefinition
|
|
17
|
+
//
|
|
18
|
+
// This implementation lives only on our fork; we are not pushing it upstream.
|
|
19
|
+
|
|
20
|
+
var fs = require("fs");
|
|
21
|
+
var path = require("path");
|
|
22
|
+
var os = require("os");
|
|
23
|
+
var { execFileSync } = require("child_process");
|
|
24
|
+
|
|
25
|
+
var REAL_HOME = process.env.SUDO_USER
|
|
26
|
+
? path.join("/home", process.env.SUDO_USER)
|
|
27
|
+
: os.homedir();
|
|
28
|
+
|
|
29
|
+
var AGENTS_SOURCE_DIR = path.join(REAL_HOME, ".claude", "agents");
|
|
30
|
+
var PLUGINS_CACHE_DIR = path.join(REAL_HOME, ".claude", "plugins", "cache");
|
|
31
|
+
|
|
32
|
+
// Minimal frontmatter parser. Reads YAML-ish key/value pairs between leading
|
|
33
|
+
// '---' fences. No nesting, no lists — agent frontmatter is flat.
|
|
34
|
+
// Returns { meta: {...}, body: "..." } or null if no frontmatter fence.
|
|
35
|
+
function parseFrontmatter(raw) {
|
|
36
|
+
if (typeof raw !== "string") return null;
|
|
37
|
+
// Allow optional UTF-8 BOM and leading whitespace before the fence.
|
|
38
|
+
var stripped = raw.replace(/^/, "");
|
|
39
|
+
if (stripped.indexOf("---") !== 0) return { meta: {}, body: stripped };
|
|
40
|
+
var rest = stripped.slice(3);
|
|
41
|
+
// The fence terminator must start a line.
|
|
42
|
+
var endIdx = rest.indexOf("\n---");
|
|
43
|
+
if (endIdx === -1) return { meta: {}, body: stripped };
|
|
44
|
+
var fmText = rest.slice(0, endIdx);
|
|
45
|
+
var afterFence = rest.slice(endIdx + 4); // skip "\n---"
|
|
46
|
+
// Trim a single leading newline after the closing fence.
|
|
47
|
+
if (afterFence.charAt(0) === "\n") afterFence = afterFence.slice(1);
|
|
48
|
+
var meta = {};
|
|
49
|
+
var lines = fmText.split("\n");
|
|
50
|
+
for (var i = 0; i < lines.length; i++) {
|
|
51
|
+
var line = lines[i];
|
|
52
|
+
if (!line || /^\s*#/.test(line)) continue;
|
|
53
|
+
var colon = line.indexOf(":");
|
|
54
|
+
if (colon === -1) continue;
|
|
55
|
+
var key = line.slice(0, colon).trim();
|
|
56
|
+
var val = line.slice(colon + 1).trim();
|
|
57
|
+
if (!key) continue;
|
|
58
|
+
// Strip matching surrounding quotes.
|
|
59
|
+
if ((val.charAt(0) === '"' && val.charAt(val.length - 1) === '"') ||
|
|
60
|
+
(val.charAt(0) === "'" && val.charAt(val.length - 1) === "'")) {
|
|
61
|
+
val = val.slice(1, -1);
|
|
62
|
+
}
|
|
63
|
+
// Coerce booleans.
|
|
64
|
+
if (val === "true") val = true;
|
|
65
|
+
else if (val === "false") val = false;
|
|
66
|
+
meta[key] = val;
|
|
67
|
+
}
|
|
68
|
+
return { meta: meta, body: afterFence };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Normalize an agent name to a filesystem-safe slug. Keeps lowercase letters,
|
|
72
|
+
// numbers, and dashes; collapses everything else.
|
|
73
|
+
function slugifyAgentName(name) {
|
|
74
|
+
if (!name) return "";
|
|
75
|
+
return String(name)
|
|
76
|
+
.toLowerCase()
|
|
77
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
78
|
+
.replace(/^-+|-+$/g, "")
|
|
79
|
+
.slice(0, 64);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Ask Claude CLI for the canonical agent catalog (user + plugin + built-in
|
|
83
|
+
// agents). Output is human-readable text, sectioned. Returns array of
|
|
84
|
+
// { name, kind, modelLabel } where kind is "user" | "plugin" | "builtin".
|
|
85
|
+
// Plugin agents arrive prefixed like "amos:amos" — we keep both the raw
|
|
86
|
+
// label and a parsed agent name.
|
|
87
|
+
function listClaudeAgents() {
|
|
88
|
+
var out;
|
|
89
|
+
try {
|
|
90
|
+
out = execFileSync("claude", ["agents", "--setting-sources", "user,project,local"], {
|
|
91
|
+
encoding: "utf8",
|
|
92
|
+
timeout: 10000,
|
|
93
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
94
|
+
});
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error("[agents] claude agents command failed:", e.message);
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
var lines = out.split("\n");
|
|
100
|
+
var agents = [];
|
|
101
|
+
var section = null;
|
|
102
|
+
for (var i = 0; i < lines.length; i++) {
|
|
103
|
+
var line = lines[i];
|
|
104
|
+
if (/^User agents:/i.test(line)) { section = "user"; continue; }
|
|
105
|
+
if (/^Plugin agents:/i.test(line)) { section = "plugin"; continue; }
|
|
106
|
+
if (/^Built-?in agents:/i.test(line)) { section = "builtin"; continue; }
|
|
107
|
+
if (!section) continue;
|
|
108
|
+
var m = line.match(/^\s+(\S.*?)\s+·\s+(\S+)\s*$/);
|
|
109
|
+
if (!m) continue;
|
|
110
|
+
var label = m[1].trim();
|
|
111
|
+
var modelLabel = m[2].trim();
|
|
112
|
+
// Plugin entries are "<plugin>:<agent>"; user/builtin are bare names.
|
|
113
|
+
var name = label;
|
|
114
|
+
var pluginName = null;
|
|
115
|
+
if (section === "plugin") {
|
|
116
|
+
var parts = label.split(":");
|
|
117
|
+
if (parts.length === 2) { pluginName = parts[0]; name = parts[1]; }
|
|
118
|
+
}
|
|
119
|
+
agents.push({ label: label, name: name, kind: section, modelLabel: modelLabel, pluginName: pluginName });
|
|
120
|
+
}
|
|
121
|
+
return agents;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Resolve an agent entry from `claude agents` to its source .md file.
|
|
125
|
+
// Returns the absolute path or null if not found. Built-ins have no .md and
|
|
126
|
+
// always return null (we don't surface them as chat sessions).
|
|
127
|
+
function resolveAgentSourcePath(agent) {
|
|
128
|
+
if (agent.kind === "user") {
|
|
129
|
+
var p = path.join(AGENTS_SOURCE_DIR, agent.name + ".md");
|
|
130
|
+
if (fs.existsSync(p)) return p;
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (agent.kind === "plugin") {
|
|
134
|
+
// Walk ~/.claude/plugins/cache/<marketplace>/<plugin>/<version>/agents/<name>.md
|
|
135
|
+
if (!fs.existsSync(PLUGINS_CACHE_DIR)) return null;
|
|
136
|
+
var marketplaces;
|
|
137
|
+
try { marketplaces = fs.readdirSync(PLUGINS_CACHE_DIR); }
|
|
138
|
+
catch (e) { return null; }
|
|
139
|
+
for (var mi = 0; mi < marketplaces.length; mi++) {
|
|
140
|
+
var marketplaceDir = path.join(PLUGINS_CACHE_DIR, marketplaces[mi]);
|
|
141
|
+
var pluginCandidate = agent.pluginName ? path.join(marketplaceDir, agent.pluginName) : null;
|
|
142
|
+
var pluginDirs = [];
|
|
143
|
+
if (pluginCandidate && fs.existsSync(pluginCandidate)) {
|
|
144
|
+
pluginDirs.push(pluginCandidate);
|
|
145
|
+
} else {
|
|
146
|
+
// Fallback: scan all plugins under this marketplace.
|
|
147
|
+
try {
|
|
148
|
+
var pls = fs.readdirSync(marketplaceDir);
|
|
149
|
+
for (var pi = 0; pi < pls.length; pi++) {
|
|
150
|
+
pluginDirs.push(path.join(marketplaceDir, pls[pi]));
|
|
151
|
+
}
|
|
152
|
+
} catch (e) { /* skip */ }
|
|
153
|
+
}
|
|
154
|
+
for (var pd = 0; pd < pluginDirs.length; pd++) {
|
|
155
|
+
// Each plugin has versioned subdirs.
|
|
156
|
+
var versions;
|
|
157
|
+
try { versions = fs.readdirSync(pluginDirs[pd]); } catch (e) { continue; }
|
|
158
|
+
for (var vi = 0; vi < versions.length; vi++) {
|
|
159
|
+
var candidate = path.join(pluginDirs[pd], versions[vi], "agents", agent.name + ".md");
|
|
160
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
// Built-ins: no source file.
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Discover all non-builtin agents from the Claude CLI catalog. This is the
|
|
171
|
+
// catalog surface for the SDK-agent path (lr-7db0): we hand the full list to
|
|
172
|
+
// the UI and let the user decide which to favorite (chattable.json), then
|
|
173
|
+
// pass the chosen agent name through the SDK `agent` option per session.
|
|
174
|
+
//
|
|
175
|
+
// Builtins are excluded because they have no source .md (resolved by name
|
|
176
|
+
// inside the Claude CLI itself) and the SDK still recognizes them by name —
|
|
177
|
+
// callers that want builtins should pass the name through directly.
|
|
178
|
+
//
|
|
179
|
+
// Returns an array of { name, slug, description, model, sourcePath, kind, pluginName }.
|
|
180
|
+
// Body is intentionally NOT loaded here — the SDK applies the agent's system
|
|
181
|
+
// prompt itself; we only need metadata for display.
|
|
182
|
+
function discoverAllAgents() {
|
|
183
|
+
var found = [];
|
|
184
|
+
var catalog = listClaudeAgents();
|
|
185
|
+
for (var i = 0; i < catalog.length; i++) {
|
|
186
|
+
var entry = catalog[i];
|
|
187
|
+
if (entry.kind === "builtin") continue;
|
|
188
|
+
var sourcePath = resolveAgentSourcePath(entry);
|
|
189
|
+
var description = "";
|
|
190
|
+
var model = entry.modelLabel || "";
|
|
191
|
+
if (sourcePath) {
|
|
192
|
+
try {
|
|
193
|
+
var raw = fs.readFileSync(sourcePath, "utf8");
|
|
194
|
+
var parsed = parseFrontmatter(raw);
|
|
195
|
+
if (parsed) {
|
|
196
|
+
if (parsed.meta.description) description = parsed.meta.description;
|
|
197
|
+
if (parsed.meta.model) model = parsed.meta.model;
|
|
198
|
+
}
|
|
199
|
+
} catch (e) { /* metadata best-effort */ }
|
|
200
|
+
}
|
|
201
|
+
var name = entry.name;
|
|
202
|
+
var slugBase = entry.kind === "plugin" && entry.pluginName
|
|
203
|
+
? entry.pluginName + "-" + name
|
|
204
|
+
: name;
|
|
205
|
+
var slug = slugifyAgentName(slugBase);
|
|
206
|
+
if (!slug) continue;
|
|
207
|
+
found.push({
|
|
208
|
+
name: name,
|
|
209
|
+
slug: slug,
|
|
210
|
+
description: description,
|
|
211
|
+
model: model,
|
|
212
|
+
sourcePath: sourcePath,
|
|
213
|
+
kind: entry.kind,
|
|
214
|
+
pluginName: entry.pluginName || null,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return found;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Build an SDK-shaped AgentDefinition from a discovered agent's source .md.
|
|
221
|
+
// The Claude SDK's `agent` option only resolves names against the in-band
|
|
222
|
+
// `agents` map (or settings.json) — file/plugin discovery via `claude agents`
|
|
223
|
+
// is a CLI-side convenience that the SDK does not honor at query time. So
|
|
224
|
+
// when we cast a session as a named agent, we must also hand the SDK the
|
|
225
|
+
// definition it needs to apply the system prompt, tool restrictions, and
|
|
226
|
+
// model.
|
|
227
|
+
//
|
|
228
|
+
// Returns null if the name can't be resolved (no source file, parse failure)
|
|
229
|
+
// — the caller treats null as "agent unknown, fall back to default identity".
|
|
230
|
+
function getAgentDefinition(name) {
|
|
231
|
+
if (!name) return null;
|
|
232
|
+
// Re-walk the catalog to find the entry for this name. Cheap; the catalog
|
|
233
|
+
// is short and `claude agents` runs in well under 100ms.
|
|
234
|
+
var catalog = listClaudeAgents();
|
|
235
|
+
var entry = null;
|
|
236
|
+
for (var i = 0; i < catalog.length; i++) {
|
|
237
|
+
if (catalog[i].kind === "builtin") continue;
|
|
238
|
+
if (catalog[i].name === name) { entry = catalog[i]; break; }
|
|
239
|
+
}
|
|
240
|
+
if (!entry) return null;
|
|
241
|
+
var sourcePath = resolveAgentSourcePath(entry);
|
|
242
|
+
if (!sourcePath) return null;
|
|
243
|
+
var raw;
|
|
244
|
+
try { raw = fs.readFileSync(sourcePath, "utf8"); }
|
|
245
|
+
catch (e) {
|
|
246
|
+
console.error("[agents] getAgentDefinition: failed to read " + sourcePath + ":", e.message);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
var parsed = parseFrontmatter(raw);
|
|
250
|
+
if (!parsed) return null;
|
|
251
|
+
var meta = parsed.meta || {};
|
|
252
|
+
var def = {
|
|
253
|
+
description: meta.description || "",
|
|
254
|
+
prompt: (parsed.body || "").trim(),
|
|
255
|
+
};
|
|
256
|
+
if (meta.model && meta.model !== "inherit") def.model = meta.model;
|
|
257
|
+
// Frontmatter `tools` is a comma-separated string; SDK wants a string array.
|
|
258
|
+
if (typeof meta.tools === "string" && meta.tools.trim()) {
|
|
259
|
+
var toolsArr = meta.tools.split(",")
|
|
260
|
+
.map(function (t) { return t.trim(); })
|
|
261
|
+
.filter(function (t) { return t.length > 0; });
|
|
262
|
+
if (toolsArr.length > 0) def.tools = toolsArr;
|
|
263
|
+
}
|
|
264
|
+
if (typeof meta.disallowedTools === "string" && meta.disallowedTools.trim()) {
|
|
265
|
+
var disArr = meta.disallowedTools.split(",")
|
|
266
|
+
.map(function (t) { return t.trim(); })
|
|
267
|
+
.filter(function (t) { return t.length > 0; });
|
|
268
|
+
if (disArr.length > 0) def.disallowedTools = disArr;
|
|
269
|
+
}
|
|
270
|
+
return def;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
module.exports = {
|
|
274
|
+
AGENTS_SOURCE_DIR: AGENTS_SOURCE_DIR,
|
|
275
|
+
PLUGINS_CACHE_DIR: PLUGINS_CACHE_DIR,
|
|
276
|
+
parseFrontmatter: parseFrontmatter,
|
|
277
|
+
slugifyAgentName: slugifyAgentName,
|
|
278
|
+
listClaudeAgents: listClaudeAgents,
|
|
279
|
+
resolveAgentSourcePath: resolveAgentSourcePath,
|
|
280
|
+
discoverAllAgents: discoverAllAgents,
|
|
281
|
+
getAgentDefinition: getAgentDefinition,
|
|
282
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Ask User MCP Server for Clay
|
|
2
|
+
// Provides a mate-only ask_user_questions tool that reuses the existing
|
|
3
|
+
// AskUserQuestion UI and ask_user_response flow.
|
|
4
|
+
|
|
5
|
+
var z;
|
|
6
|
+
try { z = require("zod"); } catch (e) { z = null; }
|
|
7
|
+
|
|
8
|
+
// Returns a Zod "shape" object (property -> zod field) matching what
|
|
9
|
+
// Claude SDK's `sdk.tool()` expects. Do NOT wrap in z.object() here —
|
|
10
|
+
// the SDK does that internally.
|
|
11
|
+
//
|
|
12
|
+
// The schema is deliberately tight: options are required (2-6), each with
|
|
13
|
+
// a label and a short description. This pushes Codex (which treats the
|
|
14
|
+
// schema as a loose hint) toward producing well-structured multiple-choice
|
|
15
|
+
// cards instead of a bare "Other..." text field.
|
|
16
|
+
function buildQuestionShape() {
|
|
17
|
+
if (!z) return {};
|
|
18
|
+
|
|
19
|
+
var optionSchema = z.object({
|
|
20
|
+
label: z.string().min(1).max(60)
|
|
21
|
+
.describe("Short button label, 1-6 words. Shown as the primary option text."),
|
|
22
|
+
description: z.string().min(1).max(160)
|
|
23
|
+
.describe("One-line clarifier shown under the label. Concrete example or scope."),
|
|
24
|
+
markdown: z.string().optional()
|
|
25
|
+
.describe("Optional longer markdown body shown on expand. Use sparingly."),
|
|
26
|
+
}).passthrough();
|
|
27
|
+
|
|
28
|
+
var questionSchema = z.object({
|
|
29
|
+
header: z.string().min(1).max(40)
|
|
30
|
+
.describe("Short ALL-CAPS-ish section header above the question (e.g. 'FIRST THINGS FIRST', 'SCOPE'). Gives the user context for this step."),
|
|
31
|
+
question: z.string().min(1)
|
|
32
|
+
.describe("The actual question in natural spoken tone. Be specific, not generic."),
|
|
33
|
+
multiSelect: z.boolean().optional()
|
|
34
|
+
.describe("Set true only when multiple answers genuinely make sense. Default false."),
|
|
35
|
+
options: z.array(optionSchema).min(2).max(6)
|
|
36
|
+
.describe("Concrete options. Preferred count is 4; acceptable range is 2-6. FOUR is the target. Do NOT default to 3 out of habit. If you can only think of 3, push yourself: add a scope variant, edge case, or 'combined' option as the 4th. Only drop below 4 when the answer space is genuinely narrower (e.g. yes/no/unsure). Never include an 'Other' option yourself (the UI renders one automatically)."),
|
|
37
|
+
}).passthrough();
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
questions: z.array(questionSchema).min(1).max(3)
|
|
41
|
+
.describe("One to three question objects to show together as a card. Prefer ONE focused question per call."),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var TOOL_DESCRIPTION = [
|
|
46
|
+
"Ask the user a structured multiple-choice question. Renders as a card with a header, the question, 2-6 clickable option buttons, and an always-present 'Other...' free-text field.",
|
|
47
|
+
"",
|
|
48
|
+
"WHEN TO USE:",
|
|
49
|
+
"- Interviewing the user at mate setup, or whenever you need to narrow scope before acting.",
|
|
50
|
+
"- Any branching decision where 2-6 concrete choices cover most of the space.",
|
|
51
|
+
"",
|
|
52
|
+
"REQUIRED STRUCTURE (all fields matter, do not skip):",
|
|
53
|
+
"- header: short section label, like 'FIRST THINGS FIRST' or 'SCOPE'. Gives context.",
|
|
54
|
+
"- question: one specific question in natural tone. Avoid generic 'how can I help?'.",
|
|
55
|
+
"- options: ALWAYS provide FOUR options by default. Acceptable range is 4-6; only drop to 3 if the answer space is genuinely binary-plus-one (rare). Each option has a short label (1-6 words) AND a one-line description giving a concrete example or scope. The UI already renders an 'Other...' text field, so you never need to include an 'Other' option yourself.",
|
|
56
|
+
"- multiSelect: omit or false unless multiple answers clearly apply.",
|
|
57
|
+
"",
|
|
58
|
+
"ON OPTION COUNT (IMPORTANT):",
|
|
59
|
+
"- Default to 4 options. Not 3. Models tend to gravitate to 3 because it feels tidy; resist that.",
|
|
60
|
+
"- If you're about to produce 3 options, stop and think: is there a fourth axis you're missing? A scope variant? A 'both' or 'neither'? A more niche case? Add it.",
|
|
61
|
+
"- 3 is only acceptable when the fourth option would be truly degenerate (e.g. yes/no/unsure).",
|
|
62
|
+
"- 5 or 6 is fine when the space is wide; don't cram.",
|
|
63
|
+
"",
|
|
64
|
+
"GOOD EXAMPLE:",
|
|
65
|
+
' { header: "FIRST THINGS FIRST",',
|
|
66
|
+
' question: "\'Language\' is broad, what do you actually want help with?",',
|
|
67
|
+
' options: [',
|
|
68
|
+
' { label: "A new language from scratch", description: "Pick up a language you don\'t speak yet (e.g. Japanese, Spanish)" },',
|
|
69
|
+
' { label: "Sharpen English", description: "Level up your English, writing, speaking, nuance, executive communication" },',
|
|
70
|
+
' { label: "Sharpen Korean", description: "Polish your Korean, writing style, formal register, etc." },',
|
|
71
|
+
' { label: "Teach me how to teach", description: "Help you teach language to others, like Elyse or team members" }',
|
|
72
|
+
" ] }",
|
|
73
|
+
"",
|
|
74
|
+
"BAD EXAMPLES (do not do this):",
|
|
75
|
+
"- Asking a vague question with no options and relying on the Other field.",
|
|
76
|
+
"- Options with only labels and no descriptions.",
|
|
77
|
+
"- Defaulting to exactly 3 options out of habit. Aim for 4.",
|
|
78
|
+
"- More than one question per call unless they are tightly related.",
|
|
79
|
+
"- Single-option 'questions' (use a plain message instead).",
|
|
80
|
+
].join("\n");
|
|
81
|
+
|
|
82
|
+
function getToolDefs(onAsk) {
|
|
83
|
+
var tools = [];
|
|
84
|
+
|
|
85
|
+
tools.push({
|
|
86
|
+
name: "ask_user_questions",
|
|
87
|
+
description: TOOL_DESCRIPTION,
|
|
88
|
+
inputSchema: buildQuestionShape(),
|
|
89
|
+
handler: function (args) {
|
|
90
|
+
if (!args || !Array.isArray(args.questions) || args.questions.length === 0) {
|
|
91
|
+
return Promise.resolve({
|
|
92
|
+
content: [{ type: "text", text: "Error: questions must be a non-empty array." }],
|
|
93
|
+
isError: true,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Defensive structural check only: zod already enforces min 2.
|
|
97
|
+
// We do NOT reject on "only 3 options" — that's a soft preference
|
|
98
|
+
// expressed via the tool description, not a hard validation rule.
|
|
99
|
+
for (var i = 0; i < args.questions.length; i++) {
|
|
100
|
+
var q = args.questions[i];
|
|
101
|
+
if (!q || !Array.isArray(q.options) || q.options.length < 2) {
|
|
102
|
+
return Promise.resolve({
|
|
103
|
+
content: [{
|
|
104
|
+
type: "text",
|
|
105
|
+
text: "Error: question " + (i + 1) + " must include at least 2 options. "
|
|
106
|
+
+ "Provide concrete { label, description } choices (4 preferred). "
|
|
107
|
+
+ "The UI already shows an 'Other...' free-text field, so never add an 'Other' option yourself.",
|
|
108
|
+
}],
|
|
109
|
+
isError: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return onAsk(args);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return tools;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { getToolDefs: getToolDefs };
|