@myrialabs/clopen 0.4.47 → 0.4.48
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 +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/stream-manager.ts +62 -62
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +13 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/index.ts +21 -7
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +361 -25
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +64 -47
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +15 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +29 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +27 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +34 -45
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +7 -7
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +2 -4
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoping a sub-agent's output to the parent tool call that spawned it.
|
|
3
|
+
*
|
|
4
|
+
* Every engine that runs sub-agents (`Agent` / `Workflow`) has to make the same
|
|
5
|
+
* decision for each output the child produces: does it belong to the parent
|
|
6
|
+
* tool block, or to the main turn? Answering that per message constructor is
|
|
7
|
+
* how sub-agent thinking leaked into the main chat — the Claude converter set
|
|
8
|
+
* `parent.toolUseId` on assistant and user messages but hard-coded `null` on
|
|
9
|
+
* reasoning, and forwarded the child's live `stream_event` deltas into the
|
|
10
|
+
* root typing placeholder. A new output kind would leak the same way.
|
|
11
|
+
*
|
|
12
|
+
* So the decision lives here, once, keyed on the output's TYPE rather than on
|
|
13
|
+
* which constructor made it: whatever the child emits either joins the parent
|
|
14
|
+
* tool or is dropped. Nothing a child produces can reach the root.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { EngineOutput } from '$shared/types/unified';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Scope one sub-agent output to `parentToolUseId`.
|
|
21
|
+
*
|
|
22
|
+
* - Persisted messages (`user`, `assistant`, `reasoning`, `compact_boundary`)
|
|
23
|
+
* are returned tagged with the parent tool id, so the frontend folds them
|
|
24
|
+
* into that tool's `subActivities`. A message already tagged by a deeper
|
|
25
|
+
* sub-agent keeps its own (closer) parent.
|
|
26
|
+
* - Everything else is turn-level — live typing deltas, results, init, rate
|
|
27
|
+
* limits, notifications. A child's copy of any of these would drive the MAIN
|
|
28
|
+
* turn's placeholder or lifecycle, and the stream protocol cannot carry a
|
|
29
|
+
* parent for them (adapter-contract §2.3, parent-tool rule 4), so they are dropped.
|
|
30
|
+
*
|
|
31
|
+
* Returns `null` for dropped outputs. Never mutates the input.
|
|
32
|
+
*/
|
|
33
|
+
export function scopeToParentTool(output: EngineOutput, parentToolUseId: string): EngineOutput | null {
|
|
34
|
+
switch (output.type) {
|
|
35
|
+
case 'user':
|
|
36
|
+
case 'assistant':
|
|
37
|
+
case 'reasoning':
|
|
38
|
+
case 'compact_boundary':
|
|
39
|
+
if (output.parent.toolUseId) return output;
|
|
40
|
+
return { ...output, parent: { ...output.parent, toolUseId: parentToolUseId } };
|
|
41
|
+
default:
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -327,7 +327,6 @@ export function createPiMessageConverter(options: PiConverterOptions): PiMessage
|
|
|
327
327
|
sessionId,
|
|
328
328
|
parent: { messageId: null, sessionId: null, toolUseId: null },
|
|
329
329
|
engine,
|
|
330
|
-
sender: { id: '', name: '' },
|
|
331
330
|
content: [{ type: 'tool_result', toolUseId: toolCallId, content: text, isError }],
|
|
332
331
|
synthetic: true,
|
|
333
332
|
};
|
|
@@ -44,6 +44,7 @@ import { artifactFilter } from '$backend/profiles';
|
|
|
44
44
|
import { resolvePermissionsFromDb, isToolAllowed } from '$backend/permissions';
|
|
45
45
|
import { buildJsonPrompt, extractJson, emptyGenerationError } from '../../structured-helpers';
|
|
46
46
|
import { EngineRuns } from '../run-registry';
|
|
47
|
+
import { scopeToParentTool } from '../parent-scope';
|
|
47
48
|
import { DbCredentialStore, canonicalPiProviderId, getPiAccountForProvider, parsePiCredential } from './credential';
|
|
48
49
|
import { createPiRuntime } from './presets';
|
|
49
50
|
import { getPiAgentDir } from './environment';
|
|
@@ -264,11 +265,9 @@ export class PiEngine implements AIEngine {
|
|
|
264
265
|
});
|
|
265
266
|
let text = '';
|
|
266
267
|
const unsub = sub.subscribe((ev) => {
|
|
267
|
-
for (const
|
|
268
|
-
|
|
269
|
-
if (out
|
|
270
|
-
out.parent = { messageId: null, sessionId: null, toolUseId: toolCallId };
|
|
271
|
-
}
|
|
268
|
+
for (const raw of subConverter.convert(ev)) {
|
|
269
|
+
const out = scopeToParentTool(raw, toolCallId);
|
|
270
|
+
if (!out) continue;
|
|
272
271
|
if (out.type === 'assistant') {
|
|
273
272
|
const t = out.content.filter((b) => b.type === 'text').map((b) => (b.type === 'text' ? b.text : '')).join('');
|
|
274
273
|
if (t.trim()) text = t;
|
|
@@ -724,7 +724,6 @@ export function convertUserMessage(msg: SDKUserMessage, state: QwenConverterStat
|
|
|
724
724
|
// (README §10.5). Sub-agent messages are an explicit exception.
|
|
725
725
|
parent: { messageId: null, sessionId: null, toolUseId: msg.parent_tool_use_id || null },
|
|
726
726
|
engine: buildEngine(state.modelId),
|
|
727
|
-
sender: { id: '', name: '' },
|
|
728
727
|
content: outBlocks,
|
|
729
728
|
synthetic: true,
|
|
730
729
|
};
|
|
@@ -748,7 +747,6 @@ function buildSyntheticToolResult(
|
|
|
748
747
|
sessionId: sessionId ?? '',
|
|
749
748
|
parent: { messageId: null, sessionId: null, toolUseId: null },
|
|
750
749
|
engine: buildEngine(state.modelId),
|
|
751
|
-
sender: { id: '', name: '' },
|
|
752
750
|
content: [result],
|
|
753
751
|
synthetic: true,
|
|
754
752
|
};
|
|
@@ -28,7 +28,7 @@ import { debug } from '$shared/utils/logger';
|
|
|
28
28
|
import { isEngineSdkInstalled } from './sdk-loader';
|
|
29
29
|
import { ENGINE_PACKAGES } from './install-recipes';
|
|
30
30
|
import { getRequiredEngineCliSpec, resolveEngineCli } from './engine-cli';
|
|
31
|
-
import { awaitInstall, InstallAlreadyRunningError, startInstall
|
|
31
|
+
import { awaitInstall, InstallAlreadyRunningError, startInstall } from './install-runner';
|
|
32
32
|
|
|
33
33
|
const DEFAULT_ENGINE = 'opencode' as const;
|
|
34
34
|
|
|
@@ -95,7 +95,7 @@ async function runDefaultEngineInstall(): Promise<void> {
|
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
try {
|
|
98
|
-
const session = await startInstall(DEFAULT_ENGINE
|
|
98
|
+
const session = await startInstall(DEFAULT_ENGINE);
|
|
99
99
|
// Callers chain work that needs a usable engine (memory picks its
|
|
100
100
|
// extraction model from the engine's catalog), so wait for the run to
|
|
101
101
|
// settle rather than returning as soon as it is spawned.
|
|
@@ -148,11 +148,18 @@ The following invariants are mandatory:
|
|
|
148
148
|
1. Emit the parent tool message before any child activity.
|
|
149
149
|
2. Set every child message's `parent.toolUseId` to the parent tool call id
|
|
150
150
|
before yielding it. Never emit a root-shaped child and patch it later.
|
|
151
|
+
This covers **every** message kind — `reasoning` included. Route child
|
|
152
|
+
output through `scopeToParentTool()` (`adapters/parent-scope.ts`) instead of
|
|
153
|
+
tagging per constructor: it scopes by output type, so a kind you forgot
|
|
154
|
+
cannot reach the root. A sub-agent's thinking once leaked into the main chat
|
|
155
|
+
because one converter tagged `assistant`/`user` but hard-coded `null` on
|
|
156
|
+
`reasoning`.
|
|
151
157
|
3. Keep top-level tool results at `parent.toolUseId = null`; the id of the tool
|
|
152
158
|
they answer belongs on the inner `tool_result.toolUseId`.
|
|
153
159
|
4. Do not forward nested text/reasoning `stream_event` deltas unless the
|
|
154
160
|
protocol can carry their parent id. Suppress them and emit the finalized
|
|
155
|
-
parent-tagged message instead.
|
|
161
|
+
parent-tagged message instead. `scopeToParentTool()` drops them (and every
|
|
162
|
+
other turn-level output: result, init, rate limit, notification).
|
|
156
163
|
5. When activity comes from a side channel, merge it with the SDK stream using
|
|
157
164
|
a push queue. Use the source's native notification mechanism (for example
|
|
158
165
|
filesystem change events for JSONL transcripts), not interval polling.
|
|
@@ -60,7 +60,6 @@ interface Session {
|
|
|
60
60
|
endedAt: number | null;
|
|
61
61
|
buffer: RingBuffer;
|
|
62
62
|
retentionTimer: ReturnType<typeof setTimeout> | null;
|
|
63
|
-
startedBy: string;
|
|
64
63
|
/** Current partial line per stream (for line-based chunking). */
|
|
65
64
|
pending: { stdout: string; stderr: string };
|
|
66
65
|
}
|
|
@@ -114,7 +113,7 @@ function emitStream(session: Session, stream: 'stdout' | 'stderr', chunk: string
|
|
|
114
113
|
session.pending[stream] = parts.pop() ?? '';
|
|
115
114
|
for (const line of parts) {
|
|
116
115
|
pushLine(session.buffer, line);
|
|
117
|
-
ws.emit.
|
|
116
|
+
ws.emit.signedIn('stack:install-stream', {
|
|
118
117
|
sessionId: session.id,
|
|
119
118
|
tool: session.tool,
|
|
120
119
|
type: stream,
|
|
@@ -128,7 +127,7 @@ function flushPending(session: Session): void {
|
|
|
128
127
|
const remaining = session.pending[stream];
|
|
129
128
|
if (remaining) {
|
|
130
129
|
pushLine(session.buffer, remaining);
|
|
131
|
-
ws.emit.
|
|
130
|
+
ws.emit.signedIn('stack:install-stream', {
|
|
132
131
|
sessionId: session.id,
|
|
133
132
|
tool: session.tool,
|
|
134
133
|
type: stream,
|
|
@@ -192,7 +191,7 @@ function finalizeSession(session: Session, preferredStatus: SessionStatus, exitC
|
|
|
192
191
|
|
|
193
192
|
debug.log('path', `[install:${session.id}] Finished status=${session.status} exit=${exitCode}`);
|
|
194
193
|
|
|
195
|
-
ws.emit.
|
|
194
|
+
ws.emit.signedIn('stack:install-finished', {
|
|
196
195
|
sessionId: session.id,
|
|
197
196
|
tool: session.tool,
|
|
198
197
|
status: session.status,
|
|
@@ -363,14 +362,11 @@ async function removeStackDependencies(session: Session, cwd: string, env: Recor
|
|
|
363
362
|
}
|
|
364
363
|
|
|
365
364
|
/**
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* (see `requireInstallSessionAccess`) so the repair is visible and cancellable.
|
|
365
|
+
* Start installing `tool`. Progress streams to every signed-in device, so an
|
|
366
|
+
* install clopen starts itself (startup repair) is as visible and cancellable
|
|
367
|
+
* as one started from Settings → Stack.
|
|
370
368
|
*/
|
|
371
|
-
export
|
|
372
|
-
|
|
373
|
-
export async function startInstall(tool: ToolId, userId: string): Promise<Session> {
|
|
369
|
+
export async function startInstall(tool: ToolId): Promise<Session> {
|
|
374
370
|
await refreshProcessPath();
|
|
375
371
|
|
|
376
372
|
const existing = activeByTool.get(tool);
|
|
@@ -400,7 +396,6 @@ export async function startInstall(tool: ToolId, userId: string): Promise<Sessio
|
|
|
400
396
|
endedAt: null,
|
|
401
397
|
buffer: newRingBuffer(),
|
|
402
398
|
retentionTimer: null,
|
|
403
|
-
startedBy: userId,
|
|
404
399
|
pending: { stdout: '', stderr: '' }
|
|
405
400
|
};
|
|
406
401
|
|
|
@@ -412,7 +407,7 @@ export async function startInstall(tool: ToolId, userId: string): Promise<Sessio
|
|
|
412
407
|
emitStream(session, 'stdout', banner + '\n');
|
|
413
408
|
|
|
414
409
|
// Broadcast the session-started event so clients that subscribe mid-run can attach.
|
|
415
|
-
ws.emit.
|
|
410
|
+
ws.emit.signedIn('stack:install-started', {
|
|
416
411
|
sessionId: id,
|
|
417
412
|
tool,
|
|
418
413
|
displayCommand: recipe.displayCommand ?? '',
|
|
@@ -458,10 +453,6 @@ export function getSession(sessionId: string) {
|
|
|
458
453
|
return session ? sessionSnapshot(session) : null;
|
|
459
454
|
}
|
|
460
455
|
|
|
461
|
-
export function getSessionOwner(sessionId: string): string | null {
|
|
462
|
-
return sessions.get(sessionId)?.startedBy ?? null;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
456
|
export function getActiveSessionForTool(tool: ToolId) {
|
|
466
457
|
const id = activeByTool.get(tool);
|
|
467
458
|
if (!id) return null;
|
|
@@ -12,17 +12,15 @@
|
|
|
12
12
|
* - a short deadline (default {@link DEFAULT_FILE_SHARE_TTL_MINUTES} minutes),
|
|
13
13
|
* a longer one, or none at all — a link only a revoke can end.
|
|
14
14
|
*
|
|
15
|
-
* Security model (mirrors the
|
|
15
|
+
* Security model (mirrors the device-code flow):
|
|
16
16
|
* - Only the raw token's SHA-256 hash is kept; the raw token is returned once,
|
|
17
17
|
* at creation time, and is embedded in the shared URL.
|
|
18
18
|
* - Tokens live in SQLite (`file_shares`, migration 080) like device codes, so
|
|
19
19
|
* a restart does not silently kill links a user already handed out.
|
|
20
|
-
* - Creation
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* the path (removed from the project, project deleted, account deleted),
|
|
25
|
-
* every link they minted for it stops serving immediately.
|
|
20
|
+
* - Creation resolves the path the same way the download route does
|
|
21
|
+
* (`resolveFilePath`). Directories are rejected.
|
|
22
|
+
* - Every open re-checks that the account which minted the link still exists
|
|
23
|
+
* and the path still resolves; a reset install leaves no working link.
|
|
26
24
|
* - Links are single-file bound: the HTTP route resolves the path from the
|
|
27
25
|
* token and ignores any caller-supplied path, so a link can never be
|
|
28
26
|
* retargeted at another file.
|
|
@@ -41,7 +39,7 @@ import { authQueries, fileShareQueries } from '../database/queries';
|
|
|
41
39
|
import { projectQueries } from '../database/queries/project-queries';
|
|
42
40
|
import { worktreeQueries } from '../database/queries/worktree-queries';
|
|
43
41
|
import { generateFileShareToken, hashToken } from '../auth/tokens';
|
|
44
|
-
import {
|
|
42
|
+
import { resolveFilePath } from '../ws/files/path-access';
|
|
45
43
|
|
|
46
44
|
/**
|
|
47
45
|
* Default lifetime of a new link, in minutes.
|
|
@@ -111,16 +109,16 @@ export function consumerFingerprint(ip?: string | null, userAgent?: string | nul
|
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
112
|
+
* A link is only ever as alive as the account that minted it: a reset install
|
|
113
|
+
* (or a removed account) must not leave a working download behind.
|
|
116
114
|
*/
|
|
117
|
-
async function
|
|
115
|
+
async function assertCreatorStillExists(filePath: string, createdBy: string): Promise<void> {
|
|
118
116
|
const user = authQueries.getUserById(createdBy);
|
|
119
117
|
if (!user) {
|
|
120
118
|
throw new FileShareGoneError();
|
|
121
119
|
}
|
|
122
120
|
try {
|
|
123
|
-
await
|
|
121
|
+
await resolveFilePath(filePath);
|
|
124
122
|
} catch {
|
|
125
123
|
throw new FileShareGoneError();
|
|
126
124
|
}
|
|
@@ -175,19 +173,17 @@ export function describeShareLocation(filePath: string): FileShareLocation {
|
|
|
175
173
|
|
|
176
174
|
/**
|
|
177
175
|
* Mint a share token for a single file. The caller must already be
|
|
178
|
-
* authenticated over the WebSocket
|
|
179
|
-
* project-scoped policy as the download route.
|
|
176
|
+
* authenticated over the WebSocket.
|
|
180
177
|
*/
|
|
181
178
|
export async function createFileShareLink(
|
|
182
179
|
requestedPath: string,
|
|
183
|
-
role: string | null,
|
|
184
180
|
userId: string | null,
|
|
185
181
|
options: FileShareOptions = {}
|
|
186
182
|
): Promise<{ shareId: string; shareToken: string; oneTime: boolean; expiresAt: string | null }> {
|
|
187
183
|
if (!userId) {
|
|
188
184
|
throw new Error('Access denied');
|
|
189
185
|
}
|
|
190
|
-
const resolvedPath = await
|
|
186
|
+
const resolvedPath = await resolveFilePath(requestedPath);
|
|
191
187
|
|
|
192
188
|
const stats = await stat(resolvedPath).catch(() => null);
|
|
193
189
|
if (!stats) {
|
|
@@ -255,7 +251,7 @@ export async function peekFileShare(shareToken: string, fingerprint: string): Pr
|
|
|
255
251
|
}
|
|
256
252
|
}
|
|
257
253
|
|
|
258
|
-
await
|
|
254
|
+
await assertCreatorStillExists(row.file_path, row.created_by);
|
|
259
255
|
|
|
260
256
|
return {
|
|
261
257
|
filePath: row.file_path,
|
|
@@ -285,22 +281,13 @@ export function recordFileShareOpen(shareToken: string): void {
|
|
|
285
281
|
}
|
|
286
282
|
|
|
287
283
|
/**
|
|
288
|
-
* Revoke a share by its row id.
|
|
289
|
-
*
|
|
284
|
+
* Revoke a share by its row id. Returns false when the id is unknown (already
|
|
285
|
+
* used up, lapsed, or revoked).
|
|
290
286
|
*
|
|
291
287
|
* Revoking a link that is inside its continuation window also ends that
|
|
292
288
|
* window, so a stream in progress stops on the next range request.
|
|
293
289
|
*/
|
|
294
|
-
export function revokeFileShareLink(
|
|
295
|
-
shareId: string,
|
|
296
|
-
role: string | null,
|
|
297
|
-
userId: string | null
|
|
298
|
-
): boolean {
|
|
299
|
-
const row = fileShareQueries.getById(shareId);
|
|
300
|
-
if (!row) return false;
|
|
301
|
-
if (role !== 'admin' && row.created_by !== userId) {
|
|
302
|
-
throw new Error('Access denied');
|
|
303
|
-
}
|
|
290
|
+
export function revokeFileShareLink(shareId: string): boolean {
|
|
304
291
|
return fileShareQueries.deleteById(shareId) > 0;
|
|
305
292
|
}
|
|
306
293
|
|
|
@@ -314,8 +301,6 @@ export interface FileShareSummary {
|
|
|
314
301
|
worktreeName: string | null;
|
|
315
302
|
/** Path within the project/worktree, `/`-separated on every platform. */
|
|
316
303
|
relativePath: string;
|
|
317
|
-
createdBy: string;
|
|
318
|
-
createdByName: string | null;
|
|
319
304
|
createdAt: string;
|
|
320
305
|
oneTime: boolean;
|
|
321
306
|
/** ISO deadline, or null for "until revoked". */
|
|
@@ -328,18 +313,11 @@ export interface FileShareSummary {
|
|
|
328
313
|
}
|
|
329
314
|
|
|
330
315
|
/**
|
|
331
|
-
* List live share links
|
|
332
|
-
*
|
|
333
|
-
* reachable right now" rather than "what was ever created".
|
|
316
|
+
* List live share links. Lapsed rows are filtered by the query, so the list
|
|
317
|
+
* answers "what is reachable right now" rather than "what was ever created".
|
|
334
318
|
*/
|
|
335
|
-
export function listFileShares(
|
|
336
|
-
|
|
337
|
-
throw new Error('Access denied');
|
|
338
|
-
}
|
|
339
|
-
const now = new Date().toISOString();
|
|
340
|
-
const rows = role === 'admin'
|
|
341
|
-
? fileShareQueries.listAll(now)
|
|
342
|
-
: fileShareQueries.listForUser(userId, now);
|
|
319
|
+
export function listFileShares(): FileShareSummary[] {
|
|
320
|
+
const rows = fileShareQueries.listLive(new Date().toISOString());
|
|
343
321
|
|
|
344
322
|
return rows.map((row) => {
|
|
345
323
|
const location = describeShareLocation(row.file_path);
|
|
@@ -350,8 +328,6 @@ export function listFileShares(role: string | null, userId: string | null): File
|
|
|
350
328
|
projectName: location.projectName,
|
|
351
329
|
worktreeName: location.worktreeName,
|
|
352
330
|
relativePath: location.relativePath,
|
|
353
|
-
createdBy: row.created_by,
|
|
354
|
-
createdByName: row.created_by_name,
|
|
355
331
|
createdAt: row.created_at,
|
|
356
332
|
oneTime: row.one_time === 1,
|
|
357
333
|
expiresAt: row.expires_at,
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Enforces a configurable maximum file size on write, upload, zip, and
|
|
5
5
|
* extract operations to prevent disk exhaustion attacks (DoS). The limit
|
|
6
|
-
* is sourced from the `system:settings.maxFileSizeMB`
|
|
6
|
+
* is sourced from the `system:settings.maxFileSizeMB` system setting and
|
|
7
7
|
* defaults to 500MB when the setting is missing or invalid.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { readSystemSetting } from '../settings/system-settings';
|
|
11
11
|
|
|
12
|
-
/** Default maximum file size in megabytes when no
|
|
12
|
+
/** Default maximum file size in megabytes when no setting is present. */
|
|
13
13
|
export const DEFAULT_MAX_FILE_SIZE_MB = 500;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Read the current maximum file size (bytes) from system settings.
|
|
17
17
|
* Falls back to the default if the row is missing, malformed, or holds a
|
|
18
18
|
* non-positive value — keeps callers resilient even if the DB is empty
|
|
19
|
-
* (e.g. on first boot before
|
|
19
|
+
* (e.g. on first boot before any system setting is written).
|
|
20
20
|
*/
|
|
21
21
|
export function getMaxFileSize(): number {
|
|
22
22
|
const limitMB = readSystemSetting((settings) => {
|
|
@@ -348,7 +348,7 @@ export async function processImageEdit(
|
|
|
348
348
|
|
|
349
349
|
const { data, info } = await encodeToBuffer(pipeline, recipe.output, fast);
|
|
350
350
|
|
|
351
|
-
// Guard against producing an output larger than the
|
|
351
|
+
// Guard against producing an output larger than the configured file-size limit.
|
|
352
352
|
validateFileSize(data.length);
|
|
353
353
|
|
|
354
354
|
return {
|
|
@@ -24,8 +24,8 @@ import { debug } from '$shared/utils/logger';
|
|
|
24
24
|
* Ctrl+V/⌘V keeps using the `paste` event fast path in the frontend.
|
|
25
25
|
*
|
|
26
26
|
* Both directions are HOST-MACHINE operations: they read and write the
|
|
27
|
-
* clipboard of the machine the server runs on, not the viewer's
|
|
28
|
-
*
|
|
27
|
+
* clipboard of the machine the server runs on, not the viewer's (see
|
|
28
|
+
* `backend/ws/files/clipboard.ts`).
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
export const OS_CLIPBOARD_ENV_VAR = 'CLOPEN_OS_CLIP_PATHS_B64';
|
|
@@ -16,6 +16,9 @@ import { resolveBinary } from '../utils/cli';
|
|
|
16
16
|
*/
|
|
17
17
|
export type GitIdentityEnv = Record<string, string>;
|
|
18
18
|
|
|
19
|
+
/** How long a timed-out git gets to exit on SIGTERM before it is killed outright. */
|
|
20
|
+
const KILL_GRACE_MS = 5000;
|
|
21
|
+
|
|
19
22
|
export interface GitExecResult {
|
|
20
23
|
stdout: string;
|
|
21
24
|
stderr: string;
|
|
@@ -108,9 +111,15 @@ export async function execGit(
|
|
|
108
111
|
}
|
|
109
112
|
});
|
|
110
113
|
|
|
111
|
-
// Timeout handling
|
|
114
|
+
// Timeout handling. SIGTERM first: git traps it and deletes the lockfile it
|
|
115
|
+
// holds, where SIGKILL would strand `.git/index.lock` and break every later
|
|
116
|
+
// command until someone removes it by hand. SIGKILL only if git ignores it.
|
|
117
|
+
let timedOut = false;
|
|
118
|
+
let killTimer: ReturnType<typeof setTimeout> | null = null;
|
|
112
119
|
const timeoutId = setTimeout(() => {
|
|
113
|
-
|
|
120
|
+
timedOut = true;
|
|
121
|
+
proc.kill('SIGTERM');
|
|
122
|
+
killTimer = setTimeout(() => proc.kill('SIGKILL'), KILL_GRACE_MS);
|
|
114
123
|
}, timeout);
|
|
115
124
|
|
|
116
125
|
try {
|
|
@@ -123,14 +132,25 @@ export async function execGit(
|
|
|
123
132
|
|
|
124
133
|
const exitCode = await proc.exited;
|
|
125
134
|
clearTimeout(timeoutId);
|
|
135
|
+
if (killTimer) clearTimeout(killTimer);
|
|
136
|
+
|
|
137
|
+
// A killed git usually prints nothing, which surfaced as an error dialog
|
|
138
|
+
// with an empty message.
|
|
139
|
+
const finalStderr = timedOut
|
|
140
|
+
? `${stderr.trim() ? `${stderr.trim()}\n` : ''}git ${args[0]} timed out after ${Math.round(timeout / 1000)}s and was stopped.`
|
|
141
|
+
: stderr;
|
|
142
|
+
const finalExitCode = timedOut && exitCode === 0 ? 1 : exitCode;
|
|
126
143
|
|
|
127
|
-
if (
|
|
128
|
-
debug.warn('git', `Command failed (exit ${
|
|
144
|
+
if (finalExitCode !== 0 && !okExitCodes.includes(finalExitCode)) {
|
|
145
|
+
debug.warn('git', `Command failed (exit ${finalExitCode}): git ${args.join(' ')}\n${finalStderr}`);
|
|
129
146
|
}
|
|
130
147
|
|
|
131
|
-
return raw
|
|
148
|
+
return raw
|
|
149
|
+
? { stdout, stderr: finalStderr, exitCode: finalExitCode, stdoutBytes }
|
|
150
|
+
: { stdout, stderr: finalStderr, exitCode: finalExitCode };
|
|
132
151
|
} catch (err) {
|
|
133
152
|
clearTimeout(timeoutId);
|
|
153
|
+
if (killTimer) clearTimeout(killTimer);
|
|
134
154
|
throw err;
|
|
135
155
|
}
|
|
136
156
|
}
|