D1: deployment UI, docs and G17
Some checks are pending
ci / ci (macos-15) (push) Waiting to run
ci / ci (ubuntu-24.04) (push) Waiting to run
ci / ci (windows-2025) (push) Waiting to run

Servers dialog (write-only keychain secret, test connection, unknown and
changed host key), status-bar progress with Cancel, Deployment log tool
window, Upload/Download in the project tree menu and Tools › Deployment.
docs/deployment.md, architecture section, G17 row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-06 18:46:11 +01:00
parent f3c9ef9ce3
commit 872b5cb258
22 changed files with 2628 additions and 26 deletions

View file

@ -20,7 +20,8 @@
* - **Navigation (M3.5):** the definition picker and the inline rename field
* are exclusive modals too. So is the branches popup (M4.5), and so are
* "Clone Repository…" and "Manage Remotes…" (M4.10), the merge
* dialog (M4.8) and the stash dialog (M4.9).
* dialog (M4.8) and the stash dialog (M4.9), and the deployment servers
* dialog (G17).
*/
import { defineStore } from "pinia";
import { ref, watch } from "vue";
@ -38,6 +39,7 @@ export type ModalId =
| "branches"
| "clone"
| "remotes"
| "deployment"
| "merge"
| "stash";

View file

@ -21,6 +21,12 @@ export interface UiCommandSpec {
/** The frontend's UI commands. */
export const UI_COMMANDS: readonly UiCommandSpec[] = [
{ id: "deployment.download", labelKey: "command.deployment.download", menuPath: "Tools/Deployment/Download Current File" },
{ id: "deployment.servers", labelKey: "command.deployment.servers", menuPath: "Tools/Deployment/Servers…" },
{ id: "deployment.showLog", labelKey: "command.deployment.showLog", menuPath: "Tools/Deployment/Deployment Log" },
{ id: "deployment.testConnection", labelKey: "command.deployment.testConnection", menuPath: "Tools/Deployment/Test Connection" },
{ id: "deployment.upload", labelKey: "command.deployment.upload", menuPath: "Tools/Deployment/Upload Current File" },
{ id: "deployment.uploadProject", labelKey: "command.deployment.uploadProject", menuPath: "Tools/Deployment/Upload Project" },
{ id: "editor.reveal", labelKey: "command.editor.reveal" },
{ id: "editor.complete", labelKey: "command.editor.complete", menuPath: "Edit/Complete Code" },
{ id: "editor.quickDocumentation", labelKey: "command.editor.quickDocumentation", menuPath: "Edit/Quick Documentation", defaultShortcut: "Mod+I" },

View file

@ -3,12 +3,14 @@
* Status bar along the bottom of the main window. Shows the product name and
* version, or the last engine error, and on the right the language server's
* progress (H3), a running fetch, pull, push or clone or the commits
* ahead and behind (M4.10), and the Git branch (M4.5).
* ahead and behind (M4.10), a running deployment job (G17), and the Git
* branch (M4.5).
*/
import { computed } from "vue";
import { t } from "../i18n";
import { useAppStore } from "../stores/app";
import LspProgressItem from "./problems/LspProgressItem.vue";
import DeployStatusItem from "./deploy/DeployStatusItem.vue";
import BranchStatusItem from "./vcs/branches/BranchStatusItem.vue";
import RemoteStatusItem from "./vcs/remote/RemoteStatusItem.vue";
@ -31,6 +33,7 @@ const label = computed(() => {
>
<span>{{ label }}</span>
<LspProgressItem />
<DeployStatusItem />
<RemoteStatusItem />
<BranchStatusItem />
</footer>

View file

@ -0,0 +1,233 @@
<script setup lang="ts">
/**
* Status-bar item of deployment (G17): while a test, upload or download
* runs, the server, the file count and the current file from
* `deployProgress`, and a Cancel button (`deploy.cancel`). Hidden
* otherwise.
*
* The item supplies the deployment UI commands, so they work wherever the
* status bar is shown (none has a default shortcut):
* - `deployment.upload {path?}` and `deployment.download {path?}`: the
* given project path (file or folder) or the active editor's file, to or
* from the default server. Without a default server the servers dialog
* opens instead;
* - `deployment.uploadProject`: the whole project;
* - `deployment.testConnection`: opens the servers dialog and tests the
* default server, so a host key can be checked there;
* - `deployment.servers`: opens the servers dialog.
* All are enabled with a project and while no job runs. It also mounts
* the dialog.
*/
import { LoaderCircle, X } from "@lucide/vue";
import { computed, onBeforeUnmount, onMounted } from "vue";
import { useCommandsStore } from "../../commands/store";
import { t } from "../../i18n";
import { useEditorStore } from "../../stores/editor";
import { useNotificationsStore } from "../../stores/notifications";
import { useProjectStore } from "../../stores/project";
import DeploymentDialog from "./DeploymentDialog.vue";
import { useDeployStore } from "./deploy";
const deploy = useDeployStore();
const commands = useCommandsStore();
const editor = useEditorStore();
const project = useProjectStore();
const notifications = useNotificationsStore();
/** The running job's text, or null while none runs. */
const progressText = computed(() => {
const p = deploy.progress;
if (p === null) {
return null;
}
const operation =
p.operation === "test"
? t("deploy.operation.test")
: p.operation === "upload"
? t("deploy.operation.upload")
: t("deploy.operation.download");
if (p.filesTotal === 0) {
return t("deploy.progress.short", { operation, server: p.server });
}
return t("deploy.progress.files", {
operation,
server: p.server,
done: p.filesDone,
total: p.filesTotal,
});
});
/**
* The path a command acts on: its `path` param, else the active file.
*
* @param params - the command's params.
*/
function pathOf(params: unknown): string | null {
const given = (params as { path?: unknown } | null)?.path;
if (typeof given === "string") {
return given;
}
return editor.activeTab?.path ?? null;
}
/**
* Runs `action` against the default server, or opens the servers dialog
* when there is none.
*
* @param action - what to do with the default server.
*/
async function withTarget(action: () => Promise<unknown>): Promise<void> {
if (deploy.servers.length === 0) {
await deploy.load();
}
if (deploy.target === null) {
notifications.notify({ level: "warning", messageKey: "notification.deploy.noServer" });
await deploy.showDialog();
return;
}
await action();
}
/** Withdraws the command handlers; filled while mounted. */
let withdraw: (() => void)[] = [];
onMounted(() => {
deploy.start();
if (project.root !== null) {
void deploy.load();
}
const idle = (): boolean => project.root !== null && !deploy.busy;
withdraw = [
commands.provide("deployment.upload", {
run: async (params) => {
const path = pathOf(params);
if (path !== null) {
await withTarget(() => deploy.upload([path]));
}
},
enabled: idle,
}),
commands.provide("deployment.download", {
run: async (params) => {
const path = pathOf(params);
if (path !== null) {
await withTarget(() => deploy.download([path]));
}
},
enabled: idle,
}),
commands.provide("deployment.uploadProject", {
run: () => withTarget(() => deploy.upload([""])),
enabled: idle,
}),
commands.provide("deployment.testConnection", {
run: async () => {
await deploy.showDialog();
const target = deploy.target;
if (target !== null) {
await deploy.testConnection(target.id);
}
},
enabled: idle,
}),
commands.provide("deployment.servers", {
run: () => deploy.showDialog(),
enabled: () => project.root !== null,
}),
];
});
onBeforeUnmount(() => {
for (const fn of withdraw) {
fn();
}
withdraw = [];
deploy.stop();
});
</script>
<template>
<span
v-if="progressText !== null"
class="deploy-item"
role="status"
:title="deploy.progress?.file || progressText"
data-test="deploy-progress"
>
<LoaderCircle
class="deploy-item__icon"
:size="12"
aria-hidden="true"
/>
<span class="deploy-item__text">{{ progressText }}</span>
<button
type="button"
class="deploy-item__cancel"
:title="t('deploy.cancel')"
:aria-label="t('deploy.cancel')"
data-test="deploy-cancel"
@click="deploy.cancel()"
>
<X
:size="12"
aria-hidden="true"
/>
</button>
</span>
<DeploymentDialog />
</template>
<style scoped>
.deploy-item {
display: inline-flex;
margin-left: auto;
align-items: center;
gap: 4px;
padding: 0 6px;
min-width: 0;
max-width: 35%;
white-space: nowrap;
}
.deploy-item__text {
overflow: hidden;
text-overflow: ellipsis;
}
.deploy-item__icon {
flex: none;
animation: deploy-item-spin 1.2s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
.deploy-item__icon {
animation: none;
}
}
@keyframes deploy-item-spin {
to {
transform: rotate(360deg);
}
}
.deploy-item__cancel {
display: inline-flex;
align-items: center;
padding: 0 2px;
font: inherit;
color: inherit;
background: transparent;
border: none;
border-radius: var(--lt-radius, 4px);
cursor: pointer;
}
.deploy-item__cancel:hover {
background: color-mix(in srgb, var(--lt-statusbar-fg) 12%, transparent);
}
.deploy-item__cancel:focus-visible {
outline: 2px solid var(--lt-accent);
}
</style>

View file

@ -0,0 +1,867 @@
<script setup lang="ts">
/**
* "Deployment Servers…" (G17): the project's servers on the left, the
* selected one's settings on the right.
*
* - **Fields:** name, type (SFTP, FTP, FTPS, local or mounted folder),
* host, port, user, root folder, sign-in (password, key file with an
* optional passphrase, or the SSH agent for SFTP), path mappings,
* excluded paths (one per line), upload on save (off by default) and
* "default server".
* - **Secrets:** the password or passphrase field is write-only. A typed
* value goes to the engine with Save and is kept only in the OS
* keychain; the field then empties again and says that one is stored.
* - **Test Connection** saves first, then tests. An unknown SFTP host key
* shows its fingerprint with "Trust and Connect"; a changed one is a
* warning whose replace button must be chosen explicitly.
* - Remove asks in place. Escape closes. The dialog is an exclusive modal
* (`commands/modals.ts`).
*/
import { computed, nextTick, ref, watch } from "vue";
import { useModalsStore } from "../../commands/modals";
import { t } from "../../i18n";
import { pickDir, pickFile } from "../../ipc";
import { blankServer, useDeployStore, type DeployServer, type ServerKind } from "./deploy";
const deploy = useDeployStore();
const modals = useModalsStore();
/** The selected server's id, "" for a new one. */
const selected = ref<string>("");
/** The form's values. */
const form = ref<DeployServer>(blankServer());
/** The typed password or passphrase, sent once with Save. */
const secret = ref("");
/** Whether the form's server is (to become) the default. */
const isDefault = ref(false);
/** The excluded paths, one per line. */
const excludedText = ref("");
/** Whether Remove waits for its confirmation. */
const confirmRemove = ref(false);
/** Whether Save or Test runs. */
const working = ref(false);
/** The name field. */
const nameInput = ref<HTMLInputElement | null>(null);
/** The host-key question box. */
const questionBox = ref<HTMLElement | null>(null);
/** The element that had the focus before the dialog opened. */
let returnFocus: HTMLElement | null = null;
/** Server types in the select, with their labels. */
const kindLabels = computed<{ id: ServerKind; label: string }[]>(() => [
{ id: "sftp", label: t("deploy.kind.sftp") },
{ id: "ftps", label: t("deploy.kind.ftps") },
{ id: "ftp", label: t("deploy.kind.ftp") },
{ id: "folder", label: t("deploy.kind.folder") },
]);
/** Whether the form needs a host, user and port. */
const remote = computed(() => form.value.kind !== "folder");
/** The secret the form's server needs, or null. */
const secretKind = computed<"password" | "passphrase" | null>(() => {
if (form.value.kind === "folder" || (form.value.kind === "sftp" && form.value.auth === "agent")) {
return null;
}
return form.value.kind === "sftp" && form.value.auth === "key" ? "passphrase" : "password";
});
/** Whether the selected server has its secret in the keychain. */
const hasSecret = computed(() => deploy.servers.find((s) => s.id === selected.value)?.hasSecret === true);
/** The port field as text; empty means the default port. */
const portText = computed({
get: () => (form.value.port === null ? "" : String(form.value.port)),
set: (text: string) => {
const n = Number.parseInt(text, 10);
form.value.port = text.trim() === "" || !Number.isFinite(n) ? null : n;
},
});
/** The key path field as text. */
const keyText = computed({
get: () => form.value.keyPath ?? "",
set: (text: string) => {
form.value.keyPath = text === "" ? null : text;
},
});
/**
* Shows a server in the form.
*
* @param id - its id, or "" for a new server.
*/
function select(id: string): void {
const server = deploy.servers.find((s) => s.id === id);
const copy = server ? { ...server, mappings: server.mappings.map((m) => ({ ...m })), excluded: [...server.excluded] } : blankServer();
selected.value = server ? id : "";
form.value = copy;
secret.value = "";
isDefault.value = server ? deploy.defaultServer === id || deploy.servers.length === 1 : deploy.servers.length === 0;
excludedText.value = copy.excluded.join("\n");
confirmRemove.value = false;
deploy.tested = null;
deploy.question = null;
}
/** Starts a new server. */
async function addNew(): Promise<void> {
select("");
await nextTick();
nameInput.value?.focus();
}
/** Adds an empty mapping row. */
function addMapping(): void {
form.value.mappings = [...form.value.mappings, { local: "", remote: "" }];
}
/**
* Removes a mapping row.
*
* @param index - the row.
*/
function removeMapping(index: number): void {
form.value.mappings = form.value.mappings.filter((_, i) => i !== index);
}
/**
* Saves the form.
*
* @returns the saved server's id, or null.
*/
async function save(): Promise<string | null> {
working.value = true;
try {
form.value.excluded = excludedText.value.split(/\r?\n/);
const id = await deploy.saveServer(form.value, secretKind.value === null ? "" : secret.value, isDefault.value);
if (id !== null) {
select(id);
}
return id;
} finally {
working.value = false;
}
}
/** Saves, then tests the connection. */
async function test(): Promise<void> {
const id = await save();
if (id === null) {
return;
}
working.value = true;
try {
await deploy.testConnection(id);
} finally {
working.value = false;
}
}
/** Removes the selected server after the confirmation. */
async function remove(): Promise<void> {
if (!confirmRemove.value) {
confirmRemove.value = true;
return;
}
const id = selected.value;
confirmRemove.value = false;
await deploy.removeServer(id);
select(deploy.servers[0]?.id ?? "");
}
/** Chooses the key file with the shell's picker. */
async function browseKey(): Promise<void> {
const picked = await pickFile(t("deploy.dialog.pickKey"));
if (picked.ok && picked.value !== null) {
form.value.keyPath = picked.value;
}
}
/** Chooses the deployment folder with the shell's picker. */
async function browseFolder(): Promise<void> {
const picked = await pickDir(t("deploy.dialog.pickFolder"));
if (picked.ok && picked.value !== null) {
form.value.root = picked.value;
}
}
/** Closes the dialog. */
function close(): void {
deploy.hideDialog();
}
/**
* Escape closes.
*
* @param event - the key.
*/
function onKeydown(event: KeyboardEvent): void {
if (event.key === "Escape") {
event.preventDefault();
close();
}
}
watch(
() => deploy.dialogOpen,
async (isOpen) => {
if (isOpen) {
const active = document.activeElement;
returnFocus = active instanceof HTMLElement ? active : null;
modals.opened("deployment", close);
select(deploy.target?.id ?? deploy.servers[0]?.id ?? "");
await nextTick();
nameInput.value?.focus();
} else {
modals.closed("deployment");
returnFocus?.focus();
returnFocus = null;
}
},
);
/**
* Scrolls a new host-key question into view; environments without
* `scrollIntoView` (tests) skip it.
*/
watch(
() => deploy.question,
async (question) => {
if (question !== null) {
await nextTick();
const box = questionBox.value;
if (box !== null && typeof box.scrollIntoView === "function") {
box.scrollIntoView({ block: "nearest" });
}
}
},
);
watch(
() => deploy.servers,
() => {
if (deploy.dialogOpen && selected.value !== "" && !deploy.servers.some((s) => s.id === selected.value)) {
select(deploy.servers[0]?.id ?? "");
}
},
);
</script>
<template>
<div
v-if="deploy.dialogOpen"
class="deploy-dialog"
data-test="deploy-dialog"
@mousedown.self="close"
>
<div
class="deploy-dialog__box"
role="dialog"
aria-modal="true"
aria-labelledby="lt-deploy-title"
@keydown="onKeydown"
>
<h2
id="lt-deploy-title"
class="deploy-dialog__title"
>
{{ t("deploy.dialog.title") }}
</h2>
<div class="deploy-dialog__body">
<nav
class="deploy-dialog__servers"
:aria-label="t('deploy.dialog.servers')"
>
<ul class="deploy-dialog__list">
<li
v-for="server in deploy.servers"
:key="server.id"
>
<button
type="button"
class="deploy-dialog__server"
:class="{ 'deploy-dialog__server--selected': server.id === selected }"
:aria-current="server.id === selected ? 'true' : undefined"
data-test="deploy-server"
@click="select(server.id)"
>
<span class="deploy-dialog__server-name">{{ server.name }}</span>
<span class="deploy-dialog__server-sub">
{{ server.kind.toUpperCase() }}{{ server.host ? ` · ${server.host}` : "" }}{{ server.id === deploy.defaultServer ? ` · ${t("deploy.dialog.defaultMark")}` : "" }}
</span>
</button>
</li>
</ul>
<button
type="button"
class="deploy-dialog__button"
data-test="deploy-add"
@click="addNew"
>
{{ t("deploy.dialog.add") }}
</button>
</nav>
<form
class="deploy-dialog__form"
@submit.prevent="save"
>
<label class="deploy-dialog__field">
<span>{{ t("deploy.field.name") }}</span>
<input
ref="nameInput"
v-model="form.name"
class="deploy-dialog__input"
type="text"
autocomplete="off"
data-test="deploy-name"
>
</label>
<label class="deploy-dialog__field">
<span>{{ t("deploy.field.kind") }}</span>
<select
v-model="form.kind"
class="deploy-dialog__input"
data-test="deploy-kind"
>
<option
v-for="kind in kindLabels"
:key="kind.id"
:value="kind.id"
>
{{ kind.label }}
</option>
</select>
</label>
<p
v-if="form.kind === 'ftp'"
class="deploy-dialog__warning"
data-test="deploy-ftp-warning"
>
{{ t("deploy.dialog.ftpWarning") }}
</p>
<template v-if="remote">
<div class="deploy-dialog__pair">
<label class="deploy-dialog__field deploy-dialog__field--grow">
<span>{{ t("deploy.field.host") }}</span>
<input
v-model="form.host"
class="deploy-dialog__input"
type="text"
spellcheck="false"
autocomplete="off"
data-test="deploy-host"
>
</label>
<label class="deploy-dialog__field deploy-dialog__field--port">
<span>{{ t("deploy.field.port") }}</span>
<input
v-model="portText"
class="deploy-dialog__input"
type="text"
inputmode="numeric"
:placeholder="form.kind === 'sftp' ? '22' : '21'"
data-test="deploy-port"
>
</label>
</div>
<label class="deploy-dialog__field">
<span>{{ t("deploy.field.user") }}</span>
<input
v-model="form.user"
class="deploy-dialog__input"
type="text"
spellcheck="false"
autocomplete="off"
data-test="deploy-user"
>
</label>
<label
v-if="form.kind === 'sftp'"
class="deploy-dialog__field"
>
<span>{{ t("deploy.field.auth") }}</span>
<select
v-model="form.auth"
class="deploy-dialog__input"
data-test="deploy-auth"
>
<option value="password">{{ t("deploy.auth.password") }}</option>
<option value="key">{{ t("deploy.auth.key") }}</option>
<option value="agent">{{ t("deploy.auth.agent") }}</option>
</select>
</label>
<label
v-if="form.kind === 'sftp' && form.auth === 'key'"
class="deploy-dialog__field"
>
<span>{{ t("deploy.field.keyPath") }}</span>
<span class="deploy-dialog__row">
<input
v-model="keyText"
class="deploy-dialog__input"
type="text"
spellcheck="false"
data-test="deploy-key"
>
<button
type="button"
class="deploy-dialog__button"
@click="browseKey"
>{{ t("deploy.dialog.browse") }}</button>
</span>
</label>
<label
v-if="secretKind !== null"
class="deploy-dialog__field"
>
<span>{{ secretKind === "password" ? t("deploy.field.password") : t("deploy.field.passphrase") }}</span>
<input
v-model="secret"
class="deploy-dialog__input"
type="password"
autocomplete="new-password"
:placeholder="hasSecret ? t('deploy.dialog.secretStored') : t('deploy.dialog.secretNone')"
data-test="deploy-secret"
>
</label>
<label class="deploy-dialog__field">
<span>{{ t("deploy.field.root") }}</span>
<input
v-model="form.root"
class="deploy-dialog__input"
type="text"
spellcheck="false"
:placeholder="t('deploy.field.rootPlaceholder')"
data-test="deploy-root"
>
</label>
</template>
<label
v-else
class="deploy-dialog__field"
>
<span>{{ t("deploy.field.folder") }}</span>
<span class="deploy-dialog__row">
<input
v-model="form.root"
class="deploy-dialog__input"
type="text"
spellcheck="false"
data-test="deploy-root"
>
<button
type="button"
class="deploy-dialog__button"
@click="browseFolder"
>{{ t("deploy.dialog.browse") }}</button>
</span>
</label>
<fieldset class="deploy-dialog__group">
<legend>{{ t("deploy.field.mappings") }}</legend>
<p class="deploy-dialog__hint">
{{ t("deploy.dialog.mappingsHint") }}
</p>
<div
v-for="(mapping, index) in form.mappings"
:key="index"
class="deploy-dialog__row"
data-test="deploy-mapping"
>
<input
v-model="mapping.local"
class="deploy-dialog__input"
type="text"
spellcheck="false"
:aria-label="t('deploy.field.mappingLocal')"
:placeholder="t('deploy.field.mappingLocal')"
>
<span aria-hidden="true">{{ t("deploy.dialog.mapsTo") }}</span>
<input
v-model="mapping.remote"
class="deploy-dialog__input"
type="text"
spellcheck="false"
:aria-label="t('deploy.field.mappingRemote')"
:placeholder="t('deploy.field.mappingRemote')"
>
<button
type="button"
class="deploy-dialog__button"
:aria-label="t('deploy.dialog.removeMapping')"
@click="removeMapping(index)"
>
×
</button>
</div>
<button
type="button"
class="deploy-dialog__button deploy-dialog__button--small"
data-test="deploy-add-mapping"
@click="addMapping"
>
{{ t("deploy.dialog.addMapping") }}
</button>
</fieldset>
<label class="deploy-dialog__field">
<span>{{ t("deploy.field.excluded") }}</span>
<textarea
v-model="excludedText"
class="deploy-dialog__input deploy-dialog__textarea"
rows="3"
spellcheck="false"
data-test="deploy-excluded"
/>
</label>
<label class="deploy-dialog__check">
<input
v-model="form.uploadOnSave"
type="checkbox"
data-test="deploy-upload-on-save"
>
{{ t("deploy.field.uploadOnSave") }}
</label>
<label class="deploy-dialog__check">
<input
v-model="isDefault"
type="checkbox"
data-test="deploy-default"
>
{{ t("deploy.field.default") }}
</label>
<div
v-if="deploy.question !== null"
ref="questionBox"
class="deploy-dialog__question"
:class="{ 'deploy-dialog__question--changed': deploy.question.status === 'changed' }"
role="alert"
data-test="deploy-hostkey"
>
<template v-if="deploy.question.status === 'unknown'">
<strong>{{ t("deploy.hostKey.unknownTitle") }}</strong>
<span>{{ t("deploy.hostKey.unknown", { host: deploy.question.host }) }}</span>
<code class="deploy-dialog__fingerprint">{{ deploy.question.algorithm }} {{ deploy.question.fingerprint }}</code>
<span class="deploy-dialog__buttons">
<button
type="button"
class="deploy-dialog__button"
@click="deploy.rejectHostKey()"
>{{ t("deploy.hostKey.reject") }}</button>
<button
type="button"
class="deploy-dialog__button deploy-dialog__button--primary"
data-test="deploy-trust"
@click="deploy.trustHostKey(false)"
>{{ t("deploy.hostKey.trust") }}</button>
</span>
</template>
<template v-else>
<strong>{{ t("deploy.hostKey.changedTitle") }}</strong>
<span>{{ t("deploy.hostKey.changed", { host: deploy.question.host }) }}</span>
<span>{{ t("deploy.hostKey.trusted") }} <code class="deploy-dialog__fingerprint">{{ deploy.question.known }}</code></span>
<span>{{ t("deploy.hostKey.offered") }} <code class="deploy-dialog__fingerprint">{{ deploy.question.algorithm }} {{ deploy.question.fingerprint }}</code></span>
<span class="deploy-dialog__buttons">
<button
type="button"
class="deploy-dialog__button deploy-dialog__button--primary"
@click="deploy.rejectHostKey()"
>{{ t("deploy.hostKey.keep") }}</button>
<button
type="button"
class="deploy-dialog__button deploy-dialog__button--danger"
data-test="deploy-replace"
@click="deploy.trustHostKey(true)"
>{{ t("deploy.hostKey.replace") }}</button>
</span>
</template>
</div>
<p
v-if="deploy.tested !== null && deploy.question === null"
class="deploy-dialog__outcome"
:class="{ 'deploy-dialog__outcome--ok': deploy.tested.ok }"
role="status"
data-test="deploy-tested"
>
{{ deploy.tested.message }}
</p>
<p
v-if="deploy.dialogError !== null"
class="deploy-dialog__error"
role="alert"
data-test="deploy-error"
>
{{ deploy.dialogError }}
</p>
</form>
</div>
<div class="deploy-dialog__buttons">
<button
v-if="selected !== ''"
type="button"
class="deploy-dialog__button"
:class="{ 'deploy-dialog__button--danger': confirmRemove }"
data-test="deploy-remove"
@click="remove"
>
{{ confirmRemove ? t("deploy.dialog.confirmRemove") : t("deploy.dialog.remove") }}
</button>
<span class="deploy-dialog__spacer" />
<button
type="button"
class="deploy-dialog__button"
:disabled="working || deploy.busy"
data-test="deploy-test"
@click="test"
>
{{ t("deploy.dialog.test") }}
</button>
<button
type="button"
class="deploy-dialog__button deploy-dialog__button--primary"
:disabled="working"
data-test="deploy-save"
@click="save"
>
{{ t("deploy.dialog.save") }}
</button>
<button
type="button"
class="deploy-dialog__button"
data-test="deploy-close"
@click="close"
>
{{ t("deploy.dialog.close") }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.deploy-dialog {
position: fixed;
inset: 0;
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 5vh;
background: color-mix(in srgb, var(--lt-bg) 50%, transparent);
z-index: 20;
}
.deploy-dialog__box {
width: min(860px, 94vw);
max-height: 90vh;
display: flex;
flex-direction: column;
gap: 10px;
padding: 16px;
background: var(--lt-bg);
color: var(--lt-fg);
border: 1px solid var(--lt-border);
border-radius: 6px;
}
.deploy-dialog__title {
margin: 0;
font-size: var(--lt-font-size-ui);
font-weight: 600;
}
.deploy-dialog__body {
display: flex;
gap: 12px;
min-height: 0;
overflow: hidden;
}
.deploy-dialog__servers {
display: flex;
flex: 0 0 200px;
flex-direction: column;
gap: 8px;
padding-right: 12px;
border-right: 1px solid var(--lt-border);
}
.deploy-dialog__list {
margin: 0;
padding: 0;
list-style: none;
overflow-y: auto;
}
.deploy-dialog__server {
display: flex;
flex-direction: column;
width: 100%;
padding: 4px 6px;
font: inherit;
text-align: left;
color: var(--lt-fg);
background: transparent;
border: none;
border-radius: 4px;
}
.deploy-dialog__server--selected {
background: var(--lt-editor-selection-bg);
}
.deploy-dialog__server-sub {
color: var(--lt-fg-muted);
font-size: var(--lt-font-size-small);
}
.deploy-dialog__form {
display: flex;
flex: 1;
flex-direction: column;
gap: 8px;
min-width: 0;
overflow-y: auto;
padding-right: 4px;
}
.deploy-dialog__field {
display: flex;
flex-direction: column;
gap: 4px;
}
.deploy-dialog__field--grow {
flex: 1;
}
.deploy-dialog__field--port {
flex: 0 0 8ch;
}
.deploy-dialog__pair,
.deploy-dialog__row {
display: flex;
align-items: center;
gap: 8px;
}
.deploy-dialog__input {
flex: 1;
min-width: 0;
padding: 4px 6px;
font: inherit;
color: var(--lt-fg);
background: var(--lt-editor-bg);
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.deploy-dialog__textarea {
resize: vertical;
font-family: var(--lt-font-mono);
}
.deploy-dialog__group {
display: flex;
flex-direction: column;
gap: 6px;
margin: 0;
padding: 6px 8px;
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.deploy-dialog__check {
display: flex;
align-items: center;
gap: 6px;
}
.deploy-dialog__hint {
margin: 0;
color: var(--lt-fg-muted);
font-size: var(--lt-font-size-small);
}
.deploy-dialog__warning {
margin: 0;
color: var(--lt-diag-warning);
font-size: var(--lt-font-size-small);
}
.deploy-dialog__question {
display: flex;
flex-direction: column;
gap: 6px;
padding: 8px;
border: 1px solid var(--lt-accent);
border-radius: 4px;
}
.deploy-dialog__question--changed {
border-color: var(--lt-error);
}
.deploy-dialog__fingerprint {
font-family: var(--lt-font-mono);
overflow-wrap: anywhere;
}
.deploy-dialog__outcome {
margin: 0;
overflow-wrap: anywhere;
}
.deploy-dialog__outcome--ok {
color: var(--lt-diag-info);
}
.deploy-dialog__error {
margin: 0;
color: var(--lt-error);
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.deploy-dialog__buttons {
display: flex;
justify-content: flex-end;
gap: 8px;
}
.deploy-dialog__spacer {
flex: 1;
}
.deploy-dialog__button {
padding: 4px 12px;
font: inherit;
color: var(--lt-fg);
background: var(--lt-editor-bg);
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.deploy-dialog__button--small {
align-self: flex-start;
padding: 2px 8px;
}
.deploy-dialog__button--primary {
border-color: var(--lt-accent);
}
.deploy-dialog__button--danger {
border-color: var(--lt-error);
color: var(--lt-error);
}
.deploy-dialog__button:disabled {
color: var(--lt-fg-muted);
}
.deploy-dialog__input:focus-visible,
.deploy-dialog__button:focus-visible,
.deploy-dialog__server:focus-visible {
outline: 1px solid var(--lt-accent);
}
</style>

View file

@ -0,0 +1,217 @@
<script setup lang="ts">
/**
* The Deployment log tool window (G17), shown in the bottom panel: every
* line of the deployment log (newest at the bottom), with its time, the
* server and a severity icon; the running job's progress above the list
* with Cancel; and Clear. The log follows new lines while it is scrolled
* to the bottom. State lives in the Deployment store (`deploy.ts`).
*/
import { CircleAlert, Info, TriangleAlert } from "@lucide/vue";
import { computed, nextTick, ref, watch } from "vue";
import { t } from "../../i18n";
import { useDeployStore, type LogEntry } from "./deploy";
const deploy = useDeployStore();
/** The list element. */
const list = ref<HTMLElement | null>(null);
/** Icons by severity. */
const ICONS = { error: CircleAlert, warning: TriangleAlert, info: Info } as const;
/**
* The time of a line, `HH:MM:SS` in local time.
*
* @param entry - the line.
*/
function timeOf(entry: LogEntry): string {
const d = new Date(entry.time);
const two = (n: number) => String(n).padStart(2, "0");
return `${two(d.getHours())}:${two(d.getMinutes())}:${two(d.getSeconds())}`;
}
/**
* The accessible name of a severity.
*
* @param level - the severity.
*/
function levelLabel(level: LogEntry["level"]): string {
return level === "error"
? t("deploy.log.error")
: level === "warning"
? t("deploy.log.warning")
: t("deploy.log.info");
}
/** The running job's line, or null. */
const running = computed(() => {
const p = deploy.progress;
if (p === null) {
return null;
}
return t("deploy.log.running", {
server: p.server,
done: p.filesDone,
total: p.filesTotal,
file: p.file,
});
});
watch(
() => deploy.entries.length,
async () => {
const el = list.value;
const atBottom = el === null || el.scrollTop + el.clientHeight >= el.scrollHeight - 24;
await nextTick();
if (atBottom && list.value) {
list.value.scrollTop = list.value.scrollHeight;
}
},
);
</script>
<template>
<section
class="deploy-log"
:aria-label="t('deploy.log.title')"
data-test="deploy-log"
>
<header class="deploy-log__header">
<span
v-if="running !== null"
class="deploy-log__running"
role="status"
>{{ running }}</span>
<span
v-else
class="deploy-log__idle"
>{{ deploy.entries.length === 0 ? t("deploy.log.empty") : "" }}</span>
<button
v-if="running !== null"
type="button"
class="deploy-log__button"
data-test="deploy-log-cancel"
@click="deploy.cancel()"
>
{{ t("deploy.cancel") }}
</button>
<button
type="button"
class="deploy-log__button"
:disabled="deploy.entries.length === 0"
data-test="deploy-log-clear"
@click="deploy.clearLog()"
>
{{ t("deploy.log.clear") }}
</button>
</header>
<ol
ref="list"
class="deploy-log__list"
>
<li
v-for="entry in deploy.entries"
:key="entry.id"
class="deploy-log__line"
:class="`deploy-log__line--${entry.level}`"
data-test="deploy-log-line"
>
<component
:is="ICONS[entry.level]"
class="deploy-log__icon"
:size="12"
:aria-label="levelLabel(entry.level)"
/>
<time class="deploy-log__time">{{ timeOf(entry) }}</time>
<span class="deploy-log__server">{{ entry.server }}</span>
<span class="deploy-log__message">{{ entry.message }}</span>
</li>
</ol>
</section>
</template>
<style scoped>
.deploy-log {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
}
.deploy-log__header {
display: flex;
align-items: center;
gap: 8px;
flex: none;
padding: 2px 8px;
border-bottom: 1px solid var(--lt-border);
}
.deploy-log__running,
.deploy-log__idle {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--lt-fg-muted);
}
.deploy-log__button {
padding: 1px 8px;
font: inherit;
color: var(--lt-fg);
background: transparent;
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.deploy-log__button:disabled {
color: var(--lt-fg-muted);
}
.deploy-log__button:focus-visible {
outline: 1px solid var(--lt-accent);
}
.deploy-log__list {
flex: 1;
margin: 0;
padding: 2px 0;
list-style: none;
overflow-y: auto;
font-family: var(--lt-font-mono);
font-size: var(--lt-font-size-small);
}
.deploy-log__line {
display: flex;
align-items: baseline;
gap: 8px;
padding: 1px 8px;
}
.deploy-log__icon {
flex: none;
align-self: center;
}
.deploy-log__line--error {
color: var(--lt-error);
}
.deploy-log__line--warning {
color: var(--lt-diag-warning);
}
.deploy-log__time,
.deploy-log__server {
flex: none;
color: var(--lt-fg-muted);
}
.deploy-log__message {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
</style>

View file

@ -0,0 +1,694 @@
/**
* Deployment (G17, owner decision D27): servers of the project, test
* connection, host keys, upload, download, the log and the running job,
* through the engine's `deploy.*` commands.
*
* - **Secrets** go to the engine once (`deploy.saveServer {secret}` or
* `deploy.setSecret`), which keeps them only in the OS keychain. The store
* never keeps or shows one; a server only says whether one is stored.
* - **Host keys:** test connection answers an unknown or changed SFTP host
* key as a {@link HostKeyQuestion}; the dialog shows the fingerprint and
* the user trusts it (`deploy.trustHostKey`), replacing a changed one only
* on an explicit second choice.
* - **Progress and log:** `deployProgress` feeds {@link progress} (the
* status-bar item, with Cancel); `deployLog` appends to {@link entries}
* (the Deployment log tool window, newest 1,000 lines).
* - **Upload and download** are pending outcomes (`runWaiting`) and end in
* a toast: what was transferred, cancelled, or the explained refusal.
*/
import { defineStore } from "pinia";
import { computed, ref, shallowRef } from "vue";
import { onEngineEvent, run, runWaiting, type EngineEventPayload, type JsonValue } from "../../ipc";
import { t } from "../../i18n";
import { useNotificationsStore } from "../../stores/notifications";
/** Most log lines kept, like the engine. */
export const MAX_LOG = 1000;
/** Most servers read from one answer. */
export const MAX_SERVERS = 100;
/** A server's protocol. */
export type ServerKind = "sftp" | "ftp" | "ftps" | "folder";
/** How a server signs in. */
export type AuthKind = "password" | "key" | "agent";
/** One local folder mapped to one remote folder. */
export interface Mapping {
/** Project-relative folder, "" for the root. */
local: string;
/** Remote folder, relative to the root or absolute. */
remote: string;
}
/** A server as `deploy.servers` lists it. */
export interface DeployServer {
/** Stable id. */
id: string;
/** Shown name. */
name: string;
/** Protocol. */
kind: ServerKind;
/** Host; "" for a folder. */
host: string;
/** Port, or null for the default. */
port: number | null;
/** User name. */
user: string;
/** Remote root, or the local folder. */
root: string;
/** How to sign in. */
auth: AuthKind;
/** Private key file for key sign-in. */
keyPath: string | null;
/** Path mappings. */
mappings: Mapping[];
/** Excluded paths and patterns. */
excluded: string[];
/** Upload after every save. */
uploadOnSave: boolean;
/** Which secret the server needs, if any. */
secretKind: "password" | "passphrase" | null;
/** Whether that secret is in the keychain. */
hasSecret: boolean;
}
/** The running job, as `deployProgress` reports it. */
export interface DeployProgress {
/** `test`, `upload` or `download`. */
operation: "test" | "upload" | "download";
/** The server's name. */
server: string;
/** `connecting`, `planning` or `transferring`. */
phase: string;
/** The file being transferred, or "". */
file: string;
/** Files done. */
filesDone: number;
/** Files planned. */
filesTotal: number;
}
/** One line of the deployment log. */
export interface LogEntry {
/** Increasing id. */
id: number;
/** Milliseconds since the epoch. */
time: number;
/** Severity. */
level: "info" | "warning" | "error";
/** The server's name. */
server: string;
/** The text. */
message: string;
}
/** An SFTP host key test connection asks about. */
export interface HostKeyQuestion {
/** The server's id. */
serverId: string;
/** `unknown`: first connection; `changed`: differs from the trusted one. */
status: "unknown" | "changed";
/** `host:port`. */
host: string;
/** The key's algorithm. */
algorithm: string;
/** The offered fingerprint. */
fingerprint: string;
/** The trusted fingerprint, for a changed key. */
known: string;
}
/** What test connection said, for the dialog. */
export interface TestOutcome {
/** Whether it connected. */
ok: boolean;
/** The engine's sentence. */
message: string;
/** Which secret is missing, if that was the reason. */
needsSecret: "password" | "passphrase" | null;
}
/**
* Reads an untrusted object.
*
* @param raw - anything.
*/
function obj(raw: unknown): Record<string, unknown> {
return typeof raw === "object" && raw !== null && !Array.isArray(raw) ? (raw as Record<string, unknown>) : {};
}
/**
* A string field, or "".
*
* @param raw - anything.
*/
function str(raw: unknown): string {
return typeof raw === "string" ? raw : "";
}
/**
* A non-negative integer field, or 0.
*
* @param raw - anything.
*/
function count(raw: unknown): number {
return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0;
}
/**
* Reads one server; null when malformed.
*
* @param raw - untrusted.
*/
export function toServer(raw: unknown): DeployServer | null {
const s = obj(raw);
const kind = s.kind;
if (typeof s.id !== "string" || s.id === "" || (kind !== "sftp" && kind !== "ftp" && kind !== "ftps" && kind !== "folder")) {
return null;
}
const auth: AuthKind = s.auth === "key" || s.auth === "agent" ? s.auth : "password";
const mappings = Array.isArray(s.mappings)
? (s.mappings as unknown[]).slice(0, 200).map((m) => ({ local: str(obj(m).local), remote: str(obj(m).remote) }))
: [];
const excluded = Array.isArray(s.excluded)
? (s.excluded as unknown[]).filter((e): e is string => typeof e === "string").slice(0, 200)
: [];
return {
id: s.id,
name: str(s.name),
kind,
host: str(s.host),
port: typeof s.port === "number" && Number.isInteger(s.port) ? s.port : null,
user: str(s.user),
root: str(s.root),
auth,
keyPath: typeof s.keyPath === "string" ? s.keyPath : null,
mappings,
excluded,
uploadOnSave: s.uploadOnSave === true,
secretKind: s.secretKind === "password" || s.secretKind === "passphrase" ? s.secretKind : null,
hasSecret: s.hasSecret === true,
};
}
/**
* Reads a `deployProgress` event; null when nothing runs or it is
* malformed.
*
* @param event - the untrusted event.
*/
export function toProgress(event: EngineEventPayload): DeployProgress | null {
if (event.kind !== "deployProgress" || event.active !== true) {
return null;
}
const operation = event.operation;
if (operation !== "test" && operation !== "upload" && operation !== "download") {
return null;
}
return {
operation,
server: str(event.server).slice(0, 200),
phase: str(event.phase).slice(0, 40),
file: str(event.file).slice(0, 500),
filesDone: count(event.filesDone),
filesTotal: count(event.filesTotal),
};
}
/**
* Reads one log line; null when malformed.
*
* @param raw - untrusted.
*/
export function toEntry(raw: unknown): LogEntry | null {
const e = obj(raw);
const level = e.level;
if (typeof e.id !== "number" || (level !== "info" && level !== "warning" && level !== "error")) {
return null;
}
return { id: e.id, time: count(e.time), level, server: str(e.server), message: str(e.message).slice(0, 4000) };
}
/**
* Reads a test-connection answer into the dialog's outcome and the host
* key question, if any.
*
* @param serverId - the tested server.
* @param raw - the untrusted value.
*/
export function toTest(serverId: string, raw: unknown): { outcome: TestOutcome; question: HostKeyQuestion | null } {
const v = obj(raw);
const key = obj(v.hostKey);
const status = key.status;
const question: HostKeyQuestion | null =
status === "unknown" || status === "changed"
? {
serverId,
status,
host: str(key.host),
algorithm: str(key.algorithm),
fingerprint: str(key.fingerprint),
known: str(key.known),
}
: null;
const needs = v.needsSecret;
return {
outcome: {
ok: v.ok === true,
message: str(v.message),
needsSecret: needs === "password" || needs === "passphrase" ? needs : null,
},
question,
};
}
/**
* A server definition as `deploy.saveServer` takes it: without the
* read-only fields, with the port only when set.
*
* @param server - the edited server; an empty id adds a new one.
*/
export function toSaveParams(server: DeployServer): Record<string, JsonValue> {
const out: Record<string, JsonValue> = {
name: server.name,
kind: server.kind,
host: server.host,
user: server.user,
root: server.root,
auth: server.kind === "sftp" ? server.auth : "password",
mappings: server.mappings
.filter((m) => m.local.trim() !== "" || m.remote.trim() !== "")
.map((m) => ({ local: m.local.trim(), remote: m.remote.trim() })),
excluded: server.excluded.map((e) => e.trim()).filter((e) => e !== ""),
uploadOnSave: server.uploadOnSave,
};
if (server.id !== "") {
out.id = server.id;
}
if (server.port !== null) {
out.port = server.port;
}
if (server.kind === "sftp" && server.auth === "key" && server.keyPath !== null) {
out.keyPath = server.keyPath;
}
return out;
}
/**
* "1 file" or "{n} files".
*
* @param n - the number of files.
*/
export function filesText(n: number): string {
return n === 1 ? t("deploy.files.one") : t("deploy.files.other", { count: String(n) });
}
/** A new server's starting values: SFTP, `.git` and `.env` excluded. */
export function blankServer(): DeployServer {
return {
id: "",
name: "",
kind: "sftp",
host: "",
port: null,
user: "",
root: "",
auth: "password",
keyPath: null,
mappings: [],
excluded: [".env", ".idea", "node_modules"],
uploadOnSave: false,
secretKind: "password",
hasSecret: false,
};
}
/** The Deployment store. */
export const useDeployStore = defineStore("deploy", () => {
const notifications = useNotificationsStore();
/** The project's servers. */
const servers = shallowRef<DeployServer[]>([]);
/** The default server's id. */
const defaultServer = ref<string | null>(null);
/** The running job, or null. */
const progress = shallowRef<DeployProgress | null>(null);
/** A job was started here and has not answered. */
const starting = ref(false);
/** Whether a job runs. */
const busy = computed(() => starting.value || progress.value !== null);
/** The log, oldest first. */
const entries = ref<LogEntry[]>([]);
/** Whether the log tool window is shown. */
const visible = ref(false);
/** Whether the bottom panel is expanded while the log is shown. */
const expanded = ref(true);
/** Whether the servers dialog is open. */
const dialogOpen = ref(false);
/** The open host-key question. */
const question = shallowRef<HostKeyQuestion | null>(null);
/** The last test's outcome, for the dialog. */
const tested = shallowRef<TestOutcome | null>(null);
/** The dialog's last error. */
const dialogError = ref<string | null>(null);
/** The default server, or null. */
const target = computed(() => servers.value.find((s) => s.id === defaultServer.value) ?? null);
/** Stops listening; set while started. */
let unsubscribe: (() => void) | null = null;
/** How many holders called {@link start}. */
let holders = 0;
/**
* Appends a log line, keeping the newest {@link MAX_LOG}.
*
* @param entry - the line.
*/
function append(entry: LogEntry): void {
const next = [...entries.value, entry];
entries.value = next.length > MAX_LOG ? next.slice(next.length - MAX_LOG) : next;
}
/** Follows the deployment events. Counted: every `start` needs a `stop`. */
function start(): void {
holders += 1;
if (unsubscribe === null) {
unsubscribe = onEngineEvent((event) => {
if (event.kind === "deployProgress") {
progress.value = toProgress(event);
} else if (event.kind === "deployLog") {
const entry = toEntry(event.entry);
if (entry !== null) {
append(entry);
}
} else if (event.kind === "projectOpened") {
void load();
} else if (event.kind === "projectClosed") {
servers.value = [];
defaultServer.value = null;
dialogOpen.value = false;
}
});
}
}
/** Stops following the events when the last holder stops. */
function stop(): void {
holders = Math.max(0, holders - 1);
if (holders === 0) {
unsubscribe?.();
unsubscribe = null;
}
}
/**
* Reads the project's servers.
*
* @returns whether it worked.
*/
async function load(): Promise<boolean> {
const result = await run("deploy.servers");
if (!result.ok) {
servers.value = [];
defaultServer.value = null;
return false;
}
const v = obj(result.value);
const list = Array.isArray(v.servers) ? (v.servers as unknown[]) : [];
servers.value = list
.slice(0, MAX_SERVERS)
.map(toServer)
.filter((s): s is DeployServer => s !== null);
defaultServer.value = typeof v.defaultServer === "string" ? v.defaultServer : null;
return true;
}
/** Reads the log the engine kept (after a reload of the window). */
async function loadLog(): Promise<void> {
const result = await run("deploy.log");
if (!result.ok) {
return;
}
const v = obj(result.value);
const list = Array.isArray(v.entries) ? (v.entries as unknown[]) : [];
entries.value = list
.map(toEntry)
.filter((e): e is LogEntry => e !== null)
.slice(-MAX_LOG);
}
/** Shows the log tool window. */
function showLog(): void {
visible.value = true;
expanded.value = true;
void loadLog();
}
/** Hides the log tool window. */
function hide(): void {
visible.value = false;
}
/** Clears the log. */
async function clearLog(): Promise<void> {
const result = await run("deploy.clearLog");
if (result.ok) {
entries.value = [];
}
}
/** Reads the servers, then opens the servers dialog on the default one. */
async function showDialog(): Promise<void> {
dialogError.value = null;
tested.value = null;
question.value = null;
await load();
dialogOpen.value = true;
}
/** Closes the servers dialog. */
function hideDialog(): void {
dialogOpen.value = false;
question.value = null;
}
/**
* Adds or replaces a server, with a new secret when one was typed.
*
* @param server - the edited server.
* @param secret - the typed password or passphrase, or "".
* @param makeDefault - also make it the default server.
* @returns the saved server's id, or null (the reason is in {@link dialogError}).
*/
async function saveServer(server: DeployServer, secret: string, makeDefault: boolean): Promise<string | null> {
const params: Record<string, JsonValue> = { server: toSaveParams(server) };
if (secret !== "") {
params.secret = secret;
}
const result = await run("deploy.saveServer", params);
if (!result.ok) {
dialogError.value = result.error.message;
return null;
}
const saved = toServer(obj(result.value).server);
if (saved === null) {
dialogError.value = null;
await load();
return null;
}
if (makeDefault && defaultServer.value !== saved.id) {
await run("deploy.setDefault", { id: saved.id });
} else if (!makeDefault && defaultServer.value === saved.id && servers.value.length > 1) {
await run("deploy.setDefault", { id: null });
}
dialogError.value = null;
await load();
return saved.id;
}
/**
* Removes a server and its keychain entries.
*
* @param id - the server.
*/
async function removeServer(id: string): Promise<void> {
const result = await run("deploy.removeServer", { id });
dialogError.value = result.ok ? null : result.error.message;
await load();
}
/**
* Tests the connection to a saved server; fills {@link tested} and, for
* an unknown or changed host key, {@link question}.
*
* @param id - the server.
*/
async function testConnection(id: string): Promise<TestOutcome | null> {
starting.value = true;
tested.value = null;
question.value = null;
try {
const result = await runWaiting("deploy.testConnection", { id });
if (!result.ok) {
dialogError.value = result.error.message;
return null;
}
dialogError.value = null;
const read = toTest(id, result.value);
tested.value = read.outcome;
question.value = read.question;
return read.outcome;
} finally {
starting.value = false;
}
}
/**
* Trusts the asked host key and tests again.
*
* @param replace - replace a changed trusted key (the second, explicit choice).
*/
async function trustHostKey(replace: boolean): Promise<void> {
const q = question.value;
if (q === null) {
return;
}
const result = await run("deploy.trustHostKey", {
id: q.serverId,
algorithm: q.algorithm,
fingerprint: q.fingerprint,
replace,
});
if (!result.ok) {
dialogError.value = result.error.message;
return;
}
question.value = null;
await testConnection(q.serverId);
}
/** Dismisses the host-key question without trusting the key. */
function rejectHostKey(): void {
question.value = null;
}
/**
* Runs an upload or download and reports it in a toast.
*
* @param command - `deploy.upload` or `deploy.download`.
* @param paths - project-relative paths, "" for the whole project.
* @param id - a server, or the default one when absent.
* @returns whether it ran without failures.
*/
async function transfer(command: "deploy.upload" | "deploy.download", paths: string[], id?: string): Promise<boolean> {
if (busy.value) {
notifications.notify({ level: "warning", messageKey: "notification.deploy.busy" });
return false;
}
starting.value = true;
try {
const params: Record<string, JsonValue> = { paths };
if (id !== undefined) {
params.id = id;
}
const result = await runWaiting(command, params);
const upload = command === "deploy.upload";
if (!result.ok) {
const reason = result.error.message.trim() || "?";
if (reason === "cancelled" || reason.endsWith(": cancelled")) {
notifications.notify({ level: "info", messageKey: "notification.deploy.cancelled" });
} else {
notifications.notify({
level: "error",
messageKey: upload ? "notification.deploy.uploadFailed" : "notification.deploy.downloadFailed",
message: reason,
params: { reason },
});
}
return false;
}
const v = obj(result.value);
const files = count(v.files);
const failed = count(v.failed);
const skipped = count(v.skipped);
const server = (id !== undefined ? servers.value.find((s) => s.id === id) : target.value)?.name ?? "";
notifications.notify({
level: failed > 0 ? "warning" : "info",
messageKey: failed > 0
? "notification.deploy.partly"
: upload
? "notification.deploy.uploaded"
: "notification.deploy.downloaded",
params: { files: filesText(files), failed: filesText(failed), skipped: String(skipped), server },
});
return failed === 0;
} finally {
starting.value = false;
}
}
/**
* Uploads files or folders.
*
* @param paths - project-relative paths, "" for the whole project.
* @param id - a server, or the default one.
*/
function upload(paths: string[], id?: string): Promise<boolean> {
return transfer("deploy.upload", paths, id);
}
/**
* Downloads files or folders, replacing the local ones.
*
* @param paths - project-relative paths.
* @param id - a server, or the default one.
*/
function download(paths: string[], id?: string): Promise<boolean> {
return transfer("deploy.download", paths, id);
}
/**
* Stops the running job.
*
* @returns whether one was stopped.
*/
async function cancel(): Promise<boolean> {
const result = await run("deploy.cancel");
return result.ok;
}
return {
servers,
defaultServer,
target,
progress,
busy,
entries,
visible,
expanded,
dialogOpen,
question,
tested,
dialogError,
start,
stop,
load,
loadLog,
showLog,
hide,
clearLog,
showDialog,
hideDialog,
saveServer,
removeServer,
testConnection,
trustHostKey,
rejectHostKey,
upload,
download,
cancel,
};
});

View file

@ -16,7 +16,8 @@
* the left window when that tool window is already shown.
*
* The bottom panel ({@link BottomPanel}) holds the Find, Terminal and
* Problems tool windows, as tabs in its header while more than one is
* Problems tool windows (and the Deployment log, G17, which appears with
* `deployment.showLog`), as tabs in its header while more than one is
* shown. Find appears with the UI command `find.open` (`Mod+Alt+F`),
* Terminal with `terminal.open` (`Mod+Shift+T`, M3.6), Problems with
* `problems.open` (`Mod+Alt+P`, M3.3); all are supplied here so they work
@ -60,6 +61,8 @@ import { useChangesStore } from "../vcs/changes/changes";
import LogToolWindow from "../vcs/log/LogToolWindow.vue";
import { SHOW_HISTORY_COMMAND, SHOW_LOG_COMMAND, useLogStore } from "../vcs/log/log";
import StashDialog from "../vcs/stash/StashDialog.vue";
import DeploymentLogToolWindow from "../deploy/DeploymentLogToolWindow.vue";
import { useDeployStore } from "../deploy/deploy";
import { SHOW_COMMIT_COMMAND, TOGGLE_BLAME_COMMAND, setCommitOpener, toggleBlame } from "../editor/blame";
import { SHOW_CHUNK_COMMAND, openChunkPopup } from "../editor/chunkPopup";
import { activeView } from "../editor/nav/navExtension";
@ -113,11 +116,12 @@ const problems = useProblemsStore();
const nav = useNavStore();
const changes = useChangesStore();
const vcsLog = useLogStore();
const deploy = useDeployStore();
const editor = useEditorStore();
const project = useProjectStore();
/** Tool windows of the bottom panel. */
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log";
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log" | "deployment";
/** The bottom tool window last chosen. */
const bottomTool = ref<BottomTool>("find");
/** Bottom tool windows that are shown, in tab order. */
@ -129,6 +133,7 @@ const bottomTools = computed(() => {
if (nav.visible) tools.push({ id: "references", title: t("nav.references.title") });
if (changes.visible) tools.push({ id: "changes", title: t("vcs.changes.toolWindow.title") });
if (vcsLog.visible) tools.push({ id: "log", title: t("vcs.log.toolWindow.title") });
if (deploy.visible) tools.push({ id: "deployment", title: t("deploy.log.title") });
return tools;
});
/** The active bottom tool window: the chosen one if shown, else the first. */
@ -148,7 +153,9 @@ const bottomStore = computed(() =>
? changes
: bottomActive.value === "log"
? vcsLog
: find,
: bottomActive.value === "deployment"
? deploy
: find,
);
/** Expansion of the panel, kept per tool window by its store. */
const bottomOpen = computed({
@ -164,7 +171,15 @@ const bottomOpen = computed({
* @param id - the tool window id from the panel.
*/
function chooseBottom(id: string): void {
if (id === "find" || id === "terminal" || id === "problems" || id === "references" || id === "changes" || id === "log") {
if (
id === "find" ||
id === "terminal" ||
id === "problems" ||
id === "references" ||
id === "changes" ||
id === "log" ||
id === "deployment"
) {
bottomTool.value = id;
}
}
@ -273,6 +288,12 @@ onMounted(() => {
},
enabled: () => project.root !== null && activeView() !== null,
}),
commands.provide("deployment.showLog", {
run: () => {
bottomTool.value = "deployment";
deploy.showLog();
},
}),
commands.provide("view.toggleStructure", {
run: () => {
toggleLeft("structure");
@ -370,6 +391,10 @@ onBeforeUnmount(() => {
v-if="vcsLog.visible"
v-show="bottomActive === 'log'"
/>
<DeploymentLogToolWindow
v-if="deploy.visible"
v-show="bottomActive === 'deployment'"
/>
</BottomPanel>
<StatusBar />
<StashDialog />

View file

@ -92,26 +92,24 @@ function isPhp(name: string): boolean {
return /\.(php|phtml|inc)$/i.test(name);
}
/** The open context menu: the file and where it shows; null when closed. */
const menu = ref<{ path: string; name: string; x: number; y: number } | null>(null);
/** The open context menu: the entry and where it shows; null when closed. */
const menu = ref<{ path: string; name: string; kind: "file" | "dir"; x: number; y: number } | null>(null);
/**
* Opens the context menu of a file; folders have none yet.
* Opens the context menu of a file or folder (folders get the deployment
* items only).
*
* @param entry - the entry.
* @param x - window x of the menu.
* @param y - window y of the menu.
*/
function openMenu(entry: TreeEntry, x: number, y: number): void {
if (entry.kind !== "file") {
return;
}
project.select(entry.path);
menu.value = { path: entry.path, name: entry.name, x, y };
menu.value = { path: entry.path, name: entry.name, kind: entry.kind === "dir" ? "dir" : "file", x, y };
}
/**
* Opens the context menu of the selected file from the keyboard, below its row.
* Opens the context menu of the selected entry from the keyboard, below its row.
*
* @param entry - the selected entry.
*/
@ -375,6 +373,7 @@ function onFocus(): void {
v-if="menu"
:path="menu.path"
:name="menu.name"
:kind="menu.kind"
:x="menu.x"
:y="menu.y"
@close="closeMenu"

View file

@ -1,8 +1,11 @@
<script setup lang="ts">
/**
* The project tree's context menu for a file (M4.3): Open, Show Diff
* The project tree's context menu (M4.3). For a file: Open, Show Diff
* (`vcs.showDiff {path}`) and Show History (`vcs.showHistory {path}`,
* M4.6), the Git items dimmed while their command is disabled.
* M4.6), the Git items dimmed while their command is disabled. For a file
* and a folder: Upload to Server and Download from Server
* (`deployment.upload` / `deployment.download {path}`, G17), dimmed while
* no project is open or a deployment job runs.
*
* Follows the WAI-ARIA menu pattern: it takes the focus when it opens,
* Up/Down move between items (wrapping), Enter or Space runs one, Escape,
@ -21,6 +24,8 @@ const props = defineProps<{
path: string;
/** File name, for the accessible label. */
name: string;
/** Whether the entry is a file or a folder; a file when absent. */
kind?: "file" | "dir";
/** Window x of the pointer (or the row) in pixels. */
x: number;
/** Window y of the pointer (or the row) in pixels. */
@ -52,8 +57,24 @@ interface MenuItem {
run: () => Promise<void>;
}
/** The items, in order. */
const items = computed<MenuItem[]>(() => [
/** The deployment items, for files and folders. */
const deployItems = computed<MenuItem[]>(() => [
{
id: "upload",
label: t("project.tree.menu.upload"),
enabled: commands.isEnabled("deployment.upload"),
run: () => commands.execute("deployment.upload", { path: props.path }),
},
{
id: "download",
label: t("project.tree.menu.download"),
enabled: commands.isEnabled("deployment.download"),
run: () => commands.execute("deployment.download", { path: props.path }),
},
]);
/** The file items. */
const fileItems = computed<MenuItem[]>(() => [
{
id: "open",
label: t("project.tree.menu.open"),
@ -76,6 +97,9 @@ const items = computed<MenuItem[]>(() => [
},
]);
/** The items, in order. */
const items = computed<MenuItem[]>(() => (props.kind === "dir" ? deployItems.value : [...fileItems.value, ...deployItems.value]));
/** The menu's position, kept inside the window. */
const position = computed(() => ({
left: `${String(Math.max(0, Math.min(props.x, window.innerWidth - 200)))}px`,

View file

@ -1,5 +1,11 @@
{
"app.statusBar.version": "{name} {version}",
"command.deployment.download": "Download Current File from Server",
"command.deployment.servers": "Deployment Servers…",
"command.deployment.showLog": "Deployment Log",
"command.deployment.testConnection": "Test Deployment Connection",
"command.deployment.upload": "Upload Current File to Server",
"command.deployment.uploadProject": "Upload Project to Server",
"command.editor.complete": "Complete Code",
"command.editor.parameterInfo": "Parameter Info",
"command.editor.quickDocumentation": "Quick Documentation",
@ -58,6 +64,75 @@
"common.toolWindow.resize": "Resize {title}",
"common.toolWindow.show": "Show {title}",
"common.toolWindow.stripe": "Tool windows",
"deploy.auth.agent": "SSH agent",
"deploy.auth.key": "Key file",
"deploy.auth.password": "Password",
"deploy.cancel": "Cancel the deployment",
"deploy.dialog.add": "Add Server",
"deploy.dialog.addMapping": "Add Mapping",
"deploy.dialog.browse": "Browse…",
"deploy.dialog.close": "Close",
"deploy.dialog.confirmRemove": "Really Remove",
"deploy.dialog.defaultMark": "default",
"deploy.dialog.ftpWarning": "Plain FTP sends everything, including the password, unencrypted. Prefer SFTP or FTPS.",
"deploy.dialog.mappingsHint": "Local folder (project-relative, empty for the project root) → remote folder (relative to the root, or absolute). Without mappings the project root goes to the root.",
"deploy.dialog.mapsTo": "→",
"deploy.dialog.pickFolder": "Choose the deployment folder",
"deploy.dialog.pickKey": "Choose the private key file",
"deploy.dialog.remove": "Remove",
"deploy.dialog.removeMapping": "Remove this mapping",
"deploy.dialog.save": "Save",
"deploy.dialog.secretNone": "Not stored yet; kept only in the system keychain",
"deploy.dialog.secretStored": "Stored in the system keychain; type to replace",
"deploy.dialog.servers": "Servers",
"deploy.dialog.test": "Test Connection",
"deploy.dialog.title": "Deployment Servers",
"deploy.field.auth": "Sign in with",
"deploy.field.default": "Default server of this project",
"deploy.field.excluded": "Excluded paths (one per line; * and ? match names)",
"deploy.field.folder": "Folder",
"deploy.field.host": "Host",
"deploy.field.keyPath": "Private key file",
"deploy.field.kind": "Type",
"deploy.field.mappingLocal": "Local folder",
"deploy.field.mappingRemote": "Remote folder",
"deploy.field.mappings": "Path mappings",
"deploy.field.name": "Name",
"deploy.field.passphrase": "Key passphrase",
"deploy.field.password": "Password",
"deploy.field.port": "Port",
"deploy.field.root": "Root folder on the server",
"deploy.field.rootPlaceholder": "/var/www/html",
"deploy.field.uploadOnSave": "Upload files when they are saved",
"deploy.field.user": "User",
"deploy.files.one": "1 file",
"deploy.files.other": "{count} files",
"deploy.hostKey.changed": "The host key of {host} is not the one you trusted. Someone may be intercepting the connection. Replace the trusted key only if you know the server was reinstalled.",
"deploy.hostKey.changedTitle": "The server's host key changed",
"deploy.hostKey.keep": "Keep the Trusted Key",
"deploy.hostKey.offered": "Offered now:",
"deploy.hostKey.reject": "Don't Trust",
"deploy.hostKey.replace": "Replace the Trusted Key",
"deploy.hostKey.trust": "Trust and Connect",
"deploy.hostKey.trusted": "Trusted:",
"deploy.hostKey.unknown": "This is the first connection to {host}. Compare this fingerprint with the one from the server's administrator before you trust it:",
"deploy.hostKey.unknownTitle": "Unknown host key",
"deploy.kind.folder": "Local or mounted folder",
"deploy.kind.ftp": "FTP",
"deploy.kind.ftps": "FTPS (FTP over TLS)",
"deploy.kind.sftp": "SFTP",
"deploy.log.clear": "Clear",
"deploy.log.empty": "No deployment yet.",
"deploy.log.error": "Error",
"deploy.log.info": "Info",
"deploy.log.running": "{server}: {done} of {total} files {file}",
"deploy.log.title": "Deployment",
"deploy.log.warning": "Warning",
"deploy.operation.download": "Downloading",
"deploy.operation.test": "Testing",
"deploy.operation.upload": "Uploading",
"deploy.progress.files": "{operation} {done}/{total} · {server}",
"deploy.progress.short": "{operation} · {server}",
"editor.assist.kind.class": "Class",
"editor.assist.kind.color": "Colour",
"editor.assist.kind.constant": "Constant",
@ -175,6 +250,15 @@
"notification.app.dataMigrationFailed": "Cannot copy your settings and tools from {from}: {error}. Lutra starts with the defaults and tries again next time.",
"notification.close": "Close notification",
"notification.command.failed": "{command} failed: {message}",
"notification.deploy.busy": "A deployment is running; wait for it or cancel it.",
"notification.deploy.cancelled": "Deployment cancelled.",
"notification.deploy.downloadFailed": "Download failed: {reason}",
"notification.deploy.downloaded": "Downloaded {files} from {server}.",
"notification.deploy.noServer": "No default deployment server yet. Add one, or choose the default.",
"notification.deploy.partly": "Transferred {files}, but {failed} failed ({server}); see the Deployment log.",
"notification.deploy.uploadFailed": "Upload failed: {reason}",
"notification.deploy.uploadOnSaveFailed": "Upload on save to {server} failed: {error}",
"notification.deploy.uploaded": "Uploaded {files} to {server}.",
"notification.lsp.failed": "The PHP language server stopped: {reason}. Run Restart PHP Language Server to try again.",
"notification.lsp.message": "PHP language server: {message}",
"notification.lsp.renamed": "Renamed to {name}: {edits} changes in {files} files ({written} closed files saved)",
@ -256,10 +340,12 @@
"project.openFolder": "Open Folder…",
"project.toolWindow.title": "Project",
"project.tree.loading": "Loading…",
"project.tree.menu.download": "Download from Server",
"project.tree.menu.label": "Actions for {name}",
"project.tree.menu.open": "Open",
"project.tree.menu.showDiff": "Show Diff",
"project.tree.menu.showHistory": "Show History",
"project.tree.menu.upload": "Upload to Server",
"project.tree.truncated": "Listing truncated: more entries than can be shown",
"recovery.dialog.changedOnDisk": "The file changed on disk since then",
"recovery.dialog.discard": "Discard",

View file

@ -165,6 +165,29 @@ export type EngineEventPayload =
phase?: unknown;
/** 0–100; unchecked. */
percent?: unknown;
}
| {
kind: "deployProgress";
/** Whether a deployment job runs; unchecked. */
active: unknown;
/** `test`, `upload` or `download`; unchecked. */
operation?: unknown;
/** The server's name; unchecked. */
server?: unknown;
/** `connecting`, `planning` or `transferring`; unchecked. */
phase?: unknown;
/** The file being transferred; unchecked. */
file?: unknown;
/** Files done and planned, bytes done and planned; unchecked. */
filesDone?: unknown;
filesTotal?: unknown;
bytesDone?: unknown;
bytesTotal?: unknown;
}
| {
kind: "deployLog";
/** `{id, time, level, server, message}`; unchecked. */
entry: unknown;
};
/** Callback receiving engine events. */