@causyne/agent 1.20.124 → 1.20.127

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 (235) hide show
  1. package/bin/causyne.js +1 -1
  2. package/package.json +4 -4
  3. package/src/acp/protocol.ts +19 -1
  4. package/src/acp/server.js +282 -8
  5. package/src/acp/server.ts +284 -8
  6. package/src/agent/abortableDelay.js +2 -2
  7. package/src/agent/abortableDelay.ts +2 -2
  8. package/src/agent/errorClassifier.js +9 -1
  9. package/src/agent/errorClassifier.ts +8 -1
  10. package/src/agentLoop.js +83 -27
  11. package/src/agentLoop.ts +92 -26
  12. package/src/approvalPolicy.js +34 -10
  13. package/src/approvalPolicy.ts +42 -11
  14. package/src/browser/causyneBrowser.js +30 -3
  15. package/src/browser/causyneBrowser.ts +33 -3
  16. package/src/browser/urlPolicy.js +14 -1
  17. package/src/browser/urlPolicy.ts +12 -1
  18. package/src/cliMode.js +21 -9
  19. package/src/cliMode.ts +20 -8
  20. package/src/commands.js +188 -32
  21. package/src/commands.ts +209 -32
  22. package/src/config.js +19 -4
  23. package/src/config.ts +18 -4
  24. package/src/core/contextCompactor.js +54 -7
  25. package/src/core/contextCompactor.ts +63 -7
  26. package/src/core/goalLoop.js +257 -0
  27. package/src/core/goalLoop.ts +310 -0
  28. package/src/entrypoint.js +135 -3
  29. package/src/entrypoint.ts +136 -3
  30. package/src/game/causyneCoreBridge.js +686 -0
  31. package/src/game/causyneCoreBridge.ts +702 -0
  32. package/src/game/gameLauncher.js +287 -0
  33. package/src/game/gameLauncher.ts +352 -0
  34. package/src/game/gameProvisioner.js +425 -0
  35. package/src/game/gameProvisioner.ts +488 -0
  36. package/src/headlessCli.js +19 -12
  37. package/src/headlessCli.ts +22 -8
  38. package/src/infra/atomicWriter.js +40 -4
  39. package/src/infra/atomicWriter.ts +36 -4
  40. package/src/launchIntent.js +73 -3
  41. package/src/launchIntent.ts +76 -3
  42. package/src/lsp/lspClient.js +83 -12
  43. package/src/lsp/lspClient.ts +75 -12
  44. package/src/mcp/mcpRegistry.js +75 -8
  45. package/src/mcp/mcpRegistry.ts +70 -7
  46. package/src/memory/contextBudget.js +2 -0
  47. package/src/memory/contextBudget.ts +1 -0
  48. package/src/modelVariants.js +45 -0
  49. package/src/modelVariants.ts +54 -0
  50. package/src/outputRecovery.js +3 -2
  51. package/src/outputRecovery.ts +4 -2
  52. package/src/permissionPresets.js +327 -0
  53. package/src/permissionPresets.ts +361 -0
  54. package/src/providers/antigravity.js +62 -9
  55. package/src/providers/antigravity.ts +73 -9
  56. package/src/providers/byokHttp.js +7 -1
  57. package/src/providers/byokHttp.ts +6 -1
  58. package/src/providers/byokStream.js +21 -8
  59. package/src/providers/byokStream.ts +17 -7
  60. package/src/providers/dashscope-byok.js +21 -5
  61. package/src/providers/dashscope-byok.ts +29 -11
  62. package/src/providers/moonshot.js +26 -7
  63. package/src/providers/moonshot.ts +34 -13
  64. package/src/providers/muse.js +6 -0
  65. package/src/providers/muse.ts +8 -0
  66. package/src/providers/ollama.js +39 -7
  67. package/src/providers/ollama.ts +36 -7
  68. package/src/providers/openai-compatible.js +16 -3
  69. package/src/providers/openai-compatible.ts +13 -3
  70. package/src/providers/openai.js +62 -4
  71. package/src/providers/openai.ts +50 -4
  72. package/src/providers/openrouter.js +19 -4
  73. package/src/providers/openrouter.ts +21 -4
  74. package/src/providers/qwen-byok.js +21 -5
  75. package/src/providers/qwen-byok.ts +29 -11
  76. package/src/providers/xai.js +26 -10
  77. package/src/providers/xai.ts +34 -16
  78. package/src/reporting.js +4 -2
  79. package/src/reporting.ts +4 -2
  80. package/src/sandbox.js +34 -0
  81. package/src/sandbox.ts +43 -0
  82. package/src/scheduler/scheduler.js +372 -0
  83. package/src/scheduler/scheduler.ts +433 -0
  84. package/src/sessionSearchIndex.js +267 -0
  85. package/src/sessionSearchIndex.ts +311 -0
  86. package/src/skillsManager.js +2 -3
  87. package/src/skillsManager.ts +2 -3
  88. package/src/toolPacks.js +6 -0
  89. package/src/toolPacks.ts +6 -0
  90. package/src/tools/applyPatch.js +1 -1
  91. package/src/tools/applyPatch.ts +1 -1
  92. package/src/tools/generateMediaViaApi.js +4 -3
  93. package/src/tools/generateMediaViaApi.ts +4 -3
  94. package/src/tools/nativeEngine.js +2 -2
  95. package/src/tools/nativeEngine.ts +2 -2
  96. package/src/tools/openSourceToolProvisioner.js +2 -2
  97. package/src/tools/openSourceToolProvisioner.ts +2 -2
  98. package/src/tools/payloadSanitizer.js +0 -1
  99. package/src/tools/payloadSanitizer.ts +0 -1
  100. package/src/tools/pdfReader.js +122 -20
  101. package/src/tools/pdfReader.ts +111 -20
  102. package/src/tools/presentDeliverable.js +103 -0
  103. package/src/tools/presentDeliverable.ts +127 -0
  104. package/src/tools/ptcRuntime.js +444 -0
  105. package/src/tools/ptcRuntime.ts +490 -0
  106. package/src/tools/ptyTerminal.js +1096 -0
  107. package/src/tools/ptyTerminal.ts +1231 -0
  108. package/src/tools/registry.js +21 -12
  109. package/src/tools/registry.ts +21 -12
  110. package/src/tools/toolOutputStore.js +26 -4
  111. package/src/tools/toolOutputStore.ts +22 -4
  112. package/src/tools/webFetch.js +158 -11
  113. package/src/tools/webFetch.ts +145 -11
  114. package/src/tools/webSearch.js +123 -36
  115. package/src/tools/webSearch.ts +124 -33
  116. package/src/tui/banner.js +5 -1
  117. package/src/tui/banner.ts +6 -1
  118. package/src/tui/chatRenderer.js +1 -2
  119. package/src/tui/chatRenderer.ts +1 -2
  120. package/src/tui/completion.js +1 -0
  121. package/src/tui/completion.ts +1 -0
  122. package/src/tui/composerControls.js +111 -27
  123. package/src/tui/composerControls.ts +124 -28
  124. package/src/tui/dialogs.js +3 -16
  125. package/src/tui/dialogs.ts +3 -16
  126. package/src/tui/home.js +1 -0
  127. package/src/tui/home.ts +1 -0
  128. package/src/tui/invocation.js +1 -2
  129. package/src/tui/invocation.ts +1 -2
  130. package/src/tui/modelPicker.js +22 -12
  131. package/src/tui/modelPicker.ts +22 -12
  132. package/src/tui/overlay.js +2 -5
  133. package/src/tui/overlay.ts +2 -5
  134. package/src/tui/prompt.js +6 -4
  135. package/src/tui/prompt.ts +6 -4
  136. package/src/tui/selectList.js +4 -12
  137. package/src/tui/selectList.ts +4 -12
  138. package/src/tui/setup.js +22 -9
  139. package/src/tui/setup.ts +26 -9
  140. package/src/tui/statusLine.ts +2 -0
  141. package/src/web/client/browserPanel.js +702 -0
  142. package/src/web/client/browserPanel.ts +663 -0
  143. package/src/web/client/chatStream.js +309 -0
  144. package/src/web/client/chatStream.ts +289 -0
  145. package/src/web/client/cliPanel.js +165 -0
  146. package/src/web/client/cliPanel.ts +171 -0
  147. package/src/web/client/composer.js +204 -0
  148. package/src/web/client/composer.ts +209 -0
  149. package/src/web/client/diffPanel.js +176 -0
  150. package/src/web/client/diffPanel.ts +203 -0
  151. package/src/web/client/dom.js +220 -0
  152. package/src/web/client/dom.ts +221 -0
  153. package/src/web/client/filesAndCanvas.js +231 -0
  154. package/src/web/client/filesAndCanvas.ts +238 -0
  155. package/src/web/client/gameLauncherUi.js +78 -0
  156. package/src/web/client/gameLauncherUi.ts +78 -0
  157. package/src/web/client/main.js +301 -0
  158. package/src/web/client/main.ts +368 -0
  159. package/src/web/client/markdown.js +364 -0
  160. package/src/web/client/markdown.ts +373 -0
  161. package/src/web/client/modelPicker.js +455 -0
  162. package/src/web/client/modelPicker.ts +451 -0
  163. package/src/web/client/permissionPresetsUi.js +307 -0
  164. package/src/web/client/permissionPresetsUi.ts +333 -0
  165. package/src/web/client/sessions.js +353 -0
  166. package/src/web/client/sessions.ts +372 -0
  167. package/src/web/client/settingsModal.js +191 -0
  168. package/src/web/client/settingsModal.ts +176 -0
  169. package/src/web/client/state.js +250 -0
  170. package/src/web/client/state.ts +233 -0
  171. package/src/web/client/streamSmoother.js +127 -0
  172. package/src/web/client/streamSmoother.ts +119 -0
  173. package/src/web/client/studioLayout.js +54 -0
  174. package/src/web/client/studioLayout.ts +60 -0
  175. package/src/web/client/studioShell.js +327 -0
  176. package/src/web/client/studioShell.ts +340 -0
  177. package/src/web/client/studioStart.js +77 -0
  178. package/src/web/client/studioStart.ts +89 -0
  179. package/src/web/client/terminalPanel.js +357 -0
  180. package/src/web/client/terminalPanel.ts +345 -0
  181. package/src/web/client/turnView.js +934 -0
  182. package/src/web/client/turnView.ts +981 -0
  183. package/src/web/client/types.js +1 -0
  184. package/src/web/client/types.ts +319 -0
  185. package/src/web/client/validators.js +106 -0
  186. package/src/web/client/validators.ts +96 -0
  187. package/src/web/server/activeRuns.js +152 -0
  188. package/src/web/server/activeRuns.ts +171 -0
  189. package/src/web/server/routesBrowser.js +355 -0
  190. package/src/web/server/routesBrowser.ts +386 -0
  191. package/src/web/server/routesChat.js +304 -0
  192. package/src/web/server/routesChat.ts +347 -0
  193. package/src/web/server/routesCore.js +472 -0
  194. package/src/web/server/routesCore.ts +522 -0
  195. package/src/web/server/routesTerminal.js +162 -0
  196. package/src/web/server/routesTerminal.ts +182 -0
  197. package/src/web/server/routesWorkspace.js +510 -0
  198. package/src/web/server/routesWorkspace.ts +546 -0
  199. package/src/web/server/security.js +98 -0
  200. package/src/web/server/security.ts +108 -0
  201. package/src/web/server/sessionTranscript.js +586 -0
  202. package/src/web/server/sessionTranscript.ts +566 -0
  203. package/src/web/server/staticAssets.js +80 -0
  204. package/src/web/server/staticAssets.ts +91 -0
  205. package/src/web/server/types.js +1 -0
  206. package/src/web/server/types.ts +135 -0
  207. package/src/web/server/workspaceFiles.js +368 -0
  208. package/src/web/server/workspaceFiles.ts +363 -0
  209. package/src/web/skybridgeServer.js +76 -2449
  210. package/src/web/skybridgeServer.ts +118 -2600
  211. package/src/web/skybridgeUi.js +16 -450
  212. package/src/web/skybridgeUi.ts +16 -454
  213. package/src/web/styles/agent.css +380 -0
  214. package/src/web/styles/composer.css +193 -0
  215. package/src/web/styles/overlays.css +436 -0
  216. package/src/web/styles/shell.css +387 -0
  217. package/src/web/styles/studio.css +723 -0
  218. package/src/web/styles/thread.css +221 -0
  219. package/src/web/styles/tokens.css +94 -0
  220. package/src/web/ui/brandMark.js +73 -0
  221. package/src/web/ui/brandMark.ts +82 -0
  222. package/src/web/ui/modalsTemplate.js +139 -0
  223. package/src/web/ui/modalsTemplate.ts +139 -0
  224. package/src/web/ui/sidebarTemplate.js +63 -0
  225. package/src/web/ui/sidebarTemplate.ts +64 -0
  226. package/src/web/ui/studioTemplate.js +258 -0
  227. package/src/web/ui/studioTemplate.ts +258 -0
  228. package/src/web/ui/workspaceTemplate.js +72 -0
  229. package/src/web/ui/workspaceTemplate.ts +73 -0
  230. package/src/worktreeManager.js +16 -1
  231. package/src/worktreeManager.ts +22 -1
  232. package/src/web/skybridgeClientScript.js +0 -3951
  233. package/src/web/skybridgeClientScript.ts +0 -3952
  234. package/src/web/skybridgeStyles.js +0 -827
  235. package/src/web/skybridgeStyles.ts +0 -828
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,319 @@
1
+ export type PermissionPresetId = 'read-only' | 'workspace-write' | 'danger-full-access';
2
+
3
+ export interface PermissionPresetItem {
4
+ readonly id: PermissionPresetId;
5
+ readonly label: string;
6
+ readonly description: string;
7
+ readonly autonomyMode: 'A' | 'B' | 'C';
8
+ readonly readOnly: boolean;
9
+ readonly requiresRiskConfirmation: boolean;
10
+ }
11
+
12
+ export interface ArtifactVersion {
13
+ version: number;
14
+ content: string;
15
+ at: number;
16
+ }
17
+
18
+ export interface SessionSummary {
19
+ id: string;
20
+ title?: string;
21
+ createdAt?: number;
22
+ updatedAt?: number;
23
+ messageCount?: number;
24
+ running?: boolean;
25
+ awaitingClient?: boolean;
26
+ }
27
+
28
+ export interface SessionWorkspaceSnapshot {
29
+ studioOpen: boolean;
30
+ studioTab: string;
31
+ canvasPath: string;
32
+ canvasContent: string;
33
+ canvasPreviewMode: boolean;
34
+ canvasStatus: string;
35
+ canvasDirty: boolean;
36
+ diffScope: 'session' | 'workspace';
37
+ diffStaged: boolean;
38
+ attachments: string[];
39
+ draftPrompt: string;
40
+ usageTokens: number;
41
+ browserEngine: 'agent' | 'frame';
42
+ browserMode: 'empty' | 'url' | 'srcdoc';
43
+ browserUrl: string;
44
+ browserSrcdoc: string;
45
+ cliConsoleText: string;
46
+ cliStatusText: string;
47
+ }
48
+
49
+ export interface ModelItemValue {
50
+ type?: string;
51
+ action?: string;
52
+ isToggle?: boolean;
53
+ peerKey?: string;
54
+ providerId?: string;
55
+ modelId?: string;
56
+ providerLabel?: string;
57
+ envVar?: string;
58
+ setupInstruction?: string;
59
+ installed?: boolean;
60
+ isCurrent?: boolean;
61
+ isConfigured?: boolean;
62
+ }
63
+
64
+ export interface ModelPickerItem {
65
+ id?: string;
66
+ label?: string;
67
+ category?: string;
68
+ description?: string;
69
+ value?: ModelItemValue;
70
+ }
71
+
72
+ export interface ModelsResponse {
73
+ activeProvider?: string;
74
+ activeModel?: string;
75
+ initialTab?: 'acp' | 'byok' | 'free';
76
+ tabs?: Record<string, ModelPickerItem[]>;
77
+ }
78
+
79
+ export interface CliCommandEntry {
80
+ name: string;
81
+ aliases?: string[];
82
+ usage?: string;
83
+ description?: string;
84
+ }
85
+
86
+ export interface WorkspaceEntry {
87
+ path: string;
88
+ name: string;
89
+ type: 'dir' | 'file';
90
+ size?: number;
91
+ }
92
+
93
+ export interface MentionEntry {
94
+ name?: string;
95
+ path?: string;
96
+ description?: string;
97
+ }
98
+
99
+ export interface BrowserTabInfo {
100
+ tabId: string;
101
+ title?: string;
102
+ url?: string;
103
+ active?: boolean;
104
+ }
105
+
106
+ export interface BrowserAgentActivityState {
107
+ active?: boolean;
108
+ tool?: string;
109
+ detail?: string;
110
+ }
111
+
112
+ export interface LiveBrowserFramePayload {
113
+ type?: string;
114
+ active?: boolean;
115
+ visible?: boolean;
116
+ engine?: string | null;
117
+ enginePreference?: string;
118
+ enginesAvailable?: { camoufox?: boolean; chromium?: boolean };
119
+ streamMode?: string;
120
+ fps?: number;
121
+ controlOwner?: string;
122
+ width?: number;
123
+ height?: number;
124
+ url?: string;
125
+ imageBase64?: string;
126
+ mimeType?: string;
127
+ tabs?: BrowserTabInfo[];
128
+ agentActivity?: BrowserAgentActivityState;
129
+ snapshot?: string;
130
+ refsCount?: number;
131
+ syncedUrl?: string;
132
+ importedUrls?: string[];
133
+ importedCookies?: number;
134
+ error?: string;
135
+ }
136
+
137
+ export interface RestoredStep {
138
+ tool?: string;
139
+ target?: string;
140
+ status?: string;
141
+ output?: string;
142
+ }
143
+
144
+ export interface RestoredBlock {
145
+ kind: 'reasoning' | 'steps' | 'text';
146
+ content?: string;
147
+ steps?: RestoredStep[];
148
+ }
149
+
150
+ export interface DecisionOption {
151
+ id?: string;
152
+ label?: string;
153
+ description?: string;
154
+ }
155
+
156
+ export interface DecisionRequestPayload {
157
+ id?: string;
158
+ question?: string;
159
+ options?: DecisionOption[];
160
+ }
161
+
162
+ export interface PlanItemPayload {
163
+ status?: string;
164
+ text?: string;
165
+ step?: string;
166
+ }
167
+
168
+ export interface StreamEventPayload {
169
+ type?: string;
170
+ sessionId?: string;
171
+ title?: string;
172
+ delta?: string;
173
+ content?: string;
174
+ streaming?: boolean;
175
+ elapsedMs?: number;
176
+ plan?: PlanItemPayload[];
177
+ explanation?: string;
178
+ message?: string;
179
+ activity?: string;
180
+ tool?: string;
181
+ toolCallId?: string;
182
+ args?: Record<string, unknown>;
183
+ success?: boolean;
184
+ error?: string;
185
+ summary?: string;
186
+ output?: string;
187
+ result?: Record<string, unknown>;
188
+ id?: string;
189
+ path?: string;
190
+ code?: string;
191
+ phase?: string;
192
+ operation?: string;
193
+ request?: DecisionRequestPayload;
194
+ totalTokens?: number;
195
+ sessionTokens?: number;
196
+ promptTokens?: number;
197
+ nativeStep?: boolean;
198
+ nativeFailed?: boolean;
199
+ actionName?: string;
200
+ detail?: string;
201
+ }
202
+
203
+ export interface AssistantTurnHandle {
204
+ setActivity(active: boolean, label: string): void;
205
+ appendText(delta: string): void;
206
+ setText(full: string, streaming: boolean): void;
207
+ updateReasoning(ev: StreamEventPayload): void;
208
+ renderRestoredBlocks(blocks: RestoredBlock[]): void;
209
+ updatePlan(ev: StreamEventPayload): void;
210
+ addStepStart(ev: StreamEventPayload): void;
211
+ addStepEnd(ev: StreamEventPayload, failed: boolean): void;
212
+ addNativeStep(ev: StreamEventPayload, failed: boolean): void;
213
+ upsertCodeProgress(ev: StreamEventPayload): void;
214
+ addApproval(ev: StreamEventPayload): void;
215
+ addDecision(reqObj: DecisionRequestPayload): void;
216
+ addNotice(msg: string): void;
217
+ addError(msg: string, retryText?: string, code?: string): void;
218
+ addInterrupted(msg: string, retryText?: string): void;
219
+ finish(): void;
220
+ }
221
+
222
+ export interface WorkspaceFileHrefInfo {
223
+ fullPath: string;
224
+ relPath: string | null;
225
+ display: string;
226
+ lineBadge: string;
227
+ }
228
+
229
+ export interface AvailableShellPayload {
230
+ id: string;
231
+ label: string;
232
+ path: string;
233
+ isDefault: boolean;
234
+ }
235
+
236
+ export interface TerminalSessionPayload {
237
+ id: string;
238
+ name: string;
239
+ shell: string;
240
+ shellLabel: string;
241
+ cwd: string;
242
+ origin: 'user' | 'agent';
243
+ control: 'user' | 'agent';
244
+ transport: 'pty' | 'pipe';
245
+ status: 'running' | 'exited';
246
+ exitCode: number | null;
247
+ cols: number;
248
+ rows: number;
249
+ createdAt: number;
250
+ lastActivityAt: number;
251
+ scrollbackBytes: number;
252
+ }
253
+
254
+ export interface AppState {
255
+ sessionId: string | null;
256
+ sessions: SessionSummary[];
257
+ models: ModelsResponse | null;
258
+ modelTab: 'acp' | 'byok' | 'free' | null;
259
+ modelQuery: string;
260
+ modelExpandedPeers: Set<string>;
261
+ modelSelectedIndex: number;
262
+ modelRefreshing: boolean;
263
+ modelLiveHydrated: boolean;
264
+ modelNotice: string;
265
+ activeProvider: string;
266
+ activeModel: string;
267
+ permissionPreset: PermissionPresetId;
268
+ defaultPermissionPreset: PermissionPresetId;
269
+ workspaceRoot: string;
270
+ lastScrollTop: number;
271
+ attachments: string[];
272
+ currentDir: string;
273
+ parentDir: string;
274
+ studioTab: string;
275
+ studioSplit: boolean;
276
+ studioSecondaryTab: string;
277
+ studioExpanded: boolean;
278
+ studioWidth: number;
279
+ terminalSessions: TerminalSessionPayload[];
280
+ activeTerminalId: string | null;
281
+ availableShells: AvailableShellPayload[];
282
+ canvasPreviewMode: boolean;
283
+ canvasDirty: boolean;
284
+ artifactVersions: Map<string, ArtifactVersion[]>;
285
+ sessionWorkspaces: Map<string, SessionWorkspaceSnapshot>;
286
+ sessionSwitchSeq: number;
287
+ usageTokens: number;
288
+ diffScope: 'session' | 'workspace';
289
+ browserEngine: 'agent' | 'frame';
290
+ browserMode: 'empty' | 'url' | 'srcdoc';
291
+ browserUrl: string;
292
+ browserSrcdoc: string;
293
+ browserViewport: string;
294
+ liveBrowserActive: boolean;
295
+ liveBrowserVisible: boolean;
296
+ liveBrowserRuntime: string | null;
297
+ liveBrowserPref: string;
298
+ liveStreamMode: string;
299
+ liveStreamAbort: AbortController | null;
300
+ liveStreamConnected: boolean;
301
+ liveFps: number;
302
+ pointerDragging: boolean;
303
+ liveBrowserWidth: number;
304
+ liveBrowserHeight: number;
305
+ controlOwner: 'human' | 'agent';
306
+ cliCommands: CliCommandEntry[];
307
+ mentionMode: 'file' | 'command';
308
+ mentionItems: MentionEntry[];
309
+ mentionIndex: number;
310
+ mentionStart: number;
311
+ diffStaged: boolean;
312
+ isComposing: boolean;
313
+ stickToBottom: boolean;
314
+ activeController: AbortController | null;
315
+ activeTurn: AssistantTurnHandle | null;
316
+ activePrompt: string;
317
+ gameStatus: Record<string, unknown> | null;
318
+ gameLaunching: boolean;
319
+ }
@@ -0,0 +1,106 @@
1
+ export function isSafeHttpUrl(raw) {
2
+ try {
3
+ const u = new URL(raw);
4
+ return u.protocol === 'https:' || u.protocol === 'http:';
5
+ }
6
+ catch {
7
+ return false;
8
+ }
9
+ }
10
+ export function parseLoopbackUrl(raw) {
11
+ try {
12
+ const trimmed = String(raw || '').trim();
13
+ if (!trimmed)
14
+ return null;
15
+ const normalized = /^https?:\/\//i.test(trimmed) ? trimmed : (`http://${trimmed}`);
16
+ const u = new URL(normalized);
17
+ const host = u.hostname.toLowerCase();
18
+ if (u.protocol !== 'http:')
19
+ return null;
20
+ if (host !== '127.0.0.1' && host !== 'localhost')
21
+ return null;
22
+ return u.href;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ export function extractLoopbackUrls(text) {
29
+ const found = [];
30
+ const matches = String(text || '').match(/http:\/\/(?:127\.0\.0\.1|localhost):\d{2,5}(?:\/[^\s)\[\]'"`<>]*)?/gi) || [];
31
+ for (const m of matches) {
32
+ const cleaned = m.replace(/[.,;:!?\])]+$/g, '');
33
+ const valid = parseLoopbackUrl(cleaned);
34
+ if (valid && !found.includes(valid))
35
+ found.push(valid);
36
+ }
37
+ return found.slice(0, 3);
38
+ }
39
+ export function parseWorkspaceFileHref(rawHref, workspaceRoot) {
40
+ const trimmed = String(rawHref || '').trim();
41
+ if (!trimmed.toLowerCase().startsWith('file://'))
42
+ return null;
43
+ let body = trimmed.slice(7);
44
+ let lineBadge = '';
45
+ const hashIdx = body.indexOf('#');
46
+ if (hashIdx >= 0) {
47
+ const frag = body.slice(hashIdx + 1);
48
+ body = body.slice(0, hashIdx);
49
+ const lm = frag.match(/^L(\d+)(?:-L?(\d+))?$/i);
50
+ if (lm?.[1])
51
+ lineBadge = lm[2] ? (`:${lm[1]}-${lm[2]}`) : (`:${lm[1]}`);
52
+ }
53
+ const qIdx = body.indexOf('?');
54
+ if (qIdx >= 0)
55
+ body = body.slice(0, qIdx);
56
+ try {
57
+ body = decodeURIComponent(body);
58
+ }
59
+ catch { /* keep raw */ }
60
+ const wsRoot = String(workspaceRoot || '').replace(/\/+$/, '');
61
+ const normPrivate = (p) => p.replace(/^\/private(?=\/(?:var|tmp)(?:\/|$))/, '');
62
+ const bodyNorm = normPrivate(body);
63
+ const wsNorm = normPrivate(wsRoot);
64
+ let relPath = null;
65
+ if (wsNorm && bodyNorm.startsWith(`${wsNorm}/`)) {
66
+ relPath = bodyNorm.slice(wsNorm.length + 1);
67
+ }
68
+ const display = relPath || body.split('/').slice(-2).join('/') || body;
69
+ return { fullPath: body, relPath, display, lineBadge };
70
+ }
71
+ export function isHtmlOrSvgPath(relPath) {
72
+ const p = String(relPath || '').toLowerCase();
73
+ return p.endsWith('.html') || p.endsWith('.htm') || p.endsWith('.svg');
74
+ }
75
+ export function artifactBadgeFor(relPath, lang) {
76
+ const p = String(relPath || '').toLowerCase();
77
+ if (p.endsWith('.idoc.md'))
78
+ return { tag: 'IDOC', label: 'idoc Document' };
79
+ if (p.endsWith('.html') || p.endsWith('.htm') || lang === 'html')
80
+ return { tag: 'HTML', label: 'Interactive HTML' };
81
+ if (p.endsWith('.svg') || lang === 'svg')
82
+ return { tag: 'SVG', label: 'SVG Graphic' };
83
+ if (p.endsWith('.md') || lang === 'markdown' || lang === 'md')
84
+ return { tag: 'DOC', label: 'Markdown Document' };
85
+ const ext = p.includes('.')
86
+ ? (p.split('.').pop() || '').toUpperCase().slice(0, 4)
87
+ : (lang ? lang.toUpperCase().slice(0, 4) : 'CODE');
88
+ return { tag: ext || 'CODE', label: 'Source File' };
89
+ }
90
+ export function isSafeBillingUrl(raw) {
91
+ try {
92
+ const u = new URL(String(raw || ''));
93
+ if (u.protocol !== 'https:' || u.username || u.password || u.port)
94
+ return false;
95
+ const h = u.hostname.toLowerCase();
96
+ return h === 'paddle.com'
97
+ || h.endsWith('.paddle.com')
98
+ || h === 'dodopayments.com'
99
+ || h.endsWith('.dodopayments.com')
100
+ || h === 'causyne.com'
101
+ || h.endsWith('.causyne.com');
102
+ }
103
+ catch {
104
+ return false;
105
+ }
106
+ }
@@ -0,0 +1,96 @@
1
+ import type { WorkspaceFileHrefInfo } from './types.js';
2
+
3
+ export function isSafeHttpUrl(raw: string): boolean {
4
+ try {
5
+ const u = new URL(raw);
6
+ return u.protocol === 'https:' || u.protocol === 'http:';
7
+ } catch {
8
+ return false;
9
+ }
10
+ }
11
+
12
+ export function parseLoopbackUrl(raw: string): string | null {
13
+ try {
14
+ const trimmed = String(raw || '').trim();
15
+ if (!trimmed) return null;
16
+ const normalized = /^https?:\/\//i.test(trimmed) ? trimmed : (`http://${trimmed}`);
17
+ const u = new URL(normalized);
18
+ const host = u.hostname.toLowerCase();
19
+ if (u.protocol !== 'http:') return null;
20
+ if (host !== '127.0.0.1' && host !== 'localhost') return null;
21
+ return u.href;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ export function extractLoopbackUrls(text: string): string[] {
28
+ const found: string[] = [];
29
+ const matches = String(text || '').match(/http:\/\/(?:127\.0\.0\.1|localhost):\d{2,5}(?:\/[^\s)\[\]'"`<>]*)?/gi) || [];
30
+ for (const m of matches) {
31
+ const cleaned = m.replace(/[.,;:!?\])]+$/g, '');
32
+ const valid = parseLoopbackUrl(cleaned);
33
+ if (valid && !found.includes(valid)) found.push(valid);
34
+ }
35
+ return found.slice(0, 3);
36
+ }
37
+
38
+ export function parseWorkspaceFileHref(rawHref: string, workspaceRoot: string): WorkspaceFileHrefInfo | null {
39
+ const trimmed = String(rawHref || '').trim();
40
+ if (!trimmed.toLowerCase().startsWith('file://')) return null;
41
+ let body = trimmed.slice(7);
42
+ let lineBadge = '';
43
+ const hashIdx = body.indexOf('#');
44
+ if (hashIdx >= 0) {
45
+ const frag = body.slice(hashIdx + 1);
46
+ body = body.slice(0, hashIdx);
47
+ const lm = frag.match(/^L(\d+)(?:-L?(\d+))?$/i);
48
+ if (lm?.[1]) lineBadge = lm[2] ? (`:${lm[1]}-${lm[2]}`) : (`:${lm[1]}`);
49
+ }
50
+ const qIdx = body.indexOf('?');
51
+ if (qIdx >= 0) body = body.slice(0, qIdx);
52
+ try { body = decodeURIComponent(body); } catch { /* keep raw */ }
53
+ const wsRoot = String(workspaceRoot || '').replace(/\/+$/, '');
54
+ const normPrivate = (p: string): string => p.replace(/^\/private(?=\/(?:var|tmp)(?:\/|$))/, '');
55
+ const bodyNorm = normPrivate(body);
56
+ const wsNorm = normPrivate(wsRoot);
57
+ let relPath: string | null = null;
58
+ if (wsNorm && bodyNorm.startsWith(`${wsNorm}/`)) {
59
+ relPath = bodyNorm.slice(wsNorm.length + 1);
60
+ }
61
+ const display = relPath || body.split('/').slice(-2).join('/') || body;
62
+ return { fullPath: body, relPath, display, lineBadge };
63
+ }
64
+
65
+ export function isHtmlOrSvgPath(relPath: string): boolean {
66
+ const p = String(relPath || '').toLowerCase();
67
+ return p.endsWith('.html') || p.endsWith('.htm') || p.endsWith('.svg');
68
+ }
69
+
70
+ export function artifactBadgeFor(relPath: string, lang: string): { tag: string; label: string } {
71
+ const p = String(relPath || '').toLowerCase();
72
+ if (p.endsWith('.idoc.md')) return { tag: 'IDOC', label: 'idoc Document' };
73
+ if (p.endsWith('.html') || p.endsWith('.htm') || lang === 'html') return { tag: 'HTML', label: 'Interactive HTML' };
74
+ if (p.endsWith('.svg') || lang === 'svg') return { tag: 'SVG', label: 'SVG Graphic' };
75
+ if (p.endsWith('.md') || lang === 'markdown' || lang === 'md') return { tag: 'DOC', label: 'Markdown Document' };
76
+ const ext = p.includes('.')
77
+ ? (p.split('.').pop() || '').toUpperCase().slice(0, 4)
78
+ : (lang ? lang.toUpperCase().slice(0, 4) : 'CODE');
79
+ return { tag: ext || 'CODE', label: 'Source File' };
80
+ }
81
+
82
+ export function isSafeBillingUrl(raw: string): boolean {
83
+ try {
84
+ const u = new URL(String(raw || ''));
85
+ if (u.protocol !== 'https:' || u.username || u.password || u.port) return false;
86
+ const h = u.hostname.toLowerCase();
87
+ return h === 'paddle.com'
88
+ || h.endsWith('.paddle.com')
89
+ || h === 'dodopayments.com'
90
+ || h.endsWith('.dodopayments.com')
91
+ || h === 'causyne.com'
92
+ || h.endsWith('.causyne.com');
93
+ } catch {
94
+ return false;
95
+ }
96
+ }
@@ -0,0 +1,152 @@
1
+ import { AgentLoop } from '../../agentLoop.js';
2
+ import { CAUSYNE_BROWSER_MCP_NAME } from '../skybridgeBrowserMcp.js';
3
+ const MAX_RUN_BUFFERED_FRAMES = 2400;
4
+ const MAX_RUN_BUFFERED_BYTES = 2 * 1024 * 1024;
5
+ const STREAM_HEARTBEAT_MS = 15_000;
6
+ export function createDefaultLoopFactory(serverApprovalScope, getBoundPort, token) {
7
+ const buildSharedBrowserPeerMcp = () => {
8
+ const port = getBoundPort();
9
+ if (!port)
10
+ return [];
11
+ return [{
12
+ type: 'http',
13
+ name: CAUSYNE_BROWSER_MCP_NAME,
14
+ url: `http://127.0.0.1:${port}/api/mcp/browser`,
15
+ headers: [{ name: 'Authorization', value: `Bearer ${token}` }]
16
+ }];
17
+ };
18
+ return (sink, taskId, prompt, opts) => {
19
+ const loopOptions = {
20
+ workspaceRoot: opts.workspaceRoot,
21
+ approvalScope: serverApprovalScope,
22
+ peerMcpServers: buildSharedBrowserPeerMcp()
23
+ };
24
+ if (opts.sessionId)
25
+ loopOptions.memorySessionId = opts.sessionId;
26
+ if (opts.provider)
27
+ loopOptions.provider = opts.provider;
28
+ if (opts.model)
29
+ loopOptions.model = opts.model;
30
+ const loop = new AgentLoop(sink, taskId, prompt, loopOptions);
31
+ if (typeof opts.permissionPreset === 'string' && opts.permissionPreset) {
32
+ try {
33
+ loop.setPermissionPreset(opts.permissionPreset);
34
+ }
35
+ catch {
36
+ // Fallback to mode normalization below.
37
+ }
38
+ }
39
+ else if (opts.mode === 'A' || opts.mode === 'B' || opts.mode === 'C') {
40
+ try {
41
+ loop.setAutonomyMode(opts.mode);
42
+ }
43
+ catch {
44
+ // Fallback when custom mode normalization differs.
45
+ }
46
+ }
47
+ const pendingDecisions = new Map();
48
+ loop.waitForDecision = (request) => {
49
+ const reqId = typeof request?.id === 'string' && request.id ? request.id : `dec_${Date.now()}`;
50
+ return new Promise((resolve) => {
51
+ pendingDecisions.set(reqId, resolve);
52
+ });
53
+ };
54
+ return {
55
+ run: () => loop.run(),
56
+ abort: () => {
57
+ for (const [, resolve] of pendingDecisions) {
58
+ try {
59
+ resolve(null);
60
+ }
61
+ catch { /* ignore */ }
62
+ }
63
+ pendingDecisions.clear();
64
+ loop.abort();
65
+ },
66
+ resolveApproval: (toolCallId, approved) => {
67
+ const resolver = loop.pendingApprovals.get(toolCallId);
68
+ if (resolver)
69
+ resolver(approved);
70
+ },
71
+ resolveDecision: (requestId, answer) => {
72
+ const resolver = pendingDecisions.get(requestId);
73
+ if (resolver) {
74
+ pendingDecisions.delete(requestId);
75
+ resolver(answer);
76
+ }
77
+ },
78
+ grantAlways: (toolName) => {
79
+ serverApprovalScope.grantAlways(toolName);
80
+ }
81
+ };
82
+ };
83
+ }
84
+ export function pushRunFrame(run, raw) {
85
+ const clean = raw.replace(/\r?\n/g, ' ');
86
+ const frameBytes = Buffer.byteLength(clean, 'utf8');
87
+ if (run.frames.length < MAX_RUN_BUFFERED_FRAMES && run.bufferedBytes + frameBytes <= MAX_RUN_BUFFERED_BYTES) {
88
+ run.frames.push(clean);
89
+ run.bufferedBytes += frameBytes;
90
+ }
91
+ for (const send of run.subscribers) {
92
+ try {
93
+ send(clean);
94
+ }
95
+ catch {
96
+ // Isolate subscriber write failures so detached runs continue uninterrupted.
97
+ }
98
+ }
99
+ }
100
+ export function attachRunStream(req, res, run, replayBuffered) {
101
+ req.setTimeout(0);
102
+ res.setTimeout(0);
103
+ try {
104
+ req.socket?.setKeepAlive(true, STREAM_HEARTBEAT_MS);
105
+ }
106
+ catch { /* ignore */ }
107
+ res.statusCode = 200;
108
+ res.setHeader('Content-Type', 'application/x-ndjson; charset=utf-8');
109
+ res.setHeader('Transfer-Encoding', 'chunked');
110
+ res.setHeader('Cache-Control', 'no-store');
111
+ res.setHeader('X-Accel-Buffering', 'no');
112
+ res.flushHeaders?.();
113
+ const writeLine = (cleanFrame) => {
114
+ if (res.writableEnded || res.destroyed)
115
+ return;
116
+ res.write(`${cleanFrame}\n`);
117
+ };
118
+ const heartbeatTimer = setInterval(() => {
119
+ if (res.writableEnded || res.destroyed)
120
+ return;
121
+ writeLine(JSON.stringify({ type: 'heartbeat', ts: Date.now() }));
122
+ }, STREAM_HEARTBEAT_MS);
123
+ heartbeatTimer.unref?.();
124
+ let detached = false;
125
+ const detach = () => {
126
+ if (detached)
127
+ return;
128
+ detached = true;
129
+ clearInterval(heartbeatTimer);
130
+ run.subscribers.delete(writeLine);
131
+ run.doneSubscribers.delete(finishResponse);
132
+ };
133
+ const finishResponse = () => {
134
+ detach();
135
+ if (!res.writableEnded && !res.destroyed)
136
+ res.end();
137
+ };
138
+ // Disconnecting a tab only unsubscribes this HTTP response; POST /api/stop cancels the run.
139
+ res.on('close', detach);
140
+ if (replayBuffered) {
141
+ for (const frame of run.frames) {
142
+ writeLine(frame);
143
+ }
144
+ }
145
+ if (run.status === 'running' || run.status === 'awaiting_client') {
146
+ run.subscribers.add(writeLine);
147
+ run.doneSubscribers.add(finishResponse);
148
+ }
149
+ else {
150
+ finishResponse();
151
+ }
152
+ }