@openchamber/web 1.19.0 → 1.21.0
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-DAvopJvy.js → CodeMirrorCommentWidgets-C2BopIs3.js} +1 -1
- package/dist/assets/CommitSection-HJeMUAWb.js +1 -0
- package/dist/assets/DiffView-D5cvbEPb.js +4 -0
- package/dist/assets/FilesView-DPU8aNPL.js +17 -0
- package/dist/assets/GitView-Ct6xWrVH.js +6 -0
- package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-osju7J70.js} +1 -1
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +12 -0
- package/dist/assets/OnboardingScreen-w2VG4fWY.js +1 -0
- package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-Dan3mADn.js} +1 -1
- package/dist/assets/PierreDiffViewer-CGoI2v0q.js +157 -0
- package/dist/assets/PlanView-Dgg-WTEc.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +1 -0
- package/dist/assets/SettingsView-D9yRuFZw.js +28 -0
- package/dist/assets/SettingsWindow-DXF-MTHG.js +1 -0
- package/dist/assets/ToolOutputDialog-DrCa1JRk.js +15 -0
- package/dist/assets/ToolPartDiffPreview-B_tfvlNF.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-CN_BctrR.js} +4 -4
- package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
- package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
- package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-D9Q4lr5x.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-Gi1d5eU1.js} +1 -1
- package/dist/assets/contextPanelEmbeddedChat-CpzVNWAv.js +1 -0
- package/dist/assets/de-B_LdJwEM.js +9 -0
- package/dist/assets/es-CubfsAYV.js +15 -0
- package/dist/assets/fr-5qJM0nFS.js +13 -0
- package/dist/assets/index-BW82eK5v.css +1 -0
- package/dist/assets/index-Brm3X9rs.js +1 -0
- package/dist/assets/index-rlLjZUM5.js +7 -0
- package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-pH9kAJQH.js} +1 -1
- package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-CVKy_dgB.js} +1 -1
- package/dist/assets/ja-DJYIBUlH.js +15 -0
- package/dist/assets/ko-DcUBkB7y.js +15 -0
- package/dist/assets/main-DLBxKIoX.js +926 -0
- package/dist/assets/main-vUCh0VB0.js +2 -0
- package/dist/assets/markdownCore-DG6GHLF4.js +3 -0
- package/dist/assets/miniChat-BlzGEYgE.js +2 -0
- package/dist/assets/mobile-CkX6H-IT.js +2 -0
- package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BCTsE43U.js} +3 -3
- package/dist/assets/pl-rB6BLcio.js +15 -0
- package/dist/assets/pt-BR-DcwtlO-o.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-CJYe_KOL.js +2 -0
- package/dist/assets/renderMobileApp-hQJTnr8B.js +25 -0
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +15 -0
- package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +1 -0
- package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-BgTPSITe.js} +1 -1
- package/dist/assets/uk-INZlFD9A.js +15 -0
- package/dist/assets/useAppFontEffects-Cll4gnsh.js +7268 -0
- package/dist/assets/useInlineCommentController-DFFv0hae.js +2 -0
- package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-_6j2xOWl.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-DkQX2EBa.js} +2 -2
- package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
- package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
- package/dist/assets/{web-components-DCLjCO9n.js → web-components-DLnGY4fs.js} +4 -4
- package/dist/assets/zh-CN-Dzda8xa1.js +15 -0
- package/dist/assets/zh-TW-Cwn3rNYZ.js +15 -0
- package/dist/index.html +6 -5
- package/dist/mini-chat.html +5 -4
- package/dist/mobile.html +5 -4
- package/package.json +5 -7
- package/server/index.js +44 -0
- package/server/lib/agent-memory/project-resolution.js +10 -1
- package/server/lib/agent-memory/project-resolution.test.js +9 -0
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/client-auth/pairing.js +8 -7
- package/server/lib/client-auth/pairing.test.js +5 -1
- package/server/lib/client-auth/remote-clients.js +9 -1
- package/server/lib/client-auth/remote-clients.test.js +17 -0
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/routes.test.js +76 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +85 -5
- package/server/lib/git/service.test.js +93 -0
- package/server/lib/github/pr-status.js +10 -1
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/feature-routes-runtime.js +5 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +15 -0
- package/server/lib/opencode/settings-helpers.test.js +22 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +32 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +2 -0
- package/server/lib/project-context/runtime.js +7 -2
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +1 -1
- package/server/lib/quota/providers/claude/index.js +2 -2
- package/server/lib/quota/providers/index.js +1 -7
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +34 -2
- package/server/lib/relay/service.test.js +69 -0
- package/server/lib/session-goal/runtime.js +2 -1
- package/server/lib/session-goal/runtime.test.js +4 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +4 -4
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +51 -8
- package/server/lib/small-model/index.test.js +73 -3
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +29 -1
- package/server/lib/terminal/runtime.test.js +26 -0
- package/server/lib/ui-auth/ui-auth.js +2 -2
- package/server/lib/ui-auth/ui-auth.test.js +2 -2
- package/dist/assets/CommitSection-D9cV-qR9.js +0 -1
- package/dist/assets/DiagramEditor-B9NCadU7.js +0 -1
- package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
- package/dist/assets/DiffView-BWNq-0ov.js +0 -4
- package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
- package/dist/assets/GitView-DsWXqWx3.js +0 -6
- package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
- package/dist/assets/OnboardingScreen-CDjgzxEe.js +0 -1
- package/dist/assets/PierreDiffViewer-D_Gt4A_6.js +0 -136
- package/dist/assets/PlanView-UvuxIl9-.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
- package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
- package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
- package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
- package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
- package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +0 -1
- package/dist/assets/de-DbV6CLxv.js +0 -9
- package/dist/assets/es-CVDlyzZ4.js +0 -15
- package/dist/assets/fr-Czc-p0g-.js +0 -13
- package/dist/assets/index-1OhiMDBz.css +0 -1
- package/dist/assets/index-BSvmTvZl.js +0 -1
- package/dist/assets/index-DzriVon2.js +0 -7
- package/dist/assets/ja-dwc9NM_S.js +0 -15
- package/dist/assets/ko-Ds1DZ8FX.js +0 -15
- package/dist/assets/main-BF51IOVF.js +0 -921
- package/dist/assets/main-D7UPARut.js +0 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
- package/dist/assets/miniChat-BISXSGOo.js +0 -2
- package/dist/assets/mobile-BnYxVuvw.js +0 -2
- package/dist/assets/pl-CLiTO7i-.js +0 -15
- package/dist/assets/pt-BR-GIimJgpK.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
- package/dist/assets/renderMobileApp-BiMbzPq9.js +0 -25
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
- package/dist/assets/scheduledTasksApi-01zzfzqH.js +0 -1
- package/dist/assets/uk-DLfgD1ki.js +0 -15
- package/dist/assets/useAppFontEffects-CbzHzFop.js +0 -7271
- package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
- package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
- package/dist/assets/zh-CN-DkeP5awK.js +0 -15
- package/dist/assets/zh-TW-BocaFm3d.js +0 -15
- package/server/lib/quota/providers/command-code.js +0 -90
- package/server/lib/quota/providers/command-code.test.js +0 -72
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -7,23 +7,54 @@
|
|
|
7
7
|
* Responsibilities:
|
|
8
8
|
* - Reorders inbound chunks by `seq` and acks the highest contiguous seq.
|
|
9
9
|
* - Resamples client PCM (16 kHz by default) to the provider's required rate.
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
10
|
+
* - Segments long dictations at natural pauses: past `segmentMinSeconds` of
|
|
11
|
+
* audio it commits on the first silent chunk, and `segmentMaxSeconds` is a
|
|
12
|
+
* hard cap for speech with no pause in it. Silence-only segments are
|
|
13
|
+
* cleared instead of committed.
|
|
12
14
|
* - Concatenates per-segment transcripts into live partials and emits the
|
|
13
|
-
* final text once every committed segment has a final transcript.
|
|
15
|
+
* final text once every committed segment has a final transcript. The
|
|
16
|
+
* manager counts the commits it issued rather than trusting the session's
|
|
17
|
+
* echoed events, so a commit still in flight when the client finishes
|
|
18
|
+
* cannot be silently dropped from the transcript.
|
|
14
19
|
* - Applies an adaptive finalization timeout budget based on pending work.
|
|
15
20
|
*/
|
|
16
21
|
|
|
17
22
|
import { Pcm16MonoResampler, parsePcmRateFromFormat, pcm16lePeakAbs } from './audio.js';
|
|
18
23
|
|
|
19
24
|
const DEFAULT_FINAL_TIMEOUT_MS = 10000;
|
|
20
|
-
|
|
25
|
+
// Parakeet is a full-attention conformer: decode cost and peak memory grow
|
|
26
|
+
// quadratically with segment length (measured: 60s -> 2.1s/+90MB,
|
|
27
|
+
// 300s -> 21.3s/+1.5GB). Segmenting keeps a long dictation off that curve and
|
|
28
|
+
// lets committed segments decode while the user is still speaking, so only the
|
|
29
|
+
// tail is left to transcribe on stop. Typical dictations are shorter than the
|
|
30
|
+
// minimum and are decoded as a single segment.
|
|
31
|
+
const DEFAULT_SEGMENT_MIN_SECONDS = 60;
|
|
32
|
+
const DEFAULT_SEGMENT_MAX_SECONDS = 90;
|
|
21
33
|
const FINAL_TIMEOUT_MAX_MS = 5 * 60 * 1000;
|
|
22
34
|
const FINAL_TIMEOUT_PER_PENDING_SEGMENT_MS = 15 * 1000;
|
|
23
35
|
const FINAL_TIMEOUT_PER_PENDING_AUDIO_SECOND_MS = 1500;
|
|
24
36
|
const FINAL_TIMEOUT_PER_MISSING_SEQ_MS = 250;
|
|
25
37
|
const SILENCE_PEAK_THRESHOLD = 300;
|
|
26
38
|
|
|
39
|
+
const secondsToPcm16Bytes = (seconds, sampleRate) =>
|
|
40
|
+
seconds > 0 ? Math.max(1, Math.round(seconds * sampleRate * 2)) : 0;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Split the current segment once it is long enough to be worth decoding on its
|
|
44
|
+
* own and the speaker has just gone quiet, or unconditionally at the hard cap.
|
|
45
|
+
* Client chunks are ~1s, so a quiet chunk is roughly a second of silence — long
|
|
46
|
+
* enough to be a sentence boundary rather than a gap between words.
|
|
47
|
+
*/
|
|
48
|
+
function shouldSplitSegment(state) {
|
|
49
|
+
if (state.segmentMaxBytes > 0 && state.bytesSinceCommit >= state.segmentMaxBytes) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (state.segmentMinBytes <= 0 || state.bytesSinceCommit < state.segmentMinBytes) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return state.lastChunkPeak < SILENCE_PEAK_THRESHOLD;
|
|
56
|
+
}
|
|
57
|
+
|
|
27
58
|
export class DictationStreamManager {
|
|
28
59
|
/**
|
|
29
60
|
* @param {object} params
|
|
@@ -33,13 +64,15 @@ export class DictationStreamManager {
|
|
|
33
64
|
* The streaming transcription session contract:
|
|
34
65
|
* { requiredSampleRate, appendPcm16(buf), commit(), clear(), close(), on(event, handler) }
|
|
35
66
|
* @param {number} [params.finalTimeoutMs]
|
|
36
|
-
* @param {number} [params.
|
|
67
|
+
* @param {number} [params.segmentMinSeconds] audio before a pause may split a segment
|
|
68
|
+
* @param {number} [params.segmentMaxSeconds] hard segment cap for pauseless speech
|
|
37
69
|
*/
|
|
38
|
-
constructor({ emit, createSttSession, finalTimeoutMs,
|
|
70
|
+
constructor({ emit, createSttSession, finalTimeoutMs, segmentMinSeconds, segmentMaxSeconds }) {
|
|
39
71
|
this.emit = emit;
|
|
40
72
|
this.createSttSession = createSttSession;
|
|
41
73
|
this.finalTimeoutMs = finalTimeoutMs ?? DEFAULT_FINAL_TIMEOUT_MS;
|
|
42
|
-
this.
|
|
74
|
+
this.segmentMinSeconds = segmentMinSeconds ?? DEFAULT_SEGMENT_MIN_SECONDS;
|
|
75
|
+
this.segmentMaxSeconds = segmentMaxSeconds ?? DEFAULT_SEGMENT_MAX_SECONDS;
|
|
43
76
|
this.streams = new Map();
|
|
44
77
|
}
|
|
45
78
|
|
|
@@ -87,13 +120,12 @@ export class DictationStreamManager {
|
|
|
87
120
|
if (!state) {
|
|
88
121
|
return;
|
|
89
122
|
}
|
|
123
|
+
// Segment accounting is reset where the commit is issued, not here: this
|
|
124
|
+
// event arrives after an async hop, and zeroing the counters on arrival
|
|
125
|
+
// would discard audio that came in meanwhile — up to and including
|
|
126
|
+
// mistaking the tail of the dictation for silence and clearing it.
|
|
90
127
|
state.committedSegmentIds.push(segmentId);
|
|
91
|
-
state.
|
|
92
|
-
state.peakSinceCommit = 0;
|
|
93
|
-
|
|
94
|
-
if (state.finishRequested && state.awaitingFinalCommit) {
|
|
95
|
-
state.awaitingFinalCommit = false;
|
|
96
|
-
}
|
|
128
|
+
state.pendingCommits = Math.max(0, state.pendingCommits - 1);
|
|
97
129
|
|
|
98
130
|
this.maybeFinalizeStream(dictationId);
|
|
99
131
|
});
|
|
@@ -108,10 +140,6 @@ export class DictationStreamManager {
|
|
|
108
140
|
state.finalTranscriptSegmentIds.add(segmentId);
|
|
109
141
|
}
|
|
110
142
|
|
|
111
|
-
if (state.finishRequested && state.awaitingFinalCommit && isFinal) {
|
|
112
|
-
state.awaitingFinalCommit = false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
143
|
const orderedIds = state.committedSegmentIds.includes(segmentId)
|
|
116
144
|
? state.committedSegmentIds
|
|
117
145
|
: [...state.committedSegmentIds, segmentId];
|
|
@@ -143,16 +171,15 @@ export class DictationStreamManager {
|
|
|
143
171
|
receivedChunks: new Map(),
|
|
144
172
|
nextSeqToForward: 0,
|
|
145
173
|
ackSeq: -1,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
? Math.max(1, Math.round(this.autoCommitSeconds * stt.requiredSampleRate * 2))
|
|
149
|
-
: 0,
|
|
174
|
+
segmentMinBytes: secondsToPcm16Bytes(this.segmentMinSeconds, stt.requiredSampleRate),
|
|
175
|
+
segmentMaxBytes: secondsToPcm16Bytes(this.segmentMaxSeconds, stt.requiredSampleRate),
|
|
150
176
|
bytesSinceCommit: 0,
|
|
151
177
|
peakSinceCommit: 0,
|
|
178
|
+
lastChunkPeak: 0,
|
|
152
179
|
committedSegmentIds: [],
|
|
153
180
|
transcriptsBySegmentId: new Map(),
|
|
154
181
|
finalTranscriptSegmentIds: new Set(),
|
|
155
|
-
|
|
182
|
+
pendingCommits: 0,
|
|
156
183
|
finishRequested: false,
|
|
157
184
|
finishSealed: false,
|
|
158
185
|
finalSeq: null,
|
|
@@ -203,7 +230,8 @@ export class DictationStreamManager {
|
|
|
203
230
|
if (resampled.length > 0) {
|
|
204
231
|
state.stt.appendPcm16(resampled);
|
|
205
232
|
state.bytesSinceCommit += resampled.length;
|
|
206
|
-
state.
|
|
233
|
+
state.lastChunkPeak = pcm16lePeakAbs(resampled);
|
|
234
|
+
state.peakSinceCommit = Math.max(state.peakSinceCommit, state.lastChunkPeak);
|
|
207
235
|
try {
|
|
208
236
|
this.maybeAutoCommitSegment(state);
|
|
209
237
|
} catch (error) {
|
|
@@ -325,9 +353,7 @@ export class DictationStreamManager {
|
|
|
325
353
|
return state.finalTranscriptSegmentIds.has(segmentId) ? count : count + 1;
|
|
326
354
|
}, 0);
|
|
327
355
|
const pendingSegments =
|
|
328
|
-
pendingCommittedSegments +
|
|
329
|
-
pendingUncommittedTranscriptSegments +
|
|
330
|
-
(state.awaitingFinalCommit ? 1 : 0);
|
|
356
|
+
pendingCommittedSegments + pendingUncommittedTranscriptSegments + state.pendingCommits;
|
|
331
357
|
const pendingAudioSeconds = Math.ceil(Math.max(0, state.bytesSinceCommit) / bytesPerSecond);
|
|
332
358
|
const missingSeqCount =
|
|
333
359
|
state.finalSeq === null ? 0 : Math.max(0, state.finalSeq - state.ackSeq);
|
|
@@ -347,19 +373,36 @@ export class DictationStreamManager {
|
|
|
347
373
|
if (state.finishRequested) {
|
|
348
374
|
return;
|
|
349
375
|
}
|
|
350
|
-
if (state
|
|
376
|
+
if (!shouldSplitSegment(state)) {
|
|
351
377
|
return;
|
|
352
378
|
}
|
|
353
379
|
if (state.peakSinceCommit < SILENCE_PEAK_THRESHOLD) {
|
|
354
380
|
state.stt.clear();
|
|
355
381
|
state.bytesSinceCommit = 0;
|
|
356
382
|
state.peakSinceCommit = 0;
|
|
383
|
+
state.lastChunkPeak = 0;
|
|
357
384
|
return;
|
|
358
385
|
}
|
|
359
386
|
|
|
360
387
|
state.bytesSinceCommit = 0;
|
|
361
388
|
state.peakSinceCommit = 0;
|
|
362
|
-
state.
|
|
389
|
+
state.lastChunkPeak = 0;
|
|
390
|
+
this.commitSegment(state);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Issue a commit and record it as in flight. The session acknowledges with a
|
|
395
|
+
* `committed` event; until then the manager must not finalize, or the
|
|
396
|
+
* segment's transcript would be missing from the final text.
|
|
397
|
+
*/
|
|
398
|
+
commitSegment(state) {
|
|
399
|
+
state.pendingCommits += 1;
|
|
400
|
+
try {
|
|
401
|
+
state.stt.commit();
|
|
402
|
+
} catch (error) {
|
|
403
|
+
state.pendingCommits -= 1;
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
363
406
|
}
|
|
364
407
|
|
|
365
408
|
maybeSealStreamFinish(dictationId) {
|
|
@@ -382,19 +425,19 @@ export class DictationStreamManager {
|
|
|
382
425
|
state.stt.clear();
|
|
383
426
|
state.bytesSinceCommit = 0;
|
|
384
427
|
state.peakSinceCommit = 0;
|
|
385
|
-
state.
|
|
428
|
+
state.lastChunkPeak = 0;
|
|
386
429
|
this.dropUncommittedNonFinalTranscripts(state);
|
|
387
430
|
} else {
|
|
388
|
-
state.
|
|
431
|
+
state.bytesSinceCommit = 0;
|
|
432
|
+
state.peakSinceCommit = 0;
|
|
433
|
+
state.lastChunkPeak = 0;
|
|
389
434
|
try {
|
|
390
|
-
|
|
435
|
+
this.commitSegment(state);
|
|
391
436
|
} catch (error) {
|
|
392
437
|
this.failAndCleanupStream(dictationId, error?.message || String(error), true);
|
|
393
438
|
return;
|
|
394
439
|
}
|
|
395
440
|
}
|
|
396
|
-
} else {
|
|
397
|
-
state.awaitingFinalCommit = false;
|
|
398
441
|
}
|
|
399
442
|
|
|
400
443
|
state.finishSealed = true;
|
|
@@ -425,7 +468,7 @@ export class DictationStreamManager {
|
|
|
425
468
|
if (state.ackSeq < state.finalSeq) {
|
|
426
469
|
return;
|
|
427
470
|
}
|
|
428
|
-
if (state.
|
|
471
|
+
if (state.pendingCommits > 0) {
|
|
429
472
|
return;
|
|
430
473
|
}
|
|
431
474
|
|
|
@@ -175,8 +175,8 @@ describe('DictationStreamManager', () => {
|
|
|
175
175
|
},
|
|
176
176
|
});
|
|
177
177
|
const { manager, messages } = createManager(session);
|
|
178
|
-
// Force
|
|
179
|
-
manager.
|
|
178
|
+
// Force a hard-cap split after ~0.05s of audio so two segments form.
|
|
179
|
+
manager.segmentMaxSeconds = 0.05;
|
|
180
180
|
|
|
181
181
|
await manager.handleStart('d1', FORMAT, {});
|
|
182
182
|
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(1600) });
|
|
@@ -191,4 +191,62 @@ describe('DictationStreamManager', () => {
|
|
|
191
191
|
const partials = messages.filter((m) => m.type === 'partial');
|
|
192
192
|
expect(partials.length).toBeGreaterThan(0);
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
it('keeps a short dictation as one segment even across pauses', async () => {
|
|
196
|
+
const session = new FakeSttSession();
|
|
197
|
+
const { manager } = createManager(session);
|
|
198
|
+
|
|
199
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
200
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
201
|
+
manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: silentChunkBase64(16000) });
|
|
202
|
+
manager.handleChunk({ dictationId: 'd1', seq: 2, audioBase64: loudChunkBase64(16000) });
|
|
203
|
+
|
|
204
|
+
expect(session.commits).toBe(0);
|
|
205
|
+
|
|
206
|
+
manager.handleFinish('d1', 2);
|
|
207
|
+
await waitFor(() => session.commits === 1);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('splits at a pause once the segment passes the minimum length', async () => {
|
|
211
|
+
const session = new FakeSttSession();
|
|
212
|
+
const { manager } = createManager(session);
|
|
213
|
+
manager.segmentMinSeconds = 3;
|
|
214
|
+
|
|
215
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
216
|
+
// 2s of audio: below the minimum, so this pause must not split.
|
|
217
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
218
|
+
manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: silentChunkBase64(16000) });
|
|
219
|
+
expect(session.commits).toBe(0);
|
|
220
|
+
|
|
221
|
+
// Past the minimum, the next quiet chunk is a segment boundary.
|
|
222
|
+
manager.handleChunk({ dictationId: 'd1', seq: 2, audioBase64: loudChunkBase64(16000) });
|
|
223
|
+
expect(session.commits).toBe(0);
|
|
224
|
+
manager.handleChunk({ dictationId: 'd1', seq: 3, audioBase64: silentChunkBase64(16000) });
|
|
225
|
+
expect(session.commits).toBe(1);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('splits pauseless speech at the hard cap', async () => {
|
|
229
|
+
const session = new FakeSttSession();
|
|
230
|
+
const { manager } = createManager(session);
|
|
231
|
+
manager.segmentMinSeconds = 60;
|
|
232
|
+
manager.segmentMaxSeconds = 2;
|
|
233
|
+
|
|
234
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
235
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: loudChunkBase64(16000) });
|
|
236
|
+
expect(session.commits).toBe(0);
|
|
237
|
+
manager.handleChunk({ dictationId: 'd1', seq: 1, audioBase64: loudChunkBase64(16000) });
|
|
238
|
+
expect(session.commits).toBe(1);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('clears a silence-only segment at the hard cap instead of committing it', async () => {
|
|
242
|
+
const session = new FakeSttSession();
|
|
243
|
+
const { manager } = createManager(session);
|
|
244
|
+
manager.segmentMaxSeconds = 1;
|
|
245
|
+
|
|
246
|
+
await manager.handleStart('d1', FORMAT, {});
|
|
247
|
+
manager.handleChunk({ dictationId: 'd1', seq: 0, audioBase64: silentChunkBase64(16000) });
|
|
248
|
+
|
|
249
|
+
expect(session.commits).toBe(0);
|
|
250
|
+
expect(session.clears).toBe(1);
|
|
251
|
+
});
|
|
194
252
|
});
|
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import { mintOutsideFileGrant, registerFsRoutes } from './routes.js';
|
|
6
|
+
import { createProjectDirectoryRuntime } from '../opencode/project-directory-runtime.js';
|
|
6
7
|
|
|
7
8
|
const createRouteRegistry = () => {
|
|
8
9
|
const routes = new Map();
|
|
@@ -1048,3 +1049,78 @@ describe('fs list symlink path space (issue 2627)', () => {
|
|
|
1048
1049
|
});
|
|
1049
1050
|
}
|
|
1050
1051
|
});
|
|
1052
|
+
|
|
1053
|
+
describe('fs stat directory scope (issue 3019)', () => {
|
|
1054
|
+
// Wires the real project-directory runtime so the stat route resolves the
|
|
1055
|
+
// workspace exactly as the server does: explicit x-opencode-directory header
|
|
1056
|
+
// first, then the settings.lastDirectory fallback. The renderer's file
|
|
1057
|
+
// reference probes must send the header because lastDirectory reflects the
|
|
1058
|
+
// directory the UI last browsed, not the session's directory.
|
|
1059
|
+
const registerStatWithProjectDirectoryRuntime = () => {
|
|
1060
|
+
const projectDirectoryRuntime = createProjectDirectoryRuntime({
|
|
1061
|
+
fsPromises: {
|
|
1062
|
+
stat: async (targetPath) => {
|
|
1063
|
+
if (targetPath === '/repo-a' || targetPath === '/repo-b') {
|
|
1064
|
+
return { isDirectory: () => true };
|
|
1065
|
+
}
|
|
1066
|
+
return { isDirectory: () => false, isFile: () => true, size: 12 };
|
|
1067
|
+
},
|
|
1068
|
+
realpath: async (targetPath) => targetPath,
|
|
1069
|
+
},
|
|
1070
|
+
path: { resolve: (p) => path.posix.resolve(p) },
|
|
1071
|
+
normalizeDirectoryPath: (p) => p,
|
|
1072
|
+
readSettingsFromDiskMigrated: async () => ({ lastDirectory: '/repo-a', projects: [] }),
|
|
1073
|
+
getReadSettingsFromDiskMigrated: undefined,
|
|
1074
|
+
sanitizeProjects: (input) => input,
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1078
|
+
registerFsRoutes(app, {
|
|
1079
|
+
os: { homedir: () => '/home/user' },
|
|
1080
|
+
path: path.posix,
|
|
1081
|
+
fsPromises: {
|
|
1082
|
+
realpath: async (targetPath) => targetPath,
|
|
1083
|
+
stat: async () => ({ isFile: () => true, size: 12 }),
|
|
1084
|
+
},
|
|
1085
|
+
spawn: vi.fn(),
|
|
1086
|
+
crypto: { randomUUID: () => 'job-0' },
|
|
1087
|
+
normalizeDirectoryPath: (p) => p,
|
|
1088
|
+
resolveProjectDirectory: projectDirectoryRuntime.resolveProjectDirectory,
|
|
1089
|
+
buildAugmentedPath: () => '/usr/bin',
|
|
1090
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
1091
|
+
openchamberUserConfigRoot: '/home/user/.config',
|
|
1092
|
+
});
|
|
1093
|
+
return getRoute('GET', '/api/fs/stat');
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
const callStat = async (handler, { headers = {}, query }) => {
|
|
1097
|
+
const res = createMockResponse();
|
|
1098
|
+
const req = {
|
|
1099
|
+
query,
|
|
1100
|
+
get: (name) => headers[name.toLowerCase()] ?? undefined,
|
|
1101
|
+
};
|
|
1102
|
+
await handler(req, res);
|
|
1103
|
+
return res;
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
it('rejects a stat for a file under the session directory when only lastDirectory resolves the workspace', async () => {
|
|
1107
|
+
const handler = registerStatWithProjectDirectoryRuntime();
|
|
1108
|
+
|
|
1109
|
+
const res = await callStat(handler, { query: { path: '/repo-b/src/index.ts', optional: 'true' } });
|
|
1110
|
+
|
|
1111
|
+
expect(res.statusCode).toBe(400);
|
|
1112
|
+
expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
it('accepts the same stat when the session directory rides the x-opencode-directory header', async () => {
|
|
1116
|
+
const handler = registerStatWithProjectDirectoryRuntime();
|
|
1117
|
+
|
|
1118
|
+
const res = await callStat(handler, {
|
|
1119
|
+
headers: { 'x-opencode-directory': '/repo-b' },
|
|
1120
|
+
query: { path: '/repo-b/src/index.ts', optional: 'true' },
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
expect(res.statusCode).toBe(200);
|
|
1124
|
+
expect(res.body.isFile).toBe(true);
|
|
1125
|
+
});
|
|
1126
|
+
});
|
package/server/lib/git/routes.js
CHANGED
|
@@ -428,6 +428,49 @@ export function registerGitRoutes(app) {
|
|
|
428
428
|
}
|
|
429
429
|
});
|
|
430
430
|
|
|
431
|
+
app.get('/api/git/branch-base', async (req, res) => {
|
|
432
|
+
const { getBranchBase } = await getGitLibraries();
|
|
433
|
+
try {
|
|
434
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
435
|
+
if (!directory) {
|
|
436
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const branch = resolveDirectoryQuery(req.query.branch);
|
|
440
|
+
if (!branch) {
|
|
441
|
+
return res.status(400).json({ error: 'branch parameter is required' });
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const result = await getBranchBase(directory, branch);
|
|
445
|
+
res.json(result);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error('Failed to get branch base:', error);
|
|
448
|
+
res.status(500).json({ error: error.message || 'Failed to get branch base' });
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
app.get('/api/git/range-files', async (req, res) => {
|
|
453
|
+
const { getRangeFiles } = await getGitLibraries();
|
|
454
|
+
try {
|
|
455
|
+
const directory = resolveDirectoryQuery(req.query.directory);
|
|
456
|
+
if (!directory) {
|
|
457
|
+
return res.status(400).json({ error: 'directory parameter is required' });
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const base = resolveDirectoryQuery(req.query.base);
|
|
461
|
+
const head = resolveDirectoryQuery(req.query.head);
|
|
462
|
+
if (!base || !head) {
|
|
463
|
+
return res.status(400).json({ error: 'base and head parameters are required' });
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const files = await getRangeFiles(directory, { base, head });
|
|
467
|
+
res.json({ files });
|
|
468
|
+
} catch (error) {
|
|
469
|
+
console.error('Failed to get git range files:', error);
|
|
470
|
+
res.status(500).json({ error: error.message || 'Failed to get git range files' });
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
431
474
|
app.post('/api/git/revert', async (req, res) => {
|
|
432
475
|
const { revertFile } = await getGitLibraries();
|
|
433
476
|
try {
|
|
@@ -2654,6 +2654,71 @@ export async function getRangeDiff(directory, { base, head, path: filePath, cont
|
|
|
2654
2654
|
return diff;
|
|
2655
2655
|
}
|
|
2656
2656
|
|
|
2657
|
+
const BRANCH_CREATION_SOURCE_RE = /^branch: Created from (.+)$/;
|
|
2658
|
+
|
|
2659
|
+
/**
|
|
2660
|
+
* Parse a branch reflog (`git reflog show --format=%gs <branch>`) and return the
|
|
2661
|
+
* ref the branch was created from, when that source is itself a named ref.
|
|
2662
|
+
*
|
|
2663
|
+
* Returns null when the branch was created from `HEAD@{...}` or a raw commit
|
|
2664
|
+
* (detached start): the original branch name is not recorded anywhere in that
|
|
2665
|
+
* case, and guessing a base from commit topology would be a heuristic, not an
|
|
2666
|
+
* answer. Callers should ask the user to pick a base instead.
|
|
2667
|
+
*/
|
|
2668
|
+
export function parseBranchCreationSource(reflogText) {
|
|
2669
|
+
const lines = String(reflogText || '')
|
|
2670
|
+
.split('\n')
|
|
2671
|
+
.map((line) => line.trim())
|
|
2672
|
+
.filter(Boolean);
|
|
2673
|
+
// Reflog lists newest entries first; the creation entry is the oldest one.
|
|
2674
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
2675
|
+
const match = lines[index].match(BRANCH_CREATION_SOURCE_RE);
|
|
2676
|
+
if (!match) continue;
|
|
2677
|
+
const source = match[1].trim();
|
|
2678
|
+
if (!source || /^HEAD@/.test(source) || /^[0-9a-f]{7,40}$/i.test(source)) {
|
|
2679
|
+
return null;
|
|
2680
|
+
}
|
|
2681
|
+
return source;
|
|
2682
|
+
}
|
|
2683
|
+
return null;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Resolve the branch the given branch was created from, from its reflog.
|
|
2688
|
+
* Returns { base: null } when git has no authoritative record (clone, detached
|
|
2689
|
+
* start, reflog expired) — callers must not fall back to main/master.
|
|
2690
|
+
*/
|
|
2691
|
+
export async function getBranchBase(directory, branch) {
|
|
2692
|
+
const branchName = String(branch || '').trim();
|
|
2693
|
+
if (!branchName) {
|
|
2694
|
+
throw new Error('branch is required');
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
const { git } = await createRepositoryGitContext(directory);
|
|
2698
|
+
|
|
2699
|
+
let reflog = '';
|
|
2700
|
+
try {
|
|
2701
|
+
reflog = await git.raw(['reflog', 'show', '--format=%gs', branchName]);
|
|
2702
|
+
} catch {
|
|
2703
|
+
return { base: null };
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
const source = parseBranchCreationSource(reflog);
|
|
2707
|
+
if (!source || source === branchName) {
|
|
2708
|
+
return { base: null };
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
const resolves = await git
|
|
2712
|
+
.raw(['rev-parse', '--verify', '--quiet', source])
|
|
2713
|
+
.then((value) => Boolean(String(value || '').trim()))
|
|
2714
|
+
.catch(() => false);
|
|
2715
|
+
if (!resolves) {
|
|
2716
|
+
return { base: null };
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
return { base: source };
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2657
2722
|
export async function getRangeFiles(directory, { base, head } = {}) {
|
|
2658
2723
|
const { git } = await createRepositoryGitContext(directory);
|
|
2659
2724
|
const baseRef = typeof base === 'string' ? base.trim() : '';
|
|
@@ -2673,11 +2738,26 @@ export async function getRangeFiles(directory, { base, head } = {}) {
|
|
|
2673
2738
|
// ignore
|
|
2674
2739
|
}
|
|
2675
2740
|
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2741
|
+
// `-C` (copy detection among changed files only, so cheap) makes copies
|
|
2742
|
+
// surface as C entries instead of plain additions; rename detection is on
|
|
2743
|
+
// by default.
|
|
2744
|
+
const raw = await git.raw(['diff', '--name-status', '-z', '-C', `${resolvedBase}...${headRef}`]);
|
|
2745
|
+
// -z format: STATUS\0PATH\0[ORIG\0] repeated. For rename/copy entries
|
|
2746
|
+
// (`R100`, `C75`) the first path token is the ORIGINAL path and the second
|
|
2747
|
+
// is the DESTINATION — the diff (and the UI) must address the destination.
|
|
2748
|
+
const tokens = String(raw || '').split('\0');
|
|
2749
|
+
const files = [];
|
|
2750
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
2751
|
+
const status = (tokens[index] || '').trim();
|
|
2752
|
+
if (!status) continue;
|
|
2753
|
+
const isRenameOrCopy = status.startsWith('R') || status.startsWith('C');
|
|
2754
|
+
const path = isRenameOrCopy ? (tokens[index + 2] || '').trim() : (tokens[index + 1] || '').trim();
|
|
2755
|
+
index += isRenameOrCopy ? 2 : 1;
|
|
2756
|
+
if (path) {
|
|
2757
|
+
files.push({ path, status: status.charAt(0) });
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
return files;
|
|
2681
2761
|
}
|
|
2682
2762
|
|
|
2683
2763
|
const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico', 'bmp', 'avif'];
|
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
getDiff,
|
|
29
29
|
getFileDiff,
|
|
30
30
|
validateWorktreeCreate,
|
|
31
|
+
parseBranchCreationSource,
|
|
32
|
+
getRangeFiles,
|
|
31
33
|
} from './service.js';
|
|
32
34
|
|
|
33
35
|
// ---------------------------------------------------------------------------
|
|
@@ -1336,3 +1338,94 @@ describe.runIf(canRunGit())('getRangeDiff', () => {
|
|
|
1336
1338
|
expect(diff).toContain('feature.txt');
|
|
1337
1339
|
});
|
|
1338
1340
|
});
|
|
1341
|
+
|
|
1342
|
+
describe('parseBranchCreationSource', () => {
|
|
1343
|
+
it('returns the source ref from the oldest creation entry', () => {
|
|
1344
|
+
// Reflog lists newest entries first; creation is the last line.
|
|
1345
|
+
const reflog = [
|
|
1346
|
+
'commit: abc123',
|
|
1347
|
+
'branch: Created from origin/main',
|
|
1348
|
+
].join('\n');
|
|
1349
|
+
expect(parseBranchCreationSource(reflog)).toBe('origin/main');
|
|
1350
|
+
});
|
|
1351
|
+
|
|
1352
|
+
it('returns null when the branch was created from a detached HEAD pointer', () => {
|
|
1353
|
+
const reflog = 'branch: Created from HEAD@{0}';
|
|
1354
|
+
expect(parseBranchCreationSource(reflog)).toBeNull();
|
|
1355
|
+
});
|
|
1356
|
+
|
|
1357
|
+
it('returns null when the branch was created from a raw commit', () => {
|
|
1358
|
+
const reflog = 'branch: Created from 9a3b2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b';
|
|
1359
|
+
expect(parseBranchCreationSource(reflog)).toBeNull();
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
it('returns null when there is no creation entry', () => {
|
|
1363
|
+
const reflog = ['commit: abc123', 'reset: moving to HEAD'].join('\n');
|
|
1364
|
+
expect(parseBranchCreationSource(reflog)).toBeNull();
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1367
|
+
it('returns null for empty input', () => {
|
|
1368
|
+
expect(parseBranchCreationSource('')).toBeNull();
|
|
1369
|
+
expect(parseBranchCreationSource(undefined)).toBeNull();
|
|
1370
|
+
});
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
describe.runIf(canRunGit())('getRangeFiles', () => {
|
|
1374
|
+
it('returns added and modified paths with their status letters', async () => {
|
|
1375
|
+
const { repository } = createRepositoryWithRemote();
|
|
1376
|
+
fs.writeFileSync(path.join(repository, 'added.txt'), 'new\n');
|
|
1377
|
+
fs.writeFileSync(path.join(repository, 'README.md'), '# Test\nchanged\n');
|
|
1378
|
+
runGit(repository, ['add', 'added.txt', 'README.md']);
|
|
1379
|
+
runGit(repository, ['commit', '-m', 'changes']);
|
|
1380
|
+
|
|
1381
|
+
const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
|
|
1382
|
+
|
|
1383
|
+
expect(files).toEqual(expect.arrayContaining([
|
|
1384
|
+
{ path: 'added.txt', status: 'A' },
|
|
1385
|
+
{ path: 'README.md', status: 'M' },
|
|
1386
|
+
]));
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
it('reports the destination path for renamed files, including spaces', async () => {
|
|
1390
|
+
const { repository } = createRepositoryWithRemote();
|
|
1391
|
+
// The original file must exist in the base: rename detection pairs a
|
|
1392
|
+
// deletion against an addition relative to base, not within the branch.
|
|
1393
|
+
fs.writeFileSync(path.join(repository, 'old name with spaces.md'), '# Test\n');
|
|
1394
|
+
runGit(repository, ['add', 'old name with spaces.md']);
|
|
1395
|
+
runGit(repository, ['commit', '-m', 'add file to rename']);
|
|
1396
|
+
runGit(repository, ['push', 'origin', 'HEAD:react']);
|
|
1397
|
+
// Spaces in filenames exercise the -z token split: a newline split would
|
|
1398
|
+
// mangle these paths long before status letters matter.
|
|
1399
|
+
fs.renameSync(path.join(repository, 'old name with spaces.md'), path.join(repository, 'new name with spaces.md'));
|
|
1400
|
+
runGit(repository, ['add', '-A']);
|
|
1401
|
+
runGit(repository, ['commit', '-m', 'rename']);
|
|
1402
|
+
|
|
1403
|
+
const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
|
|
1404
|
+
|
|
1405
|
+
const renameEntry = files.find((file) => file.status === 'R');
|
|
1406
|
+
expect(renameEntry).toBeDefined();
|
|
1407
|
+
expect(renameEntry.path).toBe('new name with spaces.md');
|
|
1408
|
+
expect(files.some((file) => file.path === 'old name with spaces.md')).toBe(false);
|
|
1409
|
+
});
|
|
1410
|
+
|
|
1411
|
+
it('reports the destination path for copied files', async () => {
|
|
1412
|
+
const { repository } = createRepositoryWithRemote();
|
|
1413
|
+
// The source must exist in the base. Copy detection needs the repository's
|
|
1414
|
+
// own `diff.renames=copies` setting on top of the service's -C flag; the
|
|
1415
|
+
// parser must survive whatever C entries git emits.
|
|
1416
|
+
runGit(repository, ['config', 'diff.renames', 'copies']);
|
|
1417
|
+
fs.writeFileSync(path.join(repository, 'copied source.md'), '# Copy me\n');
|
|
1418
|
+
runGit(repository, ['add', 'copied source.md']);
|
|
1419
|
+
runGit(repository, ['commit', '-m', 'add source']);
|
|
1420
|
+
runGit(repository, ['push', 'origin', 'HEAD:react']);
|
|
1421
|
+
fs.copyFileSync(path.join(repository, 'copied source.md'), path.join(repository, 'copied destination.md'));
|
|
1422
|
+
runGit(repository, ['add', '-A']);
|
|
1423
|
+
runGit(repository, ['commit', '-m', 'copy']);
|
|
1424
|
+
|
|
1425
|
+
const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
|
|
1426
|
+
|
|
1427
|
+
const copyEntry = files.find((file) => file.status === 'C');
|
|
1428
|
+
expect(copyEntry).toBeDefined();
|
|
1429
|
+
expect(copyEntry.path).toBe('copied destination.md');
|
|
1430
|
+
});
|
|
1431
|
+
});
|
|
@@ -674,7 +674,16 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
|
|
|
674
674
|
};
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
|
|
677
|
+
// Only the repo this branch actually pushes to (the ranked-first remote)
|
|
678
|
+
// and its fork network can be the SOURCE of the branch's PRs. Other
|
|
679
|
+
// configured remotes — a maintainer's checkout often carries contributor
|
|
680
|
+
// forks — are places to look for an open PR, but their `owner:branch`
|
|
681
|
+
// heads are unrelated branches that merely share a name; treating them as
|
|
682
|
+
// sources made a fork's closed `main` PR show up on the local main.
|
|
683
|
+
const primaryRemoteName = resolvedTargets[0]?.remoteName ?? null;
|
|
684
|
+
const sourceCandidates = resolvedTargets.filter(
|
|
685
|
+
(target) => target.remoteName === primaryRemoteName,
|
|
686
|
+
);
|
|
678
687
|
// When every consulted repo list was complete, a no-PR result is
|
|
679
688
|
// authoritative and the expensive Search API fallback is pointless.
|
|
680
689
|
const coverage = { authoritative: true };
|