@myrialabs/clopen 0.4.40 → 0.4.42
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/.env.example +1 -1
- package/backend/artifacts/detect.ts +15 -3
- package/backend/artifacts/generate.ts +2 -2
- package/backend/artifacts/index.ts +12 -4
- package/backend/artifacts/markers.ts +24 -1
- package/backend/artifacts/matrix.ts +47 -3
- package/backend/artifacts/sync.test.ts +3 -3
- package/backend/artifacts/sync.ts +8 -20
- package/backend/artifacts/types.ts +9 -3
- package/backend/auth/permissions.ts +6 -11
- package/backend/auth/session-cleanup.ts +10 -1
- package/backend/auth/tokens.ts +9 -1
- package/backend/chat/stream-manager.ts +50 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/index.ts +18 -0
- package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
- package/backend/database/migrations/080_create_file_shares.ts +111 -0
- package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
- package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
- package/backend/database/migrations/082_create_git_identities.ts +122 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/file-share-queries.ts +163 -0
- package/backend/database/queries/git-identity-queries.ts +290 -0
- package/backend/database/queries/index.ts +8 -4
- package/backend/database/queries/profile-queries.ts +5 -3
- package/backend/database/queries/push-subscription-queries.test.ts +90 -0
- package/backend/database/queries/push-subscription-queries.ts +99 -0
- package/backend/database/queries/skill-queries.ts +96 -18
- package/backend/engine/adapters/claude/environment.ts +11 -1
- package/backend/engine/adapters/claude/stream.ts +3 -2
- package/backend/engine/adapters/cline/stream.ts +3 -3
- package/backend/engine/adapters/codex/stream.ts +38 -6
- package/backend/engine/adapters/copilot/stream.ts +3 -3
- package/backend/engine/adapters/cursor/stream.ts +25 -3
- package/backend/engine/adapters/opencode/server.ts +26 -2
- package/backend/engine/adapters/opencode/stream.ts +8 -7
- package/backend/engine/adapters/pi/stream.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +5 -3
- package/backend/engine/artifact-sync.ts +26 -20
- package/backend/engine/docs/artifacts.md +81 -22
- package/backend/engine/docs/quick-reference.md +2 -1
- package/backend/engine/resolve-model.test.ts +108 -0
- package/backend/engine/resolve-model.ts +53 -10
- package/backend/engine/structured-helpers.ts +22 -0
- package/backend/engine/types.ts +10 -0
- package/backend/files/file-shares.ts +369 -0
- package/backend/files/path-browsing.ts +27 -21
- package/backend/git/git-executor.ts +28 -2
- package/backend/git/git-service.ts +59 -40
- package/backend/git/identity/cli.test.ts +58 -0
- package/backend/git/identity/cli.ts +201 -0
- package/backend/git/identity/credential-helper.test.ts +242 -0
- package/backend/git/identity/env.test.ts +214 -0
- package/backend/git/identity/env.ts +193 -0
- package/backend/git/identity/import-local.test.ts +199 -0
- package/backend/git/identity/import-local.ts +141 -0
- package/backend/git/identity/index.ts +78 -0
- package/backend/git/identity/keys.ts +183 -0
- package/backend/git/identity/resolve.ts +140 -0
- package/backend/git/identity/scope-config.test.ts +145 -0
- package/backend/git/identity/scope-config.ts +175 -0
- package/backend/git/identity/service.ts +297 -0
- package/backend/http/files-shared.test.ts +505 -0
- package/backend/http/files-shared.ts +351 -0
- package/backend/http/push.ts +150 -0
- package/backend/index.ts +24 -0
- package/backend/instructions/index.ts +1 -1
- package/backend/instructions/sync.ts +30 -6
- package/backend/memory/compose.ts +2 -2
- package/backend/memory/consolidate.ts +2 -2
- package/backend/memory/extract/episodic.ts +2 -2
- package/backend/memory/judge.ts +2 -2
- package/backend/preview/browser/browser-console-manager.ts +214 -34
- package/backend/preview/browser/browser-pool.ts +526 -123
- package/backend/preview/browser/browser-preview-service.ts +192 -8
- package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
- package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
- package/backend/preview/browser/browser-tab-manager.ts +291 -65
- package/backend/preview/browser/capture-profile.ts +15 -1
- package/backend/preview/browser/types.ts +26 -1
- package/backend/profiles/service.ts +7 -6
- package/backend/push/sender.ts +172 -0
- package/backend/push/tags.ts +25 -0
- package/backend/push/vapid-keys.ts +77 -0
- package/backend/push/webpush-crypto.test.ts +200 -0
- package/backend/push/webpush-crypto.ts +231 -0
- package/backend/skills/detect.ts +28 -0
- package/backend/skills/index.ts +22 -4
- package/backend/skills/invoke.test.ts +114 -0
- package/backend/skills/invoke.ts +222 -0
- package/backend/skills/service.ts +194 -44
- package/backend/skills/spec.ts +35 -0
- package/backend/skills/sync.ts +85 -55
- package/backend/subagents/detect.ts +2 -3
- package/backend/subagents/sync.ts +15 -8
- package/backend/terminal/ptykit.ts +24 -0
- package/backend/work/pull-requests.ts +2 -2
- package/backend/ws/chat/stream.ts +100 -8
- package/backend/ws/files/index.ts +4 -0
- package/backend/ws/files/share.ts +95 -0
- package/backend/ws/git/branch-name.ts +2 -2
- package/backend/ws/git/branch.ts +17 -6
- package/backend/ws/git/commit-message.ts +2 -2
- package/backend/ws/git/commit.ts +6 -5
- package/backend/ws/git/conflict.ts +3 -2
- package/backend/ws/git/identity-context.ts +91 -0
- package/backend/ws/git/identity.ts +200 -0
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/remote.ts +57 -11
- package/backend/ws/index.ts +3 -4
- package/backend/ws/preview/browser/data.ts +60 -0
- package/backend/ws/preview/browser/interact.ts +6 -0
- package/backend/ws/preview/browser/tab-info.ts +9 -1
- package/backend/ws/preview/browser/tab.ts +64 -8
- package/backend/ws/preview/index.ts +21 -0
- package/backend/ws/profiles/crud.ts +2 -3
- package/backend/ws/skills/catalog.ts +5 -1
- package/backend/ws/skills/crud.ts +128 -22
- package/backend/ws/skills/index.ts +4 -1
- package/backend/ws/user/crud.ts +12 -3
- package/bin/clopen.ts +9 -0
- package/dist/assets/{index-D4igjF6e.js → index-BynqyvF4.js} +1 -1
- package/dist/assets/{index-DONNwiXm.js → index-DLoJsmNQ.js} +1 -1
- package/dist/assets/{main-BrfXH1bL.js → main-CUyZAmqt.js} +601 -592
- package/dist/assets/main-DVCW3cfr.css +1 -0
- package/dist/index.html +7 -2
- package/dist/sw.js +112 -0
- package/package.json +2 -2
- package/shared/constants/engine-tools.ts +31 -6
- package/shared/constants/notification-messages.ts +142 -0
- package/shared/types/git-identity.ts +112 -0
- package/shared/types/unified/stream.ts +7 -0
- package/backend/commands/detect.ts +0 -25
- package/backend/commands/index.ts +0 -9
- package/backend/commands/service.ts +0 -178
- package/backend/commands/store.ts +0 -45
- package/backend/commands/sync.ts +0 -94
- package/backend/database/queries/command-queries.ts +0 -82
- package/backend/ws/commands/crud.ts +0 -157
- package/backend/ws/commands/index.ts +0 -8
- package/dist/assets/main-CT1PygsW.css +0 -1
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { subagentQueries } from '$backend/database/queries';
|
|
11
11
|
import { debug } from '$shared/utils/logger';
|
|
12
|
-
import { materializeArtifacts, resolveArtifact, isPromptScopedEngine, parseDoc, serializeDoc, parseEngineMap, artifactEngineToType, type ManagedArtifact, type ArtifactEngine } from '$backend/artifacts';
|
|
12
|
+
import { materializeArtifacts, resolveArtifact, isPromptScopedEngine, canDelegateSubagents, parseDoc, serializeDoc, parseEngineMap, artifactEngineToType, ARTIFACT_ENGINES, type ManagedArtifact, type ArtifactEngine } from '$backend/artifacts';
|
|
13
13
|
import { artifactFilter } from '$backend/profiles';
|
|
14
14
|
import { readSubagentMd } from './store';
|
|
15
15
|
|
|
@@ -56,11 +56,17 @@ function resolveEnabledSubagentsMeta(profileId?: number): ManagedArtifact[] {
|
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* The profile-scoped subagents preamble for PER-SESSION injection into a
|
|
59
|
-
* prompt-scoped engine's prompt
|
|
60
|
-
*
|
|
61
|
-
*
|
|
59
|
+
* prompt-scoped engine's prompt. Returns '' when none apply. Advisory: it steers
|
|
60
|
+
* which subagents the model delegates to, on top of whatever the engine's own
|
|
61
|
+
* (possibly stale/shared) agent registry exposes.
|
|
62
|
+
*
|
|
63
|
+
* Engines with no way to delegate (Codex, Copilot, Qwen) are told nothing. They
|
|
64
|
+
* used to receive the same "you can delegate matching tasks to these" preamble
|
|
65
|
+
* as engines that can, which described a capability they do not have — the model
|
|
66
|
+
* could only respond by inventing the delegation or ignoring the block.
|
|
62
67
|
*/
|
|
63
|
-
export function buildSubagentsPromptContext(profileId?: number): string {
|
|
68
|
+
export function buildSubagentsPromptContext(engine: ArtifactEngine, profileId?: number): string {
|
|
69
|
+
if (!canDelegateSubagents(engine)) return '';
|
|
64
70
|
return buildSubagentsPreamble(resolveEnabledSubagentsMeta(profileId));
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -111,7 +117,9 @@ export async function syncSubagents(engine: ArtifactEngine, profileId?: number):
|
|
|
111
117
|
// In both cases materialize an EMPTY set so any stale dir/block is stripped.
|
|
112
118
|
// Claude keeps its native filtered files; Qwen (per-query) keeps its preamble.
|
|
113
119
|
const synthetic = resolveArtifact('subagent', { engine, scope: 'global' }).format === 'preamble-region';
|
|
114
|
-
|
|
120
|
+
// An engine that cannot delegate gets an empty set too: no files, no block,
|
|
121
|
+
// no advertisement anywhere (see {@link buildSubagentsPromptContext}).
|
|
122
|
+
const viaPrompt = (synthetic && isPromptScopedEngine(engine)) || engine === 'opencode' || !canDelegateSubagents(engine);
|
|
115
123
|
const filter = artifactFilter(profileId, 'subagent');
|
|
116
124
|
// A profile activates the subagents it references even if globally disabled;
|
|
117
125
|
// with no profile filter, only the enabled set applies (unchanged).
|
|
@@ -139,6 +147,5 @@ export async function syncSubagents(engine: ArtifactEngine, profileId?: number):
|
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
export async function syncSubagentsAllEngines(): Promise<void> {
|
|
142
|
-
|
|
143
|
-
await Promise.all(engines.map(syncSubagents));
|
|
150
|
+
await Promise.all(ARTIFACT_ENGINES.map(engine => syncSubagents(engine)));
|
|
144
151
|
}
|
|
@@ -15,6 +15,7 @@ import { PtyKitManager } from '@myrialabs/ptykit/core';
|
|
|
15
15
|
import { createPtyKitServer } from '@myrialabs/ptykit/server';
|
|
16
16
|
import { projectQueries } from '$backend/database/queries';
|
|
17
17
|
import { isScopeOfProject, makeScopeKey, scopeProjectId } from '$shared/utils/workspace-scope';
|
|
18
|
+
import { writeScopeConfig } from '$backend/git/identity';
|
|
18
19
|
|
|
19
20
|
/** Terminal-friendly env, matching the previous `createCleanPtyEnv` overrides. */
|
|
20
21
|
const TERMINAL_ENV = {
|
|
@@ -51,6 +52,29 @@ export const ptyKitServer = createPtyKitServer(ptyKitManager, {
|
|
|
51
52
|
const allowed = projectQueries.userHasProject(userId, scopeProjectId(ctx.namespace));
|
|
52
53
|
if (allowed) knownNamespaces.add(ctx.namespace);
|
|
53
54
|
return allowed;
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* The shell inherits the git identity of whoever opened it, for the project
|
|
58
|
+
* it belongs to. Without this a `git commit` typed into the terminal would
|
|
59
|
+
* use the machine's identity while the same commit from the Git panel used
|
|
60
|
+
* the chosen one — the same repository, two different authors.
|
|
61
|
+
*
|
|
62
|
+
* Pointed at a FILE rather than given the `GIT_CONFIG_*` block the other
|
|
63
|
+
* surfaces use. A shell lives for hours and its environment is fixed at
|
|
64
|
+
* spawn, so an inlined identity goes stale the moment the user switches
|
|
65
|
+
* accounts — silently, since the tab keeps working. Git re-reads a config
|
|
66
|
+
* file on every invocation, so the switch reaches tabs that are already open.
|
|
67
|
+
* See `backend/git/identity/scope-config.ts`.
|
|
68
|
+
*
|
|
69
|
+
* `GIT_CONFIG_GLOBAL` is only set when the file was actually written: it
|
|
70
|
+
* REPLACES `~/.gitconfig`, so aiming it at a missing path would take the
|
|
71
|
+
* user's own global config away from every git command in the terminal.
|
|
72
|
+
*/
|
|
73
|
+
env: async (ctx): Promise<Record<string, string>> => {
|
|
74
|
+
const userId = ctx.conn.data.userId;
|
|
75
|
+
if (typeof userId !== 'string' || !userId) return {};
|
|
76
|
+
const path = await writeScopeConfig(userId, scopeProjectId(ctx.namespace));
|
|
77
|
+
return path ? { GIT_CONFIG_GLOBAL: path } : {};
|
|
54
78
|
}
|
|
55
79
|
});
|
|
56
80
|
|
|
@@ -14,7 +14,7 @@ import { execGit } from '$backend/git/git-executor';
|
|
|
14
14
|
import { gitService } from '$backend/git/git-service';
|
|
15
15
|
import { workLinkQueries } from '$backend/database/queries';
|
|
16
16
|
import { initializeEngine } from '$backend/engine';
|
|
17
|
-
import { resolveGenerationTarget } from '$backend/engine/resolve-model';
|
|
17
|
+
import { resolveGenerationTarget, GENERATION_SETTINGS } from '$backend/engine/resolve-model';
|
|
18
18
|
import { buildBudgetedDiff, PR_DESCRIPTION_BUDGET, rangeScope } from '$backend/ws/git/diff-budget';
|
|
19
19
|
import type { EngineType } from '$shared/types/unified';
|
|
20
20
|
import type { GitBranchInfo } from '$shared/types/git';
|
|
@@ -226,7 +226,7 @@ export async function draftPullRequestDescription(input: {
|
|
|
226
226
|
diffTruncated: diff.truncated
|
|
227
227
|
});
|
|
228
228
|
|
|
229
|
-
const target = await resolveGenerationTarget(engine, input.modelId, input.providerSlug);
|
|
229
|
+
const target = await resolveGenerationTarget(engine, input.modelId, input.providerSlug, GENERATION_SETTINGS.commit);
|
|
230
230
|
debug.log('work', `Drafting a PR description via ${input.engine}/${target.providerSlug}/${target.modelId}`);
|
|
231
231
|
|
|
232
232
|
const result = await engine.generateStructured<GeneratedDescription>({
|
|
@@ -15,10 +15,39 @@ import { debug } from '$shared/utils/logger';
|
|
|
15
15
|
import { trimSubAgentForWire } from '$shared/utils/subagent-wire-trim';
|
|
16
16
|
import { ws } from '$backend/utils/ws';
|
|
17
17
|
import { broadcastPresence } from '../projects/status';
|
|
18
|
-
import { sessionQueries, messageQueries } from '../../database/queries';
|
|
18
|
+
import { projectQueries, sessionQueries, messageQueries } from '../../database/queries';
|
|
19
|
+
import { sendPushToUser } from '../../push/sender';
|
|
20
|
+
import { chatStreamPushTag, waitingInputPushTag } from '../../push/tags';
|
|
21
|
+
import {
|
|
22
|
+
chatNotificationMessage,
|
|
23
|
+
type ChatNotificationContext
|
|
24
|
+
} from '$shared/constants/notification-messages';
|
|
19
25
|
import { requireSessionAccess } from '../access';
|
|
20
26
|
import { resolveSessionPath } from '../../worktrees';
|
|
21
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Where a notification-worthy event happened, resolved once on the server.
|
|
30
|
+
*
|
|
31
|
+
* The browser cannot do this itself: the sessions store only holds the project
|
|
32
|
+
* currently open, and these notifications exist precisely for the chats the
|
|
33
|
+
* user is *not* looking at. Shipping the resolved names in the event payload
|
|
34
|
+
* also keeps the tab's local toast worded identically to the server push that
|
|
35
|
+
* replaces it — they share a tag, so any difference would read as the
|
|
36
|
+
* notification rewriting itself.
|
|
37
|
+
*
|
|
38
|
+
* Missing rows yield `undefined`, never a placeholder: the composer drops an
|
|
39
|
+
* absent segment, which says more than the word "Unknown" did.
|
|
40
|
+
*/
|
|
41
|
+
function resolveNotificationContext(
|
|
42
|
+
projectId: string,
|
|
43
|
+
chatSessionId: string | undefined
|
|
44
|
+
): ChatNotificationContext {
|
|
45
|
+
return {
|
|
46
|
+
projectName: projectQueries.getById(projectId)?.name || undefined,
|
|
47
|
+
sessionTitle: chatSessionId ? sessionQueries.getById(chatSessionId)?.title || undefined : undefined
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
22
51
|
/**
|
|
23
52
|
* Broadcast presence + notify project members when a chat message may flip the
|
|
24
53
|
* stream's waiting-for-input state (an AskUserQuestion tool_use arrives, or a
|
|
@@ -52,12 +81,31 @@ function handleWaitingInputChange(
|
|
|
52
81
|
|
|
53
82
|
// Notify all project members when AskUserQuestion arrives (sound + push)
|
|
54
83
|
if (askToolUse && projectId) {
|
|
84
|
+
const context = resolveNotificationContext(projectId, chatSessionId);
|
|
85
|
+
|
|
55
86
|
ws.emit.projectMembers(projectId, 'chat:waiting-input', {
|
|
56
87
|
projectId,
|
|
57
88
|
chatSessionId,
|
|
58
89
|
toolUseId: askToolUse.id,
|
|
59
|
-
timestamp: event.data?.timestamp || new Date().toISOString()
|
|
90
|
+
timestamp: event.data?.timestamp || new Date().toISOString(),
|
|
91
|
+
...context
|
|
60
92
|
});
|
|
93
|
+
|
|
94
|
+
// Background route: reach the requester's devices even when Chrome is
|
|
95
|
+
// closed. Deterministic tag replaces (not stacks with) the local toast
|
|
96
|
+
// the open tab shows for the same question.
|
|
97
|
+
const requestedByUserId = streamManager.getSessionStream(
|
|
98
|
+
chatSessionId,
|
|
99
|
+
projectId
|
|
100
|
+
)?.requestedByUserId;
|
|
101
|
+
if (requestedByUserId) {
|
|
102
|
+
void sendPushToUser(requestedByUserId, {
|
|
103
|
+
...chatNotificationMessage('waiting-input', context),
|
|
104
|
+
tag: waitingInputPushTag(askToolUse.id)
|
|
105
|
+
}).catch((error) => {
|
|
106
|
+
debug.warn('notification', 'Background waiting-input push failed:', error);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
61
109
|
}
|
|
62
110
|
}
|
|
63
111
|
|
|
@@ -68,8 +116,8 @@ function handleWaitingInputChange(
|
|
|
68
116
|
// exists (e.g., after browser refresh when user is on a different project).
|
|
69
117
|
// Ensures cross-project notifications (presence update, sound, push) always work.
|
|
70
118
|
// ============================================================================
|
|
71
|
-
streamManager.on('stream:lifecycle', (event: { status: string; streamId: string; projectId?: string; chatSessionId?: string; timestamp: string; reason?: string }) => {
|
|
72
|
-
const { status, projectId, chatSessionId, timestamp, reason } = event;
|
|
119
|
+
streamManager.on('stream:lifecycle', (event: { status: string; streamId: string; projectId?: string; chatSessionId?: string; requestedByUserId?: string; timestamp: string; reason?: string }) => {
|
|
120
|
+
const { status, streamId, projectId, chatSessionId, requestedByUserId, timestamp, reason } = event;
|
|
73
121
|
if (!projectId) return;
|
|
74
122
|
|
|
75
123
|
debug.log('chat', `Stream lifecycle: ${status} for project ${projectId} session ${chatSessionId}${reason ? ` (reason: ${reason})` : ''}`);
|
|
@@ -83,15 +131,39 @@ streamManager.on('stream:lifecycle', (event: { status: string; streamId: string;
|
|
|
83
131
|
}
|
|
84
132
|
}
|
|
85
133
|
|
|
134
|
+
// Resolved once and shared: the payload below carries it to the open tab,
|
|
135
|
+
// and the background push below that reuses the very same values, so the
|
|
136
|
+
// two copies of one event cannot word themselves differently.
|
|
137
|
+
const context = resolveNotificationContext(projectId, chatSessionId);
|
|
138
|
+
|
|
86
139
|
// Notify all project members (cross-project notification for sound + push)
|
|
87
140
|
ws.emit.projectMembers(projectId, 'chat:stream-finished', {
|
|
88
141
|
projectId,
|
|
89
142
|
chatSessionId: chatSessionId || '',
|
|
143
|
+
streamId,
|
|
90
144
|
status: status as 'completed' | 'error' | 'cancelled',
|
|
91
145
|
timestamp,
|
|
92
|
-
reason
|
|
146
|
+
reason,
|
|
147
|
+
...context
|
|
93
148
|
});
|
|
94
149
|
|
|
150
|
+
// Background route: the open tab notifies locally via the WS event above;
|
|
151
|
+
// this reaches the requester's devices when Chrome is closed. The shared
|
|
152
|
+
// deterministic tag means an open tab's local toast is replaced, never
|
|
153
|
+
// duplicated. Never throws — chat completion must not depend on push.
|
|
154
|
+
if (requestedByUserId && reason !== 'session-deleted') {
|
|
155
|
+
// `cancelled` gets its own title. Filing it under a "complete" heading
|
|
156
|
+
// with an "interrupted" body made the notification contradict itself.
|
|
157
|
+
const notificationEvent =
|
|
158
|
+
status === 'error' ? 'error' : status === 'cancelled' ? 'cancelled' : 'completed';
|
|
159
|
+
void sendPushToUser(requestedByUserId, {
|
|
160
|
+
...chatNotificationMessage(notificationEvent, context),
|
|
161
|
+
tag: chatStreamPushTag(streamId)
|
|
162
|
+
}).catch((error) => {
|
|
163
|
+
debug.warn('notification', 'Background stream-finished push failed:', error);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
95
167
|
// Broadcast updated presence (status indicators for all projects)
|
|
96
168
|
broadcastPresence().catch((err) => {
|
|
97
169
|
debug.warn('chat', 'Presence broadcast error after stream lifecycle:', err);
|
|
@@ -241,6 +313,16 @@ export const streamHandler = createRouter()
|
|
|
241
313
|
workingRoot
|
|
242
314
|
});
|
|
243
315
|
|
|
316
|
+
// The WS user id is server-trusted (unlike the client-supplied sender)
|
|
317
|
+
// and routes background Web Push to the requester's devices. Missing
|
|
318
|
+
// context must not break the stream — push is best-effort.
|
|
319
|
+
let requestedByUserId: string | undefined;
|
|
320
|
+
try {
|
|
321
|
+
requestedByUserId = ws.getUserId(conn);
|
|
322
|
+
} catch {
|
|
323
|
+
requestedByUserId = undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
244
326
|
// Start background stream
|
|
245
327
|
const streamId = await streamManager.startStream({
|
|
246
328
|
projectPath: workingRoot,
|
|
@@ -250,7 +332,8 @@ export const streamHandler = createRouter()
|
|
|
250
332
|
engine: data.engine,
|
|
251
333
|
sender: data.sender,
|
|
252
334
|
profileId: data.profileId,
|
|
253
|
-
reasoningEffort: data.reasoningEffort
|
|
335
|
+
reasoningEffort: data.reasoningEffort,
|
|
336
|
+
requestedByUserId
|
|
254
337
|
});
|
|
255
338
|
|
|
256
339
|
debug.log('chat', 'Stream started with ID:', streamId);
|
|
@@ -1085,19 +1168,28 @@ export const streamHandler = createRouter()
|
|
|
1085
1168
|
timestamp: t.String()
|
|
1086
1169
|
}))
|
|
1087
1170
|
|
|
1171
|
+
// `projectName` / `sessionTitle` are resolved server-side and carried here
|
|
1172
|
+
// so the tab can word its local notification exactly like the background
|
|
1173
|
+
// push that replaces it. Optional because either row may be gone, and
|
|
1174
|
+
// because a tab left open across a server upgrade will not send them.
|
|
1088
1175
|
.emit('chat:stream-finished', t.Object({
|
|
1089
1176
|
projectId: t.String(),
|
|
1090
1177
|
chatSessionId: t.String(),
|
|
1178
|
+
streamId: t.Optional(t.String()),
|
|
1091
1179
|
status: t.Union([t.Literal('completed'), t.Literal('error'), t.Literal('cancelled')]),
|
|
1092
1180
|
timestamp: t.String(),
|
|
1093
|
-
reason: t.Optional(t.String())
|
|
1181
|
+
reason: t.Optional(t.String()),
|
|
1182
|
+
projectName: t.Optional(t.String()),
|
|
1183
|
+
sessionTitle: t.Optional(t.String())
|
|
1094
1184
|
}))
|
|
1095
1185
|
|
|
1096
1186
|
.emit('chat:waiting-input', t.Object({
|
|
1097
1187
|
projectId: t.String(),
|
|
1098
1188
|
chatSessionId: t.String(),
|
|
1099
1189
|
toolUseId: t.String(),
|
|
1100
|
-
timestamp: t.String()
|
|
1190
|
+
timestamp: t.String(),
|
|
1191
|
+
projectName: t.Optional(t.String()),
|
|
1192
|
+
sessionTitle: t.Optional(t.String())
|
|
1101
1193
|
}))
|
|
1102
1194
|
|
|
1103
1195
|
.emit('snapshot:captured', t.Object({
|
|
@@ -19,6 +19,7 @@ import { revealHandler } from './reveal';
|
|
|
19
19
|
import { clipboardHandler } from './clipboard';
|
|
20
20
|
import { imageEditHandler } from './image-edit';
|
|
21
21
|
import { fileSearchHandler } from './search';
|
|
22
|
+
import { fileShareHandler } from './share';
|
|
22
23
|
import { watchHandler } from './watch';
|
|
23
24
|
import { filesStateHandler } from './state';
|
|
24
25
|
|
|
@@ -41,6 +42,9 @@ export const filesRouter = createRouter()
|
|
|
41
42
|
// Search Operations (HTTP)
|
|
42
43
|
.merge(fileSearchHandler)
|
|
43
44
|
|
|
45
|
+
// Single-file share links (HTTP)
|
|
46
|
+
.merge(fileShareHandler)
|
|
47
|
+
|
|
44
48
|
// Watch Operations (Events)
|
|
45
49
|
.merge(watchHandler)
|
|
46
50
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File share-link WebSocket handlers (File Explorer → "Share Link…").
|
|
3
|
+
*
|
|
4
|
+
* - files:create-share — authenticated user mints a link for one file, with
|
|
5
|
+
* its one-time / deadline options. The raw token is embedded in the share
|
|
6
|
+
* URL; only its hash is stored, and the row id comes back alongside it so
|
|
7
|
+
* the link stays manageable afterwards.
|
|
8
|
+
* - files:list-shares — live links: every user's for an admin, your own
|
|
9
|
+
* otherwise. Carries no token material, so it can never rebuild a URL.
|
|
10
|
+
* - files:revoke-share — creator (or admin) invalidates a link by row id.
|
|
11
|
+
* - files:shares-changed — broadcast whenever that list moves, so every open
|
|
12
|
+
* management view reflects a mint, a revoke or an open without polling.
|
|
13
|
+
*
|
|
14
|
+
* Reachability (how another device can open the link) is NOT handled here —
|
|
15
|
+
* the frontend builds the URL against the Remote Access public origin
|
|
16
|
+
* (`share:ensure-origin`), reusing that system instead of a new one.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { t } from 'elysia';
|
|
20
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
21
|
+
import { ws } from '$backend/utils/ws';
|
|
22
|
+
import {
|
|
23
|
+
createFileShareLink,
|
|
24
|
+
listFileShares,
|
|
25
|
+
revokeFileShareLink,
|
|
26
|
+
MAX_FILE_SHARE_TTL_MINUTES
|
|
27
|
+
} from '../../files/file-shares';
|
|
28
|
+
|
|
29
|
+
const shareSummary = t.Object({
|
|
30
|
+
id: t.String(),
|
|
31
|
+
filePath: t.String(),
|
|
32
|
+
fileName: t.String(),
|
|
33
|
+
projectName: t.Union([t.String(), t.Null()]),
|
|
34
|
+
worktreeName: t.Union([t.String(), t.Null()]),
|
|
35
|
+
relativePath: t.String(),
|
|
36
|
+
createdBy: t.String(),
|
|
37
|
+
createdByName: t.Union([t.String(), t.Null()]),
|
|
38
|
+
createdAt: t.String(),
|
|
39
|
+
oneTime: t.Boolean(),
|
|
40
|
+
expiresAt: t.Union([t.String(), t.Null()]),
|
|
41
|
+
openCount: t.Number(),
|
|
42
|
+
lastOpenedAt: t.Union([t.String(), t.Null()]),
|
|
43
|
+
consumedAt: t.Union([t.String(), t.Null()])
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const fileShareHandler = createRouter()
|
|
47
|
+
.http('files:create-share', {
|
|
48
|
+
data: t.Object({
|
|
49
|
+
file_path: t.String({ minLength: 1 }),
|
|
50
|
+
/** Burn on the first open. Defaults to true. */
|
|
51
|
+
oneTime: t.Optional(t.Boolean()),
|
|
52
|
+
/** Minutes until it lapses, or null for "until revoked". */
|
|
53
|
+
expiresInMinutes: t.Optional(
|
|
54
|
+
t.Union([t.Number({ minimum: 1, maximum: MAX_FILE_SHARE_TTL_MINUTES }), t.Null()])
|
|
55
|
+
)
|
|
56
|
+
}),
|
|
57
|
+
response: t.Object({
|
|
58
|
+
shareId: t.String(),
|
|
59
|
+
shareToken: t.String(),
|
|
60
|
+
oneTime: t.Boolean(),
|
|
61
|
+
expiresAt: t.Union([t.String(), t.Null()])
|
|
62
|
+
})
|
|
63
|
+
}, async ({ data, conn }) => {
|
|
64
|
+
const result = await createFileShareLink(data.file_path, ws.getRole(conn), ws.getUserId(conn), {
|
|
65
|
+
oneTime: data.oneTime,
|
|
66
|
+
expiresInMinutes: data.expiresInMinutes
|
|
67
|
+
});
|
|
68
|
+
ws.emit.global('files:shares-changed', { kind: 'created' });
|
|
69
|
+
return result;
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
.http('files:list-shares', {
|
|
73
|
+
data: t.Object({}),
|
|
74
|
+
response: t.Object({ shares: t.Array(shareSummary) })
|
|
75
|
+
}, async ({ conn }) => {
|
|
76
|
+
return { shares: listFileShares(ws.getRole(conn), ws.getUserId(conn)) };
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
.http('files:revoke-share', {
|
|
80
|
+
data: t.Object({
|
|
81
|
+
shareId: t.String({ minLength: 1 })
|
|
82
|
+
}),
|
|
83
|
+
response: t.Object({ success: t.Boolean() })
|
|
84
|
+
}, async ({ data, conn }) => {
|
|
85
|
+
const success = revokeFileShareLink(data.shareId, ws.getRole(conn), ws.getUserId(conn));
|
|
86
|
+
if (success) ws.emit.global('files:shares-changed', { kind: 'revoked' });
|
|
87
|
+
return { success };
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Broadcast-only: the payload says nothing about whose link moved, because
|
|
91
|
+
// every listener re-reads its own role-scoped list. A global ping cannot
|
|
92
|
+
// leak what a user is not allowed to see.
|
|
93
|
+
.emit('files:shares-changed', t.Object({
|
|
94
|
+
kind: t.String()
|
|
95
|
+
}));
|
|
@@ -9,7 +9,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
9
9
|
import { execGit } from '../../git/git-executor';
|
|
10
10
|
import { buildBudgetedStagedDiff, BRANCH_NAME_BUDGET } from './diff-budget';
|
|
11
11
|
import { initializeEngine } from '../../engine';
|
|
12
|
-
import { resolveGenerationTarget } from '../../engine/resolve-model';
|
|
12
|
+
import { resolveGenerationTarget, GENERATION_SETTINGS } from '../../engine/resolve-model';
|
|
13
13
|
import type { EngineType } from '$shared/types/unified';
|
|
14
14
|
import type { GeneratedBranchName } from '$shared/types/git';
|
|
15
15
|
import {
|
|
@@ -171,7 +171,7 @@ export const branchNameHandler = createRouter()
|
|
|
171
171
|
const prompt = `${instructions}${extra ? `\n\nAdditional constraints:\n${extra}` : ''}\n\n${diff.text}`;
|
|
172
172
|
|
|
173
173
|
// The caller's providerSlug/account can be stale (see resolve-model.ts).
|
|
174
|
-
const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug);
|
|
174
|
+
const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug, GENERATION_SETTINGS.commit);
|
|
175
175
|
|
|
176
176
|
debug.log('git', `Generating branch name via ${engineType}/${target.providerSlug}/${target.modelId}`);
|
|
177
177
|
|
package/backend/ws/git/branch.ts
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
8
8
|
import { gitService } from '../../git/git-service';
|
|
9
9
|
import { requireProjectWorkspace } from '../access';
|
|
10
|
+
import { identityEnvFor } from './identity-context';
|
|
10
11
|
import { debug } from '$shared/utils/logger';
|
|
11
12
|
|
|
12
13
|
const BranchSchema = t.Object({
|
|
@@ -171,11 +172,16 @@ export const branchHandler = createRouter()
|
|
|
171
172
|
}, async ({ data, conn }) => {
|
|
172
173
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
173
174
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
174
|
-
return await gitService.mergeBranch(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
return await gitService.mergeBranch(
|
|
176
|
+
cwd,
|
|
177
|
+
data.branchName,
|
|
178
|
+
{
|
|
179
|
+
noFastForward: data.noFastForward ?? false,
|
|
180
|
+
squash: data.squash ?? false,
|
|
181
|
+
ffOnly: data.ffOnly ?? false
|
|
182
|
+
},
|
|
183
|
+
identityEnvFor(conn, data.projectId)
|
|
184
|
+
);
|
|
179
185
|
})
|
|
180
186
|
|
|
181
187
|
.http('git:rebase', {
|
|
@@ -194,7 +200,12 @@ export const branchHandler = createRouter()
|
|
|
194
200
|
}, async ({ data, conn }) => {
|
|
195
201
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
196
202
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
197
|
-
return await gitService.rebaseOnto(
|
|
203
|
+
return await gitService.rebaseOnto(
|
|
204
|
+
cwd,
|
|
205
|
+
data.upstream,
|
|
206
|
+
data.autostash ?? true,
|
|
207
|
+
identityEnvFor(conn, data.projectId)
|
|
208
|
+
);
|
|
198
209
|
})
|
|
199
210
|
|
|
200
211
|
.http('git:return-to-branch', {
|
|
@@ -8,7 +8,7 @@ import { t } from 'elysia';
|
|
|
8
8
|
import { createRouter } from '$shared/utils/ws-server';
|
|
9
9
|
import { buildBudgetedStagedDiff, COMMIT_MESSAGE_BUDGET } from './diff-budget';
|
|
10
10
|
import { initializeEngine } from '../../engine';
|
|
11
|
-
import { resolveGenerationTarget } from '../../engine/resolve-model';
|
|
11
|
+
import { resolveGenerationTarget, GENERATION_SETTINGS } from '../../engine/resolve-model';
|
|
12
12
|
import type { EngineType } from '$shared/types/unified';
|
|
13
13
|
import type { GeneratedCommitMessage } from '$shared/types/git';
|
|
14
14
|
import { debug } from '$shared/utils/logger';
|
|
@@ -116,7 +116,7 @@ ${diff.text}`;
|
|
|
116
116
|
: defaultPrompt;
|
|
117
117
|
|
|
118
118
|
// The caller's providerSlug/account can be stale (see resolve-model.ts).
|
|
119
|
-
const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug);
|
|
119
|
+
const target = await resolveGenerationTarget(engine, data.modelId, data.providerSlug, GENERATION_SETTINGS.commit);
|
|
120
120
|
|
|
121
121
|
debug.log('git', `Generating commit message via ${engineType}/${target.providerSlug}/${target.modelId}`);
|
|
122
122
|
|
package/backend/ws/git/commit.ts
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
8
8
|
import { gitService } from '../../git/git-service';
|
|
9
9
|
import { requireProjectWorkspace } from '../access';
|
|
10
|
+
import { identityEnvFor } from './identity-context';
|
|
10
11
|
import { debug } from '$shared/utils/logger';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -38,7 +39,7 @@ export const commitHandler = createRouter()
|
|
|
38
39
|
}, async ({ data, conn }) => {
|
|
39
40
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
40
41
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
41
|
-
const hash = await gitService.commit(cwd, data.message);
|
|
42
|
+
const hash = await gitService.commit(cwd, data.message, identityEnvFor(conn, data.projectId));
|
|
42
43
|
return { hash };
|
|
43
44
|
})
|
|
44
45
|
|
|
@@ -54,7 +55,7 @@ export const commitHandler = createRouter()
|
|
|
54
55
|
}, async ({ data, conn }) => {
|
|
55
56
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
56
57
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
57
|
-
const hash = await gitService.amendCommit(cwd, data.message);
|
|
58
|
+
const hash = await gitService.amendCommit(cwd, data.message, identityEnvFor(conn, data.projectId));
|
|
58
59
|
return { hash };
|
|
59
60
|
})
|
|
60
61
|
|
|
@@ -85,7 +86,7 @@ export const commitHandler = createRouter()
|
|
|
85
86
|
}, async ({ data, conn }) => {
|
|
86
87
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
87
88
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
88
|
-
return await gitService.revertCommit(cwd, data.ref);
|
|
89
|
+
return await gitService.revertCommit(cwd, data.ref, identityEnvFor(conn, data.projectId));
|
|
89
90
|
})
|
|
90
91
|
|
|
91
92
|
.http('git:cherry-pick', {
|
|
@@ -101,7 +102,7 @@ export const commitHandler = createRouter()
|
|
|
101
102
|
}, async ({ data, conn }) => {
|
|
102
103
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
103
104
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
104
|
-
return await gitService.cherryPick(cwd, data.hashes);
|
|
105
|
+
return await gitService.cherryPick(cwd, data.hashes, identityEnvFor(conn, data.projectId));
|
|
105
106
|
})
|
|
106
107
|
|
|
107
108
|
.http('git:clean', {
|
|
@@ -144,5 +145,5 @@ export const commitHandler = createRouter()
|
|
|
144
145
|
}, async ({ data, conn }) => {
|
|
145
146
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
146
147
|
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
147
|
-
return await gitService.npmVersion(cwd, data.bump);
|
|
148
|
+
return await gitService.npmVersion(cwd, data.bump, identityEnvFor(conn, data.projectId));
|
|
148
149
|
});
|
|
@@ -8,6 +8,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
8
8
|
import { gitService } from '../../git/git-service';
|
|
9
9
|
import { findNestedRepoPaths, findRepoForFile } from '../../git/nested-repos';
|
|
10
10
|
import { requireProjectWorkspace } from '../access';
|
|
11
|
+
import { identityEnvFor } from './identity-context';
|
|
11
12
|
import { debug } from '$shared/utils/logger';
|
|
12
13
|
|
|
13
14
|
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
|
|
@@ -167,7 +168,7 @@ export const conflictHandler = createRouter()
|
|
|
167
168
|
}, async ({ data, conn }) => {
|
|
168
169
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
169
170
|
const cwd = resolveRepoCwd(root, data.repoPath) ?? root;
|
|
170
|
-
return await gitService.continueOperation(cwd);
|
|
171
|
+
return await gitService.continueOperation(cwd, identityEnvFor(conn, data.projectId));
|
|
171
172
|
})
|
|
172
173
|
|
|
173
174
|
.http('git:skip-operation', {
|
|
@@ -179,7 +180,7 @@ export const conflictHandler = createRouter()
|
|
|
179
180
|
}, async ({ data, conn }) => {
|
|
180
181
|
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
181
182
|
const cwd = resolveRepoCwd(root, data.repoPath) ?? root;
|
|
182
|
-
return await gitService.skipOperation(cwd);
|
|
183
|
+
return await gitService.skipOperation(cwd, identityEnvFor(conn, data.projectId));
|
|
183
184
|
})
|
|
184
185
|
|
|
185
186
|
.http('git:abort-operation', {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge from a WebSocket connection to a git identity.
|
|
3
|
+
*
|
|
4
|
+
* Handlers already know the project (`data.projectId`); this adds the other
|
|
5
|
+
* half, the user, from the connection. Both are needed because an identity is
|
|
6
|
+
* owned by a person and chosen per project, so neither alone identifies one.
|
|
7
|
+
*
|
|
8
|
+
* Every helper here degrades to `{}` rather than throwing. A user with no
|
|
9
|
+
* identity, an unreadable row, a project that was never bound — all of them
|
|
10
|
+
* mean "run git the way Clopen always did", which is a working commit, not an
|
|
11
|
+
* error dialog.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { resolveGitEnv } from '$backend/git/identity';
|
|
15
|
+
import { gitService } from '$backend/git/git-service';
|
|
16
|
+
import type { GitIdentityEnv } from '$backend/git/git-executor';
|
|
17
|
+
import { ws } from '$backend/utils/ws';
|
|
18
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
19
|
+
import { debug } from '$shared/utils/logger';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Attribution-only environment: who authors what this command creates.
|
|
23
|
+
*
|
|
24
|
+
* For commits, merges, stashes, tags — anything that writes a git object
|
|
25
|
+
* without reaching the network.
|
|
26
|
+
*/
|
|
27
|
+
export function identityEnvFor(conn: WSConnection, projectId: string): GitIdentityEnv {
|
|
28
|
+
try {
|
|
29
|
+
const userId = ws.getUserId(conn);
|
|
30
|
+
if (!userId) return {};
|
|
31
|
+
return resolveGitEnv(projectId, userId);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
debug.warn('git', 'Could not resolve a git identity for this connection:', error);
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Attribution plus the credential that reaches `remote`.
|
|
40
|
+
*
|
|
41
|
+
* The remote's URL — not its name — decides which identity authenticates, so
|
|
42
|
+
* the name is resolved to a URL first. `origin` on one account and `upstream`
|
|
43
|
+
* on another is the case this exists for.
|
|
44
|
+
*
|
|
45
|
+
* When the name cannot be resolved to a URL the result is attribution only:
|
|
46
|
+
* that is what happens for a branch pushing to an upstream Clopen did not
|
|
47
|
+
* name, and falling back to the machine's credentials there is the same
|
|
48
|
+
* behaviour as before this feature.
|
|
49
|
+
*/
|
|
50
|
+
export async function identityEnvForRemote(
|
|
51
|
+
conn: WSConnection,
|
|
52
|
+
projectId: string,
|
|
53
|
+
cwd: string,
|
|
54
|
+
remoteName?: string
|
|
55
|
+
): Promise<GitIdentityEnv> {
|
|
56
|
+
try {
|
|
57
|
+
const userId = ws.getUserId(conn);
|
|
58
|
+
if (!userId) return {};
|
|
59
|
+
|
|
60
|
+
const url = await remoteUrl(cwd, remoteName);
|
|
61
|
+
return resolveGitEnv(projectId, userId, url);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
debug.warn('git', 'Could not resolve a git identity for this remote:', error);
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The URL behind a remote name.
|
|
70
|
+
*
|
|
71
|
+
* Falls back to `origin` when no name is given, because that is what git itself
|
|
72
|
+
* does for a branch with no upstream — and a branch WITH an upstream is
|
|
73
|
+
* overwhelmingly tracking origin too.
|
|
74
|
+
*/
|
|
75
|
+
async function remoteUrl(cwd: string, remoteName?: string): Promise<string | null> {
|
|
76
|
+
try {
|
|
77
|
+
const remotes = await gitService.getRemotes(cwd);
|
|
78
|
+
if (remotes.length === 0) return null;
|
|
79
|
+
const wanted = remoteName ?? 'origin';
|
|
80
|
+
const match = remotes.find((r) => r.name === wanted);
|
|
81
|
+
// A repo with exactly one remote under a different name is unambiguous, so
|
|
82
|
+
// using it beats declining to pick a credential at all.
|
|
83
|
+
const chosen = match ?? (remotes.length === 1 ? remotes[0] : undefined);
|
|
84
|
+
if (!chosen) return null;
|
|
85
|
+
// Push URL first: it is the one that needs a credential, and a remote
|
|
86
|
+
// configured with separate fetch/push URLs is doing so deliberately.
|
|
87
|
+
return chosen.pushUrl || chosen.fetchUrl || null;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|