@clagentic/console 1.12.0-beta.1 → 1.12.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 +1 -0
- package/bin/cli.js +2 -1
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +31 -7
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/duration.js +27 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +38 -7
- package/lib/daemon.js +6 -0
- package/lib/notification-prefs.js +2 -0
- package/lib/notify/core.js +175 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +63 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +64 -0
- package/lib/notify/types.js +20 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +74 -0
- package/lib/outbound-entry.js +109 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +40 -1
- package/lib/project-filesystem.js +20 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +22 -7
- package/lib/project-notifications.js +54 -32
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +2 -1
- package/lib/project.js +15 -1
- package/lib/prompt-registry.js +74 -24
- package/lib/prompt-reminders.js +38 -33
- package/lib/prompt-source.js +43 -8
- package/lib/public/app.js +1 -0
- package/lib/public/css/diagnostics.css +28 -0
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/sidebar.css +7 -0
- package/lib/public/index.html +3 -0
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/app-connection.js +22 -5
- package/lib/public/modules/app-notifications.js +47 -48
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rendering.js +10 -0
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/diagnostics.js +9 -2
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/notify-client.js +153 -0
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/server-settings.js +3 -0
- package/lib/public/modules/terminal-links.js +175 -0
- package/lib/public/modules/terminal.js +19 -103
- package/lib/public/notify-sw-logic.js +300 -0
- package/lib/public/notify-target.js +97 -0
- package/lib/public/sw.js +15 -68
- package/lib/push.js +63 -19
- package/lib/runtime-env.js +1 -0
- package/lib/sdk-bridge.js +62 -30
- package/lib/sdk-message-processor.js +78 -37
- package/lib/server.js +34 -2
- package/lib/session-directory.js +6 -4
- package/lib/session-input-ipc.js +11 -1
- package/lib/session-input.js +89 -14
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/sessions.js +31 -4
- package/lib/usage-store.js +29 -7
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +6 -1
- package/lib/yoke/adapters/claude-vendor.js +11 -1
- package/lib/yoke/adapters/claude.js +7 -0
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +8 -1
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ Agents do not need a browser. From a shell, or from inside a console session, an
|
|
|
24
24
|
- **Message sessions:** `clagentic-console send-input --to builder@my-project --prompt "The build passed."` The input is pushed into the session, which is resumed first if it was reaped.
|
|
25
25
|
- **Reply:** `clagentic-console send-input --reply --prompt "Done."` answers whoever last messaged the calling session.
|
|
26
26
|
- **List sessions:** `clagentic-console list-sessions --state live` shows each session's state and any prompts it is waiting on.
|
|
27
|
+
- **List what a session sent:** `clagentic-console list-outbound --session 4f1c9d2e-7a3b-4c55-9e0a-1b2c3d4e5f60 --since 2h` shows the calls that session (named by its vendor session id, from `list-sessions`) made with `send-input` and `open-session`: target, prompt, time and initiator. The daemon keeps them for 30 days by default (`outboundRetentionDays` in `daemon.json`; `0` stops recording and deletes existing entries). Prompt text goes to the daemon's OS user for every session that runs as it; a session that runs as another OS user (os-users mode) is listed without its text, because that text is never stored. See the [agent guide](docs/guides/AGENT-GUIDE.md#list-outbound).
|
|
27
28
|
- **Schedule input:** `clagentic-console schedule-input create --session 12 --project my-project --every 30m --count 4 --prompt "Check the build."` sends text into a session later, once or on a repeat that always has an end. People do the same from the clock button next to the message box.
|
|
28
29
|
|
|
29
30
|
Every injected message records who sent it, and an agent's message is never recorded as a human's. See the [agents guide](docs/guides/AGENT-GUIDE.md) for every verb and flag.
|
package/bin/cli.js
CHANGED
|
@@ -89,7 +89,7 @@ if (args[0] === "release") {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
// --- `open-session` / `send-input` / `list-sessions`: drive a session through the running daemon ---
|
|
92
|
+
// --- `open-session` / `send-input` / `list-sessions` / `list-outbound`: drive a session through the running daemon ---
|
|
93
93
|
// Positional verbs, handled before flag parsing: `clagentic-console send-input --project <slug> ...`.
|
|
94
94
|
var { SESSION_VERBS, runSessionVerb } = require("../lib/cli/session-subcommands");
|
|
95
95
|
if (SESSION_VERBS.indexOf(args[0]) !== -1) {
|
|
@@ -201,6 +201,7 @@ for (var i = 0; i < args.length; i++) {
|
|
|
201
201
|
console.log(" clagentic-console open-session (--project <slug> | --to <address>) --prompt <text|-> [--vendor <id>] [--agent <name>] [--name <session-name>] [--visibility shared|private] [--permission-mode <mode>] [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>] Open a session and run a first prompt (prints JSON)");
|
|
202
202
|
console.log(" clagentic-console send-input (--project <slug> --session <id> | --to <address> | --reply) --prompt <text|-> [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>] Send input to a session, resuming it if needed (prints JSON; exit 3 ambiguous, 4 not found by address)");
|
|
203
203
|
console.log(" clagentic-console list-sessions [--project <slug>] [--agent <name>] [--vendor <id>] [--state live|idle|reaped|any] List the console's sessions (prints JSON)");
|
|
204
|
+
console.log(" clagentic-console list-outbound --session <vendor-session-id> [--project <slug>] [--since <dur>] [--kind sent|opens] List what a session (by vendor session id, see list-sessions) sent out with send-input and open-session: target, prompt, time, initiator (prints JSON; read-only; kept 30 days by default)");
|
|
204
205
|
console.log(" clagentic-console schedule-input create --session <id> [--project <slug>] (--in <dur> | --at <time> | --every <dur> (--until <time> | --count <n>)) (--prompt <text|-> | --prompt-file <path>) Send text into a session later, once or on a repeat with an end (prints JSON)");
|
|
205
206
|
console.log(" clagentic-console schedule-input list [--session <id>] [--project <slug>] [--state armed|done|ended|any] List scheduled input, from the browser or the CLI (prints JSON)");
|
|
206
207
|
console.log(" clagentic-console schedule-input delete --id <id> [--project <slug>] Cancel a scheduled input");
|
package/lib/build-changes.js
CHANGED
|
@@ -16,6 +16,12 @@ var DEFAULT_LIMIT = 30;
|
|
|
16
16
|
var SUBJECT_MAX = 200;
|
|
17
17
|
var GIT_TIMEOUT_MS = 5000;
|
|
18
18
|
|
|
19
|
+
// An install made from a packed tarball (npm install -g, including the
|
|
20
|
+
// install:local-test script) carries no .git directory, so the package
|
|
21
|
+
// directory cannot answer; only buildSourceRepo in daemon.json can.
|
|
22
|
+
var NO_REPO_REASON = 'this install carries no git history (it was installed from a package, not a checkout); ' +
|
|
23
|
+
'set buildSourceRepo in daemon.json to the checkout it was built from to list the changes';
|
|
24
|
+
|
|
19
25
|
/** The repository to read history from, or null when there is none to try. */
|
|
20
26
|
function resolveHistoryRepo(configured, packageRoot) {
|
|
21
27
|
if (typeof configured === 'string' && path.isAbsolute(configured)) return configured;
|
|
@@ -47,7 +53,7 @@ function listBuildChanges(o) {
|
|
|
47
53
|
function unavailable(reason) {
|
|
48
54
|
return { available: false, commits: [], truncated: false, reason: reason };
|
|
49
55
|
}
|
|
50
|
-
if (!o.repo) return Promise.resolve(unavailable(
|
|
56
|
+
if (!o.repo) return Promise.resolve(unavailable(NO_REPO_REASON));
|
|
51
57
|
// Only hex revisions reach git, so a value can never be read as an option.
|
|
52
58
|
if (!SHA_RE.test(String(o.fromSha)) || !SHA_RE.test(String(o.toSha))) {
|
|
53
59
|
return Promise.resolve(unavailable('a build sha is not a git revision'));
|
|
@@ -76,4 +82,4 @@ function listBuildChanges(o) {
|
|
|
76
82
|
});
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
module.exports = { listBuildChanges: listBuildChanges, resolveHistoryRepo: resolveHistoryRepo, DEFAULT_LIMIT: DEFAULT_LIMIT };
|
|
85
|
+
module.exports = { listBuildChanges: listBuildChanges, resolveHistoryRepo: resolveHistoryRepo, DEFAULT_LIMIT: DEFAULT_LIMIT, NO_REPO_REASON: NO_REPO_REASON };
|
package/lib/build-sha.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
var SESSION_TITLE_MAX = 80;
|
|
12
12
|
var liveAgentTasks = require('./session-reclaim').liveAgentTasks;
|
|
13
|
+
var liveness = require('./session-liveness');
|
|
13
14
|
|
|
14
15
|
function oneLine(text, max, fallback) {
|
|
15
16
|
if (typeof text !== 'string') return fallback;
|
|
@@ -26,13 +27,14 @@ function isLive(session) {
|
|
|
26
27
|
* Everything a restart now would end, across every project.
|
|
27
28
|
*
|
|
28
29
|
* @param {Array<{slug: string, sm: {sessions: Map}}>} projects
|
|
29
|
-
* @returns {{sessions: Array<object>, sessionCount: number, processingCount: number, agentCount: number, keys: string[]}}
|
|
30
|
+
* @returns {{sessions: Array<object>, sessionCount: number, processingCount: number, waitingCount: number, agentCount: number, keys: string[]}}
|
|
30
31
|
*/
|
|
31
32
|
function collectInterruptions(projects) {
|
|
32
33
|
var sessions = [];
|
|
33
34
|
var keys = [];
|
|
34
35
|
var agentCount = 0;
|
|
35
36
|
var processingCount = 0;
|
|
37
|
+
var waitingCount = 0;
|
|
36
38
|
(projects || []).forEach(function (proj) {
|
|
37
39
|
if (!proj || !proj.sm || !proj.sm.sessions) return;
|
|
38
40
|
proj.sm.sessions.forEach(function (session) {
|
|
@@ -40,19 +42,24 @@ function collectInterruptions(projects) {
|
|
|
40
42
|
var key = proj.slug + '#' + session.localId;
|
|
41
43
|
var agents = liveAgentTasks(session);
|
|
42
44
|
var processing = !!session.isProcessing;
|
|
45
|
+
var activity = liveness.activityOf(session);
|
|
46
|
+
var waiting = activity === liveness.ACTIVITY.WAITING;
|
|
43
47
|
keys.push(key);
|
|
44
48
|
// Busy state is part of what the operator was shown: a session offered as
|
|
45
|
-
// idle that starts a turn afterwards is not covered.
|
|
49
|
+
// idle that starts a turn, or blocks on a prompt, afterwards is not covered.
|
|
46
50
|
if (processing) keys.push(key + '#busy');
|
|
51
|
+
if (waiting) keys.push(key + '#waiting');
|
|
47
52
|
agents.forEach(function (a) { keys.push(key + '#' + a.id); });
|
|
48
53
|
agentCount += agents.length;
|
|
49
54
|
if (processing) processingCount += 1;
|
|
55
|
+
if (waiting) waitingCount += 1;
|
|
50
56
|
sessions.push({
|
|
51
57
|
key: key,
|
|
52
58
|
slug: proj.slug,
|
|
53
59
|
localId: session.localId,
|
|
54
60
|
title: oneLine(session.title, SESSION_TITLE_MAX, 'Untitled session'),
|
|
55
61
|
processing: processing,
|
|
62
|
+
activity: activity,
|
|
56
63
|
agents: agents.map(function (a) { return a.label; }),
|
|
57
64
|
});
|
|
58
65
|
});
|
|
@@ -61,15 +68,32 @@ function collectInterruptions(projects) {
|
|
|
61
68
|
sessions: sessions,
|
|
62
69
|
sessionCount: sessions.length,
|
|
63
70
|
processingCount: processingCount,
|
|
71
|
+
waitingCount: waitingCount,
|
|
64
72
|
agentCount: agentCount,
|
|
65
73
|
keys: keys,
|
|
66
74
|
};
|
|
67
75
|
}
|
|
68
76
|
|
|
77
|
+
// The three words the card uses; a reaped session is not on the card.
|
|
78
|
+
var ACTIVITY_LABEL = {
|
|
79
|
+
running: 'running a turn',
|
|
80
|
+
waiting: 'waiting on a prompt',
|
|
81
|
+
idle: 'idle',
|
|
82
|
+
};
|
|
83
|
+
|
|
69
84
|
function plural(n, word) {
|
|
70
85
|
return n + ' ' + word + (n === 1 ? '' : 's');
|
|
71
86
|
}
|
|
72
87
|
|
|
88
|
+
/** One session as the card words it: "[slug] title (state; background agents: ...)". */
|
|
89
|
+
function describeSession(s) {
|
|
90
|
+
var state = ACTIVITY_LABEL[s.activity] || (s.processing ? ACTIVITY_LABEL.running : ACTIVITY_LABEL.idle);
|
|
91
|
+
var agents = s.agents.length > 0
|
|
92
|
+
? '; background agents: ' + s.agents.map(function (l) { return '"' + l + '"'; }).join(', ')
|
|
93
|
+
: '';
|
|
94
|
+
return '[' + s.slug + '] ' + s.title + ' (' + state + agents + ')';
|
|
95
|
+
}
|
|
96
|
+
|
|
73
97
|
/** The operator-facing statement of what a restart ends. */
|
|
74
98
|
function describeInterruptions(i) {
|
|
75
99
|
if (i.sessionCount === 0) {
|
|
@@ -80,11 +104,7 @@ function describeInterruptions(i) {
|
|
|
80
104
|
(i.agentCount > 0 ? ' and ' + plural(i.agentCount, 'background agent') : '') + '.',
|
|
81
105
|
];
|
|
82
106
|
i.sessions.forEach(function (s) {
|
|
83
|
-
|
|
84
|
-
var agents = s.agents.length > 0
|
|
85
|
-
? '; background agents: ' + s.agents.map(function (l) { return '"' + l + '"'; }).join(', ')
|
|
86
|
-
: '';
|
|
87
|
-
lines.push('- [' + s.slug + '] ' + s.title + ' (' + state + agents + ')');
|
|
107
|
+
lines.push('- ' + describeSession(s));
|
|
88
108
|
});
|
|
89
109
|
lines.push('Restarting ends these sessions and any that start before the restart happens. ' +
|
|
90
110
|
'Ended sessions resume when you send them a message.');
|
|
@@ -110,6 +130,9 @@ function buildOffer(o) {
|
|
|
110
130
|
sessions: o.interruptions.sessions,
|
|
111
131
|
sessionCount: o.interruptions.sessionCount,
|
|
112
132
|
agentCount: o.interruptions.agentCount,
|
|
133
|
+
// The same wording the message carries, so the client can set the list
|
|
134
|
+
// apart from the message without parsing it.
|
|
135
|
+
lines: o.interruptions.sessions.map(describeSession),
|
|
113
136
|
};
|
|
114
137
|
offer.interruptionText = describeInterruptions(o.interruptions);
|
|
115
138
|
}
|
|
@@ -174,6 +197,7 @@ module.exports = {
|
|
|
174
197
|
composeNotice: composeNotice,
|
|
175
198
|
collectInterruptions: collectInterruptions,
|
|
176
199
|
describeInterruptions: describeInterruptions,
|
|
200
|
+
describeSession: describeSession,
|
|
177
201
|
buildOffer: buildOffer,
|
|
178
202
|
summarizeOffer: summarizeOffer,
|
|
179
203
|
liveAgentTasks: liveAgentTasks,
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// claude-settings-env.js - the variables the Claude user settings file sets in
|
|
2
|
+
// its own "env" block, and which of them a Settings environment text names too.
|
|
3
|
+
//
|
|
4
|
+
// Claude Code applies that block to its own environment at startup, after the
|
|
5
|
+
// environment it was handed, so for a key present in both the settings file
|
|
6
|
+
// wins over the value saved in Settings. The editor warns about those keys
|
|
7
|
+
// rather than letting a saved value silently have no effect. Names only: no
|
|
8
|
+
// value is read out of the file into a result.
|
|
9
|
+
|
|
10
|
+
var fs = require("fs");
|
|
11
|
+
var os = require("os");
|
|
12
|
+
var path = require("path");
|
|
13
|
+
var runtimeEnv = require("./runtime-env");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The one settings file the daemon reads, located from the daemon's own
|
|
17
|
+
* environment alone: its CLAUDE_CONFIG_DIR if it has one, else its home. Text
|
|
18
|
+
* saved in Settings (shared or per project) is written by other people and
|
|
19
|
+
* never chooses the path, so the daemon cannot be pointed at another account's
|
|
20
|
+
* file. Null means "read nothing": under os-users mode the session runs as
|
|
21
|
+
* another account whose file the daemon does not read.
|
|
22
|
+
*
|
|
23
|
+
* @param {{osUsers?: boolean, homeDir?: string}} [opts]
|
|
24
|
+
* @returns {?string}
|
|
25
|
+
*/
|
|
26
|
+
function resolveSettingsFile(opts) {
|
|
27
|
+
opts = opts || {};
|
|
28
|
+
if (opts.osUsers) return null;
|
|
29
|
+
var configDir = process.env.CLAUDE_CONFIG_DIR;
|
|
30
|
+
if (configDir) return path.join(configDir, "settings.json");
|
|
31
|
+
return path.join(opts.homeDir || os.homedir(), ".claude", "settings.json");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function userSettingsEnvBlock(opts) {
|
|
35
|
+
opts = opts || {};
|
|
36
|
+
var file = resolveSettingsFile(opts);
|
|
37
|
+
if (!file) return null;
|
|
38
|
+
var parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// No file, or one that is not valid JSON, sets nothing the runtime can see.
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
var block = parsed && typeof parsed === "object" ? parsed.env : null;
|
|
46
|
+
if (!block || typeof block !== "object" || Array.isArray(block)) return null;
|
|
47
|
+
return block;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A cheap change stamp for the settings file, for cache keys: mtime and size,
|
|
52
|
+
* no content read and nothing of it logged.
|
|
53
|
+
*
|
|
54
|
+
* @param {{osUsers?: boolean, homeDir?: string}} [opts]
|
|
55
|
+
* @returns {string} "" when no file is read or it does not exist
|
|
56
|
+
*/
|
|
57
|
+
function settingsFileStamp(opts) {
|
|
58
|
+
var file = resolveSettingsFile(opts);
|
|
59
|
+
if (!file) return "";
|
|
60
|
+
try {
|
|
61
|
+
var st = fs.statSync(file);
|
|
62
|
+
return st.mtimeMs + ":" + st.size;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// An absent file is a stable, distinct state; creating it changes the stamp.
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {{osUsers?: boolean, homeDir?: string}} [opts]
|
|
71
|
+
* @returns {string[]} the names in the settings file's env block; [] when the
|
|
72
|
+
* file is absent or unreadable, or under os-users mode
|
|
73
|
+
*/
|
|
74
|
+
function userSettingsEnvKeys(opts) {
|
|
75
|
+
var block = userSettingsEnvBlock(opts);
|
|
76
|
+
return block ? Object.keys(block) : [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The environment the Claude CLI actually sees: the one it was handed with the
|
|
81
|
+
* settings file's env block applied over it (the file wins). Used to decide
|
|
82
|
+
* what the CLI will do (which provider it talks to), never to hand a value on:
|
|
83
|
+
* the result is for in-process classification and is not logged or sent.
|
|
84
|
+
*
|
|
85
|
+
* Under os-users mode the file belongs to another account and is not read, so
|
|
86
|
+
* the result is the given environment unchanged: a provider selected only in
|
|
87
|
+
* that account's own settings file is not seen by the console there.
|
|
88
|
+
* @param {object} env the composed environment the runtime is started with
|
|
89
|
+
* @param {{homeDir?: string, osUsers?: boolean}} [opts]
|
|
90
|
+
* @returns {object} a new object; env is not modified
|
|
91
|
+
*/
|
|
92
|
+
function applyUserSettingsEnv(env, opts) {
|
|
93
|
+
var out = Object.assign({}, env);
|
|
94
|
+
var block = userSettingsEnvBlock(opts);
|
|
95
|
+
if (!block) return out;
|
|
96
|
+
Object.keys(block).forEach(function (key) {
|
|
97
|
+
var value = block[key];
|
|
98
|
+
if (typeof value === "string") out[key] = value;
|
|
99
|
+
else if (typeof value === "number" || typeof value === "boolean") out[key] = String(value);
|
|
100
|
+
});
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} envText a Settings environment text
|
|
106
|
+
* @param {{homeDir?: string, osUsers?: boolean}} [opts]
|
|
107
|
+
* @returns {string[]} names the text sets that the settings file also sets; []
|
|
108
|
+
* under os-users mode, where the file is not read
|
|
109
|
+
*/
|
|
110
|
+
function shadowedKeys(envText, opts) {
|
|
111
|
+
var fileKeys = userSettingsEnvKeys(opts);
|
|
112
|
+
if (fileKeys.length === 0) return [];
|
|
113
|
+
var inFile = new Set(fileKeys);
|
|
114
|
+
var seen = new Set();
|
|
115
|
+
return runtimeEnv.scanEnvText(envText).entries
|
|
116
|
+
.map(function (entry) { return entry.key; })
|
|
117
|
+
.filter(function (key) {
|
|
118
|
+
if (!inFile.has(key) || seen.has(key)) return false;
|
|
119
|
+
seen.add(key);
|
|
120
|
+
return true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {string} envText a Settings environment text
|
|
126
|
+
* @returns {boolean} whether it sets CLAUDE_CONFIG_DIR, which the console never
|
|
127
|
+
* reads a path from (the editor says its check covers one file only)
|
|
128
|
+
*/
|
|
129
|
+
function setsConfigDir(envText) {
|
|
130
|
+
return runtimeEnv.scanEnvText(envText).entries.some(function (entry) {
|
|
131
|
+
return entry.key === "CLAUDE_CONFIG_DIR";
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = {
|
|
136
|
+
setsConfigDir: setsConfigDir,
|
|
137
|
+
resolveSettingsFile: resolveSettingsFile,
|
|
138
|
+
settingsFileStamp: settingsFileStamp,
|
|
139
|
+
userSettingsEnvKeys: userSettingsEnvKeys,
|
|
140
|
+
applyUserSettingsEnv: applyUserSettingsEnv,
|
|
141
|
+
shadowedKeys: shadowedKeys,
|
|
142
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// lib/cli/duration.js - the duration a CLI flag takes ("10m", "1h30m", "90").
|
|
2
|
+
// Shared by schedule-input (--in, --every) and list-outbound (--since).
|
|
3
|
+
|
|
4
|
+
var UNIT_MS = Object.freeze({ s: 1000, m: 60000, h: 3600000, d: 86400000 });
|
|
5
|
+
|
|
6
|
+
var DURATION_RE = /^(?:\d+[smhd])+$/;
|
|
7
|
+
var DURATION_PART_RE = /(\d+)([smhd])/g;
|
|
8
|
+
|
|
9
|
+
// A bare number is minutes, the unit the person's own field uses.
|
|
10
|
+
// Returns { ms } or { error }.
|
|
11
|
+
function parseDuration(raw) {
|
|
12
|
+
var text = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
13
|
+
if (/^\d+$/.test(text)) text += "m";
|
|
14
|
+
if (!DURATION_RE.test(text)) {
|
|
15
|
+
return { error: "not a duration: " + JSON.stringify(String(raw).slice(0, 32)) + " (use for example 90, 10m, 2h, 1h30m)" };
|
|
16
|
+
}
|
|
17
|
+
var total = 0;
|
|
18
|
+
var part;
|
|
19
|
+
DURATION_PART_RE.lastIndex = 0;
|
|
20
|
+
while ((part = DURATION_PART_RE.exec(text)) !== null) {
|
|
21
|
+
total += parseInt(part[1], 10) * UNIT_MS[part[2]];
|
|
22
|
+
}
|
|
23
|
+
if (!Number.isSafeInteger(total) || total <= 0) return { error: "a duration must be longer than zero" };
|
|
24
|
+
return { ms: total };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { parseDuration: parseDuration };
|
|
@@ -28,6 +28,7 @@ var fs = require("fs");
|
|
|
28
28
|
var senderRef = require("../sender-ref");
|
|
29
29
|
var { LIMITS, isCount } = require("../scheduled-input/records");
|
|
30
30
|
var { requestDaemon, withSenderRef, EXIT } = require("./session-subcommands");
|
|
31
|
+
var { parseDuration } = require("./duration");
|
|
31
32
|
|
|
32
33
|
// --- The time inputs: a duration ("10m", "1h30m"), a local clock time ("20:01")
|
|
33
34
|
// and a local date-time ("2026-03-01T20:01"). Pure: each takes the current time
|
|
@@ -35,31 +36,9 @@ var { requestDaemon, withSenderRef, EXIT } = require("./session-subcommands");
|
|
|
35
36
|
// (lib/public/modules/schedule-time.js) because it cannot load this CommonJS
|
|
36
37
|
// file; test/scheduled-input-client.test.js feeds both the same cases.
|
|
37
38
|
|
|
38
|
-
var UNIT_MS = Object.freeze({ s: 1000, m: 60000, h: 3600000, d: 86400000 });
|
|
39
|
-
|
|
40
|
-
var DURATION_RE = /^(?:\d+[smhd])+$/;
|
|
41
|
-
var DURATION_PART_RE = /(\d+)([smhd])/g;
|
|
42
39
|
var CLOCK_RE = /^(\d{1,2}):(\d{2})$/;
|
|
43
40
|
var DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{1,2}):(\d{2})$/;
|
|
44
41
|
|
|
45
|
-
// A bare number is minutes, the unit the person's own field uses.
|
|
46
|
-
// Returns { ms } or { error }.
|
|
47
|
-
function parseDuration(raw) {
|
|
48
|
-
var text = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
49
|
-
if (/^\d+$/.test(text)) text += "m";
|
|
50
|
-
if (!DURATION_RE.test(text)) {
|
|
51
|
-
return { error: "not a duration: " + JSON.stringify(String(raw).slice(0, 32)) + " (use for example 90, 10m, 2h, 1h30m)" };
|
|
52
|
-
}
|
|
53
|
-
var total = 0;
|
|
54
|
-
var part;
|
|
55
|
-
DURATION_PART_RE.lastIndex = 0;
|
|
56
|
-
while ((part = DURATION_PART_RE.exec(text)) !== null) {
|
|
57
|
-
total += parseInt(part[1], 10) * UNIT_MS[part[2]];
|
|
58
|
-
}
|
|
59
|
-
if (!Number.isSafeInteger(total) || total <= 0) return { error: "a duration must be longer than zero" };
|
|
60
|
-
return { ms: total };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
42
|
function validClock(hours, minutes) {
|
|
64
43
|
return hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59;
|
|
65
44
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// lib/cli/session-subcommands.js
|
|
2
2
|
//
|
|
3
|
-
// `clagentic-console open-session`, `send-input
|
|
4
|
-
// session in a project, send input to one,
|
|
5
|
-
//
|
|
3
|
+
// `clagentic-console open-session`, `send-input`, `list-sessions` and
|
|
4
|
+
// `list-outbound`: open a session in a project, send input to one, list the
|
|
5
|
+
// sessions, or list what one session sent out, through the running daemon's IPC
|
|
6
|
+
// socket. Each prints the daemon's result as JSON on stdout.
|
|
6
7
|
//
|
|
7
8
|
// Exit codes (documented in docs/guides/AGENT-GUIDE.md):
|
|
8
9
|
// 0 the request was acted on (opened, delivered, resumed-and-delivered, listed)
|
|
9
10
|
// 1 refused, error, or not-found for a request that named a session id
|
|
10
|
-
// 3 ambiguous: an address named several sessions
|
|
11
|
+
// 3 ambiguous: an address named several sessions (or, for list-outbound, a
|
|
12
|
+
// session id several projects hold); the candidates are in the JSON
|
|
11
13
|
// 4 not-found for a request that gave an address (--to) or --reply
|
|
12
14
|
|
|
13
15
|
var fs = require("fs");
|
|
@@ -15,6 +17,7 @@ var fs = require("fs");
|
|
|
15
17
|
var { loadConfig, socketPath, isDaemonAliveAsync } = require("../config");
|
|
16
18
|
var { sendIPCCommand } = require("../ipc");
|
|
17
19
|
var senderRef = require("../sender-ref");
|
|
20
|
+
var { parseDuration } = require("./duration");
|
|
18
21
|
|
|
19
22
|
// A resumed session starts a runtime before the call answers: longer than the
|
|
20
23
|
// IPC default.
|
|
@@ -37,6 +40,8 @@ var FLAGS = {
|
|
|
37
40
|
"--context-note": "contextNote",
|
|
38
41
|
"--from": "from",
|
|
39
42
|
"--from-session": "fromSession",
|
|
43
|
+
"--since": "since",
|
|
44
|
+
"--kind": "kind",
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
// Kept apart from FLAGS because the parser reads a value after every FLAGS
|
|
@@ -49,18 +54,21 @@ var USAGE = {
|
|
|
49
54
|
"open-session": "Usage: clagentic-console open-session (--project <slug> | --to <address>) --prompt <text|-> [--vendor <id>] [--agent <name>] [--name <session-name>] [--visibility shared|private] [--permission-mode <mode>] [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>]",
|
|
50
55
|
"send-input": "Usage: clagentic-console send-input (--project <slug> --session <id> | --to <address> | --reply) --prompt <text|-> [--initiator <kind>] [--context-note <text>] [--from <name>] [--from-session <id>]",
|
|
51
56
|
"list-sessions": "Usage: clagentic-console list-sessions [--project <slug>] [--agent <name>] [--vendor <id>] [--state live|idle|reaped|any]",
|
|
57
|
+
"list-outbound": "Usage: clagentic-console list-outbound --session <vendor-session-id> [--project <slug>] [--since <dur>] [--kind sent|opens]",
|
|
52
58
|
};
|
|
53
59
|
|
|
54
60
|
var ALLOWED = {
|
|
55
61
|
"open-session": ["projectSlug", "to", "prompt", "vendor", "agentName", "sessionName", "sessionVisibility", "permissionMode", "initiator", "contextNote", "from", "fromSession"],
|
|
56
62
|
"send-input": ["projectSlug", "sessionId", "to", "reply", "prompt", "initiator", "contextNote", "from", "fromSession"],
|
|
57
63
|
"list-sessions": ["projectSlug", "agentName", "vendor", "state"],
|
|
64
|
+
"list-outbound": ["sessionId", "projectSlug", "since", "kind"],
|
|
58
65
|
};
|
|
59
66
|
|
|
60
67
|
var REQUIRED = {
|
|
61
68
|
"open-session": ["prompt"],
|
|
62
69
|
"send-input": ["prompt"],
|
|
63
70
|
"list-sessions": [],
|
|
71
|
+
"list-outbound": ["sessionId"],
|
|
64
72
|
};
|
|
65
73
|
|
|
66
74
|
var TARGET_HINT = {
|
|
@@ -72,8 +80,11 @@ var IPC_COMMAND = {
|
|
|
72
80
|
"open-session": "open_session",
|
|
73
81
|
"send-input": "send_session_input",
|
|
74
82
|
"list-sessions": "list_sessions",
|
|
83
|
+
"list-outbound": "list_outbound",
|
|
75
84
|
};
|
|
76
85
|
|
|
86
|
+
var OUTBOUND_KINDS = ["sent", "opens"];
|
|
87
|
+
|
|
77
88
|
function flagOf(key) {
|
|
78
89
|
var all = Object.keys(FLAGS).concat(Object.keys(SWITCHES));
|
|
79
90
|
return all.filter(function (f) { return FLAGS[f] === key || SWITCHES[f] === key; })[0];
|
|
@@ -98,9 +109,25 @@ function checkTarget(verb, request) {
|
|
|
98
109
|
return null;
|
|
99
110
|
}
|
|
100
111
|
|
|
112
|
+
// list-outbound: --since is a duration back from now, sent to the daemon as the
|
|
113
|
+
// absolute time; --kind is one of the two. Returns an error string or null.
|
|
114
|
+
function resolveOutboundOptions(request, now) {
|
|
115
|
+
if (request.kind !== undefined && OUTBOUND_KINDS.indexOf(request.kind) === -1) {
|
|
116
|
+
return "Unknown --kind " + JSON.stringify(String(request.kind).slice(0, 32)) + " (accepted: " + OUTBOUND_KINDS.join(", ") + ")";
|
|
117
|
+
}
|
|
118
|
+
if (request.since !== undefined) {
|
|
119
|
+
var dur = parseDuration(request.since);
|
|
120
|
+
if (dur.error) return "--since: " + dur.error;
|
|
121
|
+
request.sinceMs = now - dur.ms;
|
|
122
|
+
delete request.since;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
101
127
|
// Parses the arguments after the verb. Returns { request } or { error }.
|
|
102
|
-
// Pure: reading a "-" prompt from stdin is the handler's job.
|
|
103
|
-
|
|
128
|
+
// Pure: reading a "-" prompt from stdin is the handler's job. `now` (ms) is for
|
|
129
|
+
// tests.
|
|
130
|
+
function parseSessionArgs(verb, args, now) {
|
|
104
131
|
var allowed = ALLOWED[verb];
|
|
105
132
|
var request = {};
|
|
106
133
|
for (var i = 0; i < args.length; i++) {
|
|
@@ -121,6 +148,10 @@ function parseSessionArgs(verb, args) {
|
|
|
121
148
|
}
|
|
122
149
|
var targetError = checkTarget(verb, request);
|
|
123
150
|
if (targetError) return { error: targetError };
|
|
151
|
+
if (verb === "list-outbound") {
|
|
152
|
+
var outboundError = resolveOutboundOptions(request, now === undefined ? Date.now() : now);
|
|
153
|
+
if (outboundError) return { error: outboundError };
|
|
154
|
+
}
|
|
124
155
|
return { request: request };
|
|
125
156
|
}
|
|
126
157
|
|
|
@@ -172,7 +203,7 @@ function runSessionVerb(verb, args) {
|
|
|
172
203
|
request.prompt = fs.readFileSync(0, "utf8").replace(/\n$/, "");
|
|
173
204
|
}
|
|
174
205
|
request.cmd = IPC_COMMAND[verb];
|
|
175
|
-
if (verb
|
|
206
|
+
if (verb === "open-session" || verb === "send-input") withSenderRef(request, process.env);
|
|
176
207
|
|
|
177
208
|
requestDaemon(request).then(function (res) {
|
|
178
209
|
console.log(JSON.stringify(res, null, 2));
|
package/lib/daemon.js
CHANGED
|
@@ -1714,6 +1714,12 @@ var ipc = createIPCServer(socketPath(), function (msg) {
|
|
|
1714
1714
|
case "list_sessions":
|
|
1715
1715
|
return require("./session-input-ipc").handleSessionCommand(relay.sessionInput, msg);
|
|
1716
1716
|
|
|
1717
|
+
// What one session sent out (the sender-side outbound ledger). Read-only;
|
|
1718
|
+
// the prompt text of an entry is shown only when the caller may read the
|
|
1719
|
+
// target session (lib/outbound-access.js). Same OS-level socket gate.
|
|
1720
|
+
case "list_outbound":
|
|
1721
|
+
return require("./session-input-ipc").handleOutboundCommand(relay.outboundQuery, msg);
|
|
1722
|
+
|
|
1717
1723
|
// Scheduled input: text sent into a session later, once or on a repeat with
|
|
1718
1724
|
// an end. The same service the clock button in the browser uses, so a record
|
|
1719
1725
|
// made here shows there and the reverse. Same OS-level socket gate as the
|
|
@@ -130,6 +130,8 @@ function categoryOfNotification(type) {
|
|
|
130
130
|
function categoryOfPush(payload) {
|
|
131
131
|
if (!payload || typeof payload.type !== "string") return null;
|
|
132
132
|
if (payload.type === "done") return payload.tag === "ralph-loop-done" ? "loop" : "turn_done";
|
|
133
|
+
// A close push follows the preference of the notification it closes.
|
|
134
|
+
if (payload.type === "notify_close") return categoryOfPush({ type: payload.closes });
|
|
133
135
|
return Object.prototype.hasOwnProperty.call(PUSH_CATEGORY, payload.type) ? PUSH_CATEGORY[payload.type] : null;
|
|
134
136
|
}
|
|
135
137
|
|