@openchamber/web 1.21.1 → 1.22.1
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/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
- package/dist/assets/DiffView-CNnDxRmO.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
- package/dist/assets/FilesView-8wdiG2mj.js +17 -0
- package/dist/assets/GitView-Cv2xH-S6.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
- package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
- package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
- package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
- package/dist/assets/SettingsView-xGONHFGS.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
- package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
- package/dist/assets/es-BIWNEbnS.js +16 -0
- package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
- package/dist/assets/index-CHUT_bDS.css +1 -0
- package/dist/assets/index-DDInLQDd.js +40 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
- package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
- package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
- package/dist/assets/main-De8Z5w49.js +928 -0
- package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
- package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
- package/dist/assets/pt-BR-Due4be8g.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
- package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
- package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
- package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
- package/dist/assets/tr-DBJcAv4y.js +7 -0
- package/dist/assets/uk-COYh2BaN.js +16 -0
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
- package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
- package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
- package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
- package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
- package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +35 -4
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -0
- package/server/lib/git/service.js +97 -17
- package/server/lib/git/service.test.js +153 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +148 -0
- package/server/lib/message-queue/runtime.js +818 -0
- package/server/lib/message-queue/runtime.test.js +426 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +5 -1
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/settings-runtime.js +2 -2
- package/server/lib/opencode/settings-runtime.test.js +29 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +2 -1
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/index.js +7 -0
- package/server/lib/quota/providers/opencode-go.js +1 -0
- package/server/lib/quota/providers/opencode-go.test.js +5 -1
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/tunnel-host.js +3 -1
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +1 -0
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +1 -0
- package/server/lib/small-model/DOCUMENTATION.md +4 -0
- package/server/lib/small-model/call.js +8 -2
- package/server/lib/small-model/call.test.js +23 -0
- package/server/lib/small-model/index.js +2 -1
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/runtime.js +30 -7
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/index.js +1 -0
- package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/es-DwyXCqaL.js +0 -15
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/uk-ClgQjmlw.js +0 -15
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sherpa-onnx offline TTS (Kokoro). Runs inside the dictation worker process
|
|
2
|
+
* Sherpa-onnx offline TTS (Kokoro and Piper/VITS). Runs inside the dictation worker process
|
|
3
3
|
* only — never load the native addon in the main server process.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -23,20 +23,49 @@ function float32ToPcm16le(samples) {
|
|
|
23
23
|
return Buffer.from(out.buffer, out.byteOffset, out.byteLength);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* sherpa-onnx model config for one catalog entry. Kokoro carries a voices
|
|
28
|
+
* bank (speaker ids) and optional lexicons; a Piper/VITS model is a single
|
|
29
|
+
* voice with espeak-ng phonemization.
|
|
30
|
+
* @param {{ modelDir: string, type?: string, files: Record<string, string>, lexicon?: string[] }} config
|
|
31
|
+
*/
|
|
32
|
+
function buildModelConfig(config) {
|
|
33
|
+
const file = (key, label) => {
|
|
34
|
+
const filePath = path.join(config.modelDir, config.files[key]);
|
|
35
|
+
assertFileExists(filePath, label);
|
|
36
|
+
return filePath;
|
|
37
|
+
};
|
|
38
|
+
const modelPath = file('model', 'TTS model');
|
|
39
|
+
const tokensPath = file('tokens', 'TTS tokens');
|
|
40
|
+
|
|
41
|
+
if (config.type === 'vits') {
|
|
42
|
+
// Piper models phonemize through espeak-ng (`espeakData`); character
|
|
43
|
+
// models (Coqui) read the text directly and carry no espeak data.
|
|
44
|
+
const dataDir = config.files.espeakData ? file('espeakData', 'TTS espeak-ng dataDir') : '';
|
|
45
|
+
return { vits: { model: modelPath, tokens: tokensPath, ...(dataDir ? { dataDir } : {}), lengthScale: 1.0 } };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const dataDir = file('espeakData', 'TTS espeak-ng dataDir');
|
|
49
|
+
const voicesPath = file('voices', 'TTS voices');
|
|
50
|
+
const lexicon = (config.lexicon ?? []).map((key) => file(key, 'TTS lexicon')).join(',');
|
|
51
|
+
return {
|
|
52
|
+
kokoro: {
|
|
53
|
+
model: modelPath,
|
|
54
|
+
voices: voicesPath,
|
|
55
|
+
tokens: tokensPath,
|
|
56
|
+
dataDir,
|
|
57
|
+
lengthScale: 1.0,
|
|
58
|
+
...(lexicon ? { lexicon } : {}),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
26
63
|
export class SherpaTtsEngine {
|
|
27
64
|
/**
|
|
28
|
-
* @param {{ modelDir: string,
|
|
65
|
+
* @param {{ modelDir: string, type?: string, files: Record<string, string>, lexicon?: string[], numThreads?: number }} config
|
|
29
66
|
*/
|
|
30
67
|
constructor(config) {
|
|
31
|
-
const
|
|
32
|
-
const voicesPath = path.join(config.modelDir, config.files.voices);
|
|
33
|
-
const tokensPath = path.join(config.modelDir, config.files.tokens);
|
|
34
|
-
const dataDir = path.join(config.modelDir, config.files.espeakData);
|
|
35
|
-
|
|
36
|
-
assertFileExists(modelPath, 'TTS model');
|
|
37
|
-
assertFileExists(voicesPath, 'TTS voices');
|
|
38
|
-
assertFileExists(tokensPath, 'TTS tokens');
|
|
39
|
-
assertFileExists(dataDir, 'TTS espeak-ng dataDir');
|
|
68
|
+
const model = buildModelConfig(config);
|
|
40
69
|
|
|
41
70
|
const sherpa = loadSherpaOnnxNode();
|
|
42
71
|
if (typeof sherpa.OfflineTts !== 'function') {
|
|
@@ -44,15 +73,7 @@ export class SherpaTtsEngine {
|
|
|
44
73
|
}
|
|
45
74
|
|
|
46
75
|
this.tts = new sherpa.OfflineTts({
|
|
47
|
-
model
|
|
48
|
-
kokoro: {
|
|
49
|
-
model: modelPath,
|
|
50
|
-
voices: voicesPath,
|
|
51
|
-
tokens: tokensPath,
|
|
52
|
-
dataDir,
|
|
53
|
-
lengthScale: 1.0,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
76
|
+
model,
|
|
56
77
|
numThreads: config.numThreads ?? 2,
|
|
57
78
|
provider: 'cpu',
|
|
58
79
|
maxNumSentences: 1,
|
|
@@ -102,7 +102,9 @@ function getTtsEngine(modelsDir, modelId) {
|
|
|
102
102
|
const spec = getLocalSttModelSpec(modelId);
|
|
103
103
|
const created = new SherpaTtsEngine({
|
|
104
104
|
modelDir: getLocalSttModelDir(modelsDir, modelId),
|
|
105
|
+
type: spec.type,
|
|
105
106
|
files: spec.files,
|
|
107
|
+
lexicon: spec.lexicon,
|
|
106
108
|
numThreads: 2,
|
|
107
109
|
});
|
|
108
110
|
ttsEngines.set(key, created);
|
|
@@ -63,6 +63,8 @@ export function createDictationRuntime({
|
|
|
63
63
|
model: typeof req.body?.model === 'string' ? req.body.model : undefined,
|
|
64
64
|
speakerId: Number.isInteger(req.body?.speakerId) ? req.body.speakerId : undefined,
|
|
65
65
|
speed: typeof req.body?.speed === 'number' ? req.body.speed : undefined,
|
|
66
|
+
language: req.body?.language === 'auto' ? 'auto' : undefined,
|
|
67
|
+
languageSample: typeof req.body?.languageSample === 'string' ? req.body.languageSample.slice(0, 4000) : undefined,
|
|
66
68
|
});
|
|
67
69
|
if (result.error) {
|
|
68
70
|
res.status(503).json({
|
|
@@ -73,6 +75,8 @@ export function createDictationRuntime({
|
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
77
|
res.setHeader('Content-Type', result.format || 'audio/wav');
|
|
78
|
+
res.setHeader('X-Speech-Model', result.modelId);
|
|
79
|
+
if (result.language) res.setHeader('X-Speech-Language', result.language);
|
|
76
80
|
res.send(result.audio);
|
|
77
81
|
} catch (error) {
|
|
78
82
|
res.status(500).json({ error: error?.message || 'Failed to synthesize speech' });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { detectTextLanguage } from '../tts/language-detect.js';
|
|
1
2
|
/**
|
|
2
3
|
* Dictation service: resolves STT providers, tracks local model download
|
|
3
4
|
* state, and exposes a readiness snapshot for the status route.
|
|
@@ -16,6 +17,8 @@ import { OpenAICompatibleTranscriptionSession } from './openai-compatible-sessio
|
|
|
16
17
|
import {
|
|
17
18
|
DEFAULT_LOCAL_STT_MODEL,
|
|
18
19
|
DEFAULT_LOCAL_TTS_MODEL,
|
|
20
|
+
getLocalTtsDefaultSpeaker,
|
|
21
|
+
resolveLocalTtsModelForLanguage,
|
|
19
22
|
LOCAL_STT_MODEL_CATALOG,
|
|
20
23
|
LOCAL_STT_MODEL_IDS,
|
|
21
24
|
LOCAL_TTS_MODEL_CATALOG,
|
|
@@ -220,10 +223,30 @@ export function createDictationService({ modelsDir }) {
|
|
|
220
223
|
/**
|
|
221
224
|
* Synthesize speech with the local TTS model. Returns WAV bytes, or a
|
|
222
225
|
* readiness error while the model is missing/downloading.
|
|
223
|
-
*
|
|
226
|
+
*
|
|
227
|
+
* With `language: 'auto'` the text's language decides the model: the
|
|
228
|
+
* caller's model when it speaks that language, otherwise the catalog
|
|
229
|
+
* model for it (downloaded on first use, reported as in-progress until it
|
|
230
|
+
* lands). The caller's speaker id is kept only on the caller's model; a
|
|
231
|
+
* substitute model starts from its own default speaker for the language.
|
|
232
|
+
* A language no catalog model covers keeps the caller's model, so text is
|
|
233
|
+
* never silently dropped.
|
|
234
|
+
* `languageSample` is the whole message the chunk belongs to (or a prefix
|
|
235
|
+
* of it): the language is judged on that, never on a short chunk alone.
|
|
236
|
+
* @param {{ text: string, model?: string, speakerId?: number, speed?: number, language?: string, languageSample?: string }} options
|
|
224
237
|
*/
|
|
225
|
-
const synthesizeSpeech = async ({ text, model, speakerId, speed }) => {
|
|
226
|
-
const
|
|
238
|
+
const synthesizeSpeech = async ({ text, model, speakerId, speed, language, languageSample }) => {
|
|
239
|
+
const requestedModelId = isLocalTtsModelId(model) ? model : DEFAULT_LOCAL_TTS_MODEL;
|
|
240
|
+
let modelId = requestedModelId;
|
|
241
|
+
let resolvedLanguage = null;
|
|
242
|
+
if (language === 'auto') {
|
|
243
|
+
resolvedLanguage = detectTextLanguage(languageSample || text).language;
|
|
244
|
+
const forLanguage = resolveLocalTtsModelForLanguage(resolvedLanguage, requestedModelId);
|
|
245
|
+
if (forLanguage && forLanguage !== requestedModelId) {
|
|
246
|
+
modelId = forLanguage;
|
|
247
|
+
speakerId = getLocalTtsDefaultSpeaker(modelId, resolvedLanguage);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
227
250
|
const installed = await isLocalSttModelInstalled(modelsDir, modelId);
|
|
228
251
|
if (!installed) {
|
|
229
252
|
const state = downloadStates.get(modelId);
|
|
@@ -251,7 +274,7 @@ export function createDictationService({ modelsDir }) {
|
|
|
251
274
|
speakerId,
|
|
252
275
|
speed,
|
|
253
276
|
});
|
|
254
|
-
return { audio: result.audio, format: result.format };
|
|
277
|
+
return { audio: result.audio, format: result.format, modelId, language: resolvedLanguage };
|
|
255
278
|
};
|
|
256
279
|
|
|
257
280
|
/**
|
|
@@ -23,6 +23,10 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
23
23
|
- `POST /api/fs/exec`
|
|
24
24
|
- `GET /api/fs/exec/:jobId`
|
|
25
25
|
- `GET /api/fs/list`
|
|
26
|
+
- `GET /api/fs/git-dirs` — shallow nested git repository discovery for the
|
|
27
|
+
Git tab (depth- and visit-capped readdir walk; `.git` directory, file, or
|
|
28
|
+
symlink marks a repository boundary; junk directories and symlinks are
|
|
29
|
+
never descended into)
|
|
26
30
|
- Owns exec job queue state (`execJobs`) and lifecycle/TTL pruning.
|
|
27
31
|
- Enforces workspace boundary checks with active project + worktree fallback support.
|
|
28
32
|
- The active project directory is validated with `fs.realpath`, so when the project root is itself a symlink the workspace base no longer matches the paths the client sends. Workspace resolution therefore retries against the raw directory the client requested (`requestedDirectory` from `resolveProjectDirectory`) before falling back to worktree roots. Symlinks are still resolved afterwards, and write/exec routes keep their canonical containment check against the resolved base.
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -297,6 +297,79 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
|
|
|
297
297
|
});
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
+
// Nested repository discovery bounds: only shallow walks are useful for the
|
|
301
|
+
// Git tab's "pick a repository" picker, and deep/monorepo trees can explode
|
|
302
|
+
// otherwise. Directories deeper than maxDepth or beyond the visit cap are
|
|
303
|
+
// silently not searched.
|
|
304
|
+
const GIT_DIRS_MAX_DEPTH = 3;
|
|
305
|
+
const GIT_DIRS_MAX_DIRS = 100;
|
|
306
|
+
const GIT_DIRS_SKIP_LIST = new Set(['node_modules', 'dist', 'build', '.venv', 'target', '.next']);
|
|
307
|
+
|
|
308
|
+
// Walks rootPath and returns every nested git repository path (a directory
|
|
309
|
+
// containing a `.git` entry — a directory, a worktree pointer file, or a
|
|
310
|
+
// symlink). A repository boundary stops descent: nested repos inside repos
|
|
311
|
+
// are not reported. The root itself, when it is a repo, yields no results.
|
|
312
|
+
const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxDepth, maxDirs }) => {
|
|
313
|
+
const results = [];
|
|
314
|
+
let visited = 0;
|
|
315
|
+
|
|
316
|
+
const walk = async (dir, depth) => {
|
|
317
|
+
if (visited >= maxDirs) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let dirents;
|
|
322
|
+
try {
|
|
323
|
+
dirents = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
324
|
+
} catch (error) {
|
|
325
|
+
// Unreadable subtree — skip it unless it is the root itself, which the
|
|
326
|
+
// route maps to 403/404/500 through the shared error handling.
|
|
327
|
+
if (dir === rootPath) {
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
visited += 1;
|
|
333
|
+
|
|
334
|
+
let isRepoBoundary = false;
|
|
335
|
+
const subdirectories = [];
|
|
336
|
+
for (const dirent of dirents) {
|
|
337
|
+
if (dirent.name === '.git') {
|
|
338
|
+
isRepoBoundary = true;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (!dirent.isDirectory() || dirent.isSymbolicLink()) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (GIT_DIRS_SKIP_LIST.has(dirent.name)) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (depth >= maxDepth) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
subdirectories.push(dirent.name);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (isRepoBoundary) {
|
|
354
|
+
if (dir !== rootPath) {
|
|
355
|
+
results.push(dir);
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
subdirectories.sort();
|
|
361
|
+
for (const name of subdirectories) {
|
|
362
|
+
if (visited >= maxDirs) {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
await walk(pathModule.join(dir, name), depth + 1);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
await walk(rootPath, 0);
|
|
370
|
+
return results;
|
|
371
|
+
};
|
|
372
|
+
|
|
300
373
|
const deriveCloneDirectoryName = (remoteUrl) => {
|
|
301
374
|
const remote = typeof remoteUrl === 'string' ? remoteUrl.trim() : '';
|
|
302
375
|
if (!remote) return '';
|
|
@@ -1599,4 +1672,60 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1599
1672
|
return res.status(500).json({ error: (error && error.message) || 'Failed to list directory' });
|
|
1600
1673
|
}
|
|
1601
1674
|
});
|
|
1675
|
+
|
|
1676
|
+
app.get('/api/fs/git-dirs', async (req, res) => {
|
|
1677
|
+
const rawPath = typeof req.query.path === 'string' && req.query.path.trim().length > 0
|
|
1678
|
+
? req.query.path.trim()
|
|
1679
|
+
: '';
|
|
1680
|
+
if (!rawPath) {
|
|
1681
|
+
return res.status(400).json({ error: 'Path is required' });
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
try {
|
|
1685
|
+
const resolved = await resolveWorkspacePathFromContext({
|
|
1686
|
+
req,
|
|
1687
|
+
targetPath: rawPath,
|
|
1688
|
+
resolveProjectDirectory,
|
|
1689
|
+
path,
|
|
1690
|
+
os,
|
|
1691
|
+
normalizeDirectoryPath,
|
|
1692
|
+
openchamberUserConfigRoot,
|
|
1693
|
+
});
|
|
1694
|
+
if (!resolved.ok) {
|
|
1695
|
+
return res.status(400).json({ error: resolved.error });
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
const stats = await fsPromises.stat(resolved.resolved);
|
|
1699
|
+
if (!stats.isDirectory()) {
|
|
1700
|
+
return res.status(400).json({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
const repositories = await findGitDirectories({
|
|
1704
|
+
rootPath: resolved.resolved,
|
|
1705
|
+
fsPromises,
|
|
1706
|
+
path,
|
|
1707
|
+
maxDepth: GIT_DIRS_MAX_DEPTH,
|
|
1708
|
+
maxDirs: GIT_DIRS_MAX_DIRS,
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
return res.json({
|
|
1712
|
+
path: resolved.resolved,
|
|
1713
|
+
repositories: repositories.map((repoPath) => ({
|
|
1714
|
+
path: repoPath,
|
|
1715
|
+
name: path.basename(repoPath),
|
|
1716
|
+
})),
|
|
1717
|
+
});
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
const err = error;
|
|
1720
|
+
const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
|
|
1721
|
+
if (code === 'ENOENT') {
|
|
1722
|
+
return res.status(404).json({ error: 'Directory not found', reason: 'not-found' });
|
|
1723
|
+
}
|
|
1724
|
+
if (isOsPermissionError(err)) {
|
|
1725
|
+
return sendOsPermissionDenied(res, 'Access to directory denied');
|
|
1726
|
+
}
|
|
1727
|
+
console.error('Failed to find git directories:', error);
|
|
1728
|
+
return res.status(500).json({ error: (error && error.message) || 'Failed to find git directories' });
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1602
1731
|
};
|
|
@@ -1136,6 +1136,225 @@ describe('fs list symlink path space (issue 2627)', () => {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
});
|
|
1138
1138
|
|
|
1139
|
+
describe('fs git-dirs', () => {
|
|
1140
|
+
const createDirent = (name, type) => ({
|
|
1141
|
+
name,
|
|
1142
|
+
isDirectory: () => type === 'dir',
|
|
1143
|
+
isFile: () => type === 'file',
|
|
1144
|
+
isSymbolicLink: () => type === 'symlink',
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
// tree maps directory path -> [[name, type], ...]
|
|
1148
|
+
const registerGitDirs = (tree, { stat, readdir: readdirOverride } = {}) => {
|
|
1149
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1150
|
+
const readdir = readdirOverride ?? vi.fn(async (dirPath) => (tree[dirPath] ?? []).map(([name, type]) => createDirent(name, type)));
|
|
1151
|
+
registerFsRoutes(app, {
|
|
1152
|
+
os: { homedir: () => '/home/user' },
|
|
1153
|
+
path: path.posix,
|
|
1154
|
+
fsPromises: {
|
|
1155
|
+
realpath: async (targetPath) => targetPath,
|
|
1156
|
+
stat: stat ?? vi.fn(async (targetPath) => ({ isDirectory: () => Boolean(tree[targetPath]) })),
|
|
1157
|
+
readdir,
|
|
1158
|
+
},
|
|
1159
|
+
spawn: vi.fn(),
|
|
1160
|
+
crypto: { randomUUID: () => 'job-0' },
|
|
1161
|
+
normalizeDirectoryPath: (p) => p,
|
|
1162
|
+
resolveProjectDirectory: async () => ({ directory: '/workspace' }),
|
|
1163
|
+
buildAugmentedPath: () => '/usr/bin',
|
|
1164
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
1165
|
+
openchamberUserConfigRoot: '/home/user/.config',
|
|
1166
|
+
});
|
|
1167
|
+
return { handler: getRoute('GET', '/api/fs/git-dirs'), readdir };
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
const callGitDirs = async (handler, query) => {
|
|
1171
|
+
const res = createMockResponse();
|
|
1172
|
+
await handler({ query: query ?? {} }, res);
|
|
1173
|
+
return res;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
it('returns an empty list when the root itself is a repository', async () => {
|
|
1177
|
+
const { handler, readdir } = registerGitDirs({
|
|
1178
|
+
'/workspace': [['.git', 'dir'], ['proj-a', 'dir']],
|
|
1179
|
+
'/workspace/proj-a': [['.git', 'dir']],
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1183
|
+
|
|
1184
|
+
expect(res.statusCode).toBe(200);
|
|
1185
|
+
expect(res.body).toEqual({ path: '/workspace', repositories: [] });
|
|
1186
|
+
expect(readdir).toHaveBeenCalledTimes(1);
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
it('finds nested repositories with a .git directory', async () => {
|
|
1190
|
+
const { handler } = registerGitDirs({
|
|
1191
|
+
'/workspace': [['proj-a', 'dir'], ['proj-b', 'dir']],
|
|
1192
|
+
'/workspace/proj-a': [['.git', 'dir'], ['src', 'dir']],
|
|
1193
|
+
'/workspace/proj-a/src': [['index.ts', 'file']],
|
|
1194
|
+
'/workspace/proj-b': [['.git', 'dir']],
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1198
|
+
|
|
1199
|
+
expect(res.statusCode).toBe(200);
|
|
1200
|
+
expect(res.body.repositories).toEqual([
|
|
1201
|
+
{ path: '/workspace/proj-a', name: 'proj-a' },
|
|
1202
|
+
{ path: '/workspace/proj-b', name: 'proj-b' },
|
|
1203
|
+
]);
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
it('treats a .git file (linked worktree) as a repository boundary', async () => {
|
|
1207
|
+
const { handler } = registerGitDirs({
|
|
1208
|
+
'/workspace': [['worktree', 'dir']],
|
|
1209
|
+
'/workspace/worktree': [['.git', 'file']],
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1213
|
+
|
|
1214
|
+
expect(res.statusCode).toBe(200);
|
|
1215
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/worktree', name: 'worktree' }]);
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1218
|
+
it('stops descending at repository boundaries', async () => {
|
|
1219
|
+
const { handler, readdir } = registerGitDirs({
|
|
1220
|
+
'/workspace': [['outer', 'dir']],
|
|
1221
|
+
'/workspace/outer': [['.git', 'dir'], ['inner', 'dir']],
|
|
1222
|
+
'/workspace/outer/inner': [['.git', 'dir']],
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1226
|
+
|
|
1227
|
+
expect(res.statusCode).toBe(200);
|
|
1228
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/outer', name: 'outer' }]);
|
|
1229
|
+
expect(readdir).not.toHaveBeenCalledWith('/workspace/outer/inner', { withFileTypes: true });
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
it('does not descend past the depth cap', async () => {
|
|
1233
|
+
const { handler } = registerGitDirs({
|
|
1234
|
+
'/workspace': [['a', 'dir']],
|
|
1235
|
+
'/workspace/a': [['b', 'dir']],
|
|
1236
|
+
'/workspace/a/b': [['c', 'dir']],
|
|
1237
|
+
'/workspace/a/b/c': [['.git', 'dir'], ['d', 'dir']],
|
|
1238
|
+
'/workspace/a/b/c/d': [['.git', 'dir']],
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1242
|
+
|
|
1243
|
+
expect(res.statusCode).toBe(200);
|
|
1244
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/a/b/c', name: 'c' }]);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
it('skips junk directories', async () => {
|
|
1248
|
+
const { handler, readdir } = registerGitDirs({
|
|
1249
|
+
'/workspace': [['node_modules', 'dir'], ['dist', 'dir'], ['real', 'dir']],
|
|
1250
|
+
'/workspace/node_modules': [['dep', 'dir']],
|
|
1251
|
+
'/workspace/node_modules/dep': [['.git', 'dir']],
|
|
1252
|
+
'/workspace/dist': [['.git', 'dir']],
|
|
1253
|
+
'/workspace/real': [['.git', 'dir']],
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1257
|
+
|
|
1258
|
+
expect(res.statusCode).toBe(200);
|
|
1259
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/real', name: 'real' }]);
|
|
1260
|
+
expect(readdir).not.toHaveBeenCalledWith('/workspace/node_modules', { withFileTypes: true });
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
it('never descends into symbolic links', async () => {
|
|
1264
|
+
const { handler } = registerGitDirs({
|
|
1265
|
+
'/workspace': [['link', 'symlink'], ['real', 'dir']],
|
|
1266
|
+
'/workspace/real': [['.git', 'dir']],
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1270
|
+
|
|
1271
|
+
expect(res.statusCode).toBe(200);
|
|
1272
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/real', name: 'real' }]);
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
it('returns repositories in deterministic order', async () => {
|
|
1276
|
+
const { handler } = registerGitDirs({
|
|
1277
|
+
'/workspace': [['zebra', 'dir'], ['alpha', 'dir']],
|
|
1278
|
+
'/workspace/zebra': [['.git', 'dir']],
|
|
1279
|
+
'/workspace/alpha': [['.git', 'dir']],
|
|
1280
|
+
});
|
|
1281
|
+
|
|
1282
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1283
|
+
|
|
1284
|
+
expect(res.body.repositories.map((repo) => repo.name)).toEqual(['alpha', 'zebra']);
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
it('returns 400 when path is missing', async () => {
|
|
1288
|
+
const { handler } = registerGitDirs({});
|
|
1289
|
+
|
|
1290
|
+
const res = await callGitDirs(handler, {});
|
|
1291
|
+
|
|
1292
|
+
expect(res.statusCode).toBe(400);
|
|
1293
|
+
expect(res.body.error).toBe('Path is required');
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
it('returns 400 when the path is not a directory', async () => {
|
|
1297
|
+
const { handler } = registerGitDirs({
|
|
1298
|
+
'/workspace': [['file.txt', 'file']],
|
|
1299
|
+
}, {
|
|
1300
|
+
stat: vi.fn(async (targetPath) => ({ isDirectory: () => targetPath !== '/workspace/file.txt' })),
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
const res = await callGitDirs(handler, { path: '/workspace/file.txt' });
|
|
1304
|
+
|
|
1305
|
+
expect(res.statusCode).toBe(400);
|
|
1306
|
+
expect(res.body).toEqual({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
it('returns 404 when the directory does not exist', async () => {
|
|
1310
|
+
const error = Object.assign(new Error('missing'), { code: 'ENOENT' });
|
|
1311
|
+
const { handler } = registerGitDirs({}, {
|
|
1312
|
+
stat: vi.fn(async () => { throw error; }),
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
const res = await callGitDirs(handler, { path: '/workspace/missing' });
|
|
1316
|
+
|
|
1317
|
+
expect(res.statusCode).toBe(404);
|
|
1318
|
+
expect(res.body).toEqual({ error: 'Directory not found', reason: 'not-found' });
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
for (const code of ['EACCES', 'EPERM']) {
|
|
1322
|
+
it(`maps root ${code} to the os-permission contract`, async () => {
|
|
1323
|
+
const error = Object.assign(new Error('denied'), { code });
|
|
1324
|
+
const { handler } = registerGitDirs({}, {
|
|
1325
|
+
stat: vi.fn(async () => ({ isDirectory: () => true })),
|
|
1326
|
+
readdir: vi.fn(async () => { throw error; }),
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1330
|
+
|
|
1331
|
+
expect(res.statusCode).toBe(403);
|
|
1332
|
+
expect(res.body).toEqual({ error: 'Access to directory denied', reason: 'os-permission' });
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
it('skips unreadable subtrees without failing the scan', async () => {
|
|
1337
|
+
const tree = {
|
|
1338
|
+
'/workspace': [['blocked', 'dir'], ['open', 'dir']],
|
|
1339
|
+
'/workspace/open': [['.git', 'dir']],
|
|
1340
|
+
};
|
|
1341
|
+
const blockedError = Object.assign(new Error('denied'), { code: 'EACCES' });
|
|
1342
|
+
const { handler } = registerGitDirs(tree, {
|
|
1343
|
+
readdir: vi.fn(async (dirPath) => {
|
|
1344
|
+
if (dirPath === '/workspace/blocked') {
|
|
1345
|
+
throw blockedError;
|
|
1346
|
+
}
|
|
1347
|
+
return (tree[dirPath] ?? []).map(([name, type]) => createDirent(name, type));
|
|
1348
|
+
}),
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1352
|
+
|
|
1353
|
+
expect(res.statusCode).toBe(200);
|
|
1354
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/open', name: 'open' }]);
|
|
1355
|
+
});
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1139
1358
|
describe('fs stat directory scope (issue 3019)', () => {
|
|
1140
1359
|
// Wires the real project-directory runtime so the stat route resolves the
|
|
1141
1360
|
// workspace exactly as the server does: explicit x-opencode-directory header
|
|
@@ -39,6 +39,7 @@ The following functions are exported and used by the web server:
|
|
|
39
39
|
|
|
40
40
|
### Branch Operations
|
|
41
41
|
- `getBranches(directory)`: Get list of local and remote branches (filtered to active remote branches).
|
|
42
|
+
- `getUnpushedBranchCounts(directory, branchNames)`: Count commits ahead of each locally known upstream for up to five supplied local branches. This reads local refs only and omits branches without an upstream.
|
|
42
43
|
- `createBranch(directory, branchName, options)`: Create and checkout a new branch.
|
|
43
44
|
- `checkoutBranch(directory, branchName)`: Checkout an existing branch. A remote-tracking name (`origin/main`, or the `remotes/`-prefixed form) resolves to the local branch of that name, created with `--track` when it does not exist yet, because the branch selector offers remote branches as places to work rather than commits to inspect — a literal checkout of the remote ref would detach HEAD. A local branch whose own name looks like a remote ref wins over that resolution, and anything unresolvable is checked out as requested. The returned `branch` is the branch that was actually checked out, which callers should report instead of the requested name.
|
|
44
45
|
- `deleteBranch(directory, branch, options)`: Delete a branch (supports force flag).
|
|
@@ -48,7 +49,7 @@ The following functions are exported and used by the web server:
|
|
|
48
49
|
### Worktree Operations
|
|
49
50
|
- `getWorktrees(directory)`: List all git worktrees for a repository.
|
|
50
51
|
- `validateWorktreeCreate(directory, input)`: Validate worktree creation parameters (mode, branchName, startRef, upstream config).
|
|
51
|
-
- `createWorktree(directory, input)`: Create a new worktree (supports 'new' and 'existing' modes, upstream setup). After populating the worktree, the repository's `post-checkout` hook runs once with git's standard arguments (null ref as previous HEAD, the checked-out HEAD, and flag `1`) from the worktree directory, mirroring `git worktree add` without `--no-checkout`; a missing or non-executable hook is skipped and a failing hook is logged as a warning, never failing worktree creation or the session bootstrap.
|
|
52
|
+
- `createWorktree(directory, input)`: Create a new worktree (supports 'new' and 'existing' modes, upstream setup). When the current tracked branch has no unpublished commits, the UI supplies its remote-tracking ref and this operation fetches that branch once before creating the worktree. A failed fetch falls back to the local branch and reports `sourceFetchFailed`; other remote start refs still require an existing local ref when their fetch fails. After populating the worktree, the repository's `post-checkout` hook runs once with git's standard arguments (null ref as previous HEAD, the checked-out HEAD, and flag `1`) from the worktree directory, mirroring `git worktree add` without `--no-checkout`; a missing or non-executable hook is skipped and a failing hook is logged as a warning, never failing worktree creation or the session bootstrap.
|
|
52
53
|
- `removeWorktree(directory, input)`: Remove a worktree (optionally delete local branch).
|
|
53
54
|
- `isLinkedWorktree(directory)`: Check if directory is a linked worktree (not primary).
|
|
54
55
|
|
|
@@ -142,6 +143,7 @@ The following functions are internal helpers used by exported functions:
|
|
|
142
143
|
- `path`: Absolute path to worktree directory.
|
|
143
144
|
- `directoryCreated`: Present when create returned after the target directory exists while background Git/bootstrap work continues.
|
|
144
145
|
- `bootstrapStatus`: Background setup state. The legacy `status` remains `pending`, `ready`, or `failed`, while `phase` reports `directory-created`, `git-ready`, or `setup-ready`. Fast create starts at `pending`/`directory-created`; population and upstream Git completion advances to `pending`/`git-ready` before setup/start scripts; completed setup is `ready`/`setup-ready`. A missing in-memory state falls back to `ready`/`setup-ready`; clients continue to accept legacy status responses that omit `phase`.
|
|
146
|
+
- `sourceFetchFailed`: Present when the automatic source-branch fetch failed and creation fell back to the tracked local branch.
|
|
145
147
|
- Fast-create background failures remove OpenCode sandbox metadata for directories that never became Git worktrees, and remove the pre-created directory only if it is still empty. User-created files are never recursively deleted by this cleanup.
|
|
146
148
|
- Worktree removal waits for any active create/bootstrap task for that directory before deleting it, preventing a background Git or setup task from restoring removed state or racing filesystem cleanup.
|
|
147
149
|
- Worktree bootstrap retries transient `index.lock` conflicts. If the lock remains byte-for-byte and metadata-identical across the retry window, it is treated as stale, removed, and population continues automatically; changing locks are left untouched and reported as failures.
|
package/server/lib/git/routes.js
CHANGED
|
@@ -873,6 +873,22 @@ export function registerGitRoutes(app) {
|
|
|
873
873
|
}
|
|
874
874
|
});
|
|
875
875
|
|
|
876
|
+
app.post('/api/git/branch-push-status', async (req, res) => {
|
|
877
|
+
const { getUnpushedBranchCounts } = await getGitLibraries();
|
|
878
|
+
try {
|
|
879
|
+
const directory = req.query.directory;
|
|
880
|
+
const branches = req.body?.branches;
|
|
881
|
+
if (!directory) return res.status(400).json({ error: 'directory parameter is required' });
|
|
882
|
+
if (!Array.isArray(branches) || branches.some((branch) => typeof branch !== 'string')) {
|
|
883
|
+
return res.status(400).json({ error: 'branches must be an array of branch names' });
|
|
884
|
+
}
|
|
885
|
+
res.json(await getUnpushedBranchCounts(directory, branches));
|
|
886
|
+
} catch (error) {
|
|
887
|
+
console.error('Failed to get branch push status:', error);
|
|
888
|
+
res.status(500).json({ error: error.message || 'Failed to get branch push status' });
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
|
|
876
892
|
app.post('/api/git/branches', async (req, res) => {
|
|
877
893
|
const { createBranch } = await getGitLibraries();
|
|
878
894
|
try {
|