@clagentic/console 1.5.0 → 1.6.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -4
- package/bin/cli.js +15 -82
- package/lib/agents-favorites.js +21 -6
- package/lib/config.js +1 -1
- package/lib/daemon.js +153 -22
- package/lib/drain.js +213 -0
- package/lib/lite-detect.js +6 -5
- package/lib/loop-handoff.js +282 -0
- package/lib/mcp-local.js +18 -2
- package/lib/memory-limits.js +436 -0
- package/lib/model-context-windows.js +65 -0
- package/lib/project-loop.js +31 -3
- package/lib/project-sessions.js +26 -0
- package/lib/project-team.js +4 -1
- package/lib/project.js +8 -0
- package/lib/public/app.js +4 -0
- package/lib/public/css/base.css +18 -0
- package/lib/public/css/diagnostics.css +279 -0
- package/lib/public/css/icon-strip.css +201 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +24 -0
- package/lib/public/css/server-settings.css +100 -0
- package/lib/public/index.html +26 -0
- package/lib/public/modules/app-header.js +4 -7
- package/lib/public/modules/app-home-hub.js +31 -7
- package/lib/public/modules/app-messages.js +13 -0
- package/lib/public/modules/app-notifications.js +5 -1
- package/lib/public/modules/app-panels.js +11 -21
- package/lib/public/modules/app-projects.js +10 -5
- package/lib/public/modules/command-palette.js +16 -5
- package/lib/public/modules/custom-icons-settings.js +399 -0
- package/lib/public/modules/custom-icons.js +114 -0
- package/lib/public/modules/diagnostic-format.js +34 -0
- package/lib/public/modules/diagnostics.js +297 -0
- package/lib/public/modules/emoji-picker.js +253 -6
- package/lib/public/modules/model-context-windows.js +62 -0
- package/lib/public/modules/popover-position.js +192 -0
- package/lib/public/modules/project-icon.js +113 -0
- package/lib/public/modules/project-settings.js +2 -2
- package/lib/public/modules/project-switcher.js +2 -1
- package/lib/public/modules/scheduler-config.js +5 -8
- package/lib/public/modules/scheduler.js +5 -6
- package/lib/public/modules/server-settings.js +6 -0
- package/lib/public/modules/sidebar-mobile.js +4 -6
- package/lib/public/modules/sidebar-projects.js +35 -90
- package/lib/public/modules/sidebar-sessions.js +6 -20
- package/lib/public/modules/sticky-notes.js +4 -4
- package/lib/public/modules/terminal.js +5 -12
- package/lib/public/style.css +1 -0
- package/lib/sdk-bridge.js +75 -10
- package/lib/sdk-message-processor.js +12 -0
- package/lib/sdk-worker.js +4 -1
- package/lib/server-settings.js +221 -1
- package/lib/server.js +30 -1
- package/lib/sessions.js +27 -11
- package/lib/settings-preflight.js +212 -0
- package/lib/ws-schema.js +2 -0
- package/lib/yoke/adapters/claude-worker.js +14 -2
- package/lib/yoke/adapters/claude.js +16 -0
- package/lib/yoke/adapters/diagnostic-patterns.js +120 -0
- package/lib/yoke/index.js +4 -0
- package/lib/yoke/interface.js +99 -0
- package/package.json +2 -1
- package/scripts/postinstall.js +41 -0
- package/lib/certs/fullchain.pem +0 -47
- package/lib/certs/privkey.pem +0 -5
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://clagentic.ai"><img src="https://img.shields.io/badge/-clagentic.ai-00CFFF?style=flat&logoColor=white" alt="clagentic.ai" /></a>
|
|
9
9
|
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow?style=flat" alt="License: MIT" /></a>
|
|
10
|
+
<a href="https://github.com/clagentic/clagentic-console/actions/workflows/pr-checks.yml"><img src="https://github.com/clagentic/clagentic-console/actions/workflows/pr-checks.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
10
11
|
<img src="https://img.shields.io/badge/Node.js-20+-339933?style=flat&logo=node.js&logoColor=white" alt="Node.js 20+" />
|
|
11
12
|
<a href="https://www.npmjs.com/package/@clagentic/console"><img src="https://img.shields.io/npm/v/@clagentic/console?style=flat&label=npm" alt="npm version" /></a>
|
|
12
13
|
<a href="https://www.npmjs.com/package/@clagentic/console"><img src="https://img.shields.io/npm/dw/@clagentic/console?style=flat&label=downloads" alt="npm downloads" /></a>
|
|
@@ -61,7 +62,7 @@ npm install -g @clagentic/console --ignore-scripts
|
|
|
61
62
|
|
|
62
63
|
- **Loop automation.** Write a `PROMPT.md`, start a loop. Clagentic: Console runs the prompt, evaluates the result, and retries until done or capped. Schedule loops with standard cron syntax to run unattended.
|
|
63
64
|
|
|
64
|
-
- **External triggers.** Drop a JSON file into `~/.clagentic/external-triggers/` to spawn a new AI session or inject a message into an existing one. Use this to wire agents into scripts, CI pipelines, or other AI processes — no API, no polling, just a file drop.
|
|
65
|
+
- **External triggers.** Drop a JSON file into `~/.clagentic/console/external-triggers/` to spawn a new AI session or inject a message into an existing one. Use this to wire agents into scripts, CI pipelines, or other AI processes — no API, no polling, just a file drop.
|
|
65
66
|
|
|
66
67
|
- **Mobile PWA + push notifications.** Installable on iOS and Android. Approve tool calls from your phone. Push fires on approval requests, errors, and task completion.
|
|
67
68
|
|
|
@@ -146,7 +147,7 @@ These are implementation-level properties, not configuration options — they ap
|
|
|
146
147
|
|
|
147
148
|
- **Atomic writes, mode 0o600.** All config and state files (`users.json`, `auth-tokens.json`, and similar) are written via rename-after-write: data goes to a `.tmp.<pid>` path, then `rename()` atomically replaces the target. After rename, `chmod 0o600` is applied. Concurrent writes to the same file are serialized in call order.
|
|
148
149
|
|
|
149
|
-
- **Append-only audit log.** Privileged actions — user creation, lockouts, token revocation, multi-user enable/disable — are written as newline-delimited JSON to `~/.clagentic/audit.log` (mode 0o600, opened with `O_APPEND`).
|
|
150
|
+
- **Append-only audit log.** Privileged actions — user creation, lockouts, token revocation, multi-user enable/disable — are written as newline-delimited JSON to `~/.clagentic/console/audit.log` (mode 0o600, opened with `O_APPEND`).
|
|
150
151
|
|
|
151
152
|
- **Progressive lockout.** Failed login attempts trigger escalating per-username backoff: 1s, 5s, 30s, 5 min. Reaching the threshold results in permanent lockout until an admin explicitly unlocks the account. Per-IP rate limiting runs in parallel.
|
|
152
153
|
|
|
@@ -171,6 +172,24 @@ The test suite covers 12 areas across 26 test files:
|
|
|
171
172
|
|
|
172
173
|
Run the suite: `npm test`
|
|
173
174
|
|
|
175
|
+
### Local install for manual testing (developers only)
|
|
176
|
+
|
|
177
|
+
> **Warning:** This is a manual, developer-only convenience. Do not call it from CI, automated scripts, systemd units, or any other tooling. It is not a release or deploy mechanism.
|
|
178
|
+
|
|
179
|
+
To install the current working-tree build globally and test it as a real end-user install would behave:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npm run install:local-test
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
This runs `npm pack` (which respects the `files` list in `package.json`, so you get exactly what would ship to npm), installs the resulting tarball globally with `npm install -g`, and removes the tarball. The result is indistinguishable from `npm install -g @clagentic/console` — no symlinks, no `node_modules` shortcuts.
|
|
186
|
+
|
|
187
|
+
When done testing, uninstall with:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm uninstall -g @clagentic/console
|
|
191
|
+
```
|
|
192
|
+
|
|
174
193
|
## FAQ
|
|
175
194
|
|
|
176
195
|
**"Is this a Claude Code wrapper?"**
|
|
@@ -185,7 +204,7 @@ Named agents are **currently Claude Code only.** The Codex adapter has no equiva
|
|
|
185
204
|
Open the Context panel in the session input area. Pin a running terminal, a browser tab (requires the Clagentic: Console Chrome extension), or a sticky note. From that point on, every message you send automatically includes the latest content from those sources — terminal output as a delta since the last message, browser tabs as a full page snapshot. The injection happens before your message reaches the model; you don't need to mention the sources in your prompt.
|
|
186
205
|
|
|
187
206
|
**"What's the external trigger system?"**
|
|
188
|
-
Drop a JSON file into `~/.clagentic/external-triggers/`. The daemon picks it up within seconds. A v1 trigger spawns a new session with an `initialPrompt`. A v2 trigger can either spawn a session or inject a message into an existing session by `sessionId`. The file is archived to `processed/` on success. Unprocessed files survive daemon restarts. Use this to wire Claude into scripts, CI pipelines, cron jobs, or other AI processes.
|
|
207
|
+
Drop a JSON file into `~/.clagentic/console/external-triggers/`. The daemon picks it up within seconds. A v1 trigger spawns a new session with an `initialPrompt`. A v2 trigger can either spawn a session or inject a message into an existing session by `sessionId`. The file is archived to `processed/` on success. Unprocessed files survive daemon restarts. Use this to wire Claude into scripts, CI pipelines, cron jobs, or other AI processes.
|
|
189
208
|
|
|
190
209
|
**"What instruction files does it read?"**
|
|
191
210
|
YOKE scans the project directory for `CLAUDE.md`, `AGENTS.md`, `.cursorrules`, `COPILOT.md`, and `.github/copilot-instructions.md`. Each vendor reads some of these natively — Claude reads `CLAUDE.md`, Codex reads `AGENTS.md`. Files the active vendor doesn't read natively are merged and injected as additional context, so your project instructions reach the model regardless of which vendor is running.
|
|
@@ -209,7 +228,7 @@ Yes. CLI sessions appear in the sidebar and can be picked up in the CLI.
|
|
|
209
228
|
Yes. Install as a PWA on iOS or Android. Push notifications for approvals, errors, and task completion.
|
|
210
229
|
|
|
211
230
|
**"Does it work with MCP servers?"**
|
|
212
|
-
Yes. User-configured MCPs from `~/.clagentic/mcp.json` plus built-in ask-user and browser servers work in both Claude and Codex sessions.
|
|
231
|
+
Yes. User-configured MCPs from `~/.clagentic/console/mcp.json` plus built-in ask-user and browser servers work in both Claude and Codex sessions.
|
|
213
232
|
|
|
214
233
|
**"Multi-user support?"**
|
|
215
234
|
Yes — it is a core design goal, not an add-on. Real accounts, independent session history, and a Team panel that shows every human user and agent connected to the Console. On Linux, enable OS-level isolation: each user maps to a real Linux account, file ACLs via `setfacl`, processes spawn under the correct UID/GID.
|
package/bin/cli.js
CHANGED
|
@@ -51,7 +51,6 @@ var args = process.argv.slice(2);
|
|
|
51
51
|
var port = _isDev ? 2635 : 2633;
|
|
52
52
|
var useHttps = true;
|
|
53
53
|
var forceMkcert = false;
|
|
54
|
-
var forceBuiltin = false;
|
|
55
54
|
var skipUpdate = false;
|
|
56
55
|
var debugMode = false;
|
|
57
56
|
var autoYes = false;
|
|
@@ -84,8 +83,6 @@ for (var i = 0; i < args.length; i++) {
|
|
|
84
83
|
useHttps = false;
|
|
85
84
|
} else if (args[i] === "--local-cert") {
|
|
86
85
|
forceMkcert = true;
|
|
87
|
-
} else if (args[i] === "--builtin-cert") {
|
|
88
|
-
forceBuiltin = true;
|
|
89
86
|
} else if (args[i] === "--no-update" || args[i] === "--skip-update") {
|
|
90
87
|
skipUpdate = true;
|
|
91
88
|
} else if (args[i] === "--dev") {
|
|
@@ -133,7 +130,6 @@ for (var i = 0; i < args.length; i++) {
|
|
|
133
130
|
console.log(" --host <address> Address to bind to (default: 0.0.0.0)");
|
|
134
131
|
console.log(" --no-https Disable HTTPS (enabled by default)");
|
|
135
132
|
console.log(" --local-cert Use local certificate (mkcert), suppress migration notice");
|
|
136
|
-
console.log(" --builtin-cert Use builtin certificate even if mkcert is installed");
|
|
137
133
|
console.log(" --no-update Skip auto-update check on startup");
|
|
138
134
|
console.log(" --debug Enable debug panel in the web UI");
|
|
139
135
|
console.log(" -y, --yes Skip interactive prompts (accept defaults)");
|
|
@@ -632,45 +628,10 @@ function getAllIPs() {
|
|
|
632
628
|
return ips;
|
|
633
629
|
}
|
|
634
630
|
|
|
635
|
-
function getBuiltinCert() {
|
|
636
|
-
try {
|
|
637
|
-
var certDir = path.join(__dirname, "..", "lib", "certs");
|
|
638
|
-
var keyPath = path.join(certDir, "privkey.pem");
|
|
639
|
-
var certPath = path.join(certDir, "fullchain.pem");
|
|
640
|
-
if (!fs.existsSync(keyPath) || !fs.existsSync(certPath)) return null;
|
|
641
|
-
|
|
642
|
-
// Check expiry
|
|
643
|
-
var certText = execFileSync("openssl", [
|
|
644
|
-
"x509", "-in", certPath, "-noout", "-enddate"
|
|
645
|
-
], { encoding: "utf8" });
|
|
646
|
-
var m = certText.match(/notAfter=(.+)/);
|
|
647
|
-
if (m) {
|
|
648
|
-
var expiry = new Date(m[1]);
|
|
649
|
-
var now = new Date();
|
|
650
|
-
// Skip if expiring within 7 days
|
|
651
|
-
if (expiry.getTime() - now.getTime() < 7 * 24 * 60 * 60 * 1000) return null;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return { key: keyPath, cert: certPath, caRoot: null, builtin: true };
|
|
655
|
-
} catch (e) {
|
|
656
|
-
return null;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
function toClayStudioUrl(ip, port, protocol) {
|
|
661
|
-
var dashed = ip.replace(/\./g, "-");
|
|
662
|
-
return protocol + "://" + dashed + ".d.clay.studio:" + port;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
631
|
function ensureCerts(ip) {
|
|
666
|
-
//
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
if (builtin) return builtin;
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
var certDir = path.join(process.env.CLAGENTIC_HOME || process.env.CLAY_HOME || path.join(REAL_HOME, ".clagentic"), "certs");
|
|
632
|
+
// certs/ now lives under CONFIG_DIR (= ~/.clagentic/console/).
|
|
633
|
+
// Old location was ~/.clagentic/certs/ — migration runs in daemon.js on startup.
|
|
634
|
+
var certDir = path.join(CONFIG_DIR, "certs");
|
|
674
635
|
var keyPath = path.join(certDir, "key.pem");
|
|
675
636
|
var certPath = path.join(certDir, "cert.pem");
|
|
676
637
|
|
|
@@ -726,7 +687,7 @@ function ensureCerts(ip) {
|
|
|
726
687
|
var mkcertArgs = ["-key-file", keyPath, "-cert-file", certPath].concat(domains);
|
|
727
688
|
execFileSync("mkcert", mkcertArgs, { stdio: "pipe" });
|
|
728
689
|
} catch (err) {
|
|
729
|
-
// mkcert generation failed
|
|
690
|
+
// mkcert generation failed
|
|
730
691
|
}
|
|
731
692
|
|
|
732
693
|
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
@@ -734,28 +695,20 @@ function ensureCerts(ip) {
|
|
|
734
695
|
}
|
|
735
696
|
}
|
|
736
697
|
|
|
737
|
-
// Fallback: builtin cert (unless --local-cert forces mkcert-only)
|
|
738
|
-
if (!forceMkcert) {
|
|
739
|
-
var builtin = getBuiltinCert();
|
|
740
|
-
if (builtin) return builtin;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
698
|
return null;
|
|
744
699
|
}
|
|
745
700
|
|
|
746
701
|
// --- Logo ---
|
|
747
702
|
function printLogo() {
|
|
748
703
|
var r = a.reset;
|
|
704
|
+
// Clagentic: Console — startup banner (lr-5e26)
|
|
749
705
|
var lines = [
|
|
750
|
-
"
|
|
751
|
-
"
|
|
752
|
-
"
|
|
753
|
-
"
|
|
754
|
-
"
|
|
755
|
-
"
|
|
756
|
-
" __\\///\\\\\\__________\\/\\\\\\_____________\\/\\\\\\_______\\/\\\\\\_______\\/\\\\\\______",
|
|
757
|
-
" ____\\////\\\\\\\\\\\\\\\\\\_\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\/\\\\\\_______\\/\\\\\\_______\\/\\\\\\______",
|
|
758
|
-
" _______\\/////////__\\///////////////__\\///________\\///________\\///_______",
|
|
706
|
+
" ____ _ _ ____ _____ _ _ _____ ___ ____ ",
|
|
707
|
+
" / ___| | / \\ / ___| ____| \\ | |_ _|_ _/ ___| ",
|
|
708
|
+
"| | | | / _ \\| | _| _| | \\| | | | | | | ",
|
|
709
|
+
"| |___| |___ / ___ \\ |_| | |___| |\\ | | | | | |___ ",
|
|
710
|
+
" \\____|_____/_/ \\_\\____|_____|_| \\_| |_| |___\\____| ",
|
|
711
|
+
" : Console ",
|
|
759
712
|
];
|
|
760
713
|
console.log("");
|
|
761
714
|
if (isBasicTerm) {
|
|
@@ -1503,14 +1456,12 @@ function setup(callback) {
|
|
|
1503
1456
|
async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
|
|
1504
1457
|
var ip = getLocalIP();
|
|
1505
1458
|
var hasTls = false;
|
|
1506
|
-
var hasBuiltinCert = false;
|
|
1507
1459
|
var mkcertDetected = false;
|
|
1508
1460
|
|
|
1509
1461
|
if (useHttps) {
|
|
1510
1462
|
var certPaths = ensureCerts(ip);
|
|
1511
1463
|
if (certPaths) {
|
|
1512
1464
|
hasTls = true;
|
|
1513
|
-
if (certPaths.builtin) hasBuiltinCert = true;
|
|
1514
1465
|
if (certPaths.mkcertDetected) mkcertDetected = true;
|
|
1515
1466
|
} else {
|
|
1516
1467
|
log(sym.warn + " " + a.yellow + "HTTPS unavailable" + a.reset + a.dim + " · mkcert not installed" + a.reset);
|
|
@@ -1606,14 +1557,13 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
|
|
|
1606
1557
|
host: host,
|
|
1607
1558
|
pinHash: mode === "multi" && cliPin ? generateAuthToken(cliPin) : (prevConfig && prevConfig.pinHash) || null,
|
|
1608
1559
|
tls: hasTls,
|
|
1609
|
-
builtinCert: hasBuiltinCert,
|
|
1610
1560
|
mkcertDetected: mkcertDetected,
|
|
1611
1561
|
debug: debugMode,
|
|
1612
1562
|
headless: headlessMode,
|
|
1613
1563
|
keepAwake: keepAwake,
|
|
1614
1564
|
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1615
1565
|
osUsers: wantOsUsers || osUsersMode,
|
|
1616
|
-
mode: mode || "
|
|
1566
|
+
mode: mode || "multi",
|
|
1617
1567
|
setupCompleted: true,
|
|
1618
1568
|
projects: allProjects,
|
|
1619
1569
|
});
|
|
@@ -1682,12 +1632,9 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
|
|
|
1682
1632
|
// Headless mode — print status and exit immediately
|
|
1683
1633
|
if (headlessMode) {
|
|
1684
1634
|
var protocol = config.tls ? "https" : "http";
|
|
1685
|
-
var url = config.
|
|
1686
|
-
? toClayStudioUrl(ip, config.port, protocol)
|
|
1687
|
-
: protocol + "://" + ip + ":" + config.port;
|
|
1635
|
+
var url = protocol + "://" + ip + ":" + config.port;
|
|
1688
1636
|
console.log(" " + sym.done + " Daemon started (PID " + config.pid + ")");
|
|
1689
1637
|
console.log(" " + sym.done + " " + url);
|
|
1690
|
-
if (config.mkcertDetected) console.log(" " + sym.warn + " Clagentic: Console now ships with a builtin HTTPS certificate. To use it, pass --builtin-cert or uninstall mkcert.");
|
|
1691
1638
|
if (_pendingSetupCode) {
|
|
1692
1639
|
console.log("");
|
|
1693
1640
|
console.log(" " + sym.done + " " + a.green + "Multi-user mode enabled." + a.reset);
|
|
@@ -1709,14 +1656,12 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers) {
|
|
|
1709
1656
|
async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
|
|
1710
1657
|
var ip = getLocalIP();
|
|
1711
1658
|
var hasTls = false;
|
|
1712
|
-
var hasBuiltinCert = false;
|
|
1713
1659
|
var mkcertDetected = false;
|
|
1714
1660
|
|
|
1715
1661
|
if (useHttps) {
|
|
1716
1662
|
var certPaths = ensureCerts(ip);
|
|
1717
1663
|
if (certPaths) {
|
|
1718
1664
|
hasTls = true;
|
|
1719
|
-
if (certPaths.builtin) hasBuiltinCert = true;
|
|
1720
1665
|
if (certPaths.mkcertDetected) mkcertDetected = true;
|
|
1721
1666
|
}
|
|
1722
1667
|
}
|
|
@@ -1797,12 +1742,11 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers) {
|
|
|
1797
1742
|
host: host,
|
|
1798
1743
|
pinHash: existingPinHash || null,
|
|
1799
1744
|
tls: hasTls,
|
|
1800
|
-
builtinCert: hasBuiltinCert,
|
|
1801
1745
|
mkcertDetected: mkcertDetected,
|
|
1802
1746
|
debug: true,
|
|
1803
1747
|
keepAwake: keepAwake || false,
|
|
1804
1748
|
dangerouslySkipPermissions: dangerouslySkipPermissions,
|
|
1805
|
-
mode: mode || "
|
|
1749
|
+
mode: mode || "multi",
|
|
1806
1750
|
setupCompleted: true,
|
|
1807
1751
|
projects: allProjects,
|
|
1808
1752
|
osUsers: wantOsUsers || (prevDevConfig ? (prevDevConfig.osUsers || false) : false),
|
|
@@ -1954,7 +1898,6 @@ async function restartDaemonWithTLS(config, callback) {
|
|
|
1954
1898
|
callback(config);
|
|
1955
1899
|
return;
|
|
1956
1900
|
}
|
|
1957
|
-
var hasBuiltinCert = !!(certPaths && certPaths.builtin);
|
|
1958
1901
|
var mkcertDetected = !!(certPaths && certPaths.mkcertDetected);
|
|
1959
1902
|
|
|
1960
1903
|
// Shut down old daemon
|
|
@@ -1977,7 +1920,6 @@ async function restartDaemonWithTLS(config, callback) {
|
|
|
1977
1920
|
var newConfig = Object.assign({}, config, {
|
|
1978
1921
|
pid: null,
|
|
1979
1922
|
tls: true,
|
|
1980
|
-
builtinCert: hasBuiltinCert,
|
|
1981
1923
|
mkcertDetected: mkcertDetected,
|
|
1982
1924
|
});
|
|
1983
1925
|
|
|
@@ -2055,9 +1997,7 @@ function showServerStarted(config, ip, setupCode) {
|
|
|
2055
1997
|
function showMainMenu(config, ip, setupCode) {
|
|
2056
1998
|
startDaemonWatcher();
|
|
2057
1999
|
var protocol = config.tls ? "https" : "http";
|
|
2058
|
-
var url = config.
|
|
2059
|
-
? toClayStudioUrl(ip, config.port, protocol)
|
|
2060
|
-
: protocol + "://" + ip + ":" + config.port;
|
|
2000
|
+
var url = protocol + "://" + ip + ":" + config.port;
|
|
2061
2001
|
|
|
2062
2002
|
sendIPCCommand(socketPath(), { cmd: "get_status" }).then(function (status) {
|
|
2063
2003
|
var projs = (status && status.projects) || [];
|
|
@@ -2086,13 +2026,6 @@ function showMainMenu(config, ip, setupCode) {
|
|
|
2086
2026
|
log(" Press " + a.bold + "o" + a.reset + " to open in browser");
|
|
2087
2027
|
log("");
|
|
2088
2028
|
|
|
2089
|
-
if (config.mkcertDetected) {
|
|
2090
|
-
log(" " + sym.warn + " " + a.yellow + "Clagentic: Console now ships with a builtin HTTPS certificate." + a.reset);
|
|
2091
|
-
log(" " + a.dim + "No more CA setup on each device." + a.reset);
|
|
2092
|
-
log(" " + a.dim + "To use it, pass --builtin-cert or uninstall mkcert." + a.reset);
|
|
2093
|
-
log("");
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
2029
|
showMenuItems();
|
|
2097
2030
|
}
|
|
2098
2031
|
|
package/lib/agents-favorites.js
CHANGED
|
@@ -22,12 +22,27 @@
|
|
|
22
22
|
var fs = require("fs");
|
|
23
23
|
var path = require("path");
|
|
24
24
|
var os = require("os");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var FAVORITES_PATH = path.join(
|
|
25
|
+
var { CONFIG_DIR } = require("./config");
|
|
26
|
+
|
|
27
|
+
// chattable.json lives under the Console data dir (CONFIG_DIR = ~/.clagentic/console/).
|
|
28
|
+
// One-time migration: if the old root-level file exists and the new one does not,
|
|
29
|
+
// copy it so favorites/recents are preserved on upgrade.
|
|
30
|
+
var FAVORITES_PATH = path.join(CONFIG_DIR, "agents", "chattable.json");
|
|
31
|
+
(function migrateFavorites() {
|
|
32
|
+
var _realHome = process.env.SUDO_USER
|
|
33
|
+
? path.join("/home", process.env.SUDO_USER)
|
|
34
|
+
: os.homedir();
|
|
35
|
+
var oldPath = path.join(_realHome, ".clagentic", "agents", "chattable.json");
|
|
36
|
+
try {
|
|
37
|
+
if (fs.existsSync(oldPath) && !fs.existsSync(FAVORITES_PATH)) {
|
|
38
|
+
fs.mkdirSync(path.dirname(FAVORITES_PATH), { recursive: true });
|
|
39
|
+
fs.copyFileSync(oldPath, FAVORITES_PATH);
|
|
40
|
+
console.log("[agents-favorites] Migrated chattable.json → " + FAVORITES_PATH + " — root copy can be removed when verified");
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// Non-fatal — favorites will start fresh
|
|
44
|
+
}
|
|
45
|
+
}());
|
|
31
46
|
var SCHEMA_VERSION = 2;
|
|
32
47
|
var RECENTS_LIMIT = 8;
|
|
33
48
|
|
package/lib/config.js
CHANGED
|
@@ -31,7 +31,7 @@ function getRealHome() {
|
|
|
31
31
|
|
|
32
32
|
var REAL_HOME = getRealHome();
|
|
33
33
|
|
|
34
|
-
// Data dir: ~/.clagentic/ (prev: ~/.clay/ — migrated on first run)
|
|
34
|
+
// Data dir: ~/.clagentic/console/ (prev: ~/.clagentic/ root → moved to console/ subdir by lr-12d0; prev: ~/.clay/ — migrated on first run)
|
|
35
35
|
// If CLAGENTIC_CONFIG is set (daemon mode), derive CLAGENTIC_HOME from it.
|
|
36
36
|
// CLAY_HOME and CLAY_CONFIG accepted as fallbacks for one release.
|
|
37
37
|
var CLAGENTIC_HOME = process.env.CLAGENTIC_HOME
|
package/lib/daemon.js
CHANGED
|
@@ -23,7 +23,7 @@ delete process.env.CLAUDECODE;
|
|
|
23
23
|
|
|
24
24
|
var fs = require("fs");
|
|
25
25
|
var path = require("path");
|
|
26
|
-
var { loadConfig, saveConfig, socketPath, ensureConfigDir, generateSlug, syncClayrc, removeFromClayrc, writeCrashInfo, readCrashInfo, clearCrashInfo, isPidAlive, clearStaleConfig, REAL_HOME } = require("./config");
|
|
26
|
+
var { loadConfig, saveConfig, socketPath, ensureConfigDir, generateSlug, syncClayrc, removeFromClayrc, writeCrashInfo, readCrashInfo, clearCrashInfo, isPidAlive, clearStaleConfig, REAL_HOME, CONFIG_DIR, CLAGENTIC_HOME } = require("./config");
|
|
27
27
|
var { createIPCServer } = require("./ipc");
|
|
28
28
|
var { createServer } = require("./server");
|
|
29
29
|
var { checkAclSupport, grantProjectAccess, revokeProjectAccess, provisionAllUsers, provisionLinuxUser, grantAllUsersAccess, deactivateLinuxUser, ensureProjectsDir } = require("./os-users");
|
|
@@ -31,9 +31,12 @@ var usersModule = require("./users");
|
|
|
31
31
|
var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
|
|
32
32
|
var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
|
|
33
33
|
var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
|
|
34
|
-
var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM } = require("./sdk-bridge");
|
|
34
|
+
var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount } = require("./sdk-bridge");
|
|
35
|
+
var { startMemoryHighWatcher } = require("./memory-limits");
|
|
36
|
+
var { createDrain } = require("./drain");
|
|
35
37
|
var liteDetect = require("./lite-detect");
|
|
36
38
|
var { execFile: liteExecFile } = require("child_process");
|
|
39
|
+
var { SLUG_RE: CUSTOM_ICON_SLUG_RE, CUSTOM_EMOJI_CT } = require("./server-settings");
|
|
37
40
|
|
|
38
41
|
var daemonVersion = require("../package.json").version;
|
|
39
42
|
var configFile = process.env.CLAGENTIC_CONFIG || process.env.CLAY_CONFIG || require("./config").configPath();
|
|
@@ -169,7 +172,7 @@ function migrateSingleUserToMultiUser(cfg, data) {
|
|
|
169
172
|
console.log("│ │");
|
|
170
173
|
console.log("│ " + url.padEnd(61) + "│");
|
|
171
174
|
console.log("│ │");
|
|
172
|
-
console.log("│ Setup code also stored in ~/.clagentic/users.json
|
|
175
|
+
console.log("│ Setup code also stored in ~/.clagentic/console/users.json │");
|
|
173
176
|
console.log("│ Your previous PIN cannot be transferred (format change). │");
|
|
174
177
|
console.log("│ Set a new PIN via the setup URL above. │");
|
|
175
178
|
console.log("└─────────────────────────────────────────────────────────────┘");
|
|
@@ -194,27 +197,28 @@ if (config.osUsers) {
|
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
// --- TLS ---
|
|
200
|
+
// One-time migration: certs dir moved from ~/.clagentic/certs/ → CONFIG_DIR/certs/ (lr-6204).
|
|
201
|
+
// Copy-not-rename: the old location stays so a rollback is safe.
|
|
202
|
+
// We run this before reading certs so a fresh start after upgrade picks them up immediately.
|
|
203
|
+
(function migrateCertsDir() {
|
|
204
|
+
var oldCerts = path.join(CLAGENTIC_HOME, "certs");
|
|
205
|
+
var newCerts = path.join(CONFIG_DIR, "certs");
|
|
206
|
+
try {
|
|
207
|
+
if (fs.existsSync(oldCerts) && !fs.existsSync(newCerts)) {
|
|
208
|
+
fs.cpSync(oldCerts, newCerts, { recursive: true, preserveTimestamps: true });
|
|
209
|
+
console.log("[daemon] Migrated certs/ → " + newCerts + " — root copy can be removed when verified");
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {
|
|
212
|
+
console.error("[daemon] Certs migration failed (non-fatal):", e.message);
|
|
213
|
+
}
|
|
214
|
+
}());
|
|
197
215
|
var tlsOptions = null;
|
|
198
216
|
if (config.tls) {
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var os = require("os");
|
|
205
|
-
var certDir = path.join(process.env.CLAGENTIC_HOME || process.env.CLAY_HOME || path.join(REAL_HOME, ".clagentic"), "certs");
|
|
206
|
-
var userKeyPath = path.join(certDir, "key.pem");
|
|
207
|
-
var userCertPath = path.join(certDir, "cert.pem");
|
|
208
|
-
|
|
209
|
-
var keyPath, certPath;
|
|
210
|
-
if (config.builtinCert !== false && fs.existsSync(builtinKeyPath) && fs.existsSync(builtinCertPath)) {
|
|
211
|
-
keyPath = builtinKeyPath;
|
|
212
|
-
certPath = builtinCertPath;
|
|
213
|
-
config.builtinCert = true;
|
|
214
|
-
} else {
|
|
215
|
-
keyPath = userKeyPath;
|
|
216
|
-
certPath = userCertPath;
|
|
217
|
-
}
|
|
217
|
+
// User cert (CONFIG_DIR/certs/key.pem + cert.pem, generated by mkcert or supplied manually).
|
|
218
|
+
// Old location was ~/.clagentic/certs/ — migrated above on first run.
|
|
219
|
+
var certDir = path.join(CONFIG_DIR, "certs");
|
|
220
|
+
var keyPath = path.join(certDir, "key.pem");
|
|
221
|
+
var certPath = path.join(certDir, "cert.pem");
|
|
218
222
|
|
|
219
223
|
try {
|
|
220
224
|
tlsOptions = {
|
|
@@ -750,6 +754,99 @@ var relay = createServer({
|
|
|
750
754
|
});
|
|
751
755
|
return { ok: true };
|
|
752
756
|
},
|
|
757
|
+
// Rename a custom-icon upload: oldSlug -> newSlug. Rewrites every
|
|
758
|
+
// config.projects[].icon and config.folderMeta[].icon reference that
|
|
759
|
+
// pointed at the old ":oldSlug:" sentinel, renames the file on disk, and
|
|
760
|
+
// broadcasts the updated project/folder list — all as one atomic op
|
|
761
|
+
// (lr-d1d9, LOCKED DECISION: rewrite references, not block-on-in-use).
|
|
762
|
+
// Doing this as a WS op (rather than a bare HTTP route) is what makes the
|
|
763
|
+
// file-rename + reference-rewrite + broadcast atomic: the daemon holds both
|
|
764
|
+
// the on-disk custom-emoji file and the in-memory config.projects/folderMeta
|
|
765
|
+
// that reference it, so there's no window where they can observably diverge.
|
|
766
|
+
onRenameCustomIcon: function (oldSlug, newSlug) {
|
|
767
|
+
if (typeof oldSlug !== "string" || typeof newSlug !== "string") {
|
|
768
|
+
return { ok: false, error: "Missing oldSlug or newSlug" };
|
|
769
|
+
}
|
|
770
|
+
if (!CUSTOM_ICON_SLUG_RE.test(oldSlug) || !CUSTOM_ICON_SLUG_RE.test(newSlug)) {
|
|
771
|
+
return { ok: false, error: "Invalid slug" };
|
|
772
|
+
}
|
|
773
|
+
if (oldSlug === newSlug) {
|
|
774
|
+
return { ok: false, error: "New slug must differ from the current slug" };
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
var customEmojiDir = path.join(CONFIG_DIR, "custom-emoji");
|
|
778
|
+
var oldFile = null;
|
|
779
|
+
var oldExt = null;
|
|
780
|
+
var newSlugExists = false;
|
|
781
|
+
try {
|
|
782
|
+
// Scan the FULL directory (no early break) — the newSlug collision
|
|
783
|
+
// check must run even when oldSlug's file happens to sort before
|
|
784
|
+
// newSlug's file in readdirSync order (e.g. alphabetically).
|
|
785
|
+
var existingFiles = fs.readdirSync(customEmojiDir);
|
|
786
|
+
for (var efi = 0; efi < existingFiles.length; efi++) {
|
|
787
|
+
var ef = existingFiles[efi];
|
|
788
|
+
var efExt = path.extname(ef).slice(1);
|
|
789
|
+
if (!CUSTOM_EMOJI_CT[efExt]) continue;
|
|
790
|
+
var efBasename = path.basename(ef, "." + efExt);
|
|
791
|
+
if (efBasename === oldSlug) { oldFile = ef; oldExt = efExt; }
|
|
792
|
+
// A 409 on newSlug must catch a collision regardless of extension.
|
|
793
|
+
if (efBasename === newSlug) { newSlugExists = true; }
|
|
794
|
+
}
|
|
795
|
+
} catch (e) {
|
|
796
|
+
return { ok: false, error: "Custom icon storage unavailable" };
|
|
797
|
+
}
|
|
798
|
+
if (newSlugExists) {
|
|
799
|
+
return { ok: false, error: "A custom icon named \"" + newSlug + "\" already exists" };
|
|
800
|
+
}
|
|
801
|
+
if (!oldFile) {
|
|
802
|
+
return { ok: false, error: "Custom icon \"" + oldSlug + "\" not found" };
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// Defense-in-depth: resolve both paths and confirm they stay within
|
|
806
|
+
// customEmojiDir, mirroring the safePath/resolve-prefix guard used by the
|
|
807
|
+
// existing POST/GET/DELETE routes in server-settings.js.
|
|
808
|
+
var oldPath = path.join(customEmojiDir, oldFile);
|
|
809
|
+
var newFile = newSlug + "." + oldExt;
|
|
810
|
+
var newPath = path.join(customEmojiDir, newFile);
|
|
811
|
+
var resolvedOld = path.resolve(customEmojiDir, oldFile);
|
|
812
|
+
var resolvedNew = path.resolve(customEmojiDir, newFile);
|
|
813
|
+
if (!resolvedOld.startsWith(customEmojiDir + path.sep) || !resolvedNew.startsWith(customEmojiDir + path.sep)) {
|
|
814
|
+
return { ok: false, error: "Invalid path" };
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
try {
|
|
818
|
+
fs.renameSync(oldPath, newPath);
|
|
819
|
+
} catch (e) {
|
|
820
|
+
return { ok: false, error: "Rename failed: " + e.message };
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// Rewrite every reference to the old sentinel across projects + folders.
|
|
824
|
+
var oldSentinel = ":" + oldSlug + ":";
|
|
825
|
+
var newSentinel = ":" + newSlug + ":";
|
|
826
|
+
for (var pi = 0; pi < config.projects.length; pi++) {
|
|
827
|
+
if (config.projects[pi].icon === oldSentinel) {
|
|
828
|
+
config.projects[pi].icon = newSentinel;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (config.folderMeta) {
|
|
832
|
+
var folderNames = Object.keys(config.folderMeta);
|
|
833
|
+
for (var fni = 0; fni < folderNames.length; fni++) {
|
|
834
|
+
var fMeta = config.folderMeta[folderNames[fni]];
|
|
835
|
+
if (fMeta && fMeta.icon === oldSentinel) {
|
|
836
|
+
fMeta.icon = newSentinel;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
saveConfig(config);
|
|
841
|
+
try { syncClayrc(config.projects); } catch (e) {}
|
|
842
|
+
relay.broadcastAll({
|
|
843
|
+
type: "projects_updated",
|
|
844
|
+
projects: relay.getProjects(),
|
|
845
|
+
projectCount: config.projects.length,
|
|
846
|
+
folderMeta: config.folderMeta || {},
|
|
847
|
+
});
|
|
848
|
+
return { ok: true, slug: newSlug, url: "/api/custom-emoji/" + newSlug };
|
|
849
|
+
},
|
|
753
850
|
onProjectOwnerChanged: function (slug, ownerId) {
|
|
754
851
|
console.log("[daemon] onProjectOwnerChanged:", slug, "→", ownerId);
|
|
755
852
|
var oldOwnerId = null;
|
|
@@ -1287,6 +1384,10 @@ function stopCodexReaper() {
|
|
|
1287
1384
|
clearInterval(staleCheckHandle);
|
|
1288
1385
|
staleCheckHandle = null;
|
|
1289
1386
|
}
|
|
1387
|
+
if (_memoryWatcher) {
|
|
1388
|
+
_memoryWatcher.stop();
|
|
1389
|
+
_memoryWatcher = null;
|
|
1390
|
+
}
|
|
1290
1391
|
}
|
|
1291
1392
|
|
|
1292
1393
|
function shutdownProjects() {
|
|
@@ -1632,6 +1733,30 @@ function startListening() {
|
|
|
1632
1733
|
config.pid = process.pid;
|
|
1633
1734
|
saveConfig(config);
|
|
1634
1735
|
|
|
1736
|
+
// Drain controller (lr-6b30): manages graceful drain state.
|
|
1737
|
+
// Must be created after gracefulShutdown is defined (which is true here —
|
|
1738
|
+
// gracefulShutdown is a hoisted function declared before startListening).
|
|
1739
|
+
var drainTimeoutMs = (config.drainTimeoutMs != null && config.drainTimeoutMs > 0)
|
|
1740
|
+
? config.drainTimeoutMs
|
|
1741
|
+
: undefined;
|
|
1742
|
+
_drain = createDrain({
|
|
1743
|
+
gracefulShutdown: gracefulShutdown,
|
|
1744
|
+
getActiveCount: getActiveLiveCount,
|
|
1745
|
+
drainTimeoutMs: drainTimeoutMs,
|
|
1746
|
+
});
|
|
1747
|
+
_drain.registerSignals();
|
|
1748
|
+
// Expose the drain controller on the relay so server.js can gate new connections.
|
|
1749
|
+
relay.setDrain(_drain);
|
|
1750
|
+
|
|
1751
|
+
// Start MemoryHigh watermark watcher (lr-de07).
|
|
1752
|
+
// Detects soft memory ceiling crossings and emits structured log events;
|
|
1753
|
+
// onCrossing notifies the drain controller (lr-6b30) to enter drain state.
|
|
1754
|
+
if (process.platform === "linux") {
|
|
1755
|
+
_memoryWatcher = startMemoryHighWatcher(config, {
|
|
1756
|
+
onCrossing: function (detail) { _drain.onMemoryHighCrossing(detail); },
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1635
1760
|
// Auto-provision Linux accounts on startup if OS users mode is enabled.
|
|
1636
1761
|
// ACLs are NOT re-applied on every startup (too slow with recursive setfacl).
|
|
1637
1762
|
// ACLs are set when: projects are added, users are added, or visibility changes.
|
|
@@ -1712,6 +1837,12 @@ if (relay.onboardingServer) {
|
|
|
1712
1837
|
});
|
|
1713
1838
|
}
|
|
1714
1839
|
|
|
1840
|
+
// MemoryHigh watcher handle (lr-de07) — started after the server is listening.
|
|
1841
|
+
var _memoryWatcher = null;
|
|
1842
|
+
|
|
1843
|
+
// Drain controller (lr-6b30) — initialized in startListening after gracefulShutdown is defined.
|
|
1844
|
+
var _drain = null;
|
|
1845
|
+
|
|
1715
1846
|
// --- Caffeinate (macOS) ---
|
|
1716
1847
|
var caffeinateProc = null;
|
|
1717
1848
|
if (config.keepAwake && process.platform === "darwin") {
|