@causyne/agent 1.20.120 → 1.20.121

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.
Files changed (59) hide show
  1. package/package.json +1 -1
  2. package/src/agent/errorClassifier.js +113 -0
  3. package/src/agent/errorClassifier.ts +161 -0
  4. package/src/agent/promptIntent.js +200 -0
  5. package/src/agent/promptIntent.ts +203 -0
  6. package/src/agent/toolArgValidator.js +97 -0
  7. package/src/agent/toolArgValidator.ts +112 -0
  8. package/src/agentLoop.js +22 -339
  9. package/src/agentLoop.ts +40 -347
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/cliMode.js +16 -2
  13. package/src/commands.js +10 -9
  14. package/src/config.js +42 -63
  15. package/src/configVault.js +204 -0
  16. package/src/configVault.ts +213 -0
  17. package/src/core/contextCompactor.js +70 -11
  18. package/src/core/contextCompactor.ts +83 -11
  19. package/src/dynamicCatalogue.js +42 -73
  20. package/src/dynamicCatalogue.ts +74 -60
  21. package/src/entrypoint.js +77 -4
  22. package/src/headlessCli.js +304 -0
  23. package/src/headlessCli.ts +380 -0
  24. package/src/mcp/mcpClient.js +38 -11
  25. package/src/mcp/mcpClient.ts +44 -11
  26. package/src/mcp/mcpRegistry.js +2 -5
  27. package/src/mcp/mcpRegistry.ts +2 -5
  28. package/src/mcp/mcpSecurity.js +189 -0
  29. package/src/mcp/mcpSecurity.ts +190 -0
  30. package/src/osKeychain.js +209 -0
  31. package/src/osKeychain.ts +245 -0
  32. package/src/providers/anthropic.js +28 -11
  33. package/src/providers/byokHttp.js +354 -0
  34. package/src/providers/byokHttp.ts +454 -0
  35. package/src/providers/byokStream.js +657 -0
  36. package/src/providers/byokStream.ts +759 -0
  37. package/src/providers/dashscope-byok.js +34 -25
  38. package/src/providers/deepseek.js +31 -22
  39. package/src/providers/gemini.js +40 -13
  40. package/src/providers/moonshot.js +31 -22
  41. package/src/providers/muse.js +10 -10
  42. package/src/providers/ollama.js +25 -10
  43. package/src/providers/openai-compatible.js +46 -14
  44. package/src/providers/openrouter.js +63 -29
  45. package/src/providers/openrouter.ts +73 -29
  46. package/src/providers/qwen-byok.js +33 -16
  47. package/src/providers/xai.js +31 -22
  48. package/src/sandbox.js +77 -56
  49. package/src/sandboxPolicy.js +1208 -0
  50. package/src/sandboxPolicy.ts +1300 -0
  51. package/src/sessionJournal.js +47 -0
  52. package/src/sessionJournal.ts +49 -0
  53. package/src/tools/osSandbox.js +473 -0
  54. package/src/tools/osSandbox.ts +554 -0
  55. package/src/tools/persistentShell.js +8 -3
  56. package/src/tools/subprocessEnv.js +197 -0
  57. package/src/tools/subprocessEnv.ts +212 -0
  58. package/src/tools/sysRun.js +39 -6
  59. package/src/tools/sysRun.ts +53 -7
@@ -0,0 +1,554 @@
1
+ /**
2
+ * Causyne Agent — OS-Level Process Sandboxing Wrapper (Sector 2B)
3
+ *
4
+ * Provides kernel-enforced filesystem & network isolation around shell tool
5
+ * subprocesses when enabled via `CAUSYNE_OS_SANDBOX` or `config.osSandbox`:
6
+ * - macOS (`darwin`): Apple Seatbelt (`/usr/bin/sandbox-exec -p <SBPL>`)
7
+ * - Linux (`linux`): Bubblewrap (`bwrap`) mount/network namespaces
8
+ * - Windows / nested containers: honest capability reporting (`backend: 'none'`)
9
+ * with fail-closed enforcement when `strict` mode is explicitly requested.
10
+ *
11
+ * Complements application-level `Sandbox` classification and `sanitizeSubprocessEnv`
12
+ * without ever stripping or degrading peer ACP capabilities.
13
+ */
14
+
15
+ import { spawnSync } from 'node:child_process';
16
+ import fs from 'node:fs';
17
+ import os from 'node:os';
18
+ import path from 'node:path';
19
+
20
+ export type OsSandboxMode = 'off' | 'workspace-write' | 'read-only';
21
+ export type OsSandboxBackend = 'seatbelt' | 'bubblewrap' | 'none';
22
+
23
+ export interface OsSandboxCapabilities {
24
+ backend: OsSandboxBackend;
25
+ platform: NodeJS.Platform;
26
+ available: boolean;
27
+ binaryPath: string | null;
28
+ reason: string;
29
+ }
30
+
31
+ export interface OsSandboxResolution {
32
+ mode: OsSandboxMode;
33
+ strict: boolean;
34
+ allowNetwork: boolean;
35
+ }
36
+
37
+ export interface OsSandboxWrapOptions {
38
+ mode?: OsSandboxMode | undefined;
39
+ strict?: boolean | undefined;
40
+ workspaceRoots?: readonly string[] | undefined;
41
+ cwd: string;
42
+ allowNetwork?: boolean | undefined;
43
+ allowDevCaches?: boolean | undefined;
44
+ includeTempDirs?: boolean | undefined;
45
+ extraDenyReadPaths?: readonly string[] | undefined;
46
+ homeDir?: string | undefined;
47
+ tmpDir?: string | undefined;
48
+ platform?: NodeJS.Platform | undefined;
49
+ backendOverride?: OsSandboxBackend | undefined;
50
+ binaryPathOverride?: string | undefined;
51
+ }
52
+
53
+ export interface WrappedSpawnSpec {
54
+ command: string;
55
+ args: string[];
56
+ sandboxed: boolean;
57
+ backend: OsSandboxBackend;
58
+ mode: OsSandboxMode;
59
+ profile?: string | undefined;
60
+ }
61
+
62
+ const SEATBELT_BIN = '/usr/bin/sandbox-exec';
63
+
64
+ const CREDENTIAL_SUBPATHS = [
65
+ '.ssh',
66
+ '.aws',
67
+ '.gnupg',
68
+ '.kube',
69
+ '.causyne',
70
+ '.netrc',
71
+ '.git-credentials',
72
+ '.pypirc',
73
+ 'Library/Keychains'
74
+ ];
75
+
76
+ const SHELL_PERSISTENCE_FILES = [
77
+ '.bashrc',
78
+ '.bash_profile',
79
+ '.bash_login',
80
+ '.profile',
81
+ '.zshrc',
82
+ '.zprofile',
83
+ '.zshenv',
84
+ '.zlogin',
85
+ '.config/fish/config.fish'
86
+ ];
87
+
88
+ const DEV_CACHE_SUBPATHS = [
89
+ '.npm',
90
+ '.cache',
91
+ '.cargo',
92
+ '.rustup',
93
+ '.gradle',
94
+ '.m2',
95
+ 'go/pkg',
96
+ 'Library/Caches'
97
+ ];
98
+
99
+ let cachedProbe: { platform: NodeJS.Platform; result: OsSandboxCapabilities } | null = null;
100
+
101
+ /**
102
+ * Escapes a filesystem path for safe embedding in an Apple Seatbelt SBPL string.
103
+ * Rejects control characters and NUL bytes to prevent S-expression injection.
104
+ */
105
+ export function escapeSeatbeltPath(rawPath: string): string | null {
106
+ if (typeof rawPath !== 'string' || rawPath.length === 0) return null;
107
+ for (let i = 0; i < rawPath.length; i++) {
108
+ const code = rawPath.charCodeAt(i);
109
+ if (code < 0x20 || code === 0x7f) return null;
110
+ }
111
+ return rawPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
112
+ }
113
+
114
+ function resolveCanonicalPaths(rawPath: string): string[] {
115
+ const resolved = path.resolve(rawPath);
116
+ const out = new Set<string>([resolved]);
117
+ try {
118
+ const real = fs.realpathSync.native(resolved);
119
+ out.add(real);
120
+ } catch {
121
+ // Walk up to nearest existing ancestor so symlinked prefixes (e.g. /var -> /private/var) resolve
122
+ let current = resolved;
123
+ const tail: string[] = [];
124
+ for (let depth = 0; depth < 64; depth++) {
125
+ const parent = path.dirname(current);
126
+ if (parent === current) break;
127
+ tail.unshift(path.basename(current));
128
+ current = parent;
129
+ try {
130
+ const realAncestor = fs.realpathSync.native(current);
131
+ out.add(path.resolve(realAncestor, ...tail));
132
+ break;
133
+ } catch {
134
+ continue;
135
+ }
136
+ }
137
+ }
138
+ return [...out];
139
+ }
140
+
141
+ function isSameOrChildPath(candidate: string, parent: string): boolean {
142
+ const rel = path.relative(parent, candidate);
143
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
144
+ }
145
+
146
+ function workspaceOverlapsPath(workspacePaths: readonly string[], targetPath: string): boolean {
147
+ const targetVariants = resolveCanonicalPaths(targetPath);
148
+ for (const ws of workspacePaths) {
149
+ const wsVariants = resolveCanonicalPaths(ws);
150
+ for (const wv of wsVariants) {
151
+ for (const tv of targetVariants) {
152
+ if (isSameOrChildPath(wv, tv)) return true;
153
+ }
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+
159
+ /**
160
+ * Parses `CAUSYNE_OS_SANDBOX` / `config.osSandbox` into an explicit OS sandbox mode.
161
+ * Defaults to `'off'` unless explicitly enabled so standard workflows never break unexpectedly.
162
+ */
163
+ export function resolveOsSandboxMode(
164
+ env: NodeJS.ProcessEnv = process.env,
165
+ configMode?: unknown
166
+ ): OsSandboxResolution {
167
+ const raw = (typeof env.CAUSYNE_OS_SANDBOX === 'string' && env.CAUSYNE_OS_SANDBOX.trim())
168
+ ? env.CAUSYNE_OS_SANDBOX.trim()
169
+ : (typeof configMode === 'string' ? configMode.trim() : '');
170
+ const lower = raw.toLowerCase();
171
+
172
+ const networkEnv = typeof env.CAUSYNE_OS_SANDBOX_NETWORK === 'string'
173
+ ? env.CAUSYNE_OS_SANDBOX_NETWORK.trim().toLowerCase()
174
+ : '';
175
+ const allowNetwork = !(networkEnv === '0' || networkEnv === 'false' || networkEnv === 'off' || networkEnv === 'deny');
176
+
177
+ if (!lower || lower === 'off' || lower === '0' || lower === 'false' || lower === 'disabled') {
178
+ return { mode: 'off', strict: false, allowNetwork };
179
+ }
180
+ if (lower === 'read-only' || lower === 'readonly' || lower === 'ro') {
181
+ return { mode: 'read-only', strict: false, allowNetwork };
182
+ }
183
+ if (lower === 'read-only-strict') {
184
+ return { mode: 'read-only', strict: true, allowNetwork };
185
+ }
186
+ if (lower === 'strict') {
187
+ return { mode: 'workspace-write', strict: true, allowNetwork };
188
+ }
189
+ if (lower === 'workspace-write' || lower === 'on' || lower === '1' || lower === 'true' || lower === 'auto') {
190
+ return { mode: 'workspace-write', strict: false, allowNetwork };
191
+ }
192
+ return { mode: 'off', strict: false, allowNetwork };
193
+ }
194
+
195
+ function findExecutableInPath(binaryName: string, env: NodeJS.ProcessEnv = process.env): string | null {
196
+ const pathVal = env.PATH || '';
197
+ for (const dir of pathVal.split(path.delimiter)) {
198
+ if (!dir) continue;
199
+ const candidate = path.join(dir, binaryName);
200
+ try {
201
+ fs.accessSync(candidate, fs.constants.X_OK);
202
+ if (fs.statSync(candidate).isFile()) return candidate;
203
+ } catch {
204
+ continue;
205
+ }
206
+ }
207
+ return null;
208
+ }
209
+
210
+ /**
211
+ * Probes whether an OS-level kernel sandbox backend is installed and functional
212
+ * (not blocked by a nested container or restricted user namespace).
213
+ */
214
+ export function probeOsSandbox(options?: {
215
+ platform?: NodeJS.Platform | undefined;
216
+ bypassCache?: boolean | undefined;
217
+ }): OsSandboxCapabilities {
218
+ const platform = options?.platform ?? process.platform;
219
+ if (!options?.bypassCache && cachedProbe && cachedProbe.platform === platform) {
220
+ return cachedProbe.result;
221
+ }
222
+
223
+ let result: OsSandboxCapabilities;
224
+
225
+ if (platform === 'darwin') {
226
+ if (!fs.existsSync(SEATBELT_BIN)) {
227
+ result = {
228
+ backend: 'none',
229
+ platform,
230
+ available: false,
231
+ binaryPath: null,
232
+ reason: 'macOS sandbox-exec binary not found.'
233
+ };
234
+ } else {
235
+ const check = spawnSync(SEATBELT_BIN, ['-p', '(version 1)(allow default)', '/usr/bin/true'], {
236
+ stdio: 'ignore',
237
+ timeout: 3000
238
+ });
239
+ if (check.status === 0) {
240
+ result = {
241
+ backend: 'seatbelt',
242
+ platform,
243
+ available: true,
244
+ binaryPath: SEATBELT_BIN,
245
+ reason: 'macOS Seatbelt (sandbox-exec) active and verified.'
246
+ };
247
+ } else {
248
+ result = {
249
+ backend: 'none',
250
+ platform,
251
+ available: false,
252
+ binaryPath: SEATBELT_BIN,
253
+ reason: 'macOS Seatbelt cannot apply in this environment (likely nested sandbox).'
254
+ };
255
+ }
256
+ }
257
+ } else if (platform === 'linux') {
258
+ const bwrapPath = findExecutableInPath('bwrap');
259
+ if (!bwrapPath) {
260
+ result = {
261
+ backend: 'none',
262
+ platform,
263
+ available: false,
264
+ binaryPath: null,
265
+ reason: 'Linux bubblewrap (bwrap) is not installed.'
266
+ };
267
+ } else {
268
+ const check = spawnSync(bwrapPath, ['--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '/bin/true'], {
269
+ stdio: 'ignore',
270
+ timeout: 3000
271
+ });
272
+ if (check.status === 0) {
273
+ result = {
274
+ backend: 'bubblewrap',
275
+ platform,
276
+ available: true,
277
+ binaryPath: bwrapPath,
278
+ reason: 'Linux bubblewrap (bwrap) namespaces active and verified.'
279
+ };
280
+ } else {
281
+ result = {
282
+ backend: 'none',
283
+ platform,
284
+ available: false,
285
+ binaryPath: bwrapPath,
286
+ reason: 'Linux bubblewrap (bwrap) unavailable (user namespaces disabled in container).'
287
+ };
288
+ }
289
+ }
290
+ } else {
291
+ result = {
292
+ backend: 'none',
293
+ platform,
294
+ available: false,
295
+ binaryPath: null,
296
+ reason: `Kernel subprocess sandboxing is not implemented for platform "${platform}"; application sandbox and env isolation remain active.`
297
+ };
298
+ }
299
+
300
+ if (!options?.bypassCache) {
301
+ cachedProbe = { platform, result };
302
+ }
303
+ return result;
304
+ }
305
+
306
+ /**
307
+ * Generates an Apple Seatbelt SBPL profile for macOS `sandbox-exec`.
308
+ * Uses Seatbelt's last-match-wins semantics:
309
+ * 1. Allow default reads/exec of system libraries & toolchains.
310
+ * 2. Optionally deny remote outbound IP connections (`allowNetwork === false`).
311
+ * 3. Deny all `file-write*`, then allow only safe device nodes, workspace roots,
312
+ * temp dirs, and standard dev caches (in `workspace-write` mode).
313
+ * 4. Explicitly deny `file-write*` on shell startup profiles and credential vaults.
314
+ * 5. Explicitly deny `file-read*` on credential vaults (unless the user explicitly
315
+ * selected that directory as their workspace).
316
+ */
317
+ export function buildSeatbeltProfile(options: OsSandboxWrapOptions): string {
318
+ const mode = options.mode ?? 'workspace-write';
319
+ const homeDir = options.homeDir ?? os.homedir();
320
+ const tmpDir = options.tmpDir ?? os.tmpdir();
321
+ const workspaces = options.workspaceRoots && options.workspaceRoots.length > 0
322
+ ? [...options.workspaceRoots, options.cwd]
323
+ : [options.cwd];
324
+
325
+ const lines: string[] = [
326
+ '(version 1)',
327
+ '(allow default)'
328
+ ];
329
+
330
+ if (options.allowNetwork === false) {
331
+ lines.push('(deny network-outbound (remote ip))');
332
+ }
333
+
334
+ lines.push('(deny file-write*)');
335
+
336
+ // Always allow writing to standard harmless device sinks
337
+ const safeDeviceLiterals = [
338
+ '/dev/null',
339
+ '/dev/zero',
340
+ '/dev/tty',
341
+ '/dev/ptmx',
342
+ '/dev/dtracehelper',
343
+ '/dev/stdout',
344
+ '/dev/stderr'
345
+ ];
346
+ lines.push(
347
+ `(allow file-write* ${safeDeviceLiterals.map(p => `(literal "${p}")`).join(' ')})`
348
+ );
349
+
350
+ if (mode === 'workspace-write') {
351
+ const writableSubpaths = new Set<string>();
352
+ const addWritable = (rawPath: string): void => {
353
+ for (const variant of resolveCanonicalPaths(rawPath)) {
354
+ const escaped = escapeSeatbeltPath(variant);
355
+ if (escaped) writableSubpaths.add(escaped);
356
+ }
357
+ };
358
+
359
+ for (const ws of workspaces) {
360
+ addWritable(ws);
361
+ }
362
+
363
+ if (options.includeTempDirs !== false) {
364
+ for (const t of ['/tmp', '/private/tmp', '/private/var/tmp', '/private/var/folders', tmpDir]) {
365
+ if (t) addWritable(t);
366
+ }
367
+ }
368
+
369
+ if (options.allowDevCaches !== false && homeDir) {
370
+ for (const rel of DEV_CACHE_SUBPATHS) {
371
+ addWritable(path.join(homeDir, rel));
372
+ }
373
+ }
374
+
375
+ if (writableSubpaths.size > 0) {
376
+ const clauses = [...writableSubpaths].map(p => `(subpath "${p}")`).join(' ');
377
+ lines.push(`(allow file-write* ${clauses})`);
378
+ }
379
+ }
380
+
381
+ // Last-match-wins: shell startup persistence targets remain strictly unwritable
382
+ if (homeDir) {
383
+ const denyWriteLiterals = new Set<string>();
384
+ for (const rel of SHELL_PERSISTENCE_FILES) {
385
+ const full = path.join(homeDir, rel);
386
+ for (const variant of resolveCanonicalPaths(full)) {
387
+ const escaped = escapeSeatbeltPath(variant);
388
+ if (escaped) denyWriteLiterals.add(escaped);
389
+ }
390
+ }
391
+ if (denyWriteLiterals.size > 0) {
392
+ lines.push(
393
+ `(deny file-write* ${[...denyWriteLiterals].map(p => `(literal "${p}")`).join(' ')})`
394
+ );
395
+ }
396
+ }
397
+
398
+ // Last-match-wins: credential vaults denied for both read and write unless explicitly chosen as workspace
399
+ const denyCredSubpaths = new Set<string>();
400
+ if (homeDir) {
401
+ for (const rel of CREDENTIAL_SUBPATHS) {
402
+ const full = path.join(homeDir, rel);
403
+ if (workspaceOverlapsPath(workspaces, full)) continue;
404
+ for (const variant of resolveCanonicalPaths(full)) {
405
+ const escaped = escapeSeatbeltPath(variant);
406
+ if (escaped) denyCredSubpaths.add(escaped);
407
+ }
408
+ }
409
+ }
410
+ if (Array.isArray(options.extraDenyReadPaths)) {
411
+ for (const extra of options.extraDenyReadPaths) {
412
+ for (const variant of resolveCanonicalPaths(extra)) {
413
+ const escaped = escapeSeatbeltPath(variant);
414
+ if (escaped) denyCredSubpaths.add(escaped);
415
+ }
416
+ }
417
+ }
418
+
419
+ if (denyCredSubpaths.size > 0) {
420
+ const clauses = [...denyCredSubpaths].map(p => `(subpath "${p}")`).join(' ');
421
+ lines.push(`(deny file-read* ${clauses})`);
422
+ lines.push(`(deny file-write* ${clauses})`);
423
+ }
424
+
425
+ return `${lines.join('\n')}\n`;
426
+ }
427
+
428
+ /**
429
+ * Generates shell-free argv for Linux `bwrap` (bubblewrap) isolation.
430
+ */
431
+ export function buildBubblewrapArgs(
432
+ shell: string,
433
+ shellArgs: readonly string[],
434
+ options: OsSandboxWrapOptions
435
+ ): string[] {
436
+ const mode = options.mode ?? 'workspace-write';
437
+ const homeDir = options.homeDir ?? os.homedir();
438
+ const workspaces = options.workspaceRoots && options.workspaceRoots.length > 0
439
+ ? [...options.workspaceRoots, options.cwd]
440
+ : [options.cwd];
441
+
442
+ const args: string[] = [
443
+ '--die-with-parent',
444
+ '--ro-bind', '/', '/',
445
+ '--dev', '/dev',
446
+ '--proc', '/proc'
447
+ ];
448
+
449
+ if (options.includeTempDirs !== false) {
450
+ args.push('--tmpfs', '/tmp');
451
+ }
452
+
453
+ if (options.allowNetwork === false) {
454
+ args.push('--unshare-net');
455
+ }
456
+
457
+ if (mode === 'workspace-write') {
458
+ const bound = new Set<string>();
459
+ const bindIfExists = (rawPath: string): void => {
460
+ const resolved = path.resolve(rawPath);
461
+ if (bound.has(resolved)) return;
462
+ if (!fs.existsSync(resolved)) return;
463
+ bound.add(resolved);
464
+ args.push('--bind', resolved, resolved);
465
+ };
466
+
467
+ for (const ws of workspaces) {
468
+ bindIfExists(ws);
469
+ }
470
+ if (options.allowDevCaches !== false && homeDir) {
471
+ for (const rel of DEV_CACHE_SUBPATHS) {
472
+ bindIfExists(path.join(homeDir, rel));
473
+ }
474
+ }
475
+ }
476
+
477
+ // Mask existing credential directories with empty tmpfs mounts unless inside selected workspace
478
+ if (homeDir) {
479
+ for (const rel of ['.ssh', '.aws', '.gnupg', '.kube', '.causyne']) {
480
+ const full = path.join(homeDir, rel);
481
+ if (workspaceOverlapsPath(workspaces, full)) continue;
482
+ try {
483
+ if (fs.existsSync(full) && fs.statSync(full).isDirectory()) {
484
+ args.push('--tmpfs', full);
485
+ }
486
+ } catch {
487
+ continue;
488
+ }
489
+ }
490
+ }
491
+
492
+ args.push('--chdir', path.resolve(options.cwd), '--', shell, ...shellArgs);
493
+ return args;
494
+ }
495
+
496
+ /**
497
+ * Wraps a `(shell, shellArgs)` invocation in an OS kernel sandbox when enabled.
498
+ */
499
+ export function wrapCommandWithOsSandbox(
500
+ shell: string,
501
+ shellArgs: readonly string[],
502
+ options: OsSandboxWrapOptions
503
+ ): WrappedSpawnSpec {
504
+ const mode = options.mode ?? 'off';
505
+ if (mode === 'off') {
506
+ return {
507
+ command: shell,
508
+ args: [...shellArgs],
509
+ sandboxed: false,
510
+ backend: 'none',
511
+ mode: 'off'
512
+ };
513
+ }
514
+
515
+ const platform = options.platform ?? process.platform;
516
+ const backend: OsSandboxBackend = options.backendOverride
517
+ ?? (probeOsSandbox({ platform }).available ? probeOsSandbox({ platform }).backend : 'none');
518
+
519
+ if (backend === 'seatbelt') {
520
+ const profile = buildSeatbeltProfile({ ...options, mode });
521
+ return {
522
+ command: options.binaryPathOverride || SEATBELT_BIN,
523
+ args: ['-p', profile, '--', shell, ...shellArgs],
524
+ sandboxed: true,
525
+ backend: 'seatbelt',
526
+ mode,
527
+ profile
528
+ };
529
+ }
530
+
531
+ if (backend === 'bubblewrap') {
532
+ const bin = options.binaryPathOverride || probeOsSandbox({ platform }).binaryPath || 'bwrap';
533
+ return {
534
+ command: bin,
535
+ args: buildBubblewrapArgs(shell, shellArgs, { ...options, mode }),
536
+ sandboxed: true,
537
+ backend: 'bubblewrap',
538
+ mode
539
+ };
540
+ }
541
+
542
+ if (options.strict) {
543
+ const probe = probeOsSandbox({ platform });
544
+ throw new Error(`Strict OS sandbox requested (${mode}) but no kernel sandbox backend is available: ${probe.reason}`);
545
+ }
546
+
547
+ return {
548
+ command: shell,
549
+ args: [...shellArgs],
550
+ sandboxed: false,
551
+ backend: 'none',
552
+ mode
553
+ };
554
+ }
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'child_process';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
+ import { getEnhancedEnv } from './sysRun.js';
4
5
 
5
6
  // Singleton map of active persistent shell sessions
6
7
  const sessions = new Map();
@@ -55,9 +56,13 @@ export const persistentShell = {
55
56
  const shellBin = isWin ? 'powershell.exe' : (process.env.SHELL || '/bin/zsh');
56
57
  const shellArgs = isWin ? ['-NoLogo', '-NoExit', '-Command', '-'] : ['-l'];
57
58
 
59
+ const initialCwd = typeof args.cwd === 'string' && args.cwd.trim()
60
+ ? args.cwd.replace(/^~\//, os.homedir() + '/')
61
+ : process.cwd();
62
+
58
63
  const proc = spawn(shellBin, shellArgs, {
59
- cwd: process.cwd(),
60
- env: { ...process.env, CAUSYNE_PERSISTENT_SHELL: '1', PS1: '' },
64
+ cwd: initialCwd,
65
+ env: { ...getEnhancedEnv(), CAUSYNE_PERSISTENT_SHELL: '1', PS1: '' },
61
66
  stdio: ['pipe', 'pipe', 'pipe']
62
67
  });
63
68
 
@@ -71,7 +76,7 @@ export const persistentShell = {
71
76
 
72
77
  session = {
73
78
  process: proc,
74
- currentCwd: process.cwd()
79
+ currentCwd: initialCwd
75
80
  };
76
81
  sessions.set(sessionId, session);
77
82
  }