@visual-z/xeno 0.2.1 → 0.4.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/CHANGELOG.md +18 -0
- package/README.md +126 -34
- package/docs/app-server.md +84 -0
- package/docs/install.md +51 -13
- package/docs/providers.md +24 -3
- package/package.json +7 -5
- package/src/apps/app-server.ts +28 -0
- package/src/apps/approve.ts +3 -3
- package/src/apps/cli.ts +25 -10
- package/src/apps/commands.ts +45 -8
- package/src/apps/completions.ts +78 -22
- package/src/apps/control-transport.ts +89 -0
- package/src/apps/image-draft.ts +46 -0
- package/src/apps/model-catalog.ts +2 -1
- package/src/apps/project-trust.ts +2 -42
- package/src/apps/provider-connect.ts +346 -0
- package/src/apps/render.ts +22 -47
- package/src/apps/resources.ts +5 -2
- package/src/apps/shell.ts +333 -1542
- package/src/apps/startup-input.ts +45 -9
- package/src/apps/startup.ts +149 -94
- package/src/apps/ui/app.ts +1553 -0
- package/src/apps/ui/control-model.ts +26 -0
- package/src/apps/ui/extension-host.ts +194 -0
- package/src/apps/ui/image-cache.ts +78 -0
- package/src/apps/ui/palette.ts +88 -0
- package/src/apps/ui/project.ts +127 -0
- package/src/apps/ui/standalone.ts +146 -0
- package/src/apps/ui/status-model.ts +68 -0
- package/src/apps/ui/surface.ts +86 -0
- package/src/apps/ui/theme.ts +86 -0
- package/src/core/acceptance.ts +107 -0
- package/src/core/action-defaults.ts +47 -295
- package/src/core/benchmark.ts +2 -2
- package/src/core/branch-receipt.ts +24 -0
- package/src/core/checkpoints.ts +64 -0
- package/src/core/churn.ts +2 -0
- package/src/core/command-artifacts.ts +94 -0
- package/src/core/command-contract.ts +35 -0
- package/src/core/completion-action.ts +20 -0
- package/src/core/completion-review.ts +37 -21
- package/src/core/context-detail.ts +37 -0
- package/src/core/context-policy.ts +74 -1
- package/src/core/continuation.ts +17 -2
- package/src/core/control-protocol.ts +62 -0
- package/src/core/control-view.ts +42 -0
- package/src/core/derive.ts +29 -3
- package/src/core/draft-images.ts +56 -0
- package/src/core/environment.ts +145 -0
- package/src/core/evaluation-coverage.ts +74 -0
- package/src/core/event-validation.ts +81 -6
- package/src/core/events.ts +99 -3
- package/src/core/evidence-links.ts +7 -0
- package/src/core/evidence.ts +13 -3
- package/src/core/execution.ts +8 -2
- package/src/core/experiment.ts +133 -0
- package/src/core/export.ts +9 -0
- package/src/core/failure-recovery.ts +173 -0
- package/src/core/file-precondition.ts +72 -0
- package/src/core/handoff.ts +65 -4
- package/src/core/harness-diagnostics.ts +206 -0
- package/src/core/history-query.ts +38 -2
- package/src/core/history.ts +38 -1
- package/src/core/integration-health.ts +34 -0
- package/src/core/keymap.ts +8 -20
- package/src/core/model-picker.ts +64 -0
- package/src/core/native-eval.ts +25 -0
- package/src/core/note-guidance.ts +34 -0
- package/src/core/oauth-fields.ts +44 -0
- package/src/core/observation-view.ts +49 -8
- package/src/core/permissions.ts +24 -2
- package/src/core/process-receipt.ts +105 -0
- package/src/core/process-state.ts +37 -0
- package/src/core/program-status.ts +31 -0
- package/src/core/project.ts +70 -19
- package/src/core/prompt-policy.ts +37 -0
- package/src/core/query-eval-contract.ts +14 -0
- package/src/core/read-observation.ts +82 -0
- package/src/core/recovery-corpus.ts +17 -0
- package/src/core/recovery-evaluation.ts +60 -0
- package/src/core/recovery-sources.ts +74 -0
- package/src/core/request-progress.ts +87 -0
- package/src/core/request-state.ts +114 -0
- package/src/core/runtime-target.ts +94 -0
- package/src/core/search-observation.ts +97 -0
- package/src/core/session-tree.ts +147 -0
- package/src/core/settings.ts +33 -10
- package/src/core/skills.ts +44 -0
- package/src/core/sql-query.ts +211 -0
- package/src/core/theme.ts +36 -58
- package/src/core/tool-contract.ts +51 -2
- package/src/core/tool-discovery.ts +87 -0
- package/src/core/tool-failure.ts +60 -0
- package/src/core/tool-input.ts +6 -0
- package/src/core/tool-mode-protocol.ts +25 -0
- package/src/core/transcript.ts +19 -4
- package/src/core/trial-lifecycle.ts +14 -0
- package/src/core/tui-mode.ts +29 -0
- package/src/core/update-check.ts +97 -0
- package/src/core/version.ts +55 -0
- package/src/core/work-state.ts +49 -3
- package/src/core/working-set.ts +91 -0
- package/src/runtime/auth.ts +11 -4
- package/src/runtime/branch-jobs.ts +36 -0
- package/src/runtime/catalog.ts +13 -3
- package/src/runtime/clipboard.ts +15 -4
- package/src/runtime/command-artifacts.ts +64 -0
- package/src/runtime/control-connection.ts +104 -0
- package/src/runtime/environment-tools.ts +60 -0
- package/src/runtime/evidence-notes.ts +4 -2
- package/src/runtime/exec-sessions.ts +206 -61
- package/src/runtime/execution-control.ts +1 -0
- package/src/runtime/extension-ui.ts +22 -30
- package/src/runtime/extensions.ts +95 -16
- package/src/runtime/harness-comparison.ts +27 -7
- package/src/runtime/harness-eval.ts +462 -0
- package/src/runtime/history-cache.ts +57 -0
- package/src/runtime/history-tools.ts +62 -12
- package/src/runtime/integrations.ts +210 -0
- package/src/runtime/loop.ts +1088 -282
- package/src/runtime/model-discovery.ts +208 -0
- package/src/runtime/model.ts +9 -0
- package/src/runtime/native-eval-fixtures.ts +33 -0
- package/src/runtime/native-eval.ts +146 -0
- package/src/runtime/oauth.ts +80 -3
- package/src/runtime/pi-provider.ts +169 -12
- package/src/runtime/program-status.ts +38 -0
- package/src/runtime/provider-connect.ts +109 -0
- package/src/runtime/provider-presets.ts +87 -0
- package/src/runtime/provider-request.ts +13 -2
- package/src/runtime/provider.ts +23 -9
- package/src/runtime/query-eval-verifier.ts +28 -0
- package/src/runtime/recovery-coverage.ts +71 -0
- package/src/runtime/recovery-evidence.ts +76 -0
- package/src/runtime/recovery-fixtures.ts +116 -0
- package/src/runtime/runtime-target.ts +149 -0
- package/src/runtime/session-control.ts +198 -0
- package/src/runtime/tool-broker.ts +137 -0
- package/src/runtime/tool-discovery.ts +57 -0
- package/src/runtime/tool-mode-eval.ts +146 -0
- package/src/runtime/tool-queue.ts +77 -0
- package/src/runtime/tools.ts +628 -183
- package/src/runtime/trial-control.ts +45 -0
- package/src/runtime/update-check.ts +47 -0
- package/src/runtime/window-trial.ts +2 -1
- package/src/runtime/working-notes.ts +33 -3
- package/src/runtime/workspace-lifecycle.ts +97 -0
- package/src/store/acceptance.ts +15 -0
- package/src/store/checkpoint-history.ts +43 -0
- package/src/store/command-artifacts.ts +96 -0
- package/src/store/command.ts +65 -37
- package/src/store/file-checkpoints.ts +104 -0
- package/src/store/file-index.ts +13 -1
- package/src/store/git-checkpoints.ts +67 -0
- package/src/store/observations.ts +61 -20
- package/src/store/process-receipts.ts +34 -0
- package/src/store/query-source.ts +13 -8
- package/src/store/recovery.ts +2 -3
- package/src/store/replay.ts +16 -4
- package/src/store/runtime-target.ts +64 -0
- package/src/store/search.ts +171 -132
- package/src/store/session-archive.ts +4 -0
- package/src/store/source-cancellation.ts +6 -0
- package/src/store/update-cache.ts +36 -0
- package/src/store/workspace-observation.ts +113 -0
- package/src/tui/ansi-spans.ts +126 -0
- package/src/tui/style.ts +19 -16
- package/src/tui/ui/atomic-draft.ts +121 -0
- package/src/tui/ui/canvas.ts +96 -0
- package/src/tui/ui/colors.ts +70 -0
- package/src/tui/ui/composer.ts +200 -0
- package/src/tui/ui/control-panel.ts +23 -0
- package/src/tui/ui/dialog.ts +379 -0
- package/src/tui/ui/draft.ts +23 -0
- package/src/tui/ui/edge.ts +186 -0
- package/src/tui/ui/image-size.ts +40 -0
- package/src/tui/ui/ink.ts +210 -0
- package/src/tui/ui/items.ts +40 -0
- package/src/tui/ui/keys.ts +40 -0
- package/src/tui/ui/layout.ts +74 -0
- package/src/tui/ui/list-model.ts +86 -0
- package/src/tui/ui/list-view.ts +172 -0
- package/src/tui/ui/mascot.ts +67 -0
- package/src/tui/ui/messages.ts +518 -0
- package/src/tui/ui/motion.ts +28 -0
- package/src/tui/ui/paths.ts +10 -0
- package/src/tui/ui/pictures.ts +78 -0
- package/src/tui/ui/screen.ts +421 -0
- package/src/tui/ui/status.ts +279 -0
- package/src/tui/ui/styled.ts +85 -0
- package/src/tui/ui/testing.ts +5 -0
- package/src/tui/ui/tool-card.ts +150 -0
- package/src/apps/extension-ui.ts +0 -330
- package/src/apps/resource-browser.ts +0 -75
- package/src/apps/session-browser.ts +0 -113
- package/src/apps/session-picker.ts +0 -55
- package/src/tui/ansi.ts +0 -67
- package/src/tui/autocomplete.ts +0 -29
- package/src/tui/chat-viewport.ts +0 -47
- package/src/tui/complete.ts +0 -87
- package/src/tui/editor.ts +0 -940
- package/src/tui/host.ts +0 -264
- package/src/tui/input.ts +0 -75
- package/src/tui/keys.ts +0 -378
- package/src/tui/markdown.ts +0 -17
- package/src/tui/render.ts +0 -153
- package/src/tui/select.ts +0 -258
- package/src/tui/settings.ts +0 -44
- package/src/tui/statusline.ts +0 -162
- package/src/tui/system-theme.ts +0 -700
- package/src/tui/terminal.ts +0 -30
- package/src/tui/text.ts +0 -52
- package/src/tui/toolview.ts +0 -386
- package/src/tui/transcript.ts +0 -123
- package/src/tui/tree.ts +0 -471
- package/src/vendor/pi-tui/LICENSE.upstream +0 -21
- package/src/vendor/pi-tui/UPSTREAM.json +0 -50
- package/src/vendor/pi-tui/VENDOR.md +0 -25
- package/src/vendor/pi-tui/alt-screen-search.ts +0 -327
- package/src/vendor/pi-tui/autocomplete.ts +0 -860
- package/src/vendor/pi-tui/colors.ts +0 -367
- package/src/vendor/pi-tui/components/alt-screen-flash.ts +0 -51
- package/src/vendor/pi-tui/components/box.ts +0 -166
- package/src/vendor/pi-tui/components/cancellable-loader.ts +0 -40
- package/src/vendor/pi-tui/components/editor.ts +0 -2472
- package/src/vendor/pi-tui/components/h-stack.ts +0 -44
- package/src/vendor/pi-tui/components/image.ts +0 -127
- package/src/vendor/pi-tui/components/input.ts +0 -494
- package/src/vendor/pi-tui/components/loader.ts +0 -101
- package/src/vendor/pi-tui/components/markdown.ts +0 -1021
- package/src/vendor/pi-tui/components/mouse-region.ts +0 -33
- package/src/vendor/pi-tui/components/scroll-view.ts +0 -224
- package/src/vendor/pi-tui/components/select-list.ts +0 -273
- package/src/vendor/pi-tui/components/settings-list.ts +0 -328
- package/src/vendor/pi-tui/components/spacer.ts +0 -28
- package/src/vendor/pi-tui/components/stack.ts +0 -154
- package/src/vendor/pi-tui/components/text.ts +0 -107
- package/src/vendor/pi-tui/components/truncated-text.ts +0 -65
- package/src/vendor/pi-tui/components/v-stack.ts +0 -33
- package/src/vendor/pi-tui/editor-component.ts +0 -74
- package/src/vendor/pi-tui/fuzzy.ts +0 -138
- package/src/vendor/pi-tui/index.ts +0 -186
- package/src/vendor/pi-tui/keybindings.ts +0 -320
- package/src/vendor/pi-tui/keys.ts +0 -1401
- package/src/vendor/pi-tui/kill-ring.ts +0 -46
- package/src/vendor/pi-tui/latex.ts +0 -1506
- package/src/vendor/pi-tui/layout-node.ts +0 -51
- package/src/vendor/pi-tui/layout.ts +0 -449
- package/src/vendor/pi-tui/native/UPSTREAM.json +0 -23
- package/src/vendor/pi-tui/native/clipboard.h +0 -208
- package/src/vendor/pi-tui/native/darwin/README.md +0 -22
- package/src/vendor/pi-tui/native/darwin/build.sh +0 -69
- package/src/vendor/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/src/vendor/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/src/vendor/pi-tui/native/darwin/src/darwin-platform.m +0 -132
- package/src/vendor/pi-tui/native/linux/README.md +0 -23
- package/src/vendor/pi-tui/native/linux/build.sh +0 -65
- package/src/vendor/pi-tui/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/src/vendor/pi-tui/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/src/vendor/pi-tui/native/linux/src/clipboard-worker.h +0 -70
- package/src/vendor/pi-tui/native/linux/src/linux-platform-x11.c +0 -274
- package/src/vendor/pi-tui/native/napi.h +0 -91
- package/src/vendor/pi-tui/native/win32/README.md +0 -31
- package/src/vendor/pi-tui/native/win32/build.mjs +0 -232
- package/src/vendor/pi-tui/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/src/vendor/pi-tui/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/src/vendor/pi-tui/native/win32/src/win32-platform.c +0 -241
- package/src/vendor/pi-tui/native-modifiers.ts +0 -13
- package/src/vendor/pi-tui/native-module-path.ts +0 -31
- package/src/vendor/pi-tui/native-platform.ts +0 -65
- package/src/vendor/pi-tui/oklab.ts +0 -233
- package/src/vendor/pi-tui/stdin-buffer.ts +0 -444
- package/src/vendor/pi-tui/terminal-colors.ts +0 -91
- package/src/vendor/pi-tui/terminal-image.ts +0 -731
- package/src/vendor/pi-tui/terminal.ts +0 -554
- package/src/vendor/pi-tui/tui-alt-screen.ts +0 -1750
- package/src/vendor/pi-tui/tui-main-screen.ts +0 -655
- package/src/vendor/pi-tui/tui.ts +0 -1493
- package/src/vendor/pi-tui/undo-stack.ts +0 -28
- package/src/vendor/pi-tui/utils.ts +0 -1385
- package/src/vendor/pi-tui/wheel-scroll.ts +0 -82
- package/src/vendor/pi-tui/word-navigation.ts +0 -117
package/src/tui/autocomplete.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { CombinedAutocompleteProvider, type AutocompleteItem, type AutocompleteSuggestions, type SlashCommand } from "../vendor/pi-tui/autocomplete.ts";
|
|
2
|
-
import { fuzzyFilter } from "../vendor/pi-tui/fuzzy.ts";
|
|
3
|
-
|
|
4
|
-
/** Pi's completion rules, with xeno's workspace index in place of an fd dependency. */
|
|
5
|
-
export class WorkspaceAutocomplete extends CombinedAutocompleteProvider {
|
|
6
|
-
triggerCharacters = ["/", "@"];
|
|
7
|
-
private readonly paths: (refresh?: boolean) => Promise<readonly string[]>;
|
|
8
|
-
|
|
9
|
-
constructor(commands: SlashCommand[], workspace: string, paths: (refresh?: boolean) => Promise<readonly string[]>) {
|
|
10
|
-
super(commands, workspace);
|
|
11
|
-
this.paths = paths;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
override async getSuggestions(lines: string[], line: number, col: number,
|
|
15
|
-
options: { signal: AbortSignal; force?: boolean }): Promise<AutocompleteSuggestions | null> {
|
|
16
|
-
const before = (lines[line] ?? "").slice(0, col);
|
|
17
|
-
const prefix = /(?:^|\s)(@(?:"[^"]*|[^\s]*))$/.exec(before)?.[1];
|
|
18
|
-
if (prefix !== undefined) {
|
|
19
|
-
const paths = await this.paths(options.force === true || prefix === "@");
|
|
20
|
-
if (options.signal.aborted) return null;
|
|
21
|
-
const query = prefix.slice(1).replace(/^"/, "");
|
|
22
|
-
const items: AutocompleteItem[] = fuzzyFilter([...paths], query, (p) => p).map((path) => ({
|
|
23
|
-
value: `@${/\s/.test(path) ? `"${path}"` : path}`, label: path,
|
|
24
|
-
}));
|
|
25
|
-
return items.length > 0 ? { items, prefix } : null;
|
|
26
|
-
}
|
|
27
|
-
return super.getSuggestions(lines, line, col, options);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/tui/chat-viewport.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/** Ported from Pi (MIT), coding-agent/chat-viewport.ts at 02eed88. */
|
|
2
|
-
import { type Component, ScrollView, type ScrollViewScrollbar, VStack } from "../vendor/pi-tui/index.ts";
|
|
3
|
-
|
|
4
|
-
export interface ChatViewportOptions {
|
|
5
|
-
readonly document: Component;
|
|
6
|
-
readonly pendingMessages: Component;
|
|
7
|
-
readonly status: Component;
|
|
8
|
-
readonly editor: Component;
|
|
9
|
-
readonly footer: Component;
|
|
10
|
-
readonly widgetsAbove?: Component;
|
|
11
|
-
readonly widgetsBelow?: Component;
|
|
12
|
-
readonly scrollbar?: ScrollViewScrollbar;
|
|
13
|
-
readonly scrollbarTrackStyle?: (text: string) => string;
|
|
14
|
-
readonly scrollbarThumbStyle?: (text: string) => string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ChatViewport {
|
|
18
|
-
readonly root: Component;
|
|
19
|
-
readonly transcript: ScrollView;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Shared fullscreen transcript and fixed input-dock layout. */
|
|
23
|
-
export function createChatViewport(options: ChatViewportOptions): ChatViewport {
|
|
24
|
-
const transcript = new ScrollView(options.document, {
|
|
25
|
-
follow: "end",
|
|
26
|
-
primary: true,
|
|
27
|
-
overscroll: "chain",
|
|
28
|
-
scrollbar: options.scrollbar ?? "auto",
|
|
29
|
-
...(options.scrollbarTrackStyle === undefined ? {} : { scrollbarTrackStyle: options.scrollbarTrackStyle }),
|
|
30
|
-
...(options.scrollbarThumbStyle === undefined ? {} : { scrollbarThumbStyle: options.scrollbarThumbStyle }),
|
|
31
|
-
});
|
|
32
|
-
const dock = new VStack([
|
|
33
|
-
{ component: options.pendingMessages, shrink: 1, minSize: 0 },
|
|
34
|
-
{ component: options.status, shrink: 1, minSize: 0 },
|
|
35
|
-
...(options.widgetsAbove === undefined ? [] : [{ component: options.widgetsAbove, shrink: 1, minSize: 0 }]),
|
|
36
|
-
{ component: options.editor, shrink: 1, minSize: 3 },
|
|
37
|
-
...(options.widgetsBelow === undefined ? [] : [{ component: options.widgetsBelow, shrink: 1, minSize: 0 }]),
|
|
38
|
-
{ component: options.footer, shrink: 1, minSize: 0 },
|
|
39
|
-
]);
|
|
40
|
-
return {
|
|
41
|
-
transcript,
|
|
42
|
-
root: new VStack([
|
|
43
|
-
{ component: transcript, basis: 0, grow: 1, shrink: 1, minSize: 1 },
|
|
44
|
-
{ component: dock, basis: "auto", grow: 0, shrink: 1, minSize: 1 },
|
|
45
|
-
]),
|
|
46
|
-
};
|
|
47
|
-
}
|
package/src/tui/complete.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Path completion as a pure function: the caller reads the directory,
|
|
3
|
-
* this module only matches names. I/O in applyKey would make "tab on
|
|
4
|
-
* src/fo" a test that needs a disk.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export interface PathCompletion {
|
|
8
|
-
readonly completed: string;
|
|
9
|
-
readonly candidates: readonly string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface PathToken {
|
|
13
|
-
readonly start: number;
|
|
14
|
-
readonly end: number;
|
|
15
|
-
readonly prefix: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Longest prefix of `entries` that still starts with `prefix`. One match
|
|
20
|
-
* completes fully; several matches complete only as far as they agree,
|
|
21
|
-
* so a later Tab can still distinguish them.
|
|
22
|
-
*/
|
|
23
|
-
export function completePath(prefix: string, entries: readonly string[]): PathCompletion {
|
|
24
|
-
const candidates = entries.filter((e) => e.startsWith(prefix));
|
|
25
|
-
if (candidates.length === 0) return { completed: prefix, candidates: [] };
|
|
26
|
-
if (candidates.length === 1) return { completed: candidates[0]!, candidates };
|
|
27
|
-
return { completed: longestCommonPrefix(candidates), candidates };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The whitespace-delimited token the cursor is in. Null when it does not
|
|
32
|
-
* look like a path, so Tab in ordinary prose keeps its existing no-op
|
|
33
|
-
* rather than swallowing the key.
|
|
34
|
-
*/
|
|
35
|
-
export function pathTokenAtCursor(text: string, cursor: number): PathToken | null {
|
|
36
|
-
let start = cursor;
|
|
37
|
-
while (start > 0 && !isTokenSep(text[start - 1]!)) start--;
|
|
38
|
-
let end = cursor;
|
|
39
|
-
while (end < text.length && !isTokenSep(text[end]!)) end++;
|
|
40
|
-
const prefix = text.slice(start, end);
|
|
41
|
-
if (!looksLikePath(prefix)) return null;
|
|
42
|
-
return { start, end, prefix };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function looksLikePath(s: string): boolean {
|
|
46
|
-
if (s.length === 0) return false;
|
|
47
|
-
// @-mentions are a different picker; stealing them here would hide
|
|
48
|
-
// the file-index path the user already has.
|
|
49
|
-
if (s.startsWith("@")) return false;
|
|
50
|
-
return s.includes("/") || s.startsWith("~") || s.startsWith(".");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Directory to list for a typed prefix. "src/fo" → "src"; "fo" → ".". */
|
|
54
|
-
export function dirOfPrefix(prefix: string): string {
|
|
55
|
-
if (prefix.endsWith("/")) return prefix.slice(0, -1) || ".";
|
|
56
|
-
const i = prefix.lastIndexOf("/");
|
|
57
|
-
if (i < 0) return ".";
|
|
58
|
-
if (i === 0) return "/";
|
|
59
|
-
return prefix.slice(0, i);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Join listing names back onto the prefix's directory, matching completePath. */
|
|
63
|
-
export function entriesFromNames(prefix: string, names: readonly string[]): readonly string[] {
|
|
64
|
-
const dir = dirOfPrefix(prefix);
|
|
65
|
-
return names.map((name) => {
|
|
66
|
-
if (dir === ".") return name;
|
|
67
|
-
if (dir === "/") return `/${name}`;
|
|
68
|
-
return `${dir}/${name}`;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function isTokenSep(ch: string): boolean {
|
|
73
|
-
return /\s/.test(ch);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function longestCommonPrefix(xs: readonly string[]): string {
|
|
77
|
-
const first = xs[0];
|
|
78
|
-
if (first === undefined) return "";
|
|
79
|
-
let p = first;
|
|
80
|
-
for (const s of xs) {
|
|
81
|
-
while (!s.startsWith(p)) {
|
|
82
|
-
if (p.length === 0) return "";
|
|
83
|
-
p = p.slice(0, -1);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return p;
|
|
87
|
-
}
|