CI / Build & test (Node 22) (push) Successful in 10m17s
CI / Build & test (Node 24) (push) Successful in 10m13s
CI / No em/en dashes (push) Successful in 4s
Deploy site (production) / build-and-deploy (push) Successful in 24s
Release / Publish to Gitea npm registry (push) Successful in 10m17s
VSCode Release / Package VSIX (push) Successful in 9m39s
Desktop Release / Build Linux (AppImage + deb) (push) Successful in 15m41s
CI / Pack & boot smoke (Node 22) (push) Successful in 10m3s
« Démarrer le projet » : un repo définit une fois ses commandes de démarrage (serveur de dev, API, base de données), un clic ouvre un terminal PTY par commande dans le dock IDE. Serveur (additif, PROTOCOL_VERSION inchangé) : - LaunchCommand[] persistées sur repos.launch_commands (migration 13) ; champ additif SessionSummary.launchRunId. - POST /repos/:id/launch : résolution du worktree côté serveur, cwd de commande borné (anti-traversal), commandIds outrepasse enabled. - GET /repos/:id/launch/detect : détection package.json / Procfile / docker-compose. - Shell de login interactif ($SHELL -l -i, charge le PATH nvm/asdf) + auto-type de la commande ; le shell survit à la commande (échec visible). Web : LaunchProjectModal + actions (ProjectTreeNode, SessionsPanel, CommandPalette), stores sessions/worktrees, i18n EN/FR. Alignement du reste du projet : - Extension VS Code 0.4.0 : commande Start Project (repo/worktree), Stop Launch, badge « launch » dans l'arbre, méthode REST startLaunch. - Site vitrine : 16e feature card (Rocket) + section showcase « Start the project » (mockup fidèle au modal), i18n EN/FR. - Documentation : README (EN + FR), help-content (EN + FR), CHANGELOGs server + vscode. Vérifié : 430 tests, typecheck, build (web + site + vscode), acceptance-p13 ALL GREEN, VSIX packagé, garde anti-tirets, vérif visuelle du site (thèmes clair et sombre).
194 lines
6.9 KiB
TypeScript
194 lines
6.9 KiB
TypeScript
// Client REST typé du daemon Arboretum : module pur (pas d'import vscode), testable.
|
|
// Auth par en-tête `Authorization: Bearer <token>` (le hook preValidation du serveur l'accepte
|
|
// au même titre que le cookie). Un client Node n'envoie pas d'en-tête Origin → il passe le check
|
|
// Origin strict côté serveur. Réutilise les types de `@arboretum/shared`.
|
|
import type {
|
|
ApiError,
|
|
CommitWorktreeRequest,
|
|
CreateGroupSessionRequest,
|
|
CreateSessionRequest,
|
|
CreateWorktreeRequest,
|
|
CreateWorktreeResponse,
|
|
FetchWorktreeRequest,
|
|
GroupSessionResponse,
|
|
GroupsListResponse,
|
|
MeResponse,
|
|
PromoteWorktreeRequest,
|
|
PullWorktreeRequest,
|
|
PushWorktreeRequest,
|
|
RepoBranchesResponse,
|
|
ReposListResponse,
|
|
SessionResponse,
|
|
SessionsListResponse,
|
|
StartLaunchRequest,
|
|
StartLaunchResponse,
|
|
StartRepoSessionRequest,
|
|
WorktreeResponse,
|
|
WorktreesListResponse,
|
|
} from '@arboretum/shared';
|
|
import { normalizeBaseUrl } from '../config.js';
|
|
|
|
/** Erreur normalisée portant le code/HTTP renvoyés par le serveur. */
|
|
export class RestError extends Error {
|
|
constructor(
|
|
message: string,
|
|
readonly status: number,
|
|
readonly code: string,
|
|
) {
|
|
super(message);
|
|
this.name = 'RestError';
|
|
}
|
|
}
|
|
|
|
type FetchLike = typeof fetch;
|
|
|
|
export class RestClient {
|
|
private baseUrl: string;
|
|
private token: string | null;
|
|
|
|
constructor(
|
|
opts: { baseUrl: string; token?: string | null },
|
|
private readonly fetchImpl: FetchLike = fetch,
|
|
) {
|
|
this.baseUrl = normalizeBaseUrl(opts.baseUrl);
|
|
this.token = opts.token ?? null;
|
|
}
|
|
|
|
setBaseUrl(url: string): void {
|
|
this.baseUrl = normalizeBaseUrl(url);
|
|
}
|
|
|
|
setToken(token: string | null): void {
|
|
this.token = token;
|
|
}
|
|
|
|
get url(): string {
|
|
return this.baseUrl;
|
|
}
|
|
|
|
// ---- auth ----
|
|
/** Valide le token courant ; lève RestError(401) si invalide. */
|
|
me(): Promise<MeResponse> {
|
|
return this.request<MeResponse>('GET', '/api/v1/auth/me');
|
|
}
|
|
|
|
// ---- repos & worktrees ----
|
|
listRepos(): Promise<ReposListResponse> {
|
|
return this.request<ReposListResponse>('GET', '/api/v1/repos');
|
|
}
|
|
|
|
listWorktrees(): Promise<WorktreesListResponse> {
|
|
return this.request<WorktreesListResponse>('GET', '/api/v1/worktrees');
|
|
}
|
|
|
|
getBranches(repoId: string): Promise<RepoBranchesResponse> {
|
|
return this.request<RepoBranchesResponse>('GET', `/api/v1/repos/${encodeURIComponent(repoId)}/branches`);
|
|
}
|
|
|
|
createWorktree(repoId: string, body: CreateWorktreeRequest): Promise<CreateWorktreeResponse> {
|
|
return this.request<CreateWorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees`, body);
|
|
}
|
|
|
|
commitWorktree(repoId: string, body: CommitWorktreeRequest): Promise<WorktreeResponse> {
|
|
return this.request<WorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees/commit`, body);
|
|
}
|
|
|
|
pushWorktree(repoId: string, body: PushWorktreeRequest): Promise<WorktreeResponse> {
|
|
return this.request<WorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees/push`, body);
|
|
}
|
|
|
|
fetchWorktree(repoId: string, body: FetchWorktreeRequest): Promise<WorktreeResponse> {
|
|
return this.request<WorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees/fetch`, body);
|
|
}
|
|
|
|
pullWorktree(repoId: string, body: PullWorktreeRequest): Promise<WorktreeResponse> {
|
|
return this.request<WorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees/pull`, body);
|
|
}
|
|
|
|
promoteWorktree(repoId: string, body: PromoteWorktreeRequest): Promise<WorktreeResponse> {
|
|
return this.request<WorktreeResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/worktrees/promote`, body);
|
|
}
|
|
|
|
startRepoSession(repoId: string, body: StartRepoSessionRequest): Promise<SessionResponse> {
|
|
return this.request<SessionResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/session`, body);
|
|
}
|
|
|
|
/** « Démarrer le projet » : lance un terminal par commande de démarrage activée du repo. */
|
|
startLaunch(repoId: string, body: StartLaunchRequest): Promise<StartLaunchResponse> {
|
|
return this.request<StartLaunchResponse>('POST', `/api/v1/repos/${encodeURIComponent(repoId)}/launch`, body);
|
|
}
|
|
|
|
// ---- sessions ----
|
|
createSession(body: CreateSessionRequest): Promise<SessionResponse> {
|
|
return this.request<SessionResponse>('POST', '/api/v1/sessions', body);
|
|
}
|
|
|
|
listSessions(opts: { includeHidden?: boolean; includeArchived?: boolean } = {}): Promise<SessionsListResponse> {
|
|
const params = new URLSearchParams();
|
|
if (opts.includeHidden) params.set('includeHidden', 'true');
|
|
if (opts.includeArchived) params.set('includeArchived', 'true');
|
|
const q = params.toString();
|
|
return this.request<SessionsListResponse>('GET', `/api/v1/sessions${q ? `?${q}` : ''}`);
|
|
}
|
|
|
|
resumeSession(id: string): Promise<SessionResponse> {
|
|
return this.request<SessionResponse>('POST', `/api/v1/sessions/${encodeURIComponent(id)}/resume`, {});
|
|
}
|
|
|
|
forkSession(id: string): Promise<SessionResponse> {
|
|
return this.request<SessionResponse>('POST', `/api/v1/sessions/${encodeURIComponent(id)}/fork`, {});
|
|
}
|
|
|
|
hideSession(id: string): Promise<{ ok: true }> {
|
|
return this.request<{ ok: true }>('POST', `/api/v1/sessions/${encodeURIComponent(id)}/hide`, {});
|
|
}
|
|
|
|
killSession(id: string): Promise<{ ok: true }> {
|
|
return this.request<{ ok: true }>('DELETE', `/api/v1/sessions/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
// ---- groupes ----
|
|
listGroups(): Promise<GroupsListResponse> {
|
|
return this.request<GroupsListResponse>('GET', '/api/v1/groups');
|
|
}
|
|
|
|
createGroupSession(groupId: string, body: CreateGroupSessionRequest): Promise<GroupSessionResponse> {
|
|
return this.request<GroupSessionResponse>('POST', `/api/v1/groups/${encodeURIComponent(groupId)}/session`, body);
|
|
}
|
|
|
|
// ---- interne ----
|
|
private async request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
const headers: Record<string, string> = { Accept: 'application/json' };
|
|
if (this.token) headers.Authorization = `Bearer ${this.token}`;
|
|
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
|
|
|
const init: RequestInit = { method, headers };
|
|
if (body !== undefined) init.body = JSON.stringify(body);
|
|
|
|
let res: Response;
|
|
try {
|
|
res = await this.fetchImpl(`${this.baseUrl}${path}`, init);
|
|
} catch (err) {
|
|
throw new RestError(`Cannot reach Arboretum at ${this.baseUrl}: ${(err as Error).message}`, 0, 'NETWORK');
|
|
}
|
|
|
|
if (!res.ok) {
|
|
let code = `HTTP_${res.status}`;
|
|
let message = `${method} ${path} → ${res.status}`;
|
|
try {
|
|
const data = (await res.json()) as ApiError;
|
|
if (data?.error) {
|
|
code = data.error.code ?? code;
|
|
message = data.error.message ?? message;
|
|
}
|
|
} catch {
|
|
/* corps non-JSON : on garde le message générique */
|
|
}
|
|
throw new RestError(message, res.status, code);
|
|
}
|
|
|
|
if (res.status === 204) return undefined as T;
|
|
return (await res.json()) as T;
|
|
}
|
|
}
|