@causyne/agent 1.20.124 → 1.20.128

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 (254) hide show
  1. package/bin/causyne.js +1 -1
  2. package/docs/THIRD_PARTY_NOTICES.md +36 -2
  3. package/package.json +6 -4
  4. package/src/acp/protocol.ts +19 -1
  5. package/src/acp/server.js +282 -8
  6. package/src/acp/server.ts +284 -8
  7. package/src/agent/abortableDelay.js +2 -2
  8. package/src/agent/abortableDelay.ts +2 -2
  9. package/src/agent/errorClassifier.js +9 -1
  10. package/src/agent/errorClassifier.ts +8 -1
  11. package/src/agentLoop.js +142 -53
  12. package/src/agentLoop.ts +151 -50
  13. package/src/approvalPolicy.js +34 -10
  14. package/src/approvalPolicy.ts +42 -11
  15. package/src/browser/causyneBrowser.js +61 -3
  16. package/src/browser/causyneBrowser.ts +65 -3
  17. package/src/browser/urlPolicy.js +14 -1
  18. package/src/browser/urlPolicy.ts +12 -1
  19. package/src/cliMode.js +21 -9
  20. package/src/cliMode.ts +20 -8
  21. package/src/commands.js +365 -45
  22. package/src/commands.ts +403 -45
  23. package/src/config.js +19 -4
  24. package/src/config.ts +18 -4
  25. package/src/core/contextCompactor.js +54 -7
  26. package/src/core/contextCompactor.ts +63 -7
  27. package/src/core/goalLoop.js +257 -0
  28. package/src/core/goalLoop.ts +310 -0
  29. package/src/entrypoint.js +135 -3
  30. package/src/entrypoint.ts +136 -3
  31. package/src/game/causyneCoreBridge.js +686 -0
  32. package/src/game/causyneCoreBridge.ts +702 -0
  33. package/src/game/gameLauncher.js +287 -0
  34. package/src/game/gameLauncher.ts +352 -0
  35. package/src/game/gameProvisioner.js +425 -0
  36. package/src/game/gameProvisioner.ts +488 -0
  37. package/src/headlessCli.js +19 -12
  38. package/src/headlessCli.ts +22 -8
  39. package/src/infra/atomicWriter.js +40 -4
  40. package/src/infra/atomicWriter.ts +36 -4
  41. package/src/launchIntent.js +73 -3
  42. package/src/launchIntent.ts +76 -3
  43. package/src/lsp/lspClient.js +83 -12
  44. package/src/lsp/lspClient.ts +75 -12
  45. package/src/mcp/mcpRegistry.js +75 -8
  46. package/src/mcp/mcpRegistry.ts +70 -7
  47. package/src/memory/contextBudget.js +2 -0
  48. package/src/memory/contextBudget.ts +1 -0
  49. package/src/memory/episodicStore.js +40 -0
  50. package/src/memory/episodicStore.ts +46 -0
  51. package/src/memory.js +67 -0
  52. package/src/memory.ts +65 -0
  53. package/src/modelVariants.js +45 -0
  54. package/src/modelVariants.ts +54 -0
  55. package/src/outputRecovery.js +3 -2
  56. package/src/outputRecovery.ts +4 -2
  57. package/src/permissionPresets.js +327 -0
  58. package/src/permissionPresets.ts +361 -0
  59. package/src/personalization.js +365 -0
  60. package/src/personalization.ts +471 -0
  61. package/src/projectInstructions.js +30 -10
  62. package/src/projectInstructions.ts +31 -12
  63. package/src/providers/acp.js +3 -2
  64. package/src/providers/acp.ts +3 -2
  65. package/src/providers/antigravity.js +64 -9
  66. package/src/providers/antigravity.ts +75 -9
  67. package/src/providers/byokHttp.js +7 -1
  68. package/src/providers/byokHttp.ts +6 -1
  69. package/src/providers/byokStream.js +21 -8
  70. package/src/providers/byokStream.ts +17 -7
  71. package/src/providers/dashscope-byok.js +21 -5
  72. package/src/providers/dashscope-byok.ts +29 -11
  73. package/src/providers/moonshot.js +26 -7
  74. package/src/providers/moonshot.ts +34 -13
  75. package/src/providers/muse.js +6 -0
  76. package/src/providers/muse.ts +8 -0
  77. package/src/providers/ollama.js +39 -7
  78. package/src/providers/ollama.ts +36 -7
  79. package/src/providers/openai-compatible.js +16 -3
  80. package/src/providers/openai-compatible.ts +13 -3
  81. package/src/providers/openai.js +62 -4
  82. package/src/providers/openai.ts +50 -4
  83. package/src/providers/openrouter.js +19 -4
  84. package/src/providers/openrouter.ts +21 -4
  85. package/src/providers/qwen-byok.js +21 -5
  86. package/src/providers/qwen-byok.ts +29 -11
  87. package/src/providers/xai.js +26 -10
  88. package/src/providers/xai.ts +34 -16
  89. package/src/reporting.js +4 -2
  90. package/src/reporting.ts +4 -2
  91. package/src/sandbox.js +34 -0
  92. package/src/sandbox.ts +43 -0
  93. package/src/scheduler/scheduler.js +372 -0
  94. package/src/scheduler/scheduler.ts +433 -0
  95. package/src/sessionSearchIndex.js +267 -0
  96. package/src/sessionSearchIndex.ts +311 -0
  97. package/src/skillsManager.js +2 -3
  98. package/src/skillsManager.ts +2 -3
  99. package/src/toolPacks.js +6 -0
  100. package/src/toolPacks.ts +6 -0
  101. package/src/tools/applyPatch.js +1 -1
  102. package/src/tools/applyPatch.ts +1 -1
  103. package/src/tools/generateMediaViaApi.js +4 -3
  104. package/src/tools/generateMediaViaApi.ts +4 -3
  105. package/src/tools/memoryWrite.js +15 -1
  106. package/src/tools/memoryWrite.ts +16 -1
  107. package/src/tools/nativeEngine.js +2 -2
  108. package/src/tools/nativeEngine.ts +2 -2
  109. package/src/tools/openSourceToolProvisioner.js +2 -2
  110. package/src/tools/openSourceToolProvisioner.ts +2 -2
  111. package/src/tools/osSandbox.js +1 -1
  112. package/src/tools/osSandbox.ts +1 -1
  113. package/src/tools/payloadSanitizer.js +0 -1
  114. package/src/tools/payloadSanitizer.ts +0 -1
  115. package/src/tools/pdfReader.js +122 -20
  116. package/src/tools/pdfReader.ts +111 -20
  117. package/src/tools/presentDeliverable.js +103 -0
  118. package/src/tools/presentDeliverable.ts +127 -0
  119. package/src/tools/ptcRuntime.js +444 -0
  120. package/src/tools/ptcRuntime.ts +490 -0
  121. package/src/tools/ptyTerminal.js +1108 -0
  122. package/src/tools/ptyTerminal.ts +1245 -0
  123. package/src/tools/registry.js +21 -12
  124. package/src/tools/registry.ts +21 -12
  125. package/src/tools/toolOutputStore.js +26 -4
  126. package/src/tools/toolOutputStore.ts +22 -4
  127. package/src/tools/webFetch.js +158 -11
  128. package/src/tools/webFetch.ts +145 -11
  129. package/src/tools/webSearch.js +123 -36
  130. package/src/tools/webSearch.ts +124 -33
  131. package/src/tui/banner.js +5 -1
  132. package/src/tui/banner.ts +6 -1
  133. package/src/tui/chatRenderer.js +1 -2
  134. package/src/tui/chatRenderer.ts +1 -2
  135. package/src/tui/completion.js +1 -0
  136. package/src/tui/completion.ts +1 -0
  137. package/src/tui/composerControls.js +111 -27
  138. package/src/tui/composerControls.ts +124 -28
  139. package/src/tui/dialogs.js +3 -16
  140. package/src/tui/dialogs.ts +3 -16
  141. package/src/tui/home.js +1 -0
  142. package/src/tui/home.ts +1 -0
  143. package/src/tui/invocation.js +1 -2
  144. package/src/tui/invocation.ts +1 -2
  145. package/src/tui/modelPicker.js +22 -12
  146. package/src/tui/modelPicker.ts +22 -12
  147. package/src/tui/overlay.js +2 -5
  148. package/src/tui/overlay.ts +2 -5
  149. package/src/tui/prompt.js +6 -4
  150. package/src/tui/prompt.ts +6 -4
  151. package/src/tui/selectList.js +4 -12
  152. package/src/tui/selectList.ts +4 -12
  153. package/src/tui/setup.js +22 -9
  154. package/src/tui/setup.ts +26 -9
  155. package/src/tui/statusLine.ts +2 -0
  156. package/src/web/client/browserPanel.js +905 -0
  157. package/src/web/client/browserPanel.ts +872 -0
  158. package/src/web/client/chatStream.js +321 -0
  159. package/src/web/client/chatStream.ts +297 -0
  160. package/src/web/client/cliPanel.js +165 -0
  161. package/src/web/client/cliPanel.ts +171 -0
  162. package/src/web/client/composer.js +204 -0
  163. package/src/web/client/composer.ts +209 -0
  164. package/src/web/client/diffPanel.js +176 -0
  165. package/src/web/client/diffPanel.ts +203 -0
  166. package/src/web/client/dom.js +271 -0
  167. package/src/web/client/dom.ts +272 -0
  168. package/src/web/client/filesAndCanvas.js +233 -0
  169. package/src/web/client/filesAndCanvas.ts +240 -0
  170. package/src/web/client/gameLauncherUi.js +78 -0
  171. package/src/web/client/gameLauncherUi.ts +78 -0
  172. package/src/web/client/main.js +316 -0
  173. package/src/web/client/main.ts +391 -0
  174. package/src/web/client/markdown.js +364 -0
  175. package/src/web/client/markdown.ts +373 -0
  176. package/src/web/client/modelPicker.js +455 -0
  177. package/src/web/client/modelPicker.ts +451 -0
  178. package/src/web/client/permissionPresetsUi.js +307 -0
  179. package/src/web/client/permissionPresetsUi.ts +333 -0
  180. package/src/web/client/sessions.js +353 -0
  181. package/src/web/client/sessions.ts +372 -0
  182. package/src/web/client/settingsModal.js +824 -0
  183. package/src/web/client/settingsModal.ts +959 -0
  184. package/src/web/client/state.js +280 -0
  185. package/src/web/client/state.ts +259 -0
  186. package/src/web/client/streamSmoother.js +127 -0
  187. package/src/web/client/streamSmoother.ts +119 -0
  188. package/src/web/client/studioLayout.js +89 -0
  189. package/src/web/client/studioLayout.ts +103 -0
  190. package/src/web/client/studioShell.js +660 -0
  191. package/src/web/client/studioShell.ts +672 -0
  192. package/src/web/client/studioStart.js +77 -0
  193. package/src/web/client/studioStart.ts +89 -0
  194. package/src/web/client/terminalPanel.js +606 -0
  195. package/src/web/client/terminalPanel.ts +632 -0
  196. package/src/web/client/terminalTheme.js +249 -0
  197. package/src/web/client/terminalTheme.ts +258 -0
  198. package/src/web/client/turnView.js +934 -0
  199. package/src/web/client/turnView.ts +981 -0
  200. package/src/web/client/types.js +1 -0
  201. package/src/web/client/types.ts +322 -0
  202. package/src/web/client/validators.js +147 -0
  203. package/src/web/client/validators.ts +140 -0
  204. package/src/web/server/activeRuns.js +152 -0
  205. package/src/web/server/activeRuns.ts +171 -0
  206. package/src/web/server/routesBrowser.js +409 -0
  207. package/src/web/server/routesBrowser.ts +435 -0
  208. package/src/web/server/routesChat.js +304 -0
  209. package/src/web/server/routesChat.ts +347 -0
  210. package/src/web/server/routesCore.js +472 -0
  211. package/src/web/server/routesCore.ts +522 -0
  212. package/src/web/server/routesSettings.js +344 -0
  213. package/src/web/server/routesSettings.ts +397 -0
  214. package/src/web/server/routesTerminal.js +162 -0
  215. package/src/web/server/routesTerminal.ts +182 -0
  216. package/src/web/server/routesWorkspace.js +510 -0
  217. package/src/web/server/routesWorkspace.ts +546 -0
  218. package/src/web/server/security.js +98 -0
  219. package/src/web/server/security.ts +108 -0
  220. package/src/web/server/sessionTranscript.js +586 -0
  221. package/src/web/server/sessionTranscript.ts +566 -0
  222. package/src/web/server/staticAssets.js +104 -0
  223. package/src/web/server/staticAssets.ts +116 -0
  224. package/src/web/server/types.js +1 -0
  225. package/src/web/server/types.ts +135 -0
  226. package/src/web/server/workspaceFiles.js +368 -0
  227. package/src/web/server/workspaceFiles.ts +363 -0
  228. package/src/web/skybridgeServer.js +78 -2448
  229. package/src/web/skybridgeServer.ts +120 -2600
  230. package/src/web/skybridgeUi.js +20 -450
  231. package/src/web/skybridgeUi.ts +24 -455
  232. package/src/web/styles/agent.css +380 -0
  233. package/src/web/styles/composer.css +193 -0
  234. package/src/web/styles/overlays.css +935 -0
  235. package/src/web/styles/shell.css +387 -0
  236. package/src/web/styles/studio.css +951 -0
  237. package/src/web/styles/thread.css +221 -0
  238. package/src/web/styles/tokens.css +94 -0
  239. package/src/web/ui/brandMark.js +73 -0
  240. package/src/web/ui/brandMark.ts +82 -0
  241. package/src/web/ui/modalsTemplate.js +388 -0
  242. package/src/web/ui/modalsTemplate.ts +388 -0
  243. package/src/web/ui/sidebarTemplate.js +63 -0
  244. package/src/web/ui/sidebarTemplate.ts +64 -0
  245. package/src/web/ui/studioTemplate.js +256 -0
  246. package/src/web/ui/studioTemplate.ts +256 -0
  247. package/src/web/ui/workspaceTemplate.js +72 -0
  248. package/src/web/ui/workspaceTemplate.ts +73 -0
  249. package/src/worktreeManager.js +16 -1
  250. package/src/worktreeManager.ts +22 -1
  251. package/src/web/skybridgeClientScript.js +0 -3951
  252. package/src/web/skybridgeClientScript.ts +0 -3952
  253. package/src/web/skybridgeStyles.js +0 -827
  254. package/src/web/skybridgeStyles.ts +0 -828
@@ -5,9 +5,10 @@ function normalizePathKey(filePath) {
5
5
  const resolved = path.resolve(filePath);
6
6
  return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
7
7
  }
8
- /** Read only an exact output file already attached to this session's history. */
8
+ const RECOVERY_READ_TOOLS = new Set(['fs_read', 'code_search_ripgrep', 'fs_search']);
9
+ /** Read or search only an exact output file already attached to this session's history. */
9
10
  export function isOutputRecoveryRead(tool, target, knownPaths) {
10
- if (tool !== 'fs_read' || typeof target !== 'string')
11
+ if (!RECOVERY_READ_TOOLS.has(tool) || typeof target !== 'string')
11
12
  return false;
12
13
  const targetKey = normalizePathKey(target);
13
14
  const isKnown = Array.from(knownPaths).some(known => normalizePathKey(known) === targetKey);
@@ -7,9 +7,11 @@ function normalizePathKey(filePath: string): string {
7
7
  return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
8
8
  }
9
9
 
10
- /** Read only an exact output file already attached to this session's history. */
10
+ const RECOVERY_READ_TOOLS = new Set(['fs_read', 'code_search_ripgrep', 'fs_search']);
11
+
12
+ /** Read or search only an exact output file already attached to this session's history. */
11
13
  export function isOutputRecoveryRead(tool: string, target: unknown, knownPaths: ReadonlySet<string>): boolean {
12
- if (tool !== 'fs_read' || typeof target !== 'string') return false;
14
+ if (!RECOVERY_READ_TOOLS.has(tool) || typeof target !== 'string') return false;
13
15
  const targetKey = normalizePathKey(target);
14
16
  const isKnown = Array.from(knownPaths).some(known => normalizePathKey(known) === targetKey);
15
17
  if (!isKnown) return false;
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Causyne Agent — Unified Permission Presets (`read-only` | `workspace-write` | `danger-full-access`)
3
+ *
4
+ * Single source of truth governing Causyne's execution posture across:
5
+ * - Sandbox enforcement (`src/sandbox.ts`)
6
+ * - Tool approval policy (`src/approvalPolicy.ts` / `AgentLoop`)
7
+ * - Skybridge Web Studio composer pill, Settings default selector, and Risk Confirmation gate
8
+ * - CLI/TUI `/mode` and `/permissions` commands
9
+ *
10
+ * Preserves connected ACP peer capabilities per ACP capability policy (never strips peer tools).
11
+ */
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { atomicWriteFileSync } from './infra/atomicWriter.js';
15
+ import { loadConfig, saveConfig } from './config.js';
16
+ import { causyneHome } from './utils/paths.js';
17
+ export const PERMISSION_PRESET_IDS = Object.freeze([
18
+ 'read-only',
19
+ 'workspace-write',
20
+ 'danger-full-access'
21
+ ]);
22
+ export const PERMISSION_PRESET_CATALOG = Object.freeze([
23
+ {
24
+ id: 'read-only',
25
+ label: 'Read Only',
26
+ shortLabel: 'Read Only',
27
+ description: 'Inspect files, search code, and read web pages without modifying workspace files or running mutating commands.',
28
+ autonomyMode: 'A',
29
+ readOnly: true,
30
+ requiresRiskConfirmation: false
31
+ },
32
+ {
33
+ id: 'workspace-write',
34
+ label: 'Workspace Write',
35
+ shortLabel: 'Workspace Write',
36
+ description: 'Read and modify files strictly within the locked workspace while asking approval for dangerous or external actions.',
37
+ autonomyMode: 'B',
38
+ readOnly: false,
39
+ requiresRiskConfirmation: false
40
+ },
41
+ {
42
+ id: 'danger-full-access',
43
+ label: 'Full access',
44
+ shortLabel: 'Full access',
45
+ description: 'Reduces confirmation steps and performs workspace actions and commands directly while keeping forbidden-command and credential safeguards active.',
46
+ autonomyMode: 'C',
47
+ readOnly: false,
48
+ requiresRiskConfirmation: true
49
+ }
50
+ ]);
51
+ export function normalizePermissionPreset(raw) {
52
+ if (typeof raw !== 'string')
53
+ return null;
54
+ const cleaned = raw.trim().toLowerCase();
55
+ if (!cleaned)
56
+ return null;
57
+ if (cleaned === 'read-only'
58
+ || cleaned === 'readonly'
59
+ || cleaned === 'read_only'
60
+ || cleaned === 'read only'
61
+ || cleaned === 'a'
62
+ || cleaned === 'ask'
63
+ || cleaned === 'supervised'
64
+ || cleaned === 'strict') {
65
+ return 'read-only';
66
+ }
67
+ if (cleaned === 'workspace-write'
68
+ || cleaned === 'workspace_write'
69
+ || cleaned === 'workspace write'
70
+ || cleaned === 'workspace'
71
+ || cleaned === 'b'
72
+ || cleaned === 'balanced'
73
+ || cleaned === 'default') {
74
+ return 'workspace-write';
75
+ }
76
+ if (cleaned === 'danger-full-access'
77
+ || cleaned === 'full-access'
78
+ || cleaned === 'full_access'
79
+ || cleaned === 'full access'
80
+ || cleaned === 'full'
81
+ || cleaned === 'c'
82
+ || cleaned === 'autonomous'
83
+ || cleaned === 'auto') {
84
+ return 'danger-full-access';
85
+ }
86
+ return null;
87
+ }
88
+ export function getPermissionPresetDescriptor(id) {
89
+ return PERMISSION_PRESET_CATALOG.find((p) => p.id === id) ?? PERMISSION_PRESET_CATALOG[1];
90
+ }
91
+ export function resolveConfigPermissionPreset(config, fallback = 'workspace-write') {
92
+ if (!config || typeof config !== 'object')
93
+ return fallback;
94
+ const explicit = normalizePermissionPreset(config.permissionPreset);
95
+ const legacy = normalizePermissionPreset(config.autonomyMode);
96
+ if (explicit && legacy && presetToAutonomyMode(explicit) !== presetToAutonomyMode(legacy)) {
97
+ return legacy;
98
+ }
99
+ if (explicit)
100
+ return explicit;
101
+ if (legacy)
102
+ return legacy;
103
+ return fallback;
104
+ }
105
+ export function formatPermissionPresetLabel(raw, fallback = 'workspace-write') {
106
+ const preset = normalizePermissionPreset(raw) ?? fallback;
107
+ return getPermissionPresetDescriptor(preset).label;
108
+ }
109
+ export function presetToAutonomyMode(preset) {
110
+ return getPermissionPresetDescriptor(preset).autonomyMode;
111
+ }
112
+ export function autonomyModeToPreset(mode) {
113
+ const m = typeof mode === 'string' ? mode.trim().toUpperCase() : '';
114
+ if (m === 'A')
115
+ return 'read-only';
116
+ if (m === 'C')
117
+ return 'danger-full-access';
118
+ return 'workspace-write';
119
+ }
120
+ export function renderPermissionPolicyContext(preset, workspaceRoot) {
121
+ switch (preset) {
122
+ case 'read-only':
123
+ return `Current Causyne permission preset: Read Only. File modifications and mutating shell commands are blocked while Read Only is active (workspace: ${JSON.stringify(workspaceRoot)}).`;
124
+ case 'workspace-write':
125
+ return `Current Causyne permission preset: Workspace Write. File edits are scoped to the locked session workspace (${JSON.stringify(workspaceRoot)}) with approval required for dangerous operations.`;
126
+ case 'danger-full-access':
127
+ return `Current Causyne permission preset: Full access. Routine workspace edits and commands execute directly within policy; forbidden commands and credential safeguards remain enforced.`;
128
+ }
129
+ }
130
+ const READ_ONLY_BLOCKED_TOOLS = new Set([
131
+ 'fs_write',
132
+ 'fs_edit',
133
+ 'MultiEdit',
134
+ 'apply_patch',
135
+ 'fs_move',
136
+ 'fs_delete',
137
+ 'skill_create',
138
+ 'tool_forge',
139
+ 'plugin_manager',
140
+ 'plugins_factory',
141
+ 'document_forge',
142
+ 'ui_forge',
143
+ 'desktop_act',
144
+ 'computer_use',
145
+ 'proc_term',
146
+ 'printer_print',
147
+ 'archive',
148
+ 'manage_local_dependencies',
149
+ 'open_source_tool_provisioner',
150
+ 'generate_media_via_api',
151
+ 'execute_procedural_media',
152
+ 'game_build_html5',
153
+ 'game_asset_fetch',
154
+ 'game_asset_harvest',
155
+ 'game_scene_build',
156
+ 'game_entity_spawner',
157
+ 'game_tilemap_gen',
158
+ 'game_ui_hud_builder',
159
+ 'game_audio_synth',
160
+ 'game_vfx_emitter_gen',
161
+ 'game_shader_forge',
162
+ 'game_data_forge',
163
+ 'blender_act',
164
+ 'godot_act',
165
+ 'resolve_act',
166
+ 'palmier_act',
167
+ 'native_engine'
168
+ ]);
169
+ const READ_ONLY_GIT_SUBCOMMANDS = new Set([
170
+ 'status', 'diff', 'log', 'show', 'branch', 'tag', 'rev-parse', 'ls-files', 'ls-tree',
171
+ 'blame', 'shortlog', 'describe', 'cat-file', 'merge-base', 'grep', 'config', 'remote'
172
+ ]);
173
+ const READ_ONLY_SHELL_LEADING = new Set([
174
+ 'ls', 'pwd', 'cat', 'head', 'tail', 'wc', 'grep', 'rg', 'find', 'which', 'whereis',
175
+ 'echo', 'printf', 'env', 'printenv', 'uname', 'whoami', 'id', 'date', 'stat', 'file',
176
+ 'du', 'df', 'ps', 'lsof', 'tree', 'git', 'node', 'npm', 'tsc', 'python3', 'python'
177
+ ]);
178
+ const SHELL_MUTATION_OPERATORS = /(?:^|[^0-9])>>?\s*\S|\b(?:rm|mv|cp|mkdir|rmdir|touch|chmod|chown|ln|dd|tee|truncate|unlink|shred|sed\s+-i|perl\s+-i|npm\s+(?:i|install|uninstall|ci|publish|update)|git\s+(?:add|commit|push|pull|merge|rebase|checkout|switch|reset|clean|rm|mv|stash|cherry-pick|revert))\b/i;
179
+ function isReadOnlyShellCommand(rawCmd) {
180
+ const cmd = rawCmd.trim();
181
+ if (!cmd)
182
+ return false;
183
+ if (SHELL_MUTATION_OPERATORS.test(cmd))
184
+ return false;
185
+ const firstToken = cmd.split(/\s+/)[0]?.toLowerCase() ?? '';
186
+ if (!READ_ONLY_SHELL_LEADING.has(firstToken))
187
+ return false;
188
+ if (firstToken === 'find' && /\s-(?:delete|exec|execdir|ok|okdir)\b/i.test(cmd))
189
+ return false;
190
+ if (firstToken === 'git') {
191
+ const sub = cmd.split(/\s+/)[1]?.toLowerCase() ?? '';
192
+ return READ_ONLY_GIT_SUBCOMMANDS.has(sub);
193
+ }
194
+ if (firstToken === 'node' || firstToken === 'python' || firstToken === 'python3') {
195
+ return /^[\w.-]+\s+(?:--version|-v)\s*$/i.test(cmd);
196
+ }
197
+ if (firstToken === 'npm') {
198
+ return /^npm\s+(?:--version|-v|ls|list|outdated|view|info|search)\b/i.test(cmd);
199
+ }
200
+ if (firstToken === 'tsc') {
201
+ return /\s--noEmit\b/.test(cmd);
202
+ }
203
+ return true;
204
+ }
205
+ /**
206
+ * Returns a human-readable denial reason when a tool invocation would mutate state
207
+ * under the `read-only` permission preset, or `null` if permitted.
208
+ */
209
+ export function readOnlyPresetViolation(toolName, args) {
210
+ const canonical = String(toolName || '').trim().replace(/\./g, '_');
211
+ if (READ_ONLY_BLOCKED_TOOLS.has(canonical)) {
212
+ return `Blocked by Read Only permission preset: "${toolName}" modifies workspace or host state. Switch to Workspace Write or Full access to proceed.`;
213
+ }
214
+ if (canonical === 'web_fetch' && typeof args.outputFile === 'string' && args.outputFile.trim()) {
215
+ return 'Blocked by Read Only permission preset: downloading files to disk is disabled in Read Only mode.';
216
+ }
217
+ if (canonical === 'git_worktree') {
218
+ const act = String(args.action ?? '').trim().toLowerCase();
219
+ if (act !== 'list' && act !== 'diff') {
220
+ return `Blocked by Read Only permission preset: git_worktree action "${act || 'mutate'}" modifies worktrees.`;
221
+ }
222
+ return null;
223
+ }
224
+ if (canonical === 'gitOp') {
225
+ const raw = String(args.subcommand ?? args.command ?? args.action ?? args.op ?? '').trim();
226
+ const withoutPrefix = raw.toLowerCase().startsWith('git ') ? raw.slice(4).trim() : raw;
227
+ const sub = withoutPrefix.split(/\s+/)[0]?.toLowerCase() ?? '';
228
+ if (!READ_ONLY_GIT_SUBCOMMANDS.has(sub)) {
229
+ return `Blocked by Read Only permission preset: "git ${sub || raw}" can mutate repository state.`;
230
+ }
231
+ return null;
232
+ }
233
+ if (canonical === 'terminal_pty') {
234
+ const act = String(args.action ?? '').trim().toLowerCase();
235
+ if (act === 'list' || act === 'read' || act === 'resize')
236
+ return null;
237
+ if (act === 'send' && typeof args.input === 'string' && isReadOnlyShellCommand(args.input))
238
+ return null;
239
+ return `Blocked by Read Only permission preset: interactive terminal action "${act || 'open'}" is restricted in Read Only mode.`;
240
+ }
241
+ if (canonical === 'sysRun' || canonical === 'sysRunBg' || canonical === 'terminal_persistent_shell' || canonical === 'task_bg') {
242
+ if (canonical === 'task_bg') {
243
+ const act = String(args.action ?? 'list').trim().toLowerCase();
244
+ if (act === 'list' || act === 'status' || act === 'output' || act === 'wait')
245
+ return null;
246
+ }
247
+ const command = String(args.command ?? args.input ?? args.cmd ?? '').trim();
248
+ if (!isReadOnlyShellCommand(command)) {
249
+ return 'Blocked by Read Only permission preset: only read-only inspection commands are allowed. Switch to Workspace Write or Full access to execute mutating commands.';
250
+ }
251
+ return null;
252
+ }
253
+ return null;
254
+ }
255
+ const MAX_PERSISTED_SESSION_OVERRIDES = 250;
256
+ function sessionPermissionsPath() {
257
+ return path.join(causyneHome(), 'session-permissions.json');
258
+ }
259
+ function readSessionPermissionStore() {
260
+ try {
261
+ const fp = sessionPermissionsPath();
262
+ if (!fs.existsSync(fp))
263
+ return { version: 1, sessions: {} };
264
+ const stat = fs.lstatSync(fp);
265
+ if (stat.isSymbolicLink() || !stat.isFile())
266
+ return { version: 1, sessions: {} };
267
+ const raw = JSON.parse(fs.readFileSync(fp, 'utf8'));
268
+ const sessions = {};
269
+ if (raw && raw.sessions && typeof raw.sessions === 'object') {
270
+ for (const [sid, entry] of Object.entries(raw.sessions)) {
271
+ if (!sid || sid === '__proto__' || sid === 'constructor' || sid === 'prototype')
272
+ continue;
273
+ const norm = normalizePermissionPreset(entry?.preset);
274
+ if (!norm)
275
+ continue;
276
+ const updatedAt = Number(entry?.updatedAt) || Date.now();
277
+ sessions[sid] = { preset: norm, updatedAt };
278
+ }
279
+ }
280
+ return { version: 1, sessions };
281
+ }
282
+ catch {
283
+ return { version: 1, sessions: {} };
284
+ }
285
+ }
286
+ function writeSessionPermissionStore(store) {
287
+ const entries = Object.entries(store.sessions)
288
+ .sort((a, b) => b[1].updatedAt - a[1].updatedAt)
289
+ .slice(0, MAX_PERSISTED_SESSION_OVERRIDES);
290
+ const pruned = {
291
+ version: 1,
292
+ sessions: Object.fromEntries(entries)
293
+ };
294
+ atomicWriteFileSync(sessionPermissionsPath(), `${JSON.stringify(pruned, null, 2)}\n`);
295
+ }
296
+ export function getDefaultPermissionPreset() {
297
+ const config = loadConfig();
298
+ const explicit = normalizePermissionPreset(config.permissionPreset);
299
+ if (explicit)
300
+ return explicit;
301
+ return autonomyModeToPreset(config.autonomyMode);
302
+ }
303
+ export function setDefaultPermissionPreset(preset) {
304
+ const config = loadConfig();
305
+ config.permissionPreset = preset;
306
+ config.autonomyMode = presetToAutonomyMode(preset);
307
+ saveConfig(config);
308
+ return preset;
309
+ }
310
+ export function getSessionPermissionPreset(sessionId) {
311
+ if (typeof sessionId === 'string' && sessionId.trim()) {
312
+ const store = readSessionPermissionStore();
313
+ const rec = store.sessions[sessionId.trim()];
314
+ if (rec)
315
+ return rec.preset;
316
+ }
317
+ return getDefaultPermissionPreset();
318
+ }
319
+ export function setSessionPermissionPreset(sessionId, preset) {
320
+ const sid = sessionId.trim();
321
+ if (!sid)
322
+ return setDefaultPermissionPreset(preset);
323
+ const store = readSessionPermissionStore();
324
+ store.sessions[sid] = { preset, updatedAt: Date.now() };
325
+ writeSessionPermissionStore(store);
326
+ return preset;
327
+ }