@openchamber/web 1.24.0 → 1.24.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/bin/cli.test.js +7 -6
- package/bin/lib/cli-http.js +5 -1
- package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
- package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
- package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-D0bM9FVB.js} +6 -6
- package/dist/assets/GitView-Bxuv3dfP.js +6 -0
- package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
- package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-BBVPFM5K.js} +1 -1
- package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-UI1FcSC8.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-D5BZOg8X.js} +1 -1
- package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-5Gou9cGD.js} +1 -1
- package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-C4rE5k6z.js} +1 -1
- package/dist/assets/{PierreDiffViewer-53Ghfnlr.js → PierreDiffViewer-ByRVu6ss.js} +1 -1
- package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-u2yi5XGJ.js} +4 -4
- package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
- package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
- package/dist/assets/SettingsWindow-HVDVANjJ.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-D3hzkybB.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-3J6IRayW.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-DarxPjSd.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
- package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-wSpED5L4.js} +2 -2
- package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-Cf8KitzT.js} +1 -1
- package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
- package/dist/assets/{de-CX_f-T5U.js → de-BM_8EDD3.js} +4 -4
- package/dist/assets/{es-BERmWNn_.js → es-CxZjlqpo.js} +3 -3
- package/dist/assets/{fr-BjYYE_-z.js → fr-VCixCnMW.js} +4 -4
- package/dist/assets/{index-WjufPkIV.js → index-3U4CtS9b.js} +1 -1
- package/dist/assets/index-B9Hvzjwl.css +1 -0
- package/dist/assets/index-DLHQogv8.js +40 -0
- package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
- package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-D_YDVYDb.js} +1 -1
- package/dist/assets/{ja-DxqeAk9N.js → ja-CZ5k_GyD.js} +4 -4
- package/dist/assets/{ko-Dty1aUod.js → ko-7YM3A1Xh.js} +4 -4
- package/dist/assets/{main-Bjcre_GE.js → main-CycplCph.js} +2 -2
- package/dist/assets/main-DFYTCx5o.js +896 -0
- package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
- package/dist/assets/{miniChat-Dz_bPgMc.js → miniChat-DIQKfY2V.js} +2 -2
- package/dist/assets/{mobile-BbZPBJrK.js → mobile-BMwz5q-m.js} +2 -2
- package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
- package/dist/assets/{pl-CX-_ROkr.js → pl-BcgDO_w5.js} +4 -4
- package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-CU2u_1q5.js} +3 -3
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
- package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
- package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
- package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-1imXsir9.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-Dgqc63LZ.js} +1 -1
- package/dist/assets/tr-DuYhOzNe.js +7 -0
- package/dist/assets/{uk-CD21CXFV.js → uk-Cuk7-uvq.js} +3 -3
- package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-BItUWdo4.js} +147 -147
- package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-CkbKsm7m.js} +2 -2
- package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{web-components-U-hWbgJo.js → web-components-D7FinaeH.js} +1 -1
- package/dist/assets/{zh-CN-BWvlPHY-.js → zh-CN-CUWoiRHd.js} +3 -3
- package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-CQ8EBSBN.js} +3 -3
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +4 -3
- package/server/index.js +26 -7
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/git/DOCUMENTATION.md +17 -4
- package/server/lib/git/routes.js +1 -1
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +232 -62
- package/server/lib/git/service.test.js +273 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +5 -3
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/catalog.js +20 -9
- package/server/lib/guests/catalog.test.js +5 -5
- package/server/lib/guests/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +6 -0
- package/server/lib/message-queue/runtime.js +5 -0
- package/server/lib/message-queue/runtime.test.js +32 -1
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-registry.json +8 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/routing/DOCUMENTATION.md +81 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +13 -9
- package/server/lib/ui-auth/ui-auth.test.js +56 -0
- package/dist/assets/DiffView-B7YkbY-u.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
- package/dist/assets/GitView-BLhlMYEY.js +0 -6
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
- package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
- package/dist/assets/index-DpzTz2UH.css +0 -1
- package/dist/assets/index-Dy8xgawx.js +0 -40
- package/dist/assets/main-BOYSXfYn.js +0 -896
- package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
- package/dist/assets/tr-cIQtYBpg.js +0 -7
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import simpleGit from 'simple-git';
|
|
2
|
+
import { createSerialRefresh } from './serial-refresh.js';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import os from 'os';
|
|
5
|
-
import { execFile } from 'child_process';
|
|
6
|
+
import { execFile, spawn } from 'child_process';
|
|
6
7
|
import { promisify } from 'util';
|
|
7
8
|
import { createRequire } from 'module';
|
|
8
9
|
|
|
@@ -349,6 +350,12 @@ const buildGitEnv = async () => {
|
|
|
349
350
|
env.SSH_AUTH_SOCK = resolved;
|
|
350
351
|
}
|
|
351
352
|
}
|
|
353
|
+
// The server has no terminal a user could answer. Without this, Git asks
|
|
354
|
+
// for a username or password on its (hidden, on Windows) console and waits
|
|
355
|
+
// forever; credential helpers and GUI prompts still run before this point.
|
|
356
|
+
if (env.GIT_TERMINAL_PROMPT === undefined) {
|
|
357
|
+
env.GIT_TERMINAL_PROMPT = '0';
|
|
358
|
+
}
|
|
352
359
|
return env;
|
|
353
360
|
};
|
|
354
361
|
|
|
@@ -517,14 +524,16 @@ const GITLINK_MODE = '160000';
|
|
|
517
524
|
// tell these apart by `code`, and diff routes send the code to clients as is.
|
|
518
525
|
const GIT_PATH_NOT_FOUND = 'path_not_found';
|
|
519
526
|
const GIT_PATH_IS_NESTED_REPOSITORY = 'nested_repository';
|
|
527
|
+
const GIT_PATH_IS_UNTRACKED_DIRECTORY = 'untracked_directory';
|
|
520
528
|
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return Object.assign(new Error(message), { code });
|
|
529
|
+
const GIT_PATH_ERROR_MESSAGES = {
|
|
530
|
+
[GIT_PATH_IS_NESTED_REPOSITORY]: (filePath) => `Path is a separate Git repository: ${filePath}`,
|
|
531
|
+
[GIT_PATH_IS_UNTRACKED_DIRECTORY]: (filePath) => `Path is a directory of untracked files: ${filePath}`,
|
|
532
|
+
[GIT_PATH_NOT_FOUND]: (filePath) => `Path not found in working tree, index, or HEAD: ${filePath}`,
|
|
526
533
|
};
|
|
527
534
|
|
|
535
|
+
const createGitPathError = (code, filePath) => Object.assign(new Error(GIT_PATH_ERROR_MESSAGES[code](filePath)), { code });
|
|
536
|
+
|
|
528
537
|
// Mode of the exact entry at `repoPath`, or null. `cat-file -e` cannot answer
|
|
529
538
|
// this: a gitlink's commit lives in the submodule's object store, so git exits 1
|
|
530
539
|
// without stderr, which simple-git reports as success.
|
|
@@ -547,6 +556,7 @@ const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverr
|
|
|
547
556
|
path.resolve(directoryPath, filePath),
|
|
548
557
|
]));
|
|
549
558
|
let nestedRepository = false;
|
|
559
|
+
let untrackedDirectory = false;
|
|
550
560
|
|
|
551
561
|
for (const absolutePath of candidates) {
|
|
552
562
|
if (!isInsideOrSameDirectory(repoRoot, absolutePath)) {
|
|
@@ -570,12 +580,20 @@ const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverr
|
|
|
570
580
|
};
|
|
571
581
|
}
|
|
572
582
|
|
|
573
|
-
if (worktreeEntry?.isDirectory()
|
|
574
|
-
|
|
583
|
+
if (worktreeEntry?.isDirectory()) {
|
|
584
|
+
if (await fsp.lstat(path.join(absolutePath, '.git')).then(() => true, () => false)) {
|
|
585
|
+
nestedRepository = true;
|
|
586
|
+
} else {
|
|
587
|
+
// Status lists a directory whose untracked files were not expanded
|
|
588
|
+
// (see readStatus) as `dir/`; there is no single patch for it.
|
|
589
|
+
untrackedDirectory = true;
|
|
590
|
+
}
|
|
575
591
|
}
|
|
576
592
|
}
|
|
577
593
|
|
|
578
|
-
|
|
594
|
+
if (nestedRepository) throw createGitPathError(GIT_PATH_IS_NESTED_REPOSITORY, filePath);
|
|
595
|
+
if (untrackedDirectory) throw createGitPathError(GIT_PATH_IS_UNTRACKED_DIRECTORY, filePath);
|
|
596
|
+
throw createGitPathError(GIT_PATH_NOT_FOUND, filePath);
|
|
579
597
|
};
|
|
580
598
|
|
|
581
599
|
/**
|
|
@@ -2258,13 +2276,149 @@ export async function setLocalIdentity(directory, profile) {
|
|
|
2258
2276
|
}
|
|
2259
2277
|
}
|
|
2260
2278
|
|
|
2279
|
+
// Beyond this many untracked files, a directory stays one `dir/` entry in
|
|
2280
|
+
// status. Every file would otherwise become a row, a diff request, and a stat
|
|
2281
|
+
// on the server, and the only directories that large are ones that belong in
|
|
2282
|
+
// .gitignore.
|
|
2283
|
+
const UNTRACKED_DIRECTORY_EXPANSION_LIMIT = 1000;
|
|
2284
|
+
|
|
2285
|
+
// Untracked files under `dirPath` (repository-relative, trailing slash), read
|
|
2286
|
+
// from a streamed `ls-files` that is stopped once the bound is exceeded so a
|
|
2287
|
+
// huge directory is never listed in full. `paths` is complete when
|
|
2288
|
+
// `truncated` is false.
|
|
2289
|
+
const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
|
|
2290
|
+
const env = await buildGitEnv();
|
|
2291
|
+
return new Promise((resolve, reject) => {
|
|
2292
|
+
const child = spawn(getGitBinary(), ['ls-files', '--others', '--exclude-standard', '-z', '--', dirPath], {
|
|
2293
|
+
cwd: repoRoot,
|
|
2294
|
+
env,
|
|
2295
|
+
windowsHide: true,
|
|
2296
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
2297
|
+
});
|
|
2298
|
+
const paths = [];
|
|
2299
|
+
let pending = '';
|
|
2300
|
+
let truncated = false;
|
|
2301
|
+
let settled = false;
|
|
2302
|
+
const finish = (error) => {
|
|
2303
|
+
if (settled) return;
|
|
2304
|
+
settled = true;
|
|
2305
|
+
if (error) {
|
|
2306
|
+
reject(error);
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
resolve({ paths, truncated });
|
|
2310
|
+
};
|
|
2311
|
+
child.stdout.on('data', (chunk) => {
|
|
2312
|
+
if (truncated) return;
|
|
2313
|
+
pending += chunk.toString('utf8');
|
|
2314
|
+
const records = pending.split('\0');
|
|
2315
|
+
pending = records.pop() ?? '';
|
|
2316
|
+
for (const record of records) {
|
|
2317
|
+
if (!record) continue;
|
|
2318
|
+
paths.push(record);
|
|
2319
|
+
if (paths.length > limit) {
|
|
2320
|
+
truncated = true;
|
|
2321
|
+
child.kill();
|
|
2322
|
+
finish();
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
child.on('error', (error) => finish(error));
|
|
2328
|
+
child.on('close', (code) => {
|
|
2329
|
+
if (truncated) {
|
|
2330
|
+
finish();
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2333
|
+
if (code !== 0) {
|
|
2334
|
+
finish(new Error(`git ls-files exited with code ${code} for ${dirPath}`));
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
if (pending) paths.push(pending);
|
|
2338
|
+
finish();
|
|
2339
|
+
});
|
|
2340
|
+
});
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
// Replaces each untracked `dir/` entry from `-unormal` with one entry per file
|
|
2344
|
+
// inside it, the listing `-uall` would have produced, unless the directory
|
|
2345
|
+
// holds more than the bound; then the `dir/` entry stays. A nested repository
|
|
2346
|
+
// lists as itself and stays a `dir/` entry too, which is what the diff routes
|
|
2347
|
+
// expect. A listing failure keeps the `dir/` entry rather than dropping the
|
|
2348
|
+
// change from the status.
|
|
2349
|
+
const expandUntrackedDirectories = async (repoRoot, files) => {
|
|
2350
|
+
const expanded = [];
|
|
2351
|
+
for (const file of files) {
|
|
2352
|
+
const isUntrackedDirectory = file.path.endsWith('/')
|
|
2353
|
+
&& (file.working_dir || '').trim() === '?'
|
|
2354
|
+
&& (file.index || '').trim() === '?';
|
|
2355
|
+
if (!isUntrackedDirectory) {
|
|
2356
|
+
expanded.push(file);
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
const listing = await listUntrackedFilesBounded(repoRoot, file.path, UNTRACKED_DIRECTORY_EXPANSION_LIMIT)
|
|
2360
|
+
.catch((error) => {
|
|
2361
|
+
console.warn(`[GitService] Could not expand untracked directory ${file.path}:`, error?.message || error);
|
|
2362
|
+
return null;
|
|
2363
|
+
});
|
|
2364
|
+
if (!listing || listing.truncated || listing.paths.some((entry) => entry === file.path)) {
|
|
2365
|
+
expanded.push(file);
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
for (const entryPath of listing.paths) {
|
|
2369
|
+
expanded.push({ ...file, path: entryPath });
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
return expanded;
|
|
2373
|
+
};
|
|
2374
|
+
|
|
2375
|
+
// A status read walks the working tree and runs a dozen Git processes; on a
|
|
2376
|
+
// large repository it takes seconds. Clients ask for it after every completed
|
|
2377
|
+
// agent tool call, from several surfaces, and from PR polling, so without a
|
|
2378
|
+
// bound one slow repository ends up with many identical `git status` processes
|
|
2379
|
+
// side by side. Runs are serialized per directory and capped across
|
|
2380
|
+
// directories; a caller that asks during a run gets a run started after it
|
|
2381
|
+
// asked, so results are never older than the request.
|
|
2382
|
+
const MAX_CONCURRENT_STATUS_READS = 4;
|
|
2383
|
+
const statusRefresh = createSerialRefresh({ maxConcurrent: MAX_CONCURRENT_STATUS_READS });
|
|
2384
|
+
|
|
2261
2385
|
export async function getStatus(directory, options = {}) {
|
|
2262
|
-
const lightMode = options.mode === 'light';
|
|
2263
2386
|
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2264
2387
|
if (typeof normalizedDirectory !== 'string' || !normalizedDirectory.trim()) {
|
|
2265
2388
|
throw new Error('directory is required');
|
|
2266
2389
|
}
|
|
2390
|
+
const lightMode = options.mode === 'light';
|
|
2391
|
+
// A full read satisfies light callers too, so one run serves whichever
|
|
2392
|
+
// callers it answers, at the widest mode any of them asked for.
|
|
2393
|
+
return statusRefresh.run(
|
|
2394
|
+
normalizedDirectory,
|
|
2395
|
+
{ lightMode },
|
|
2396
|
+
(requests) => readStatus(normalizedDirectory, requests.every((request) => request.lightMode)),
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2267
2399
|
|
|
2400
|
+
/**
|
|
2401
|
+
* Upstream of the checked-out branch as `remote/branch`, or `null` when HEAD
|
|
2402
|
+
* is detached, unborn, or the branch has no upstream configured. Reads refs
|
|
2403
|
+
* and config only, never the working tree: callers that only need the
|
|
2404
|
+
* tracking name must not pay for a status read.
|
|
2405
|
+
*/
|
|
2406
|
+
export async function getTrackingBranch(directory) {
|
|
2407
|
+
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2408
|
+
if (!normalizedDirectory) {
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
const head = await runGitCommand(normalizedDirectory, ['symbolic-ref', '--quiet', 'HEAD']);
|
|
2412
|
+
const headRef = head.success ? head.stdout.trim() : '';
|
|
2413
|
+
if (!headRef.startsWith('refs/heads/')) {
|
|
2414
|
+
return null;
|
|
2415
|
+
}
|
|
2416
|
+
const upstream = await runGitCommand(normalizedDirectory, ['for-each-ref', '--format=%(upstream:short)', headRef]);
|
|
2417
|
+
const tracking = upstream.success ? upstream.stdout.trim() : '';
|
|
2418
|
+
return tracking || null;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
async function readStatus(normalizedDirectory, lightMode) {
|
|
2268
2422
|
try {
|
|
2269
2423
|
// Prefer an explicit non-repo check before simple-git status so a missing
|
|
2270
2424
|
// repository never depends on process.cwd() or an opaque GitError shape.
|
|
@@ -2274,10 +2428,18 @@ export async function getStatus(directory, options = {}) {
|
|
|
2274
2428
|
|
|
2275
2429
|
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory);
|
|
2276
2430
|
|
|
2277
|
-
//
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
//
|
|
2431
|
+
// `-unormal` lists a directory with no tracked files as one `dir/` entry
|
|
2432
|
+
// and stops walking it at its first file. `-uall` would walk every file
|
|
2433
|
+
// in it: on a forgotten build or dependency directory that is a scan of
|
|
2434
|
+
// tens of thousands of files and hundreds of megabytes per status read.
|
|
2435
|
+
// Directories are expanded to their files afterwards, up to a bound.
|
|
2436
|
+
const status = await git.status(['-unormal']);
|
|
2437
|
+
status.files = await expandUntrackedDirectories(repoRoot, status.files);
|
|
2438
|
+
|
|
2439
|
+
// Light mode: skip numstat + new-file line counting for faster response.
|
|
2440
|
+
// Staged (`--cached`: HEAD -> index) and working (`--numstat`: index -> worktree)
|
|
2441
|
+
// stay in separate maps. A partially staged file has an entry in both, and the
|
|
2442
|
+
// UI shows each row's own scope instead of a combined total.
|
|
2281
2443
|
const [stagedStatsRaw, workingStatsRaw] = lightMode
|
|
2282
2444
|
? ['', '']
|
|
2283
2445
|
: await Promise.all([
|
|
@@ -2285,9 +2447,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2285
2447
|
git.raw(['diff', '--numstat']).catch(() => ''),
|
|
2286
2448
|
]);
|
|
2287
2449
|
|
|
2288
|
-
const
|
|
2450
|
+
const stagedDiffStats = {};
|
|
2451
|
+
const workingDiffStats = {};
|
|
2289
2452
|
|
|
2290
|
-
const accumulateStats = (raw) => {
|
|
2453
|
+
const accumulateStats = (raw, target) => {
|
|
2291
2454
|
if (!raw) return;
|
|
2292
2455
|
raw
|
|
2293
2456
|
.split('\n')
|
|
@@ -2306,18 +2469,18 @@ export async function getStatus(directory, options = {}) {
|
|
|
2306
2469
|
const insertions = insertionsRaw === '-' ? 0 : parseInt(insertionsRaw, 10) || 0;
|
|
2307
2470
|
const deletions = deletionsRaw === '-' ? 0 : parseInt(deletionsRaw, 10) || 0;
|
|
2308
2471
|
|
|
2309
|
-
const existing =
|
|
2310
|
-
|
|
2472
|
+
const existing = target[path] || { insertions: 0, deletions: 0 };
|
|
2473
|
+
target[path] = {
|
|
2311
2474
|
insertions: existing.insertions + insertions,
|
|
2312
2475
|
deletions: existing.deletions + deletions,
|
|
2313
|
-
}
|
|
2476
|
+
};
|
|
2314
2477
|
});
|
|
2315
2478
|
};
|
|
2316
2479
|
|
|
2317
|
-
accumulateStats(stagedStatsRaw);
|
|
2318
|
-
accumulateStats(workingStatsRaw);
|
|
2480
|
+
accumulateStats(stagedStatsRaw, stagedDiffStats);
|
|
2481
|
+
accumulateStats(workingStatsRaw, workingDiffStats);
|
|
2319
2482
|
|
|
2320
|
-
const diffStats =
|
|
2483
|
+
const diffStats = { staged: stagedDiffStats, working: workingDiffStats };
|
|
2321
2484
|
|
|
2322
2485
|
const MAX_NEW_FILE_STATS = 200;
|
|
2323
2486
|
const MAX_NEW_FILE_STAT_SIZE = 1024 * 1024;
|
|
@@ -2337,7 +2500,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2337
2500
|
continue;
|
|
2338
2501
|
}
|
|
2339
2502
|
|
|
2340
|
-
|
|
2503
|
+
// Untracked and working-tree-added files belong to the working scope;
|
|
2504
|
+
// a file whose 'A' code is on the index belongs to the staged scope.
|
|
2505
|
+
const target = working === '?' || working === 'A' ? workingDiffStats : stagedDiffStats;
|
|
2506
|
+
const existing = target[file.path];
|
|
2341
2507
|
if (existing && existing.insertions > 0) {
|
|
2342
2508
|
continue;
|
|
2343
2509
|
}
|
|
@@ -2353,6 +2519,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2353
2519
|
const buffer = await fsp.readFile(absolutePath);
|
|
2354
2520
|
if (buffer.indexOf(0) !== -1) {
|
|
2355
2521
|
newFileStats.push({
|
|
2522
|
+
target,
|
|
2356
2523
|
path: file.path,
|
|
2357
2524
|
insertions: existing?.insertions ?? 0,
|
|
2358
2525
|
deletions: existing?.deletions ?? 0,
|
|
@@ -2363,6 +2530,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2363
2530
|
const normalized = buffer.toString('utf8').replace(/\r\n/g, '\n');
|
|
2364
2531
|
if (!normalized.length) {
|
|
2365
2532
|
newFileStats.push({
|
|
2533
|
+
target,
|
|
2366
2534
|
path: file.path,
|
|
2367
2535
|
insertions: 0,
|
|
2368
2536
|
deletions: 0,
|
|
@@ -2377,6 +2545,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2377
2545
|
|
|
2378
2546
|
const lineCount = segments.length;
|
|
2379
2547
|
newFileStats.push({
|
|
2548
|
+
target,
|
|
2380
2549
|
path: file.path,
|
|
2381
2550
|
insertions: lineCount,
|
|
2382
2551
|
deletions: 0,
|
|
@@ -2390,7 +2559,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2390
2559
|
}
|
|
2391
2560
|
|
|
2392
2561
|
for (const entry of newFileStats) {
|
|
2393
|
-
|
|
2562
|
+
entry.target[entry.path] = {
|
|
2394
2563
|
insertions: entry.insertions,
|
|
2395
2564
|
deletions: entry.deletions,
|
|
2396
2565
|
};
|
|
@@ -3450,26 +3619,45 @@ export async function push(directory, options = {}) {
|
|
|
3450
3619
|
);
|
|
3451
3620
|
};
|
|
3452
3621
|
|
|
3453
|
-
const
|
|
3622
|
+
const remote = String(options.remote || '').trim();
|
|
3623
|
+
const status = await git.status();
|
|
3624
|
+
const config = await git.listConfig();
|
|
3625
|
+
const remotes = await git.getRemotes(true);
|
|
3626
|
+
const remoteName = remote
|
|
3627
|
+
|| config.all[`branch.${status.current}.pushremote`]
|
|
3628
|
+
|| config.all['remote.pushdefault']
|
|
3629
|
+
|| config.all[`branch.${status.current}.remote`]
|
|
3630
|
+
|| (remotes.length === 1 ? remotes[0].name : 'origin');
|
|
3631
|
+
|
|
3632
|
+
const pushTo = async (target, branch, pushOptions) => {
|
|
3633
|
+
// simple-git drops forced updates and puts no-ops in `pushed`. Read Git's
|
|
3634
|
+
// porcelain status flags so feedback reflects actual remote ref changes.
|
|
3635
|
+
let output = '';
|
|
3636
|
+
git.outputHandler((_command, stdout) => {
|
|
3637
|
+
stdout.on('data', (chunk) => { output += chunk.toString(); });
|
|
3638
|
+
});
|
|
3639
|
+
const result = await git.push(target, branch, pushOptions);
|
|
3640
|
+
const pushed = [];
|
|
3641
|
+
for (const line of output.split(/\r?\n/)) {
|
|
3642
|
+
const match = /^([ *+\-])\t([^:]*):([^\t]+)\t/.exec(line);
|
|
3643
|
+
if (match) {
|
|
3644
|
+
pushed.push({ local: match[2], remote: remoteName });
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3454
3647
|
return {
|
|
3455
3648
|
success: true,
|
|
3456
|
-
pushed
|
|
3457
|
-
repo: result.repo,
|
|
3458
|
-
ref: result.ref,
|
|
3649
|
+
pushed,
|
|
3650
|
+
repo: result.repo || directory,
|
|
3651
|
+
ref: result.ref || null,
|
|
3459
3652
|
};
|
|
3460
3653
|
};
|
|
3461
3654
|
|
|
3462
|
-
const remote = String(options.remote || '').trim();
|
|
3463
|
-
|
|
3464
3655
|
if (!remote && !options.branch) {
|
|
3465
3656
|
try {
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
repo: directory,
|
|
3471
|
-
ref: null,
|
|
3472
|
-
};
|
|
3657
|
+
const pushOptions = status.current && !status.tracking
|
|
3658
|
+
? buildUpstreamOptions(options.options)
|
|
3659
|
+
: options.options || {};
|
|
3660
|
+
return await pushTo(undefined, undefined, pushOptions);
|
|
3473
3661
|
} catch (error) {
|
|
3474
3662
|
if (!looksLikeMissingUpstream(error)) {
|
|
3475
3663
|
const message = describePushError(error);
|
|
@@ -3478,17 +3666,13 @@ export async function push(directory, options = {}) {
|
|
|
3478
3666
|
}
|
|
3479
3667
|
|
|
3480
3668
|
try {
|
|
3481
|
-
const status = await git.status();
|
|
3482
3669
|
const branch = status.current;
|
|
3483
|
-
|
|
3484
|
-
const fallbackRemote = remotes.find((entry) => entry.name === 'origin')?.name || remotes[0]?.name;
|
|
3485
|
-
if (!branch || !fallbackRemote) {
|
|
3670
|
+
if (!branch || !remoteName) {
|
|
3486
3671
|
const message = describePushError(error);
|
|
3487
3672
|
throw new Error(message);
|
|
3488
3673
|
}
|
|
3489
3674
|
|
|
3490
|
-
|
|
3491
|
-
return normalizePushResult(result);
|
|
3675
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3492
3676
|
} catch (fallbackError) {
|
|
3493
3677
|
const message = describePushError(fallbackError);
|
|
3494
3678
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -3497,26 +3681,14 @@ export async function push(directory, options = {}) {
|
|
|
3497
3681
|
}
|
|
3498
3682
|
}
|
|
3499
3683
|
|
|
3500
|
-
const remoteName = remote || 'origin';
|
|
3501
|
-
|
|
3502
3684
|
// If caller didn't specify a branch, this is the common "Push"/"Commit & Push" path.
|
|
3503
3685
|
// When there's no upstream yet (typical for freshly-created worktree branches), publish it on first push.
|
|
3504
|
-
if (!options.branch) {
|
|
3505
|
-
|
|
3506
|
-
const status = await git.status();
|
|
3507
|
-
if (status.current && !status.tracking) {
|
|
3508
|
-
const result = await git.push(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3509
|
-
return normalizePushResult(result);
|
|
3510
|
-
}
|
|
3511
|
-
} catch (error) {
|
|
3512
|
-
// If we can't read status, fall back to the regular push path below.
|
|
3513
|
-
console.warn('Failed to read git status before push:', error);
|
|
3514
|
-
}
|
|
3686
|
+
if (!options.branch && status.current && !status.tracking) {
|
|
3687
|
+
return pushTo(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3515
3688
|
}
|
|
3516
3689
|
|
|
3517
3690
|
try {
|
|
3518
|
-
|
|
3519
|
-
return normalizePushResult(result);
|
|
3691
|
+
return await pushTo(remoteName, options.branch, options.options || {});
|
|
3520
3692
|
} catch (error) {
|
|
3521
3693
|
// Last-resort fallback: retry with upstream if the error suggests it's missing.
|
|
3522
3694
|
if (!looksLikeMissingUpstream(error)) {
|
|
@@ -3526,15 +3698,13 @@ export async function push(directory, options = {}) {
|
|
|
3526
3698
|
}
|
|
3527
3699
|
|
|
3528
3700
|
try {
|
|
3529
|
-
const status = await git.status();
|
|
3530
3701
|
const branch = options.branch || status.current;
|
|
3531
3702
|
if (!branch) {
|
|
3532
3703
|
console.error('Failed to push: missing branch name for upstream setup:', error);
|
|
3533
3704
|
throw error;
|
|
3534
3705
|
}
|
|
3535
3706
|
|
|
3536
|
-
|
|
3537
|
-
return normalizePushResult(result);
|
|
3707
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3538
3708
|
} catch (fallbackError) {
|
|
3539
3709
|
const message = describePushError(fallbackError);
|
|
3540
3710
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -5161,7 +5331,7 @@ export async function canonicalizeWorktreeState(directory) {
|
|
|
5161
5331
|
|
|
5162
5332
|
// Detect attention reasons from getStatus side-effects
|
|
5163
5333
|
try {
|
|
5164
|
-
const status = await git.status(['-
|
|
5334
|
+
const status = await git.status(['-unormal']);
|
|
5165
5335
|
if (status.current && (await git.raw(['rev-parse', '--verify', 'MERGE_HEAD']).then(() => true).catch(() => false))) {
|
|
5166
5336
|
attentionReason = 'merge';
|
|
5167
5337
|
} else {
|