@firstpick/pi-package-webui 0.11.1 → 0.11.3
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/DEVELOPMENT.md +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +4 -4
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3886
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +322 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +21 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { platform } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathInside } from "../git-worktrees.mjs";
|
|
6
|
+
|
|
7
|
+
const FILE_VIEWER_MAX_BYTES = 2 * 1024 * 1024;
|
|
8
|
+
export const FILE_VIEWER_BODY_LIMIT_BYTES = FILE_VIEWER_MAX_BYTES + 64 * 1024;
|
|
9
|
+
const FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION = Object.freeze({
|
|
10
|
+
".png": "image/png",
|
|
11
|
+
".jpg": "image/jpeg",
|
|
12
|
+
".jpeg": "image/jpeg",
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".webp": "image/webp",
|
|
15
|
+
".avif": "image/avif",
|
|
16
|
+
});
|
|
17
|
+
const FILE_TREE_MAX_ENTRIES = 1200;
|
|
18
|
+
const FILE_TREE_ENTRY_STAT_CONCURRENCY = 32;
|
|
19
|
+
const FILE_SEARCH_MAX_RESULTS = 200;
|
|
20
|
+
const FILE_SEARCH_MAX_SCANNED = 12_000;
|
|
21
|
+
const FILE_SEARCH_MAX_DEPTH = 8;
|
|
22
|
+
const FILE_SEARCH_EXCLUDED_DIRS = new Set([".git", "node_modules"]);
|
|
23
|
+
|
|
24
|
+
export function createWorkspaceFilesService({
|
|
25
|
+
defaultCwd,
|
|
26
|
+
makeHttpError,
|
|
27
|
+
displayPath,
|
|
28
|
+
formatBytes,
|
|
29
|
+
sanitizeError,
|
|
30
|
+
runCommand,
|
|
31
|
+
isLikelyBinaryBuffer,
|
|
32
|
+
getGitRoot,
|
|
33
|
+
readWorkspaceGitStatusIndex,
|
|
34
|
+
readWorkspaceGitIgnoredPaths,
|
|
35
|
+
withFileTreeGitStatus,
|
|
36
|
+
withFileTreeGitIgnored,
|
|
37
|
+
fileTreeGitStatusPayload,
|
|
38
|
+
}) {
|
|
39
|
+
async function workspaceRoot(tab) {
|
|
40
|
+
const root = path.resolve(tab?.cwd || defaultCwd);
|
|
41
|
+
return { root, realRoot: await realpath(root).catch(() => root) };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function resolveWorkspacePath(tab, value = "", { mustExist = true } = {}) {
|
|
45
|
+
const { root, realRoot } = await workspaceRoot(tab);
|
|
46
|
+
const text = String(value || "").trim();
|
|
47
|
+
if (text.includes("\0")) throw makeHttpError(400, "Path cannot contain null bytes");
|
|
48
|
+
const targetPath = text ? (path.isAbsolute(text) ? path.resolve(text) : path.resolve(root, text)) : root;
|
|
49
|
+
if (targetPath !== root && !pathInside(root, targetPath)) throw makeHttpError(403, "Path must stay inside the active tab working directory");
|
|
50
|
+
let info = null;
|
|
51
|
+
let realTarget = targetPath;
|
|
52
|
+
try {
|
|
53
|
+
info = await stat(targetPath);
|
|
54
|
+
realTarget = await realpath(targetPath).catch(() => targetPath);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (mustExist) throw makeHttpError(error?.code === "ENOENT" ? 404 : 400, `Path not found: ${displayPath(targetPath)}`);
|
|
57
|
+
}
|
|
58
|
+
if (realTarget !== realRoot && !pathInside(realRoot, realTarget)) throw makeHttpError(403, "Resolved path escapes the active tab working directory");
|
|
59
|
+
const relative = path.relative(root, targetPath).split(path.sep).join("/");
|
|
60
|
+
return { root, realRoot, targetPath, realTarget, relative, info };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function fileViewerLanguage(filePath) {
|
|
64
|
+
const ext = path.extname(String(filePath || "")).toLowerCase();
|
|
65
|
+
if (ext === ".md" || ext === ".markdown") return "markdown";
|
|
66
|
+
return "text";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function fileViewerImageMimeType(filePath) {
|
|
70
|
+
return FILE_VIEWER_IMAGE_MIME_TYPES_BY_EXTENSION[path.extname(String(filePath || "")).toLowerCase()] || "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function fileTreeEntryType(dirent, info) {
|
|
74
|
+
if (info?.isDirectory?.() || dirent?.isDirectory?.()) return "directory";
|
|
75
|
+
if (info?.isFile?.() || dirent?.isFile?.()) return "file";
|
|
76
|
+
return dirent?.isSymbolicLink?.() ? "symlink" : "other";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function statFileTreeEntries(dirPath, dirents, root, realRoot) {
|
|
80
|
+
const ordered = [...dirents].sort((a, b) => {
|
|
81
|
+
const aRank = a.isDirectory() ? 0 : a.isFile() ? 1 : 2;
|
|
82
|
+
const bRank = b.isDirectory() ? 0 : b.isFile() ? 1 : 2;
|
|
83
|
+
return aRank - bRank || a.name.localeCompare(b.name);
|
|
84
|
+
});
|
|
85
|
+
const selected = ordered.slice(0, FILE_TREE_MAX_ENTRIES);
|
|
86
|
+
const entries = [];
|
|
87
|
+
let cursor = 0;
|
|
88
|
+
async function worker() {
|
|
89
|
+
while (cursor < selected.length) {
|
|
90
|
+
const dirent = selected[cursor++];
|
|
91
|
+
const targetPath = path.join(dirPath, dirent.name);
|
|
92
|
+
const relative = path.relative(root, targetPath).split(path.sep).join("/");
|
|
93
|
+
try {
|
|
94
|
+
const [info, realTarget] = await Promise.all([stat(targetPath), realpath(targetPath).catch(() => targetPath)]);
|
|
95
|
+
const outsideRoot = realTarget !== realRoot && !pathInside(realRoot, realTarget);
|
|
96
|
+
const type = outsideRoot ? "other" : fileTreeEntryType(dirent, info);
|
|
97
|
+
entries.push({
|
|
98
|
+
name: dirent.name,
|
|
99
|
+
path: relative,
|
|
100
|
+
type,
|
|
101
|
+
directory: type === "directory",
|
|
102
|
+
file: type === "file",
|
|
103
|
+
symlink: dirent.isSymbolicLink(),
|
|
104
|
+
outsideRoot,
|
|
105
|
+
size: info.size,
|
|
106
|
+
mtimeMs: info.mtimeMs,
|
|
107
|
+
extension: path.extname(dirent.name).toLowerCase(),
|
|
108
|
+
canOpenInWebui: type === "file",
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
entries.push({ name: dirent.name, path: relative, type: "error", directory: false, file: false, error: sanitizeError(error), canOpenInWebui: false });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const workers = Array.from({ length: Math.min(FILE_TREE_ENTRY_STAT_CONCURRENCY, selected.length) }, () => worker());
|
|
116
|
+
await Promise.all(workers);
|
|
117
|
+
entries.sort((a, b) => {
|
|
118
|
+
const aRank = a.type === "directory" ? 0 : a.type === "file" ? 1 : 2;
|
|
119
|
+
const bRank = b.type === "directory" ? 0 : b.type === "file" ? 1 : 2;
|
|
120
|
+
return aRank - bRank || a.name.localeCompare(b.name);
|
|
121
|
+
});
|
|
122
|
+
return { entries, truncated: ordered.length > selected.length, total: ordered.length };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function getFileTreeData(tab, requestedPath = "") {
|
|
126
|
+
const resolved = await resolveWorkspacePath(tab, requestedPath);
|
|
127
|
+
if (!resolved.info?.isDirectory()) throw makeHttpError(400, "Path is not a directory");
|
|
128
|
+
const dirents = await readdir(resolved.targetPath, { withFileTypes: true });
|
|
129
|
+
const [listed, gitStatus] = await Promise.all([
|
|
130
|
+
statFileTreeEntries(resolved.targetPath, dirents, resolved.root, resolved.realRoot),
|
|
131
|
+
readWorkspaceGitStatusIndex(resolved.root),
|
|
132
|
+
]);
|
|
133
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, listed.entries, gitStatus?.root);
|
|
134
|
+
return {
|
|
135
|
+
root: resolved.root,
|
|
136
|
+
displayRoot: displayPath(resolved.root),
|
|
137
|
+
path: resolved.relative,
|
|
138
|
+
displayPath: displayPath(resolved.targetPath),
|
|
139
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(listed.entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
140
|
+
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
141
|
+
truncated: listed.truncated,
|
|
142
|
+
total: listed.total,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function normalizeFileSearchQuery(value = "") {
|
|
147
|
+
const query = String(value || "").trim().replace(/\s+/g, " ");
|
|
148
|
+
if (query.includes("\0")) throw makeHttpError(400, "Search query cannot contain null bytes");
|
|
149
|
+
if (query.length > 160) throw makeHttpError(400, "Search query is too long");
|
|
150
|
+
return query;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function fileSearchMatches(entry, queryLower) {
|
|
154
|
+
const name = String(entry.name || "").toLowerCase();
|
|
155
|
+
const filePath = String(entry.path || "").toLowerCase();
|
|
156
|
+
return name.includes(queryLower) || filePath.includes(queryLower);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function getFileSearchData(tab, rawQuery = "") {
|
|
160
|
+
const query = normalizeFileSearchQuery(rawQuery);
|
|
161
|
+
if (!query) {
|
|
162
|
+
const root = path.resolve(tab?.cwd || defaultCwd);
|
|
163
|
+
return { root, displayRoot: displayPath(root), query, entries: [], truncated: false, total: 0, scanned: 0, maxDepth: FILE_SEARCH_MAX_DEPTH };
|
|
164
|
+
}
|
|
165
|
+
const resolved = await resolveWorkspacePath(tab, "");
|
|
166
|
+
if (!resolved.info?.isDirectory()) throw makeHttpError(400, "Workspace root is not a directory");
|
|
167
|
+
const gitStatus = await readWorkspaceGitStatusIndex(resolved.root);
|
|
168
|
+
const queryLower = query.toLowerCase();
|
|
169
|
+
const entries = [];
|
|
170
|
+
const queue = [{ dirPath: resolved.root, relative: "", depth: 0 }];
|
|
171
|
+
const visitedRealDirs = new Set([resolved.realRoot]);
|
|
172
|
+
let scanned = 0;
|
|
173
|
+
let truncated = false;
|
|
174
|
+
|
|
175
|
+
while (queue.length && scanned < FILE_SEARCH_MAX_SCANNED && entries.length < FILE_SEARCH_MAX_RESULTS) {
|
|
176
|
+
const current = queue.shift();
|
|
177
|
+
let dirents = [];
|
|
178
|
+
try {
|
|
179
|
+
dirents = await readdir(current.dirPath, { withFileTypes: true });
|
|
180
|
+
} catch {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
dirents.sort((a, b) => {
|
|
184
|
+
const aRank = a.isDirectory() ? 0 : a.isFile() ? 1 : 2;
|
|
185
|
+
const bRank = b.isDirectory() ? 0 : b.isFile() ? 1 : 2;
|
|
186
|
+
return aRank - bRank || a.name.localeCompare(b.name);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
for (const dirent of dirents) {
|
|
190
|
+
if (scanned >= FILE_SEARCH_MAX_SCANNED || entries.length >= FILE_SEARCH_MAX_RESULTS) break;
|
|
191
|
+
scanned += 1;
|
|
192
|
+
const targetPath = path.join(current.dirPath, dirent.name);
|
|
193
|
+
const relative = (current.relative ? `${current.relative}/${dirent.name}` : dirent.name).split(path.sep).join("/");
|
|
194
|
+
const depth = current.depth + 1;
|
|
195
|
+
try {
|
|
196
|
+
const [info, realTarget] = await Promise.all([stat(targetPath), realpath(targetPath).catch(() => targetPath)]);
|
|
197
|
+
const outsideRoot = realTarget !== resolved.realRoot && !pathInside(resolved.realRoot, realTarget);
|
|
198
|
+
const type = outsideRoot ? "other" : fileTreeEntryType(dirent, info);
|
|
199
|
+
const entry = {
|
|
200
|
+
name: dirent.name,
|
|
201
|
+
path: relative,
|
|
202
|
+
type,
|
|
203
|
+
directory: type === "directory",
|
|
204
|
+
file: type === "file",
|
|
205
|
+
symlink: dirent.isSymbolicLink(),
|
|
206
|
+
outsideRoot,
|
|
207
|
+
size: info.size,
|
|
208
|
+
mtimeMs: info.mtimeMs,
|
|
209
|
+
extension: path.extname(dirent.name).toLowerCase(),
|
|
210
|
+
depth,
|
|
211
|
+
canOpenInWebui: type === "file",
|
|
212
|
+
};
|
|
213
|
+
if (fileSearchMatches(entry, queryLower)) entries.push(entry);
|
|
214
|
+
if (depth < FILE_SEARCH_MAX_DEPTH && type === "directory" && !FILE_SEARCH_EXCLUDED_DIRS.has(dirent.name) && !visitedRealDirs.has(realTarget)) {
|
|
215
|
+
visitedRealDirs.add(realTarget);
|
|
216
|
+
queue.push({ dirPath: targetPath, relative, depth });
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
const entry = { name: dirent.name, path: relative, type: "error", directory: false, file: false, depth, error: sanitizeError(error), canOpenInWebui: false };
|
|
220
|
+
if (fileSearchMatches(entry, queryLower)) entries.push(entry);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
truncated = queue.length > 0 || scanned >= FILE_SEARCH_MAX_SCANNED || entries.length >= FILE_SEARCH_MAX_RESULTS;
|
|
225
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, entries, gitStatus?.root);
|
|
226
|
+
return {
|
|
227
|
+
root: resolved.root,
|
|
228
|
+
displayRoot: displayPath(resolved.root),
|
|
229
|
+
query,
|
|
230
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
231
|
+
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
232
|
+
truncated,
|
|
233
|
+
total: entries.length,
|
|
234
|
+
scanned,
|
|
235
|
+
maxDepth: FILE_SEARCH_MAX_DEPTH,
|
|
236
|
+
excludedDirs: [...FILE_SEARCH_EXCLUDED_DIRS],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function assertTextFileBuffer(buffer) {
|
|
241
|
+
if (isLikelyBinaryBuffer(buffer)) throw makeHttpError(415, "File appears to be binary; only text files and supported raster images can be opened in WebUI");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function getFileContentData(tab, requestedPath = "") {
|
|
245
|
+
const resolved = await resolveWorkspacePath(tab, requestedPath);
|
|
246
|
+
if (!resolved.info?.isFile()) throw makeHttpError(400, "Path is not a regular file");
|
|
247
|
+
if (resolved.info.size > FILE_VIEWER_MAX_BYTES) throw makeHttpError(413, `File is too large to open in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
248
|
+
const buffer = await readFile(resolved.targetPath);
|
|
249
|
+
const extension = path.extname(resolved.targetPath).toLowerCase();
|
|
250
|
+
const imageMimeType = fileViewerImageMimeType(resolved.targetPath);
|
|
251
|
+
const shared = {
|
|
252
|
+
root: resolved.root,
|
|
253
|
+
path: resolved.relative,
|
|
254
|
+
name: path.basename(resolved.targetPath),
|
|
255
|
+
size: resolved.info.size,
|
|
256
|
+
mtimeMs: resolved.info.mtimeMs,
|
|
257
|
+
extension,
|
|
258
|
+
};
|
|
259
|
+
if (imageMimeType) {
|
|
260
|
+
return { ...shared, kind: "image", mimeType: imageMimeType, data: buffer.toString("base64") };
|
|
261
|
+
}
|
|
262
|
+
assertTextFileBuffer(buffer);
|
|
263
|
+
return { ...shared, kind: "text", content: buffer.toString("utf8"), language: fileViewerLanguage(resolved.targetPath) };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function aurReviewReportPathSegments(value = "") {
|
|
267
|
+
const requested = String(value || "").trim();
|
|
268
|
+
if (!requested || requested.length > 1024 || requested.includes("\0")) throw makeHttpError(400, "Report path must be a non-empty repo-root-relative path");
|
|
269
|
+
if (path.isAbsolute(requested) || path.win32.isAbsolute(requested) || requested.includes("\\")) {
|
|
270
|
+
throw makeHttpError(400, "Report path must be a repo-root-relative path");
|
|
271
|
+
}
|
|
272
|
+
const segments = requested.split("/");
|
|
273
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) {
|
|
274
|
+
throw makeHttpError(400, "Report path cannot contain traversal segments");
|
|
275
|
+
}
|
|
276
|
+
return segments;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function canonicalGitRootForTab(tab) {
|
|
280
|
+
const root = await getGitRoot(tab.cwd);
|
|
281
|
+
try {
|
|
282
|
+
return await realpath(root);
|
|
283
|
+
} catch {
|
|
284
|
+
throw makeHttpError(404, "Git repository root is no longer accessible");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function readBoundedAurReviewReport(targetPath) {
|
|
289
|
+
const handle = await open(targetPath, "r");
|
|
290
|
+
try {
|
|
291
|
+
const info = await handle.stat();
|
|
292
|
+
if (!info.isFile()) throw makeHttpError(400, "Report path is not a regular file");
|
|
293
|
+
if (info.size > FILE_VIEWER_MAX_BYTES) throw makeHttpError(413, `Report is too large to open in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
294
|
+
const chunks = [];
|
|
295
|
+
let total = 0;
|
|
296
|
+
while (true) {
|
|
297
|
+
const remaining = FILE_VIEWER_MAX_BYTES + 1 - total;
|
|
298
|
+
if (remaining <= 0) throw makeHttpError(413, `Report is too large to open in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
299
|
+
const chunk = Buffer.allocUnsafe(Math.min(64 * 1024, remaining));
|
|
300
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, total);
|
|
301
|
+
if (bytesRead === 0) break;
|
|
302
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
303
|
+
total += bytesRead;
|
|
304
|
+
}
|
|
305
|
+
return { buffer: Buffer.concat(chunks, total), info };
|
|
306
|
+
} finally {
|
|
307
|
+
await handle.close().catch(() => {});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Read-only AUR-review report access rooted at the tab's canonical Git root. */
|
|
312
|
+
async function getAurReviewReportContentData(tab, { path: requestedPath = "", repoRoot = "" } = {}) {
|
|
313
|
+
if (typeof repoRoot !== "string" || !repoRoot || repoRoot.includes("\0")) {
|
|
314
|
+
throw makeHttpError(400, "repoRoot is required for an AUR review report");
|
|
315
|
+
}
|
|
316
|
+
const root = await canonicalGitRootForTab(tab);
|
|
317
|
+
if (repoRoot !== root) throw makeHttpError(403, "Report repoRoot does not match this tab's canonical Git root");
|
|
318
|
+
const segments = aurReviewReportPathSegments(requestedPath);
|
|
319
|
+
let targetPath = root;
|
|
320
|
+
let info;
|
|
321
|
+
for (const [index, segment] of segments.entries()) {
|
|
322
|
+
targetPath = path.join(targetPath, segment);
|
|
323
|
+
try {
|
|
324
|
+
info = await lstat(targetPath);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
throw makeHttpError(error?.code === "ENOENT" ? 404 : 400, `Report path not found: ${segments.join("/")}`);
|
|
327
|
+
}
|
|
328
|
+
if (info.isSymbolicLink()) throw makeHttpError(403, "Report path cannot contain symlinks");
|
|
329
|
+
if (index < segments.length - 1 && !info.isDirectory()) throw makeHttpError(400, "Report path contains a non-directory component");
|
|
330
|
+
}
|
|
331
|
+
if (!info?.isFile()) throw makeHttpError(400, "Report path is not a regular file");
|
|
332
|
+
const realTarget = await realpath(targetPath).catch(() => "");
|
|
333
|
+
if (!realTarget || !pathInside(root, realTarget)) throw makeHttpError(403, "Resolved report path escapes the canonical Git root");
|
|
334
|
+
const opened = await readBoundedAurReviewReport(targetPath);
|
|
335
|
+
assertTextFileBuffer(opened.buffer);
|
|
336
|
+
return {
|
|
337
|
+
root,
|
|
338
|
+
path: segments.join("/"),
|
|
339
|
+
name: path.basename(targetPath),
|
|
340
|
+
content: opened.buffer.toString("utf8"),
|
|
341
|
+
size: opened.buffer.length,
|
|
342
|
+
mtimeMs: opened.info.mtimeMs,
|
|
343
|
+
extension: path.extname(targetPath).toLowerCase(),
|
|
344
|
+
language: fileViewerLanguage(targetPath),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function saveFileContentData(tab, body = {}) {
|
|
349
|
+
if (typeof body.content !== "string") throw makeHttpError(400, "File content must be a string");
|
|
350
|
+
if (body.content.includes("\0")) throw makeHttpError(400, "File content cannot contain null bytes");
|
|
351
|
+
if (Buffer.byteLength(body.content, "utf8") > FILE_VIEWER_MAX_BYTES) throw makeHttpError(413, `File is too large to save in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
352
|
+
const resolved = await resolveWorkspacePath(tab, body.path || body.filePath || "");
|
|
353
|
+
if (!resolved.info?.isFile()) throw makeHttpError(400, "Path is not a regular file");
|
|
354
|
+
if (resolved.info.size > FILE_VIEWER_MAX_BYTES) throw makeHttpError(413, `File is too large to save in WebUI (limit ${formatBytes(FILE_VIEWER_MAX_BYTES)})`);
|
|
355
|
+
assertTextFileBuffer(await readFile(resolved.targetPath));
|
|
356
|
+
const expectedMtimeMs = Number(body.mtimeMs);
|
|
357
|
+
if (Number.isFinite(expectedMtimeMs) && Math.abs(resolved.info.mtimeMs - expectedMtimeMs) > 5) {
|
|
358
|
+
throw makeHttpError(409, "File changed on disk after it was opened. Reopen it before saving.");
|
|
359
|
+
}
|
|
360
|
+
const tmpFile = `${resolved.targetPath}.${process.pid}.${Date.now()}.tmp`;
|
|
361
|
+
try {
|
|
362
|
+
await writeFile(tmpFile, body.content, { encoding: "utf8", mode: resolved.info.mode & 0o777 });
|
|
363
|
+
await rename(tmpFile, resolved.targetPath);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
await rm(tmpFile, { force: true }).catch(() => {});
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
const nextStats = await stat(resolved.targetPath);
|
|
369
|
+
return {
|
|
370
|
+
path: resolved.relative,
|
|
371
|
+
name: path.basename(resolved.targetPath),
|
|
372
|
+
size: nextStats.size,
|
|
373
|
+
mtimeMs: nextStats.mtimeMs,
|
|
374
|
+
extension: path.extname(resolved.targetPath).toLowerCase(),
|
|
375
|
+
language: fileViewerLanguage(resolved.targetPath),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function workspaceRelativePath(root, targetPath) {
|
|
380
|
+
return path.relative(root, targetPath).split(path.sep).join("/");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function fileOperationEntryType(info) {
|
|
384
|
+
if (info?.isDirectory?.()) return "directory";
|
|
385
|
+
if (info?.isFile?.()) return "file";
|
|
386
|
+
return "other";
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function assertWorkspaceEntryMutable(resolved, action) {
|
|
390
|
+
if (!resolved.relative) throw makeHttpError(400, `Workspace root cannot be ${action}`);
|
|
391
|
+
const type = fileOperationEntryType(resolved.info);
|
|
392
|
+
if (type !== "file" && type !== "directory") throw makeHttpError(400, "Only regular files and directories can be modified from WebUI");
|
|
393
|
+
return type;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function existingDestinationStats(targetPath) {
|
|
397
|
+
try {
|
|
398
|
+
return await stat(targetPath);
|
|
399
|
+
} catch (error) {
|
|
400
|
+
if (error?.code === "ENOENT") return null;
|
|
401
|
+
throw makeHttpError(400, `Cannot access destination: ${displayPath(targetPath)}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function resolveWorkspaceMoveDestination(tab, source, rawDestination = "") {
|
|
406
|
+
const destinationText = String(rawDestination || "").trim();
|
|
407
|
+
if (!destinationText) throw makeHttpError(400, "Destination path is required");
|
|
408
|
+
if (destinationText.includes("\0")) throw makeHttpError(400, "Destination path cannot contain null bytes");
|
|
409
|
+
|
|
410
|
+
const candidatePath = path.isAbsolute(destinationText) ? path.resolve(destinationText) : path.resolve(source.root, destinationText);
|
|
411
|
+
if (candidatePath !== source.root && !pathInside(source.root, candidatePath)) throw makeHttpError(403, "Destination path must stay inside the active tab working directory");
|
|
412
|
+
|
|
413
|
+
const candidateInfo = await existingDestinationStats(candidatePath);
|
|
414
|
+
let targetPath = candidatePath;
|
|
415
|
+
let targetInfo = candidateInfo;
|
|
416
|
+
if (candidateInfo?.isDirectory?.()) {
|
|
417
|
+
targetPath = path.join(candidatePath, path.basename(source.targetPath));
|
|
418
|
+
targetInfo = await existingDestinationStats(targetPath);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (path.resolve(targetPath) === path.resolve(source.targetPath)) throw makeHttpError(400, "Source and destination are the same path");
|
|
422
|
+
if (targetInfo) throw makeHttpError(409, `Destination already exists: ${workspaceRelativePath(source.root, targetPath)}`);
|
|
423
|
+
if (source.info?.isDirectory?.() && pathInside(source.targetPath, targetPath)) throw makeHttpError(400, "A directory cannot be moved into itself or one of its descendants");
|
|
424
|
+
|
|
425
|
+
const parentPath = path.dirname(targetPath);
|
|
426
|
+
if (parentPath !== source.root && !pathInside(source.root, parentPath)) throw makeHttpError(403, "Destination parent must stay inside the active tab working directory");
|
|
427
|
+
const parentInfo = await stat(parentPath).catch((error) => {
|
|
428
|
+
if (error?.code === "ENOENT") throw makeHttpError(404, `Destination parent not found: ${displayPath(parentPath)}`);
|
|
429
|
+
throw makeHttpError(400, `Cannot access destination parent: ${displayPath(parentPath)}`);
|
|
430
|
+
});
|
|
431
|
+
if (!parentInfo?.isDirectory?.()) throw makeHttpError(400, "Destination parent is not a directory");
|
|
432
|
+
const realParent = await realpath(parentPath).catch(() => parentPath);
|
|
433
|
+
if (realParent !== source.realRoot && !pathInside(source.realRoot, realParent)) throw makeHttpError(403, "Destination parent escapes the active tab working directory");
|
|
434
|
+
|
|
435
|
+
return {
|
|
436
|
+
targetPath,
|
|
437
|
+
relative: workspaceRelativePath(source.root, targetPath),
|
|
438
|
+
parentPath: workspaceRelativePath(source.root, parentPath),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async function deleteFileSystemEntryData(tab, body = {}) {
|
|
443
|
+
if (body.confirmed !== true) throw makeHttpError(409, "Deleting files or directories requires confirmed: true");
|
|
444
|
+
const resolved = await resolveWorkspacePath(tab, body.path || body.filePath || "");
|
|
445
|
+
const type = assertWorkspaceEntryMutable(resolved, "deleted");
|
|
446
|
+
await rm(resolved.targetPath, { recursive: type === "directory" });
|
|
447
|
+
return {
|
|
448
|
+
path: resolved.relative,
|
|
449
|
+
name: path.basename(resolved.targetPath),
|
|
450
|
+
type,
|
|
451
|
+
parentPath: workspaceRelativePath(resolved.root, path.dirname(resolved.targetPath)),
|
|
452
|
+
deleted: true,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Create an empty file or a directory inside the tab's working directory (Files panel
|
|
457
|
+
// "New file…" / "New folder…"). Never overwrites; parents must already exist.
|
|
458
|
+
async function createFileSystemEntryData(tab, body = {}) {
|
|
459
|
+
const kind = body.type === "directory" ? "directory" : "file";
|
|
460
|
+
const resolved = await resolveWorkspacePath(tab, body.path || body.filePath || "", { mustExist: false });
|
|
461
|
+
if (resolved.targetPath === resolved.root) throw makeHttpError(400, "A name is required");
|
|
462
|
+
if (resolved.info) throw makeHttpError(409, `Already exists: ${resolved.relative}`);
|
|
463
|
+
const parentPath = path.dirname(resolved.targetPath);
|
|
464
|
+
const parentInfo = await stat(parentPath).catch(() => null);
|
|
465
|
+
if (!parentInfo?.isDirectory?.()) throw makeHttpError(404, `Parent folder not found: ${workspaceRelativePath(resolved.root, parentPath) || "."}`);
|
|
466
|
+
const realParent = await realpath(parentPath).catch(() => parentPath);
|
|
467
|
+
if (realParent !== resolved.realRoot && !pathInside(resolved.realRoot, realParent)) throw makeHttpError(403, "Parent folder escapes the active tab working directory");
|
|
468
|
+
if (kind === "directory") await mkdir(resolved.targetPath);
|
|
469
|
+
else await writeFile(resolved.targetPath, "", { encoding: "utf8", flag: "wx" });
|
|
470
|
+
const nextStats = await stat(resolved.targetPath);
|
|
471
|
+
return {
|
|
472
|
+
path: resolved.relative,
|
|
473
|
+
name: path.basename(resolved.targetPath),
|
|
474
|
+
type: kind,
|
|
475
|
+
parentPath: workspaceRelativePath(resolved.root, parentPath),
|
|
476
|
+
created: true,
|
|
477
|
+
size: nextStats.size,
|
|
478
|
+
mtimeMs: nextStats.mtimeMs,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
async function moveFileSystemEntryData(tab, body = {}) {
|
|
483
|
+
if (body.confirmed !== true) throw makeHttpError(409, "Moving files or directories requires confirmed: true");
|
|
484
|
+
const source = await resolveWorkspacePath(tab, body.path || body.filePath || body.sourcePath || "");
|
|
485
|
+
const type = assertWorkspaceEntryMutable(source, "moved");
|
|
486
|
+
const destination = await resolveWorkspaceMoveDestination(tab, source, body.toPath || body.destinationPath || body.destination || "");
|
|
487
|
+
await rename(source.targetPath, destination.targetPath);
|
|
488
|
+
const nextStats = await stat(destination.targetPath).catch(() => null);
|
|
489
|
+
return {
|
|
490
|
+
path: source.relative,
|
|
491
|
+
destination: destination.relative,
|
|
492
|
+
name: path.basename(destination.targetPath),
|
|
493
|
+
type,
|
|
494
|
+
parentPath: workspaceRelativePath(source.root, path.dirname(source.targetPath)),
|
|
495
|
+
destinationParentPath: destination.parentPath,
|
|
496
|
+
moved: true,
|
|
497
|
+
size: nextStats?.size,
|
|
498
|
+
mtimeMs: nextStats?.mtimeMs,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function defaultEditorCommand(targetPath) {
|
|
503
|
+
if (process.env.PI_WEBUI_OPEN_COMMAND) {
|
|
504
|
+
const override = process.env.PI_WEBUI_OPEN_COMMAND;
|
|
505
|
+
return [".js", ".cjs", ".mjs"].includes(path.extname(override).toLowerCase())
|
|
506
|
+
? { command: process.execPath, args: [override, targetPath] }
|
|
507
|
+
: { command: override, args: [targetPath] };
|
|
508
|
+
}
|
|
509
|
+
if (platform() === "win32") return { command: "cmd", args: ["/c", "start", "", targetPath] };
|
|
510
|
+
if (platform() === "darwin") return { command: "open", args: [targetPath] };
|
|
511
|
+
return { command: "xdg-open", args: [targetPath] };
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function firstCommandOutputLine(value = "") {
|
|
515
|
+
return String(value || "").split(/\r?\n/).map((line) => line.trim()).find(Boolean) || "";
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
async function queryXdgMime(args = [], cwd = defaultCwd) {
|
|
519
|
+
const result = await runCommand("xdg-mime", args, { cwd, timeoutMs: 1500, maxOutputLength: 4096 });
|
|
520
|
+
if (result.exitCode !== 0) return "";
|
|
521
|
+
return firstCommandOutputLine(result.stdout);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
async function linuxDefaultEditorCommand(targetPath, { cwd = defaultCwd, isFile = true } = {}) {
|
|
525
|
+
if (process.env.PI_WEBUI_OPEN_COMMAND) return defaultEditorCommand(targetPath);
|
|
526
|
+
if (!isFile) return defaultEditorCommand(targetPath);
|
|
527
|
+
const fileMime = await queryXdgMime(["query", "filetype", targetPath], cwd);
|
|
528
|
+
const fileDefaultDesktop = fileMime ? await queryXdgMime(["query", "default", fileMime], cwd) : "";
|
|
529
|
+
if (fileDefaultDesktop) return { command: "xdg-open", args: [targetPath], mime: fileMime, desktopFile: fileDefaultDesktop, fallbackToTextEditor: false };
|
|
530
|
+
const textDefaultDesktop = await queryXdgMime(["query", "default", "text/plain"], cwd);
|
|
531
|
+
if (textDefaultDesktop) {
|
|
532
|
+
return { command: "gio", args: ["launch", textDefaultDesktop, targetPath], mime: fileMime, desktopFile: textDefaultDesktop, fallbackToTextEditor: true };
|
|
533
|
+
}
|
|
534
|
+
return { ...defaultEditorCommand(targetPath), mime: fileMime, fallbackToTextEditor: false };
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async function defaultEditorCommandForPath(targetPath, options = {}) {
|
|
538
|
+
if (platform() === "linux") return linuxDefaultEditorCommand(targetPath, options);
|
|
539
|
+
return defaultEditorCommand(targetPath);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
async function openPathInDefaultEditor(tab, requestedPath = "") {
|
|
543
|
+
if (!String(requestedPath || "").trim()) throw makeHttpError(400, "Path to open is required");
|
|
544
|
+
const resolved = await resolveWorkspacePath(tab, requestedPath);
|
|
545
|
+
const { command, args, mime, desktopFile, fallbackToTextEditor } = await defaultEditorCommandForPath(resolved.targetPath, { cwd: resolved.root, isFile: !!resolved.info?.isFile?.() });
|
|
546
|
+
const child = spawn(command, args, { cwd: resolved.root, stdio: "ignore", detached: true, windowsHide: true });
|
|
547
|
+
child.on("error", () => {});
|
|
548
|
+
child.unref?.();
|
|
549
|
+
return { path: resolved.relative, command: [command, ...args].join(" "), mime, desktopFile, fallbackToTextEditor: !!fallbackToTextEditor };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return {
|
|
553
|
+
getFileTreeData,
|
|
554
|
+
getFileSearchData,
|
|
555
|
+
getFileContentData,
|
|
556
|
+
getAurReviewReportContentData,
|
|
557
|
+
saveFileContentData,
|
|
558
|
+
deleteFileSystemEntryData,
|
|
559
|
+
createFileSystemEntryData,
|
|
560
|
+
moveFileSystemEntryData,
|
|
561
|
+
openPathInDefaultEditor,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
@@ -115,6 +115,10 @@ function normalizeRestoreTab(item, seen) {
|
|
|
115
115
|
const id = rawId && /^[A-Za-z0-9._:-]+$/.test(rawId) && !seen.has(rawId) ? rawId : undefined;
|
|
116
116
|
if (id) seen.add(id);
|
|
117
117
|
const tab = { id, title: text(item.title, 160), titleSource: text(item.titleSource, 32), cwd: text(item.cwd, 4096), sessionFile: text(item.sessionFile, 4096), conversationStarted: item.conversationStarted === true };
|
|
118
|
+
if (item.workspaceKind === "no-project") {
|
|
119
|
+
tab.workspaceKind = "no-project";
|
|
120
|
+
tab.noProjectId = text(item.noProjectId, 128);
|
|
121
|
+
}
|
|
118
122
|
if (Number.isInteger(item.index) && item.index > 0) tab.index = item.index;
|
|
119
123
|
return tab;
|
|
120
124
|
}
|
package/lib/webui-workspaces.mjs
CHANGED
|
@@ -48,6 +48,8 @@ export function normalizeWorkspaceTabDescriptor(value, seenIds = new Set()) {
|
|
|
48
48
|
title: boundedString(value.title, 160),
|
|
49
49
|
titleSource: ["explicit", "auto", "default"].includes(value.titleSource) ? value.titleSource : undefined,
|
|
50
50
|
cwd,
|
|
51
|
+
...(value.workspaceKind !== undefined ? { workspaceKind: value.workspaceKind } : {}),
|
|
52
|
+
...(value.noProjectId !== undefined ? { noProjectId: value.noProjectId } : {}),
|
|
51
53
|
conversationStarted: value.conversationStarted === true,
|
|
52
54
|
sessionFile: boundedString(value.sessionFile || value.state?.sessionFile, 4096),
|
|
53
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"pi-webui": "./bin/pi-webui-launcher.mjs"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"check": "node --check public/app.js && node --check public/codex-speed-mode.mjs && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && node --check public/transcript-renderer.mjs && node --check public/syntax-highlight.mjs && node --check public/mobile-shell-state.mjs && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-launcher.mjs && node --check bin/pi-webui-native-update-runner.mjs && node --check bin/pi-webui-update-context.mjs && node --check lib/update/coordination.mjs && node --check lib/update/native-jobs.mjs && node --check lib/update/discovery.mjs && node --check lib/update/native-targets.mjs && node --check lib/update/path-pi.mjs && node --check lib/update/migration.mjs && node --check lib/update/supervisor.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/workspace-files-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/codex-cli-usage.mjs && node --check lib/codex-usage-source.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
33
|
+
"check": "node --check public/app.js && node --check public/settings-workspace.mjs && node --check public/settings-resource-controller.mjs && node --check public/settings-navigation-controller.mjs && node --check public/project-file-viewer-controller.mjs && node --check public/project-artifact-controller.mjs && node --check public/activity-queue-controller.mjs && node --check public/activity-agents-controller.mjs && node --check public/activity-todo-view.mjs && node --check public/activity-intercom-controller.mjs && node --check public/activity-usage-controller.mjs && node --check public/activity-events-controller.mjs && node --check public/project-git-tools-controller.mjs && node --check public/project-runners-controller.mjs && node --check public/codex-speed-mode.mjs && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && node --check public/transcript-renderer.mjs && node --check public/syntax-highlight.mjs && node --check public/mobile-shell-state.mjs && node --check public/shell-actions.mjs && node --check public/shell-navigation.mjs && node --check public/shell-preferences.mjs && node --check public/shell-view-host.mjs && node --check public/shell-surfaces.mjs && node --check public/shell-workspace.mjs && node --check public/shell-tools-launcher.mjs && node --check public/focused-shell-adapter.mjs && node --check public/session-context.mjs && node --check public/session-shelf-state.mjs && node --check public/session-shelves.mjs && node --check public/session-composer-store.mjs && node --check public/session-attention-scheduler.mjs && node --check public/platform-event-stream.mjs && node --check public/session-extension-requests.mjs && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check lib/server/app-runners.mjs && node --check lib/server/git-worktree-sessions.mjs && node --check lib/server/git-generation.mjs && node --check lib/server/conversation-mode.mjs && node --check lib/server/codex-fast-mode.mjs && node --check lib/server/conversation-voice.mjs && node --check lib/server/rpc-transports.mjs && node --check lib/server/sse-delivery.mjs && node --check lib/server/helper-requests.mjs && node --check lib/server/extension-ui-requests.mjs && node --check lib/server/git-mutations.mjs && node --check lib/server/git-reads.mjs && node --check lib/server/workspace-files.mjs && node --check lib/server/settings-store.mjs && node --check lib/git-workflow-preference-values.mjs && node --check lib/git-workflow-preferences.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-launcher.mjs && node --check bin/pi-webui-native-update-runner.mjs && node --check bin/pi-webui-update-context.mjs && node --check lib/update/coordination.mjs && node --check lib/update/native-jobs.mjs && node --check lib/update/discovery.mjs && node --check lib/update/native-targets.mjs && node --check lib/update/path-pi.mjs && node --check lib/update/migration.mjs && node --check lib/update/supervisor.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/workspace-files-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/codex-cli-usage.mjs && node --check lib/codex-usage-source.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
34
34
|
"test": "node tests/run-all.mjs",
|
|
35
35
|
"test:browser": "playwright test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@firstpick/pi-utils": "^0.2
|
|
39
|
-
"mermaid": "^
|
|
38
|
+
"@firstpick/pi-utils": "^0.3.2",
|
|
39
|
+
"mermaid": "^12.2.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@earendil-works/pi-ai": "*",
|