@clagentic/console 1.9.0 → 1.10.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/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/memory-shed.js +13 -32
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +37 -22
- package/lib/project-external-trigger.js +166 -105
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +17 -9
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// build-update-standing.js — the one standing "newer build installed" offer.
|
|
4
|
+
//
|
|
5
|
+
// The offer is level-triggered. After every build poll the daemon calls
|
|
6
|
+
// reconcile() with the DESIRED state (the confirmed stale assessment, or null),
|
|
7
|
+
// and this module changes only the difference between that and what clients
|
|
8
|
+
// were last shown: show, refresh in place, or retract. Calling it again with the
|
|
9
|
+
// same input changes nothing and broadcasts nothing. There are no announce and
|
|
10
|
+
// retract events for another module to keep in step with.
|
|
11
|
+
//
|
|
12
|
+
// While the build is genuinely stale an actionable offer is always visible: it
|
|
13
|
+
// is shown at once, with its change list marked unavailable, and refreshed in
|
|
14
|
+
// place when a read succeeds. A slow, failed or throwing read never removes or
|
|
15
|
+
// withholds the restart action.
|
|
16
|
+
//
|
|
17
|
+
// It broadcasts; it never restarts anything (that is
|
|
18
|
+
// lib/build-update-restart.js, on a confirmed click).
|
|
19
|
+
|
|
20
|
+
var SOURCE = 'build-update';
|
|
21
|
+
|
|
22
|
+
var READING = 'the change list is still being read';
|
|
23
|
+
var FAILED_REASON = 'the change list could not be read';
|
|
24
|
+
|
|
25
|
+
// What the change list looks like to a client, ordered by what can change it.
|
|
26
|
+
var PENDING = 'pending';
|
|
27
|
+
var LISTED = 'listed';
|
|
28
|
+
var FAILED = 'failed';
|
|
29
|
+
|
|
30
|
+
function unavailable(reason) {
|
|
31
|
+
return { available: false, commits: [], truncated: false, reason: reason };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function offerKeyOf(a) {
|
|
35
|
+
return a.loadedBuildSha + ':' + a.installedBuildSha + ':' + a.installedContentHash;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The change list depends only on the two builds, not on the content hash.
|
|
39
|
+
function readKeyOf(a) {
|
|
40
|
+
return a.loadedBuildSha + ':' + a.installedBuildSha;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {object} o
|
|
45
|
+
* @param {function(object): Promise<object>} o.listChanges — ({fromSha, toSha}) -> changes
|
|
46
|
+
* @param {function(object, object): object} o.compose — (assessment, changes) -> diagnostic message
|
|
47
|
+
* @param {function(object): void} o.broadcast — sends a message to every connected client
|
|
48
|
+
* @param {function(): ?object} o.desired — the CURRENT desired assessment (confirmed stale) or null
|
|
49
|
+
* @param {number} [o.retryAfterMs] — minimum time between retries of a failed read
|
|
50
|
+
* @param {function(): number} [o.now]
|
|
51
|
+
* @param {function(string): void} [o.log]
|
|
52
|
+
*/
|
|
53
|
+
function createStandingOffer(o) {
|
|
54
|
+
var log = typeof o.log === 'function' ? o.log : function () {};
|
|
55
|
+
var now = typeof o.now === 'function' ? o.now : Date.now;
|
|
56
|
+
var retryAfterMs = o.retryAfterMs >= 0 ? o.retryAfterMs : 30 * 60 * 1000;
|
|
57
|
+
|
|
58
|
+
// What clients were last shown: {offerKey, changeListStatus, message}, set only
|
|
59
|
+
// after the broadcast succeeded.
|
|
60
|
+
var shown = null;
|
|
61
|
+
// readKey -> {status, changes, reason, failedAt, inFlight}
|
|
62
|
+
var reads = {};
|
|
63
|
+
|
|
64
|
+
function describe(e) { return e && e.message ? e.message : String(e); }
|
|
65
|
+
|
|
66
|
+
function readChanges(a) {
|
|
67
|
+
// A synchronous throw from the reader is a failed read like a rejection.
|
|
68
|
+
try {
|
|
69
|
+
return Promise.resolve(o.listChanges({ fromSha: a.loadedBuildSha, toSha: a.installedBuildSha }));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return Promise.reject(e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function startRead(a, key) {
|
|
76
|
+
var entry = reads[key] || { status: PENDING, changes: null, reason: null, failedAt: 0, inFlight: false };
|
|
77
|
+
reads[key] = entry;
|
|
78
|
+
entry.inFlight = true;
|
|
79
|
+
readChanges(a).then(function (changes) {
|
|
80
|
+
entry.inFlight = false;
|
|
81
|
+
entry.status = LISTED;
|
|
82
|
+
entry.changes = changes;
|
|
83
|
+
}, function (err) {
|
|
84
|
+
entry.inFlight = false;
|
|
85
|
+
// A list already read stays; otherwise the failure and its reason are cached.
|
|
86
|
+
if (entry.status !== LISTED) {
|
|
87
|
+
entry.status = FAILED;
|
|
88
|
+
entry.reason = FAILED_REASON;
|
|
89
|
+
}
|
|
90
|
+
entry.failedAt = now();
|
|
91
|
+
// The detail stays in the journal; clients get only the reason class.
|
|
92
|
+
log('Could not read the changes for the build-update offer: ' + describe(err));
|
|
93
|
+
}).then(function () {
|
|
94
|
+
// Always against the LATEST desired state, never the one this read started
|
|
95
|
+
// under, so an obsolete result cannot restore an offer.
|
|
96
|
+
var latest;
|
|
97
|
+
try {
|
|
98
|
+
latest = o.desired();
|
|
99
|
+
} catch (e) {
|
|
100
|
+
log('Could not read the current build assessment: ' + describe(e));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
reconcile(latest);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function changesFor(entry) {
|
|
108
|
+
if (entry.status === LISTED) return entry.changes;
|
|
109
|
+
if (entry.status === FAILED) return unavailable(entry.reason);
|
|
110
|
+
return unavailable(READING);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function retract() {
|
|
114
|
+
o.broadcast({ type: 'diagnostic_retract', source: SOURCE });
|
|
115
|
+
shown = null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function prune(keepKey) {
|
|
119
|
+
Object.keys(reads).forEach(function (k) {
|
|
120
|
+
if (k !== keepKey && !reads[k].inFlight) delete reads[k];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function reconcileUnsafe(desired) {
|
|
125
|
+
if (!desired) {
|
|
126
|
+
if (shown !== null) retract();
|
|
127
|
+
prune(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
var offerKey = offerKeyOf(desired);
|
|
131
|
+
var readKey = readKeyOf(desired);
|
|
132
|
+
var entry = reads[readKey];
|
|
133
|
+
if (!entry) {
|
|
134
|
+
startRead(desired, readKey);
|
|
135
|
+
entry = reads[readKey];
|
|
136
|
+
} else if (!entry.inFlight && entry.status === FAILED && now() - entry.failedAt >= retryAfterMs) {
|
|
137
|
+
startRead(desired, readKey);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var summary = { offerKey: offerKey, changeListStatus: entry.status };
|
|
141
|
+
if (shown !== null && shown.offerKey === summary.offerKey && shown.changeListStatus === summary.changeListStatus) {
|
|
142
|
+
prune(readKey);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var message = o.compose(desired, changesFor(entry));
|
|
147
|
+
// A different build replaces the offer; the same build is refreshed in place
|
|
148
|
+
// (never retracted first, so the restart action does not flicker).
|
|
149
|
+
var refresh = shown !== null && shown.offerKey === summary.offerKey;
|
|
150
|
+
if (shown !== null && !refresh) retract();
|
|
151
|
+
// The stored copy, replayed to a client that connects later, is a plain
|
|
152
|
+
// diagnostic; `refresh` tells a client already holding the entry to update it
|
|
153
|
+
// and not to bring back one the operator dismissed.
|
|
154
|
+
o.broadcast(refresh ? Object.assign({}, message, { refresh: true }) : message);
|
|
155
|
+
shown = { offerKey: summary.offerKey, changeListStatus: summary.changeListStatus, message: message };
|
|
156
|
+
prune(readKey);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Bring what clients see in line with `desired`. Idempotent; never throws:
|
|
161
|
+
* the poll loop that calls it must survive a compose or broadcast failure,
|
|
162
|
+
* and the next poll retries because nothing is recorded as shown until the
|
|
163
|
+
* broadcast has succeeded.
|
|
164
|
+
*/
|
|
165
|
+
function reconcile(desired) {
|
|
166
|
+
try {
|
|
167
|
+
reconcileUnsafe(desired);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
log('Could not reconcile the build-update offer: ' + describe(e));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
reconcile: reconcile,
|
|
175
|
+
/** What a client that connects now should be shown, or null when no offer stands. */
|
|
176
|
+
current: function () { return shown === null ? null : shown.message; },
|
|
177
|
+
/** The state to send a client on connect: the held offer, or an explicit "no offer". */
|
|
178
|
+
forNewClient: function () {
|
|
179
|
+
return shown === null ? { type: 'diagnostic_retract', source: SOURCE } : shown.message;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
module.exports = { createStandingOffer: createStandingOffer, SOURCE: SOURCE };
|
package/lib/cli/daemon-launch.js
CHANGED
|
@@ -22,6 +22,9 @@ var {
|
|
|
22
22
|
loadClayrc, readCrashInfo, CONFIG_DIR, CLAGENTIC_HOME,
|
|
23
23
|
} = require("../config");
|
|
24
24
|
var { sendIPCCommand } = require("../ipc");
|
|
25
|
+
// A daemon this CLI starts is not a service manager's main process, whatever
|
|
26
|
+
// environment the CLI itself was run from.
|
|
27
|
+
var { unsupervisedEnv } = require("../supervisor");
|
|
25
28
|
var { hasAdmin, getSetupCode, hashPin } = require("../users");
|
|
26
29
|
var { log, sym, a } = require("./tui");
|
|
27
30
|
var { getLocalIP, ensureCerts, isPortFree } = require("./net-detect");
|
|
@@ -190,8 +193,8 @@ async function restartDaemonFromConfig(opts) {
|
|
|
190
193
|
|
|
191
194
|
// Debug mode: run in foreground with logs to stdout
|
|
192
195
|
if (opts.debugMode) {
|
|
193
|
-
process.env.
|
|
194
|
-
process.env.
|
|
196
|
+
process.env.CLAGENTIC_CONSOLE_CONFIG = configPath();
|
|
197
|
+
process.env.CLAGENTIC_CONSOLE_HOME = CLAGENTIC_HOME;
|
|
195
198
|
newConfig.pid = process.pid;
|
|
196
199
|
saveConfig(newConfig);
|
|
197
200
|
require(daemonScript);
|
|
@@ -205,9 +208,9 @@ async function restartDaemonFromConfig(opts) {
|
|
|
205
208
|
detached: true,
|
|
206
209
|
windowsHide: true,
|
|
207
210
|
stdio: ["ignore", logFd, logFd],
|
|
208
|
-
env: Object.assign(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
212
|
+
CLAGENTIC_CONSOLE_CONFIG: configPath(),
|
|
213
|
+
CLAGENTIC_CONSOLE_HOME: CLAGENTIC_HOME,
|
|
211
214
|
}),
|
|
212
215
|
});
|
|
213
216
|
child.unref();
|
|
@@ -311,7 +314,7 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers, c
|
|
|
311
314
|
if (addCwd) {
|
|
312
315
|
var slug = generateSlug(cwd, []);
|
|
313
316
|
var cwdEntry = { path: cwd, slug: slug, addedAt: Date.now() };
|
|
314
|
-
// Restore title/icon from
|
|
317
|
+
// Restore title/icon from the recent-projects file if available
|
|
315
318
|
var cwdRc = loadClayrc();
|
|
316
319
|
var cwdRecent = cwdRc.recentProjects || [];
|
|
317
320
|
for (var cr = 0; cr < cwdRecent.length; cr++) {
|
|
@@ -329,7 +332,7 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers, c
|
|
|
329
332
|
usedSlugs.push(slug);
|
|
330
333
|
}
|
|
331
334
|
|
|
332
|
-
// Add restored projects (from
|
|
335
|
+
// Add restored projects (from the recent-projects file)
|
|
333
336
|
if (extraProjects && extraProjects.length > 0) {
|
|
334
337
|
for (var ep = 0; ep < extraProjects.length; ep++) {
|
|
335
338
|
var rp = extraProjects[ep];
|
|
@@ -371,8 +374,8 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers, c
|
|
|
371
374
|
|
|
372
375
|
// Debug mode: run in foreground with logs to stdout
|
|
373
376
|
if (cliOpts.debugMode) {
|
|
374
|
-
process.env.
|
|
375
|
-
process.env.
|
|
377
|
+
process.env.CLAGENTIC_CONSOLE_CONFIG = configPath();
|
|
378
|
+
process.env.CLAGENTIC_CONSOLE_HOME = CLAGENTIC_HOME;
|
|
376
379
|
config.pid = process.pid;
|
|
377
380
|
saveConfig(config);
|
|
378
381
|
require(daemonScript);
|
|
@@ -386,9 +389,9 @@ async function forkDaemon(mode, keepAwake, extraProjects, addCwd, wantOsUsers, c
|
|
|
386
389
|
detached: true,
|
|
387
390
|
windowsHide: true,
|
|
388
391
|
stdio: ["ignore", logFd, logFd],
|
|
389
|
-
env: Object.assign(
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
393
|
+
CLAGENTIC_CONSOLE_CONFIG: configPath(),
|
|
394
|
+
CLAGENTIC_CONSOLE_HOME: CLAGENTIC_HOME,
|
|
392
395
|
}),
|
|
393
396
|
});
|
|
394
397
|
child.unref();
|
|
@@ -505,7 +508,7 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers, cliOpts) {
|
|
|
505
508
|
var restorable = (rc.recentProjects || []).filter(function (p) {
|
|
506
509
|
return p.path !== cwd && fs.existsSync(p.path);
|
|
507
510
|
});
|
|
508
|
-
// Restore title/icon for cwd from
|
|
511
|
+
// Restore title/icon for cwd from the recent-projects file
|
|
509
512
|
var rcAll = rc.recentProjects || [];
|
|
510
513
|
for (var ci = 0; ci < rcAll.length; ci++) {
|
|
511
514
|
if (rcAll[ci].path === cwd) {
|
|
@@ -569,9 +572,9 @@ async function devMode(mode, keepAwake, existingPinHash, wantOsUsers, cliOpts) {
|
|
|
569
572
|
function spawnDaemon() {
|
|
570
573
|
child = spawn(process.execPath, [daemonScript], {
|
|
571
574
|
stdio: ["ignore", "inherit", "inherit"],
|
|
572
|
-
env: Object.assign(
|
|
573
|
-
|
|
574
|
-
|
|
575
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
576
|
+
CLAGENTIC_CONSOLE_CONFIG: configPath(),
|
|
577
|
+
CLAGENTIC_CONSOLE_HOME: CLAGENTIC_HOME,
|
|
575
578
|
}),
|
|
576
579
|
});
|
|
577
580
|
|
|
@@ -734,9 +737,9 @@ async function _restartDaemonWithTLS(config, callback, cliOpts) {
|
|
|
734
737
|
detached: true,
|
|
735
738
|
windowsHide: true,
|
|
736
739
|
stdio: ["ignore", logFd, logFd],
|
|
737
|
-
env: Object.assign(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
741
|
+
CLAGENTIC_CONSOLE_CONFIG: configPath(),
|
|
742
|
+
CLAGENTIC_CONSOLE_HOME: CLAGENTIC_HOME,
|
|
740
743
|
}),
|
|
741
744
|
});
|
|
742
745
|
child.unref();
|
|
@@ -761,9 +764,9 @@ async function _restartDaemonWithTLS(config, callback, cliOpts) {
|
|
|
761
764
|
detached: true,
|
|
762
765
|
windowsHide: true,
|
|
763
766
|
stdio: ["ignore", logFd2, logFd2],
|
|
764
|
-
env: Object.assign(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
+
env: Object.assign(unsupervisedEnv(), {
|
|
768
|
+
CLAGENTIC_CONSOLE_CONFIG: configPath(),
|
|
769
|
+
CLAGENTIC_CONSOLE_HOME: CLAGENTIC_HOME,
|
|
767
770
|
}),
|
|
768
771
|
});
|
|
769
772
|
child2.unref();
|
|
@@ -217,6 +217,12 @@ function handleProcessBuildStatus() {
|
|
|
217
217
|
// formatted output).
|
|
218
218
|
console.log(JSON.stringify({
|
|
219
219
|
loadedBuildSha: res.loadedBuildSha,
|
|
220
|
+
installedBuildSha: res.installedBuildSha,
|
|
221
|
+
state: res.state,
|
|
222
|
+
reason: res.reason,
|
|
223
|
+
detail: res.detail,
|
|
224
|
+
loadedContentHash: res.loadedContentHash,
|
|
225
|
+
installedContentHash: res.installedContentHash,
|
|
220
226
|
staleInodes: res.staleInodes,
|
|
221
227
|
pid: res.pid,
|
|
222
228
|
}, null, 2));
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// lib/cli/session-subcommands.js
|
|
2
|
+
//
|
|
3
|
+
// `clagentic-console open-session` and `clagentic-console send-input`: open a
|
|
4
|
+
// session in a project, or send input to one, through the running daemon's IPC
|
|
5
|
+
// socket. Both print the daemon's result as JSON on stdout and exit 0 when the
|
|
6
|
+
// request was acted on (opened, delivered, resumed-and-delivered), 1 otherwise
|
|
7
|
+
// (not-found, refused, error), so a script can branch on either.
|
|
8
|
+
|
|
9
|
+
var fs = require("fs");
|
|
10
|
+
|
|
11
|
+
var { loadConfig, socketPath, isDaemonAliveAsync } = require("../config");
|
|
12
|
+
var { sendIPCCommand } = require("../ipc");
|
|
13
|
+
|
|
14
|
+
// A resumed session starts a runtime before the call answers: longer than the
|
|
15
|
+
// IPC default.
|
|
16
|
+
var IPC_TIMEOUT_MS = 30000;
|
|
17
|
+
|
|
18
|
+
var FLAGS = {
|
|
19
|
+
"--project": "projectSlug",
|
|
20
|
+
"--session": "sessionId",
|
|
21
|
+
"--prompt": "prompt",
|
|
22
|
+
"--vendor": "vendor",
|
|
23
|
+
"--agent": "agentName",
|
|
24
|
+
"--visibility": "sessionVisibility",
|
|
25
|
+
"--initiator": "initiator",
|
|
26
|
+
"--context-note": "contextNote",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var USAGE = {
|
|
30
|
+
"open-session": "Usage: clagentic-console open-session --project <slug> --prompt <text|-> [--vendor <id>] [--agent <name>] [--visibility shared|private] [--initiator <kind>] [--context-note <text>]",
|
|
31
|
+
"send-input": "Usage: clagentic-console send-input --project <slug> --session <id> --prompt <text|-> [--initiator <kind>] [--context-note <text>]",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var ALLOWED = {
|
|
35
|
+
"open-session": ["projectSlug", "prompt", "vendor", "agentName", "sessionVisibility", "initiator", "contextNote"],
|
|
36
|
+
"send-input": ["projectSlug", "sessionId", "prompt", "initiator", "contextNote"],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var REQUIRED = {
|
|
40
|
+
"open-session": ["projectSlug", "prompt"],
|
|
41
|
+
"send-input": ["projectSlug", "sessionId", "prompt"],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var IPC_COMMAND = {
|
|
45
|
+
"open-session": "open_session",
|
|
46
|
+
"send-input": "send_session_input",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Parses the arguments after the verb. Returns { request } or { error }.
|
|
50
|
+
// Pure: reading a "-" prompt from stdin is the handler's job.
|
|
51
|
+
function parseSessionArgs(verb, args) {
|
|
52
|
+
var allowed = ALLOWED[verb];
|
|
53
|
+
var request = {};
|
|
54
|
+
for (var i = 0; i < args.length; i++) {
|
|
55
|
+
var key = Object.prototype.hasOwnProperty.call(FLAGS, args[i]) ? FLAGS[args[i]] : null;
|
|
56
|
+
if (!key || allowed.indexOf(key) === -1) return { error: "Unknown option for " + verb + ": " + args[i] };
|
|
57
|
+
if (i + 1 >= args.length) return { error: "Missing value for " + args[i] };
|
|
58
|
+
request[key] = args[++i];
|
|
59
|
+
}
|
|
60
|
+
var required = REQUIRED[verb];
|
|
61
|
+
for (var r = 0; r < required.length; r++) {
|
|
62
|
+
if (!request[required[r]]) {
|
|
63
|
+
var flag = Object.keys(FLAGS).filter(function (f) { return FLAGS[f] === required[r]; })[0];
|
|
64
|
+
return { error: "Missing required option " + flag };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { request: request };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The IPC layer reports its own failures (timeout, refused connection) as
|
|
71
|
+
// { ok: false, error }; give them the same result shape as the daemon's.
|
|
72
|
+
function normalizeResponse(res) {
|
|
73
|
+
if (res && typeof res === "object" && res.result) return res;
|
|
74
|
+
var reason = res && res.error ? String(res.error) : "unexpected response from the daemon";
|
|
75
|
+
return { ok: false, result: "error", reason: reason };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fail(message) {
|
|
79
|
+
console.error(message);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function runSessionVerb(verb, args) {
|
|
84
|
+
var parsed = parseSessionArgs(verb, args);
|
|
85
|
+
if (parsed.error) {
|
|
86
|
+
console.error(parsed.error);
|
|
87
|
+
fail(USAGE[verb]);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var request = parsed.request;
|
|
91
|
+
if (request.prompt === "-") {
|
|
92
|
+
request.prompt = fs.readFileSync(0, "utf8").replace(/\n$/, "");
|
|
93
|
+
}
|
|
94
|
+
request.cmd = IPC_COMMAND[verb];
|
|
95
|
+
|
|
96
|
+
requestDaemon(request).then(function (res) {
|
|
97
|
+
console.log(JSON.stringify(res, null, 2));
|
|
98
|
+
// Not process.exit: on a pipe it can cut the JSON off before stdout drains.
|
|
99
|
+
process.exitCode = res && res.ok ? 0 : 1;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Always resolves to a result object: an IPC failure of any kind (a rejected
|
|
104
|
+
// promise included) becomes { ok: false, result: "error" }. deps is for tests.
|
|
105
|
+
function requestDaemon(request, deps) {
|
|
106
|
+
deps = deps || {};
|
|
107
|
+
var isAlive = deps.isDaemonAlive || function () { return isDaemonAliveAsync(loadConfig()); };
|
|
108
|
+
var send = deps.sendIPC || function (req) { return sendIPCCommand(socketPath(), req, IPC_TIMEOUT_MS); };
|
|
109
|
+
return Promise.resolve().then(isAlive).then(function (alive) {
|
|
110
|
+
if (!alive) return { ok: false, result: "error", reason: "no running daemon" };
|
|
111
|
+
return send(request).then(normalizeResponse);
|
|
112
|
+
}).catch(function (err) {
|
|
113
|
+
return { ok: false, result: "error", reason: "daemon request failed: " + (err && err.message ? err.message : String(err)) };
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
requestDaemon: requestDaemon,
|
|
119
|
+
parseSessionArgs: parseSessionArgs,
|
|
120
|
+
runSessionVerb: runSessionVerb,
|
|
121
|
+
SESSION_VERBS: Object.keys(IPC_COMMAND),
|
|
122
|
+
};
|
package/lib/cli-sessions.js
CHANGED
|
@@ -3,6 +3,7 @@ var path = require("path");
|
|
|
3
3
|
var readline = require("readline");
|
|
4
4
|
var utils = require("./utils");
|
|
5
5
|
var { REAL_HOME } = require("./config");
|
|
6
|
+
var { sessionPathWithin } = require("./session-id");
|
|
6
7
|
|
|
7
8
|
var encodeCwd = utils.encodeCwd;
|
|
8
9
|
|
|
@@ -220,7 +221,13 @@ function extractText(content) {
|
|
|
220
221
|
*/
|
|
221
222
|
function readCliSessionHistory(cwd, sessionId) {
|
|
222
223
|
var encoded = encodeCwd(cwd);
|
|
223
|
-
var filePath
|
|
224
|
+
var filePath;
|
|
225
|
+
try {
|
|
226
|
+
filePath = sessionPathWithin(path.join(REAL_HOME, ".claude", "projects", encoded), sessionId, ".jsonl");
|
|
227
|
+
} catch (e) {
|
|
228
|
+
// An id that is not a plain file name has no history to read.
|
|
229
|
+
return Promise.resolve([]);
|
|
230
|
+
}
|
|
224
231
|
|
|
225
232
|
return new Promise(function (resolve) {
|
|
226
233
|
var history = [];
|
package/lib/codex-defaults.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
var normalizeApprovalPolicy = require("./yoke/codex-protocol").normalizeApprovalPolicy;
|
|
2
|
+
|
|
1
3
|
// lr-f7a4 — sandbox defaults to "workspace-write" (matches the Codex CLI's own
|
|
2
4
|
// safe default). "danger-full-access" removes all filesystem guardrails and
|
|
3
5
|
// must be an explicit opt-in via the UI/session setting, never the default.
|
|
6
|
+
//
|
|
7
|
+
// The approval default is "on-request". "on-failure" is not a policy of its
|
|
8
|
+
// own in current Codex releases (it is an alias of "on-request"), so a saved
|
|
9
|
+
// "on-failure" is read as the value it means.
|
|
4
10
|
var CODEX_DEFAULTS = {
|
|
5
|
-
approval: "on-
|
|
11
|
+
approval: "on-request",
|
|
6
12
|
sandbox: "workspace-write",
|
|
7
13
|
webSearch: "live",
|
|
8
14
|
};
|
|
9
15
|
|
|
10
16
|
function getCodexConfig(sm) {
|
|
11
17
|
return {
|
|
12
|
-
approval:
|
|
18
|
+
approval: sm && sm.codexApproval ? normalizeApprovalPolicy(sm.codexApproval) : CODEX_DEFAULTS.approval,
|
|
13
19
|
sandbox: (sm && sm.codexSandbox) || CODEX_DEFAULTS.sandbox,
|
|
14
20
|
webSearch: (sm && sm.codexWebSearch) || CODEX_DEFAULTS.webSearch,
|
|
15
21
|
};
|
package/lib/config.js
CHANGED
|
@@ -3,6 +3,8 @@ var path = require("path");
|
|
|
3
3
|
var os = require("os");
|
|
4
4
|
var net = require("net");
|
|
5
5
|
var execFileSync = require("child_process").execFileSync;
|
|
6
|
+
var { readConsoleEnv } = require("./env-compat");
|
|
7
|
+
var { migrateRc, RC_FILENAME } = require("./rc-migrate");
|
|
6
8
|
var _store = null; // lazy to avoid circular-require at module load time
|
|
7
9
|
|
|
8
10
|
function isSafeSystemUserName(name) {
|
|
@@ -32,12 +34,12 @@ function getRealHome() {
|
|
|
32
34
|
var REAL_HOME = getRealHome();
|
|
33
35
|
|
|
34
36
|
// Data dir: ~/.clagentic/console/ (prev: ~/.clagentic/ root → moved to console/ subdir by lr-12d0; prev: ~/.clay/ — migrated on first run)
|
|
35
|
-
// If
|
|
36
|
-
//
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|| (
|
|
37
|
+
// If CLAGENTIC_CONSOLE_CONFIG is set (daemon mode), derive the home from it.
|
|
38
|
+
// The un-scoped names are accepted for one release (see env-compat.js).
|
|
39
|
+
var _envHome = readConsoleEnv("CLAGENTIC_CONSOLE_HOME");
|
|
40
|
+
var _envConfig = _envHome ? undefined : readConsoleEnv("CLAGENTIC_CONSOLE_CONFIG");
|
|
41
|
+
var CLAGENTIC_HOME = _envHome
|
|
42
|
+
|| (_envConfig ? path.dirname(_envConfig) : null)
|
|
41
43
|
|| path.join(REAL_HOME, ".clagentic");
|
|
42
44
|
|
|
43
45
|
// One-time migration: copy ~/.clay/ → ~/.clagentic/ if clagentic dir absent
|
|
@@ -92,16 +94,20 @@ var CONFIG_DIR = CONSOLE_DIR;
|
|
|
92
94
|
var EXTERNAL_TRIGGERS_DIR = path.join(CONFIG_DIR, "external-triggers");
|
|
93
95
|
var OLD_EXTERNAL_TRIGGERS_DIR = path.join(CLAGENTIC_HOME, "external-triggers");
|
|
94
96
|
var OLD_CLAYRC = path.join(REAL_HOME, ".clayrc");
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
// Recent-projects file. Kept beside daemon.json under the console data dir
|
|
98
|
+
// (not ~/.config/clagentic/console/) so it follows CLAGENTIC_CONSOLE_HOME and
|
|
99
|
+
// lives with the rest of this product's state, which already sits in CONFIG_DIR.
|
|
100
|
+
var RC_PATH = path.join(CONFIG_DIR, RC_FILENAME);
|
|
101
|
+
// One-time COPY from the old home-directory dotfiles; the originals are never touched.
|
|
102
|
+
migrateRc({
|
|
103
|
+
rcPath: RC_PATH,
|
|
104
|
+
legacyPaths: [path.join(REAL_HOME, ".clagentic-rc"), OLD_CLAYRC],
|
|
105
|
+
});
|
|
100
106
|
var CRASH_INFO_PATH = path.join(CONFIG_DIR, "crash.json");
|
|
101
107
|
var OLD_CRASH_INFO_PATH = path.join(CLAGENTIC_HOME, "crash.json");
|
|
102
108
|
|
|
103
109
|
// Dev mode uses separate daemon files so dev and prod can run simultaneously
|
|
104
|
-
var _devMode = !!(
|
|
110
|
+
var _devMode = !!readConsoleEnv("CLAGENTIC_CONSOLE_DEV");
|
|
105
111
|
|
|
106
112
|
function configPath() {
|
|
107
113
|
return path.join(CONFIG_DIR, _devMode ? "daemon-dev.json" : "daemon.json");
|
|
@@ -112,10 +118,13 @@ function oldConfigPath() {
|
|
|
112
118
|
return path.join(CLAGENTIC_HOME, _devMode ? "daemon-dev.json" : "daemon.json");
|
|
113
119
|
}
|
|
114
120
|
|
|
121
|
+
function windowsPipePath(devMode) {
|
|
122
|
+
return "\\\\.\\pipe\\" + (devMode ? "clagentic-console-daemon-dev" : "clagentic-console-daemon");
|
|
123
|
+
}
|
|
124
|
+
|
|
115
125
|
function socketPath() {
|
|
116
126
|
if (process.platform === "win32") {
|
|
117
|
-
|
|
118
|
-
return "\\\\.\\pipe\\" + pipeName;
|
|
127
|
+
return windowsPipePath(_devMode);
|
|
119
128
|
}
|
|
120
129
|
return path.join(CONFIG_DIR, _devMode ? "daemon-dev.sock" : "daemon.sock");
|
|
121
130
|
}
|
|
@@ -147,7 +156,7 @@ function ensureConfigDir() {
|
|
|
147
156
|
// One-time migrations: copy Console-owned runtime files to console/ subdir.
|
|
148
157
|
// Rules: copy-not-rename (rollback safety), never overwrite newer dest,
|
|
149
158
|
// non-fatal on permission errors, skip when CLAGENTIC_HOME is custom.
|
|
150
|
-
if (!
|
|
159
|
+
if (!readConsoleEnv("CLAGENTIC_CONSOLE_HOME")) {
|
|
151
160
|
// daemon.log / daemon-dev.log
|
|
152
161
|
var oldLog = oldLogPath();
|
|
153
162
|
var newLog = logPath();
|
|
@@ -455,11 +464,11 @@ function clearCrashInfo() {
|
|
|
455
464
|
try { fs.unlinkSync(CRASH_INFO_PATH); } catch (e) {}
|
|
456
465
|
}
|
|
457
466
|
|
|
458
|
-
// ---
|
|
467
|
+
// --- recent projects persistence (RC_PATH) ---
|
|
459
468
|
|
|
460
469
|
function loadClayrc() {
|
|
461
470
|
try {
|
|
462
|
-
var data = fs.readFileSync(
|
|
471
|
+
var data = fs.readFileSync(RC_PATH, "utf8");
|
|
463
472
|
return JSON.parse(data);
|
|
464
473
|
} catch (e) {
|
|
465
474
|
return { recentProjects: [] };
|
|
@@ -467,13 +476,14 @@ function loadClayrc() {
|
|
|
467
476
|
}
|
|
468
477
|
|
|
469
478
|
function saveClayrc(rc) {
|
|
470
|
-
var tmpPath =
|
|
479
|
+
var tmpPath = RC_PATH + ".tmp";
|
|
480
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
471
481
|
fs.writeFileSync(tmpPath, JSON.stringify(rc, null, 2) + "\n");
|
|
472
|
-
fs.renameSync(tmpPath,
|
|
482
|
+
fs.renameSync(tmpPath, RC_PATH);
|
|
473
483
|
}
|
|
474
484
|
|
|
475
485
|
/**
|
|
476
|
-
* Update
|
|
486
|
+
* Update the recent-projects file with the current project list from daemon config.
|
|
477
487
|
* Merges with existing entries (preserves addedAt, updates lastUsed).
|
|
478
488
|
*/
|
|
479
489
|
function syncClayrc(projects) {
|
|
@@ -546,6 +556,8 @@ module.exports = {
|
|
|
546
556
|
EXTERNAL_TRIGGERS_DIR: EXTERNAL_TRIGGERS_DIR,
|
|
547
557
|
configPath: configPath,
|
|
548
558
|
socketPath: socketPath,
|
|
559
|
+
windowsPipePath: windowsPipePath,
|
|
560
|
+
RC_PATH: RC_PATH,
|
|
549
561
|
oldSocketPath: oldSocketPath,
|
|
550
562
|
logPath: logPath,
|
|
551
563
|
ensureConfigDir: ensureConfigDir,
|