@radnine/claude-session-daemon 0.9.6 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/package.json +1 -1
- package/src/claude-process.js +20 -0
- package/src/codex-process.js +39 -14
- package/src/config.js +28 -1
- package/src/connections/action-cable-client.js +13 -0
- package/src/daemon.js +9 -0
- package/src/index.js +1 -0
- package/src/job-styles.js +156 -0
- package/src/persona-scanner.js +7 -3
package/README.md
CHANGED
|
@@ -235,12 +235,15 @@ In Docker mode, `CLAUDE_WORKING_DIR` should point to your mounted workspace (e.g
|
|
|
235
235
|
| `CLAUDE_COMMAND` | `claude` | Claude CLI binary to spawn. Also used for `claude auth status` |
|
|
236
236
|
| `CLAUDE_EFFORT` | — | Machine default reasoning effort (`low`, `medium`, `high`, `xhigh`, `max`) that the daemon reports to FlightDeck. Overrides the `effort` key in `~/.claude/settings.json` |
|
|
237
237
|
| `CLAUDE_PERMISSION_MODE` | `auto` | Claude CLI permission mode: `auto`, `acceptEdits`, `manual`, `dontAsk`, `plan`, `bypassPermissions` |
|
|
238
|
+
| `CODEX_SANDBOX_MODE` | `workspace-write` | Sandbox every Codex chat runs in: `read-only`, `workspace-write` or `danger-full-access`. Set `danger-full-access` to let Codex chats launch a browser (Playwright, Rails system tests); it also drops the `sandbox_workspace_write.*` overrides. Any other value stops the daemon at startup. One setting for the whole machine, so Codex builders and verifiers both get it (#723) |
|
|
238
239
|
| `CLAUDE_PERMISSION_TIMEOUT` | `600` | Seconds a permission prompt waits for an operator before auto-denying (1–86400) |
|
|
239
240
|
| `CLAUDE_SKIP_PERMISSIONS` | `false` | **Deprecated** — alias for `CLAUDE_PERMISSION_MODE=bypassPermissions` |
|
|
240
241
|
| `CLAUDE_DISABLE_AUTH` | `false` | Disable WebSocket auth (Docker only) |
|
|
241
242
|
|
|
242
243
|
Sessions inherit the daemon's environment, so Claude CLI variables such as `CLAUDE_CONFIG_DIR` and `CLAUDE_CODE_OAUTH_TOKEN` apply to every session. The daemon reads those two itself only to report which Claude account the pilot runs as.
|
|
243
244
|
|
|
245
|
+
**Jobs (#638).** A chat can run as a job (lead, builder, verifier, investigator, writer or reporter). Each job is a Claude Code output style file that FlightDeck serves at `GET /api/jobs` (pilot token, ETag). Before it launches a chat with a job, the daemon writes the files into `$CLAUDE_CONFIG_DIR/output-styles/` (else `~/.claude/output-styles/`) as `flightdeck-<job>.md`, refetching only when the `jobs_etag` in `session_activate` changes. Every Claude launch and resume passes `--settings '{"outputStyle":"<style>"}'`: the job's style ("FlightDeck Builder"), or `default` for a chat with no job. A missing job file logs a warning naming the job, and the chat still launches. A Codex chat gets the job file's text at the front of its developer instructions.
|
|
246
|
+
|
|
244
247
|
**Addon-side variables** (set when starting Storybook):
|
|
245
248
|
|
|
246
249
|
| Variable | Default | Description |
|
|
@@ -248,6 +251,10 @@ Sessions inherit the daemon's environment, so Claude CLI variables such as `CLAU
|
|
|
248
251
|
| `STORYBOOK_CLAUDE_DAEMON_PORT` | `3001` | Daemon port (or inject via `window.__CLAUDE_DAEMON_PORT__`) |
|
|
249
252
|
| `STORYBOOK_CLAUDE_DAEMON_TOKEN` | — | Shared secret (or inject via `window.__CLAUDE_DAEMON_TOKEN__`) |
|
|
250
253
|
|
|
254
|
+
## Releasing
|
|
255
|
+
|
|
256
|
+
How a new daemon version reaches npm and the pilots: [docs/releasing.md](../docs/releasing.md).
|
|
257
|
+
|
|
251
258
|
## License
|
|
252
259
|
|
|
253
260
|
Proprietary. See [LICENSE](./LICENSE) for terms.
|
package/package.json
CHANGED
package/src/claude-process.js
CHANGED
|
@@ -12,6 +12,7 @@ const { TurnTracker } = require('./turn-tracker');
|
|
|
12
12
|
// process ends it, and a resumed chat never hears from it.
|
|
13
13
|
const LIFELONG_BACKGROUND_TOOLS = new Set(['Monitor', 'CronCreate', 'ScheduleWakeup']);
|
|
14
14
|
const { stripDaemonSecrets } = require('./harness');
|
|
15
|
+
const { validJob, styleNameFor, jobFilePath } = require('./job-styles');
|
|
15
16
|
|
|
16
17
|
const MAX_CHUNK_SIZE = 50000; // 50KB — lines larger than this get flagged
|
|
17
18
|
|
|
@@ -43,6 +44,8 @@ class ClaudeProcess extends EventEmitter {
|
|
|
43
44
|
* @param {object} [options.sessionEnv] - Extra env vars to inject into the spawned process
|
|
44
45
|
* @param {string} [options.systemPrompt] - Appended to Claude's default system prompt at spawn time via --append-system-prompt
|
|
45
46
|
* @param {string} [options.model] - Claude model id passed to the CLI via --model (the server always sends the session's stored model)
|
|
47
|
+
* @param {string} [options.job] - #638: the chat's job slug; its output style goes in --settings
|
|
48
|
+
* @param {string} [options.outputStyle] - #638: the job's style name, as Rails sends it
|
|
46
49
|
*/
|
|
47
50
|
constructor(sessionId, options = {}) {
|
|
48
51
|
super();
|
|
@@ -59,6 +62,8 @@ class ClaudeProcess extends EventEmitter {
|
|
|
59
62
|
this._systemPrompt = options.systemPrompt || null;
|
|
60
63
|
this._model = options.model || null;
|
|
61
64
|
this._effort = options.effort || null;
|
|
65
|
+
this._job = validJob(options.job) ? options.job : null;
|
|
66
|
+
this._outputStyle = this._job ? (options.outputStyle || styleNameFor(this._job)) : null;
|
|
62
67
|
|
|
63
68
|
this._state = 'idle';
|
|
64
69
|
this._child = null;
|
|
@@ -132,6 +137,11 @@ class ClaudeProcess extends EventEmitter {
|
|
|
132
137
|
args.push('--effort', this._effort);
|
|
133
138
|
}
|
|
134
139
|
|
|
140
|
+
// #638: name the style on every launch, resume included. A resume without
|
|
141
|
+
// the flag runs Default, and the flag beats a .claude/settings.local.json
|
|
142
|
+
// that sets one. With no job the chat runs Default on purpose.
|
|
143
|
+
args.push('--settings', JSON.stringify({ outputStyle: this._outputStyle || 'default' }));
|
|
144
|
+
|
|
135
145
|
if (this._systemPrompt) {
|
|
136
146
|
args.push('--append-system-prompt', this._systemPrompt);
|
|
137
147
|
}
|
|
@@ -158,6 +168,16 @@ class ClaudeProcess extends EventEmitter {
|
|
|
158
168
|
delete env.CLAUDECODE; // Prevent nested session detection
|
|
159
169
|
stripDaemonSecrets(env);
|
|
160
170
|
|
|
171
|
+
// #638: the CLI silently runs Default for a style it can't find, so say so.
|
|
172
|
+
if (this._job) {
|
|
173
|
+
const jobFile = jobFilePath(this._job, env);
|
|
174
|
+
if (!fs.existsSync(jobFile)) {
|
|
175
|
+
this._logger.warn(`Job file for job "${this._job}" is missing; the chat runs the Default output style`, {
|
|
176
|
+
sessionId: this._sessionId, job: this._job, outputStyle: this._outputStyle, path: jobFile,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
161
181
|
const opts = {
|
|
162
182
|
cwd: this._workingDir,
|
|
163
183
|
stdio: ['pipe', 'pipe', 'pipe'],
|
package/src/codex-process.js
CHANGED
|
@@ -10,6 +10,7 @@ const path = require('node:path');
|
|
|
10
10
|
const { TurnTracker } = require('./turn-tracker');
|
|
11
11
|
const { CodexTranslator } = require('./codex-translator');
|
|
12
12
|
const { stripDaemonSecrets } = require('./harness');
|
|
13
|
+
const { validJob, readJobBody, jobFilePath } = require('./job-styles');
|
|
13
14
|
|
|
14
15
|
const REQUEST_TIMEOUT_MS = 60000;
|
|
15
16
|
|
|
@@ -58,9 +59,11 @@ class CodexProcess extends EventEmitter {
|
|
|
58
59
|
* @param {boolean} [options.resume]
|
|
59
60
|
* @param {object} [options.logger]
|
|
60
61
|
* @param {string} [options.codexCommand] - path to the codex binary
|
|
62
|
+
* @param {string} [options.codexSandboxMode] - #723: read-only, workspace-write (default) or danger-full-access
|
|
61
63
|
* @param {string} [options.systemPrompt] - persona prompt, sent as developer instructions
|
|
62
64
|
* @param {string} [options.model] - Codex model id
|
|
63
65
|
* @param {string} [options.effort] - reasoning effort for each turn
|
|
66
|
+
* @param {string} [options.job] - #638: the chat's job; its file's text leads the developer instructions
|
|
64
67
|
* @param {object} [options.sessionEnv] - extra env for the child
|
|
65
68
|
* @param {{command: string, args: string[], env?: object}} [options.radMcp] - how to start the rad MCP server
|
|
66
69
|
* @param {Array<{name: string, command: string, args: string[], env?: object}>} [options.mcpServers] - the other
|
|
@@ -76,11 +79,14 @@ class CodexProcess extends EventEmitter {
|
|
|
76
79
|
this._workingDir = options.workingDir || process.cwd();
|
|
77
80
|
this._logger = options.logger || _defaultLogger();
|
|
78
81
|
this._codexCommand = options.codexCommand || 'codex';
|
|
82
|
+
this._sandboxMode = options.codexSandboxMode || 'workspace-write';
|
|
79
83
|
this._spawnFn = options._spawnFn || defaultSpawn;
|
|
80
84
|
this._sessionEnv = options.sessionEnv || {};
|
|
81
85
|
this._systemPrompt = options.systemPrompt || null;
|
|
82
86
|
this._model = options.model || null;
|
|
83
87
|
this._effort = options.effort || null;
|
|
88
|
+
this._job = validJob(options.job) ? options.job : null;
|
|
89
|
+
this._jobText = null;
|
|
84
90
|
this._radMcp = options.radMcp;
|
|
85
91
|
this._mcpServers = options.mcpServers;
|
|
86
92
|
this._skillRoots = [];
|
|
@@ -127,10 +133,20 @@ class CodexProcess extends EventEmitter {
|
|
|
127
133
|
radMcp: this._radMcp,
|
|
128
134
|
mcpServers,
|
|
129
135
|
writableRoots: gitWritableRoots(this._workingDir),
|
|
136
|
+
sandboxMode: this._sandboxMode,
|
|
130
137
|
logger: this._logger,
|
|
131
138
|
});
|
|
132
139
|
this._skillRoots = claudeSkillRoots(env, this._workingDir);
|
|
133
140
|
this._memoryIndex = memoryIndexPath(env, this._workingDir);
|
|
141
|
+
// #638: Codex takes no output style file, so the job reaches it as text.
|
|
142
|
+
if (this._job) {
|
|
143
|
+
this._jobText = readJobBody(this._job, env);
|
|
144
|
+
if (!this._jobText) {
|
|
145
|
+
this._logger.warn(`Job file for job "${this._job}" is missing; the Codex chat starts without its job text`, {
|
|
146
|
+
sessionId: this._sessionId, job: this._job, path: jobFilePath(this._job, env),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
134
150
|
|
|
135
151
|
this._logger.info(`Spawning Codex app-server: ${this._codexCommand}`, {
|
|
136
152
|
sessionId: this._sessionId,
|
|
@@ -308,15 +324,16 @@ class CodexProcess extends EventEmitter {
|
|
|
308
324
|
}
|
|
309
325
|
}
|
|
310
326
|
|
|
311
|
-
//
|
|
312
|
-
//
|
|
327
|
+
// CODEX_SANDBOX_MODE (#723), workspace-write by default. workspace-write
|
|
328
|
+
// gets network and the git dirs (set in buildCodexLaunch): git commit works
|
|
329
|
+
// in a worktree, and git push / package installs reach the network.
|
|
313
330
|
const params = {
|
|
314
331
|
cwd: this._workingDir,
|
|
315
332
|
approvalPolicy: 'never',
|
|
316
|
-
sandbox:
|
|
333
|
+
sandbox: this._sandboxMode,
|
|
317
334
|
};
|
|
318
335
|
if (this._model) params.model = this._model;
|
|
319
|
-
const instructions = developerInstructions(this._systemPrompt, this._memoryIndex);
|
|
336
|
+
const instructions = developerInstructions(this._systemPrompt, this._memoryIndex, this._jobText);
|
|
320
337
|
if (instructions) params.developerInstructions = instructions;
|
|
321
338
|
|
|
322
339
|
let response;
|
|
@@ -751,11 +768,15 @@ function memoryIndexPath(env = process.env, workingDir = process.cwd(), home = o
|
|
|
751
768
|
return fs.existsSync(index) ? index : null;
|
|
752
769
|
}
|
|
753
770
|
|
|
754
|
-
// The persona prompt,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
|
|
771
|
+
// The job's text (#638), then the persona prompt, then one line pointing at
|
|
772
|
+
// the memory index when there is one.
|
|
773
|
+
function developerInstructions(systemPrompt, memoryIndex, jobText = null) {
|
|
774
|
+
const parts = [jobText, systemPrompt];
|
|
775
|
+
if (memoryIndex) {
|
|
776
|
+
parts.push(`Before you start, read your memory index at ${memoryIndex}. It lists what earlier chats in this repo learned; open the files it links to when they bear on your task.`);
|
|
777
|
+
}
|
|
778
|
+
const present = parts.filter(Boolean);
|
|
779
|
+
return present.length ? present.join('\n\n') : null;
|
|
759
780
|
}
|
|
760
781
|
|
|
761
782
|
/**
|
|
@@ -973,7 +994,8 @@ function gitWritableRoots(workingDir, exec = childProcess.execFileSync) {
|
|
|
973
994
|
* Arguments and env for `codex app-server`. Per-process `-c` overrides, so no
|
|
974
995
|
* config file is written:
|
|
975
996
|
* - sandbox_workspace_write.network_access: workspace-write blocks the network
|
|
976
|
-
* by default, which breaks git push and installs.
|
|
997
|
+
* by default, which breaks git push and installs. Left off, with
|
|
998
|
+
* writable_roots, in danger-full-access (#723), which has no sandbox.
|
|
977
999
|
* - project_doc_fallback_filenames: Codex reads CLAUDE.md in a directory with
|
|
978
1000
|
* no AGENTS.md, so a chat gets the repo's Claude rules (#491).
|
|
979
1001
|
* - mcp_servers.rad: the command a Claude chat uses, plus env_vars so that
|
|
@@ -997,11 +1019,14 @@ function gitWritableRoots(workingDir, exec = childProcess.execFileSync) {
|
|
|
997
1019
|
*
|
|
998
1020
|
* @returns {{args: string[], env: object}} env is a new object
|
|
999
1021
|
*/
|
|
1000
|
-
function buildCodexLaunch({ env = {}, radMcp, mcpServers = [], writableRoots, logger = _defaultLogger() } = {}) {
|
|
1022
|
+
function buildCodexLaunch({ env = {}, radMcp, mcpServers = [], writableRoots, sandboxMode = 'workspace-write', logger = _defaultLogger() } = {}) {
|
|
1001
1023
|
const childEnv = { ...env };
|
|
1002
|
-
const args = ['app-server'
|
|
1003
|
-
if (
|
|
1004
|
-
args.push('-c',
|
|
1024
|
+
const args = ['app-server'];
|
|
1025
|
+
if (sandboxMode !== 'danger-full-access') {
|
|
1026
|
+
args.push('-c', 'sandbox_workspace_write.network_access=true');
|
|
1027
|
+
if (Array.isArray(writableRoots) && writableRoots.length) {
|
|
1028
|
+
args.push('-c', `sandbox_workspace_write.writable_roots=${JSON.stringify(writableRoots)}`);
|
|
1029
|
+
}
|
|
1005
1030
|
}
|
|
1006
1031
|
// Even an empty Codex home gets the built-in `codex_apps` MCP server (the
|
|
1007
1032
|
// ChatGPT account's connectors, 100+ tools) and the curated plugin catalog
|
package/src/config.js
CHANGED
|
@@ -66,6 +66,28 @@ function resolvePermissionMode(env) {
|
|
|
66
66
|
return { mode, warnings };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// Sandbox modes accepted by Codex's `thread/start` and `thread/resume` (#723).
|
|
70
|
+
const CODEX_SANDBOX_MODES = ['read-only', 'workspace-write', 'danger-full-access'];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the sandbox every Codex chat runs in from CODEX_SANDBOX_MODE.
|
|
74
|
+
* Unset or blank keeps workspace-write, the mode every Codex chat ran in
|
|
75
|
+
* before the setting existed. Any other value stops the daemon at startup.
|
|
76
|
+
*
|
|
77
|
+
* @param {object} env
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
function resolveCodexSandboxMode(env) {
|
|
81
|
+
const raw = (env.CODEX_SANDBOX_MODE || '').trim();
|
|
82
|
+
if (!raw) return 'workspace-write';
|
|
83
|
+
if (!CODEX_SANDBOX_MODES.includes(raw)) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Invalid CODEX_SANDBOX_MODE: "${raw}". Must be one of: ${CODEX_SANDBOX_MODES.join(', ')}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return raw;
|
|
89
|
+
}
|
|
90
|
+
|
|
69
91
|
const DEFAULT_PERMISSION_TIMEOUT = 600;
|
|
70
92
|
|
|
71
93
|
/**
|
|
@@ -110,6 +132,7 @@ function loadConfig() {
|
|
|
110
132
|
const { mode: permissionMode, warnings: modeWarnings } = resolvePermissionMode(env);
|
|
111
133
|
const { timeout: permissionTimeout, warnings: timeoutWarnings } = resolvePermissionTimeout(env);
|
|
112
134
|
const permissionWarnings = [...modeWarnings, ...timeoutWarnings];
|
|
135
|
+
const codexSandboxMode = resolveCodexSandboxMode(env);
|
|
113
136
|
|
|
114
137
|
const config = {
|
|
115
138
|
// Operating mode: 'standalone' runs own WS server, 'actioncable' connects to Rails
|
|
@@ -165,6 +188,10 @@ function loadConfig() {
|
|
|
165
188
|
// Path to the Codex CLI binary, for chats on a Codex model (#480)
|
|
166
189
|
codexCommand: env.CODEX_COMMAND || 'codex',
|
|
167
190
|
|
|
191
|
+
// Sandbox every Codex chat runs in (#723): read-only, workspace-write or
|
|
192
|
+
// danger-full-access. The Codex counterpart of permissionMode.
|
|
193
|
+
codexSandboxMode,
|
|
194
|
+
|
|
168
195
|
// Stale session timeout in seconds — kill alive processes with no activity beyond this threshold.
|
|
169
196
|
// Safety net for when WebSocket-based deactivation messages are lost.
|
|
170
197
|
// Default: off (0). It never ran on a real process before #488 restored
|
|
@@ -212,4 +239,4 @@ function loadConfig() {
|
|
|
212
239
|
return Object.freeze(config);
|
|
213
240
|
}
|
|
214
241
|
|
|
215
|
-
module.exports = { loadConfig, PERMISSION_MODES };
|
|
242
|
+
module.exports = { loadConfig, PERMISSION_MODES, CODEX_SANDBOX_MODES };
|
|
@@ -12,6 +12,7 @@ const { getClaudeAccount } = require('../claude-account');
|
|
|
12
12
|
const { getMachineEffort } = require('../machine-effort');
|
|
13
13
|
const { scanPersonas, readPersonaBody, scanCrewMap, buildCrewHeader, personaSlugFromPath } = require('../persona-scanner');
|
|
14
14
|
const { handleFsRequest } = require('../fs-bridge');
|
|
15
|
+
const { JobFiles } = require('../job-styles');
|
|
15
16
|
const daemonPkg = require('../../package.json');
|
|
16
17
|
|
|
17
18
|
// #109: a session holds at most this many commands for its activation; the
|
|
@@ -50,6 +51,9 @@ class ActionCableClient extends BaseConnection {
|
|
|
50
51
|
this._capabilities = config.capabilities || {};
|
|
51
52
|
this._workingDir = config.workingDir || process.cwd();
|
|
52
53
|
|
|
54
|
+
// #638: the job files FlightDeck serves, written before a launch.
|
|
55
|
+
this._jobFiles = new JobFiles({ railsUrl: this._railsUrl, authToken: this._authToken, logger: this._logger });
|
|
56
|
+
|
|
53
57
|
// CREW-3 #181: whether the last heartbeat found .claude/crew.yml, and
|
|
54
58
|
// whether a {removed: true} for a lost file still has to go out.
|
|
55
59
|
this._crewMapSeen = false;
|
|
@@ -844,6 +848,8 @@ class ActionCableClient extends BaseConnection {
|
|
|
844
848
|
const systemPromptPath = message.system_prompt_path || undefined;
|
|
845
849
|
const model = message.model || undefined;
|
|
846
850
|
const effort = message.reasoning_effort || undefined;
|
|
851
|
+
const job = message.job || undefined;
|
|
852
|
+
const outputStyle = message.output_style || undefined;
|
|
847
853
|
let systemPrompt = message.system_prompt || undefined;
|
|
848
854
|
|
|
849
855
|
if (systemPromptPath) {
|
|
@@ -868,8 +874,13 @@ class ActionCableClient extends BaseConnection {
|
|
|
868
874
|
sessionId, userId, claudeSessionId, resetGit,
|
|
869
875
|
hasSystemPrompt: !!systemPrompt,
|
|
870
876
|
fileBacked: !!systemPromptPath,
|
|
877
|
+
job,
|
|
871
878
|
});
|
|
872
879
|
|
|
880
|
+
// #638: write the current job files before the CLI looks for them. A
|
|
881
|
+
// failure is a warning (sync never rejects); the chat still launches.
|
|
882
|
+
if (job) await this._jobFiles.sync(message.jobs_etag);
|
|
883
|
+
|
|
873
884
|
try {
|
|
874
885
|
const proc = await this._daemon.activateSession(sessionId, {
|
|
875
886
|
workingDir: this._config.workingDir,
|
|
@@ -878,6 +889,8 @@ class ActionCableClient extends BaseConnection {
|
|
|
878
889
|
systemPrompt,
|
|
879
890
|
model,
|
|
880
891
|
effort,
|
|
892
|
+
job,
|
|
893
|
+
outputStyle,
|
|
881
894
|
});
|
|
882
895
|
|
|
883
896
|
this.sendDaemonMessage({
|
package/src/daemon.js
CHANGED
|
@@ -283,6 +283,10 @@ class Daemon extends EventEmitter {
|
|
|
283
283
|
const systemPrompt = options.systemPrompt || inherited.systemPrompt;
|
|
284
284
|
const model = options.model || inherited.model;
|
|
285
285
|
const effort = options.effort || inherited.effort;
|
|
286
|
+
// #638: the job (and its style name) is fixed for the chat's life, so a
|
|
287
|
+
// resume the daemon starts on its own keeps it.
|
|
288
|
+
const job = options.job || inherited.job;
|
|
289
|
+
const outputStyle = options.outputStyle || inherited.outputStyle;
|
|
286
290
|
|
|
287
291
|
// Reset git state to clean main when requested (scheduled sessions).
|
|
288
292
|
// Awaited so spawn waits for a clean tree, but async under the hood so the
|
|
@@ -301,10 +305,13 @@ class Daemon extends EventEmitter {
|
|
|
301
305
|
claudeCommand: this._config.claudeCommand || 'claude',
|
|
302
306
|
codexCommand: this._config.codexCommand || 'codex',
|
|
303
307
|
permissionMode: this._config.permissionMode || 'auto',
|
|
308
|
+
codexSandboxMode: this._config.codexSandboxMode || 'workspace-write',
|
|
304
309
|
sessionEnv: options.sessionEnv || {},
|
|
305
310
|
systemPrompt,
|
|
306
311
|
model,
|
|
307
312
|
effort,
|
|
313
|
+
job,
|
|
314
|
+
outputStyle,
|
|
308
315
|
logger: this._logger.child(`Session:${sessionId}`),
|
|
309
316
|
});
|
|
310
317
|
|
|
@@ -337,6 +344,8 @@ class Daemon extends EventEmitter {
|
|
|
337
344
|
systemPrompt,
|
|
338
345
|
model,
|
|
339
346
|
effort,
|
|
347
|
+
job,
|
|
348
|
+
outputStyle,
|
|
340
349
|
});
|
|
341
350
|
|
|
342
351
|
this._logger.info('Session activated', { sessionId, activeCount: this._processes.size });
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const matter = require('gray-matter');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Jobs (#638). A FlightDeck chat runs as a job (lead, builder, verifier,
|
|
10
|
+
* investigator, writer, reporter), and each job is a Claude Code output style
|
|
11
|
+
* file. FlightDeck holds the files and serves them at GET /api/jobs with an
|
|
12
|
+
* ETag. Before a Claude launch the daemon writes them into the Claude config
|
|
13
|
+
* folder's output-styles/ ($CLAUDE_CONFIG_DIR, else ~/.claude), where the CLI
|
|
14
|
+
* looks them up by the `name` in their frontmatter. A Codex chat reads the
|
|
15
|
+
* same file and gets its body in its developer instructions.
|
|
16
|
+
*
|
|
17
|
+
* Rails sends the job, its style name and the files' ETag (jobs_etag) in
|
|
18
|
+
* session_activate, so the daemon fetches only when the set changed.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// A job slug is plain lowercase letters: it becomes part of a file name.
|
|
22
|
+
const JOB_PATTERN = /^[a-z]+$/;
|
|
23
|
+
const JOB_FILENAME = /^flightdeck-[a-z]+\.md$/;
|
|
24
|
+
const FETCH_TIMEOUT_MS = 5000;
|
|
25
|
+
|
|
26
|
+
function validJob(job) {
|
|
27
|
+
return typeof job === 'string' && JOB_PATTERN.test(job);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** "FlightDeck Builder" for "builder" — the name FlightDeck gives the style. */
|
|
31
|
+
function styleNameFor(job) {
|
|
32
|
+
return `FlightDeck ${job.charAt(0).toUpperCase()}${job.slice(1)}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function outputStylesDir(env = process.env, home = os.homedir()) {
|
|
36
|
+
return path.join(env.CLAUDE_CONFIG_DIR || path.join(home, '.claude'), 'output-styles');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function jobFilePath(job, env = process.env, home = os.homedir()) {
|
|
40
|
+
return path.join(outputStylesDir(env, home), `flightdeck-${job}.md`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The job file's text without its frontmatter, or null when it isn't there. */
|
|
44
|
+
function readJobBody(job, env = process.env, home = os.homedir()) {
|
|
45
|
+
if (!validJob(job)) return null;
|
|
46
|
+
let raw;
|
|
47
|
+
try {
|
|
48
|
+
raw = fs.readFileSync(jobFilePath(job, env, home), 'utf8');
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return matter(raw).content.trim() || null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Keeps the pilot's copy of the job files current. One per daemon connection.
|
|
57
|
+
*/
|
|
58
|
+
class JobFiles {
|
|
59
|
+
/**
|
|
60
|
+
* @param {object} options
|
|
61
|
+
* @param {string} options.railsUrl - FlightDeck's base URL
|
|
62
|
+
* @param {string|null} options.authToken - the pilot token (CLAUDE_AUTH_TOKEN)
|
|
63
|
+
* @param {object} options.logger
|
|
64
|
+
* @param {object} [options.env] - where CLAUDE_CONFIG_DIR is read (default process.env)
|
|
65
|
+
* @param {Function} [options.fetchFn] - tests: replacement for global fetch
|
|
66
|
+
*/
|
|
67
|
+
constructor({ railsUrl, authToken, logger, env = process.env, fetchFn = globalThis.fetch }) {
|
|
68
|
+
this._railsUrl = railsUrl;
|
|
69
|
+
this._authToken = authToken;
|
|
70
|
+
this._logger = logger;
|
|
71
|
+
this._env = env;
|
|
72
|
+
this._fetch = fetchFn;
|
|
73
|
+
this._etag = null; // the ETag of the set last written
|
|
74
|
+
this._inFlight = null; // one fetch at a time; concurrent launches share it
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get etag() {
|
|
78
|
+
return this._etag;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Write the current job files unless `etag` names the set already written.
|
|
83
|
+
* Never rejects: a failure is a warning, and the launch goes on (the CLI
|
|
84
|
+
* runs Default for a style it can't find, and ClaudeProcess warns).
|
|
85
|
+
*
|
|
86
|
+
* @param {string|null|undefined} etag - jobs_etag from session_activate
|
|
87
|
+
*/
|
|
88
|
+
async sync(etag) {
|
|
89
|
+
if (etag && etag === this._etag) return;
|
|
90
|
+
if (!this._inFlight) {
|
|
91
|
+
this._inFlight = this._fetchAndWrite().finally(() => { this._inFlight = null; });
|
|
92
|
+
}
|
|
93
|
+
await this._inFlight;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async _fetchAndWrite() {
|
|
97
|
+
// CLAUDE_RAILS_URL is http(s); a ws(s) one still names the same server.
|
|
98
|
+
const url = new URL('/api/jobs', String(this._railsUrl).replace(/^ws(s?):/, 'http$1:')).toString();
|
|
99
|
+
const headers = { Accept: 'application/json' };
|
|
100
|
+
if (this._authToken) headers.Authorization = `Bearer ${this._authToken}`;
|
|
101
|
+
if (this._etag) headers['If-None-Match'] = this._etag;
|
|
102
|
+
|
|
103
|
+
let response;
|
|
104
|
+
try {
|
|
105
|
+
response = await this._fetch(url, { headers, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
106
|
+
} catch (err) {
|
|
107
|
+
this._logger.warn('Could not fetch the job files from FlightDeck', { url, error: err.message });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (response.status === 304) return;
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
this._logger.warn(`Could not fetch the job files from FlightDeck: HTTP ${response.status}`, { url });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let body;
|
|
118
|
+
try {
|
|
119
|
+
body = await response.json();
|
|
120
|
+
} catch (err) {
|
|
121
|
+
this._logger.warn('FlightDeck sent job files that are not JSON', { url, error: err.message });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const dir = outputStylesDir(this._env);
|
|
126
|
+
try {
|
|
127
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
128
|
+
for (const job of Array.isArray(body.jobs) ? body.jobs : []) {
|
|
129
|
+
if (!JOB_FILENAME.test(job.filename || '') || typeof job.content !== 'string') {
|
|
130
|
+
this._logger.warn('Skipping a job file with an unexpected name', { filename: job.filename });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// Write then rename, so a CLI starting now never reads half a file.
|
|
134
|
+
const target = path.join(dir, job.filename);
|
|
135
|
+
const temp = `${target}.${process.pid}.tmp`;
|
|
136
|
+
fs.writeFileSync(temp, job.content);
|
|
137
|
+
fs.renameSync(temp, target);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
this._logger.warn('Could not write the job files', { dir, error: err.message });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this._etag = response.headers.get('etag') || null;
|
|
145
|
+
this._logger.info('Wrote the job files', { dir, etag: this._etag });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
JobFiles,
|
|
151
|
+
validJob,
|
|
152
|
+
styleNameFor,
|
|
153
|
+
outputStylesDir,
|
|
154
|
+
jobFilePath,
|
|
155
|
+
readJobBody,
|
|
156
|
+
};
|
package/src/persona-scanner.js
CHANGED
|
@@ -21,7 +21,7 @@ const RANK_TITLES = { 1: 'Chief of Staff', 2: 'officer', 3: 'crew' };
|
|
|
21
21
|
* - slug is derived from the filename (minus the .md suffix)
|
|
22
22
|
* - YAML frontmatter is parsed for optional `name`, `description`, `role`, `tokens`
|
|
23
23
|
* (the heartbeat wire format calls this field `decision_tokens` — see below),
|
|
24
|
-
* `model` and `
|
|
24
|
+
* `model`, `reasoning_effort` and `default_job`
|
|
25
25
|
* - body is parsed but NOT included in the returned metadata (heartbeat carries
|
|
26
26
|
* metadata only; body is re-read at activation time in Phase 3)
|
|
27
27
|
* - path is returned relative to workingDir for stable cross-pilot keys
|
|
@@ -33,7 +33,8 @@ const RANK_TITLES = { 1: 'Chief of Staff', 2: 'officer', 3: 'crew' };
|
|
|
33
33
|
*
|
|
34
34
|
* `model` and `reasoning_effort` (#596) are what the persona launches with
|
|
35
35
|
* when nobody picks. They pass through as trimmed text; Rails owns the model
|
|
36
|
-
* list and drops a value it doesn't know.
|
|
36
|
+
* list and drops a value it doesn't know. `default_job` (#638) is the job it
|
|
37
|
+
* launches as, passed through the same way.
|
|
37
38
|
*
|
|
38
39
|
* Failure modes are non-fatal:
|
|
39
40
|
* - missing personas directory => empty array
|
|
@@ -44,7 +45,7 @@ const RANK_TITLES = { 1: 'Chief of Staff', 2: 'officer', 3: 'crew' };
|
|
|
44
45
|
* @param {string} workingDir - The pilot's working directory.
|
|
45
46
|
* @param {object} [opts]
|
|
46
47
|
* @param {{warn: function}} [opts.logger] - Optional logger; warnings only.
|
|
47
|
-
* @returns {Promise<Array<{slug: string, name: string|null, description: string|null, path: string, role: string|null, decision_tokens: Array|null, model: string|null, reasoning_effort: string|null}>>}
|
|
48
|
+
* @returns {Promise<Array<{slug: string, name: string|null, description: string|null, path: string, role: string|null, decision_tokens: Array|null, model: string|null, reasoning_effort: string|null, default_job: string|null}>>}
|
|
48
49
|
*/
|
|
49
50
|
async function scanPersonas(workingDir, opts = {}) {
|
|
50
51
|
if (!workingDir) return [];
|
|
@@ -107,6 +108,9 @@ async function _parsePersonaFile(filePath, fileName, workingDir, logger) {
|
|
|
107
108
|
decision_tokens: Array.isArray(frontmatter.tokens) ? frontmatter.tokens.slice() : null,
|
|
108
109
|
model: _trimmedOrNull(frontmatter.model),
|
|
109
110
|
reasoning_effort: _trimmedOrNull(frontmatter.reasoning_effort),
|
|
111
|
+
// #638: the job the persona launches as when nobody picks one. Passed
|
|
112
|
+
// through as written; Rails drops one that isn't a job it knows.
|
|
113
|
+
default_job: _trimmedOrNull(frontmatter.default_job),
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
116
|
|