25 Commits

Author SHA1 Message Date
062bb64d41 release: git-arboretum 0.1.1
All checks were successful
CI / Build & test (Node 22) (push) Successful in 10m6s
CI / Build & test (Node 24) (push) Successful in 9m58s
Deploy site (production) / build-and-deploy (push) Successful in 15s
VSCode Release / Package VSIX (push) Successful in 9m37s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m50s
2026-06-24 10:28:44 +02:00
a67871b9b9 release: @johanleroy/git-arboretum 1.11.0
All checks were successful
Release / Publish to Gitea npm registry (push) Successful in 9m52s
2026-06-24 10:28:28 +02:00
69123eaf0e feat(site): renomme l'état de session « inactif » en « disponible »
Aligne le site marketing sur le renommage de l'app (idle → disponible /
available), badges d'état et FAQ (EN + FR).
2026-06-24 10:28:28 +02:00
0f126cf911 fix(web): repeindre les terminaux au retour-visible + flush ACK ciblé
Some checks failed
CI / Build & test (Node 24) (push) Has been cancelled
CI / Pack & boot smoke (Node 22) (push) Has been cancelled
CI / Build & test (Node 22) (push) Has been cancelled
Un terminal caché dans une grille de groupe (ou hors-écran) n'était pas repeint
au retour — `visibilitychange` ne couvre que l'onglet — d'où l'écran noir avec
curseur ; et son ACK ne progressait plus (callback xterm.write throttlé) → le
serveur mettait le PTY en pause → sortie « par à-coups ». Ajoute un
IntersectionObserver (repaint + flushAck ciblé au retour-visible) et expose
Attachment.flushAck (factorisé avec flushAcks).
2026-06-24 10:15:29 +02:00
b5236b41c8 feat(settings): réglages Claude CLI (binaire + ~/.claude) & notif « disponible »
- Réglages → Claude CLI : override du chemin du binaire `claude` (effet à la
  prochaine session, fallback `which claude`), diagnostic de détection, et
  override de la racine ~/.claude (effet au redémarrage). Validateurs stricts.
- Push : notifie aussi sur le front busy→idle (session redevenue disponible).
- Renomme l'état affiché idle → « disponible » / « available » (web EN/FR + VS Code) ;
  l'enum SessionActivity du protocole reste inchangé.
2026-06-24 10:15:29 +02:00
2506dfb1f3 fix(cli): figer le PATH d'installation dans l'unit systemd / plist launchd
Un service systemd user / LaunchAgent démarre avec un PATH minimal qui n'inclut
pas ~/.local/bin (où vit le binaire `claude`) → resolveClaudeBin (`which claude`)
échouait avec « Claude Code CLI not found in PATH ». `arboretum install` fige
désormais le PATH de l'environnement d'installation dans l'unit/plist.
2026-06-24 10:15:29 +02:00
7d618c30d5 release: @johanleroy/git-arboretum 1.10.0
All checks were successful
CI / Build & test (Node 22) (push) Successful in 10m6s
CI / Build & test (Node 24) (push) Successful in 9m58s
Deploy site (production) / build-and-deploy (push) Successful in 15s
Release / Publish to Gitea npm registry (push) Successful in 9m51s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m50s
2026-06-23 18:52:39 +02:00
529c136199 docs(site): carte feature « créer un projet » 2026-06-23 18:52:39 +02:00
7fc1f6f747 fix(ci): restreindre la release daemon aux tags v[0-9]*
Le trigger 'v*' capturait aussi les tags 'vscode-v*' de l'extension : le workflow strippait alors
'v' (→ scode-v0.1.0) et échouait contre la version du daemon. 'v[0-9]*' n'écoute que les tags vX.Y.Z.
2026-06-23 18:52:39 +02:00
8b9060e0c0 feat: création de projet (nouveau dossier + session) & en-tête de session enrichi
- POST /api/v1/projects : crée <root>/<name> (mkdir non récursif, 409 si existant),
  git init optionnel, puis lance une session dedans. Anti-traversal sur le nom (core/project.ts).
- Web : NewProjectModal (racine préremplie scanRoots[0], case git init) + bouton dans SessionsListView.
- SessionContextBar : badge du groupe (cliquable) + repos couverts avec leur branche dans l'en-tête
  de session ; session simple = repo+branche déduits du cwd.
- 14 tests (unitaires + route).
2026-06-23 18:52:22 +02:00
06a400acc7 ci(vscode): réutiliser NPM_TOKEN pour l'asset de release du VSIX
Some checks failed
CI / Build & test (Node 22) (push) Successful in 10m1s
CI / Build & test (Node 24) (push) Successful in 9m53s
Release / Publish to Gitea npm registry (push) Failing after 5m5s
VSCode Release / Package VSIX (push) Successful in 9m39s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m54s
Le token Gitea NPM_TOKEN (déjà utilisé pour publier le daemon) a les droits repository
suffisants pour l'API release → pas de secret RELEASE_TOKEN dédié à configurer.
2026-06-23 17:48:45 +02:00
a1fd00b046 release: @johanleroy/git-arboretum 1.9.0
Some checks failed
CI / Build & test (Node 24) (push) Has been cancelled
CI / Pack & boot smoke (Node 22) (push) Has been cancelled
CI / Build & test (Node 22) (push) Has been cancelled
VSCode Release / Package VSIX (push) Has been cancelled
Deploy site (production) / build-and-deploy (push) Successful in 17s
Release / Publish to Gitea npm registry (push) Successful in 9m53s
2026-06-23 17:43:48 +02:00
057c2d55ed docs: documenter l'extension VS Code (README EN/FR, centre d'aide, site)
- README.md / README.fr.md : bullet dans « What Arboretum does », section dédiée
  « VS Code extension » (build/packaging VSIX, install, sign in), ligne monorepo.
- Centre d'aide in-app (help-content.ts) : item « VS Code extension » dans Integrations (EN/FR).
- Site vitrine : 9e carte de features « Native VS Code extension » (feat9, EN/FR + icône).
2026-06-23 17:43:12 +02:00
cf7eb05aca feat(vscode): extension VS Code native (intégration native, pas un webview)
Nouveau workspace packages/vscode (git-arboretum, privé, non publié sur npm), client REST/WS
réutilisant @arboretum/shared. Auth Authorization: Bearer sur REST et l'upgrade WS (via `ws`) ;
un client Node sans en-tête Origin passe le check Origin strict du serveur.

- Arbres temps réel : Repositories (repos → worktrees → sessions) et Groups, via le WebSocket.
- Terminaux natifs (vscode.Pseudoterminal) pour attacher/observer une session — rendu et
  scrollback de VS Code ; décodage UTF-8 streaming + comptabilité ACK dans des modules purs.
- Status bar (compteur waiting) + notifications natives sur passage en waiting, réponses Yes/No
  via la commande WS answer.
- Mutations git (create worktree, commit, push, promote), start/kill/hide/resume/fork, session
  de groupe ; conscience du workspace (reveal + start/create here).
- Bundle esbuild (format cjs, external vscode) inlinant @arboretum/shared → VSIX autonome.
  Logique réutilisable sans import vscode → testée par vitest (19 tests).
- CI : .gitea/workflows/vscode-release.yml package le VSIX sur tag vscode-vX.Y.Z (artefact +
  asset de release best-effort). build:vscode hors du build principal (comme le site).
- spikes/s5-vscode/STUDY.md : décision de conception (GO phasé A→D), marquée implémentée.
2026-06-23 17:43:03 +02:00
663ae7ace1 fix: recherche worktrees, sessions externes masquées, rendu/historique terminal & plein écran grille
- Recherche : le watcher débouncé du singleton useWorktreeView est créé dans un effectScope
  détaché → ne gèle plus après une navigation ; recherche aussi par label de dépôt ; accès à
  la palette depuis le MoreSheet mobile (sidebar/⌘K indisponibles sur mobile).
- Sessions : sessionsForCwd exclut désormais toujours les sessions masquées ; les sessions
  externes (discovered) sont masquées par défaut côté UI, avec puce de révélation par carte et
  case globale dans le dashboard.
- Terminal : ACK découplé du callback de rendu (armé à la réception + flush au retour de
  visibilité) → plus de pause PTY quand l'onglet passe en arrière-plan ; repaint forcé sur
  perte de contexte WebGL / resize / retour en avant-plan. Historique élargi : REPLAY_TAIL_BYTES
  1 Mo, RING_CAPACITY 4 Mo, scrollback xterm 20k.
- Grille de groupe : bouton « plein écran » sur chaque cellule ouvrant /sessions/:id.
2026-06-23 17:42:49 +02:00
5ebe3a0f37 release: @johanleroy/git-arboretum 1.8.0
All checks were successful
CI / Build & test (Node 22) (push) Successful in 10m0s
CI / Build & test (Node 24) (push) Successful in 9m54s
Deploy site (production) / build-and-deploy (push) Successful in 16s
Release / Publish to Gitea npm registry (push) Successful in 9m46s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m45s
2026-06-22 19:55:52 +02:00
eb843be9c1 docs(site): refléter la gestion git des worktrees (commit/push/promotion)
feat1 + showcase worktree-first mentionnent commit/push/promotion sans terminal ; carte worktree du mockup montre les actions Commit/Push (fidèle au WorktreeCard).
2026-06-22 19:55:52 +02:00
f4fb6c3b52 feat(worktrees): création intelligente (auto) + commit/push/promotion + grille agrandissable
- addWorktree résout la branche par dépôt (branchExists) : checkout si présente, suivi de origin/<b> si seulement remote, sinon création (-b) depuis la branche par défaut. Corrige le 'fatal: invalid reference' sur les groupes hétérogènes ; newBranch -> mode (déprécié, mappé en route).
- Nouvelles opérations git : commit (add -A), push (upstream auto), promotion « en principal » (la branche du worktree devient le checkout principal, sans merge ni conflit, ancienne branche conservée). Routes /worktrees/{commit,push,promote} auditées + GET /repos/:id/branches.
- Web : actions Commit/Push/Promouvoir sur WorktreeCard, sélecteur de branche de base (datalist) dans RepoSection et GroupSessionModal, agrandissement d'un terminal au choix dans TerminalGrid.
- Court-circuite la session de groupe quand aucun worktree n'a pu être créé (fini le masquage par « no resolvable worktree »).
- Tests : git.ts (branchExists/listBranches/commitAll/auto), worktree-manager (commit/promote/branches) ; acceptance P5 étend le scénario worktree de groupe sur branche neuve + commit + promotion.
2026-06-22 19:55:45 +02:00
e84c6a7f6d release: @johanleroy/git-arboretum 1.7.0
All checks were successful
CI / Build & test (Node 22) (push) Successful in 10m0s
CI / Build & test (Node 24) (push) Successful in 9m53s
Deploy site (production) / build-and-deploy (push) Successful in 16s
Release / Publish to Gitea npm registry (push) Successful in 9m46s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m50s
2026-06-22 16:03:11 +02:00
dacff2b98f feat(sessions): masquer les sessions externes + terminal plein écran
Masquage persistant des sessions Claude découvertes (lancées hors Arboretum)
qui polluent la liste — calqué sur repos.hidden :
- table hidden_sessions (#9) clé claudeSessionId ; helpers DB
- DiscoveryService pose le champ additif SessionSummary.hidden (resume/fork
  restent possibles, survit à un re-scan)
- routes POST/DELETE /sessions/:id/hide, POST /sessions/hide-discovered
  (masse, un clic), GET /sessions?includeHidden=true
- UI : bouton Masquer par ligne, « Masquer l'historique externe », toggle
  « Afficher les masquées », badge masquée ; store + i18n EN/FR + audit

Terminal plein écran (corrige le sizing) :
- SessionView root s'étire (flex-1) → xterm calcule les bonnes dimensions
- refit robuste (requestAnimationFrame + après resync), h-full sur le wrapper
- bouton plein écran (API Fullscreen), tabbar mobile masquée en fullbleed

DialogPrompt : options en liste verticale pleine largeur (plus de troncature
ni de chevauchement sur les libellés longs / multi-lignes).

Doc : centre d'aide (sessions), README EN/FR, site (showcase), CLAUDE.md.
Tests : discovery (hidden) + route hide/unhide/hide-discovered.
2026-06-22 16:02:27 +02:00
bf9c6ba8f3 release: @johanleroy/git-arboretum 1.6.1
All checks were successful
CI / Build & test (Node 22) (push) Successful in 10m0s
CI / Build & test (Node 24) (push) Successful in 9m54s
Deploy site (production) / build-and-deploy (push) Successful in 16s
Release / Publish to Gitea npm registry (push) Successful in 9m46s
CI / Pack & boot smoke (Node 22) (push) Successful in 9m45s
2026-06-22 14:41:36 +02:00
d02c1dabd4 docs(help): refléter la session de groupe unique (P6) + retouche FAQ du site
Le centre d'aide décrivait encore le modèle P5 (une session par repo) ;
l'entrée « cross-repo » dit désormais qu'un groupe lance UNE seule session
Claude couvrant tous ses repos (contexte partagé) et s'ouvre sur son terminal.
Inclut aussi un ajustement de copie de la FAQ du site.
2026-06-22 14:41:29 +02:00
86cdc1f597 fix(web): agrandir les terminaux de la grille sur grand écran (hauteur responsive)
Hauteur de cellule relative au viewport (h-[68dvh] min-h-80
lg:h-[calc((100dvh-9rem)/2)]) au lieu de h-80 fixe : terminaux grands sur PC,
exploitables sur mobile. xterm se re-fit via son ResizeObserver.
2026-06-22 14:41:22 +02:00
1b57c3801c feat(groups): session de groupe au parent commun + redirection vers le terminal
Le cwd d'une session de groupe devient le PARENT COMMUN des répertoires
couverts (racine neutre, chemins relatifs cross-repo naturels) au lieu du
premier repo arbitraire ; chaque repo reste relié en --add-dir. Garde-fou :
si le parent commun est la racine du FS, on retombe sur le premier répertoire.
Nouveau module pur resolveGroupCwd (core/group-session.ts). Côté web, un
lancement réussi redirige vers le terminal plein écran de la session, avec
un toast (succès ou couverture partielle).
2026-06-22 14:41:15 +02:00
4e3b1f5604 fix(sessions): reprendre/forker une session managée morte par UUID (résout le 404)
Le bouton « Reprendre » envoie l'UUID Arboretum, mais resume/fork ne
résolvaient l'id que via la découverte (indexée par claudeSessionId, qui
exclut justement les sessions managées) → 404 systématique après fermeture.
Ajoute PtyManager.resumeTargetById (cwd d'origine + claudeSessionId + groupe
lus en DB par UUID) et un résolveur unifié dans resume ET fork : session
managée morte par UUID, sinon session claude externe découverte par
claudeSessionId. Garde-fous anti-resume d'une session vivante conservés.
2026-06-22 14:41:06 +02:00
103 changed files with 8978 additions and 188 deletions

View File

@@ -4,7 +4,9 @@ name: Release
on: on:
push: push:
tags: ['v*'] # `v[0-9]*` (et non `v*`) : sinon ce workflow capture aussi les tags `vscode-v*` de l'extension
# — il stripperait alors `v` (→ `scode-v0.1.0`) et échouerait contre la version du daemon.
tags: ['v[0-9]*']
permissions: permissions:
contents: read contents: read

View File

@@ -0,0 +1,74 @@
# Packaging du VSIX de l'extension VS Code, déclenché UNIQUEMENT par un tag vscode-vX.Y.Z
# (séparé de la release du daemon, qui écoute les tags v*). Le .vsix est exposé en artefact du run
# (toujours) et, en best-effort, attaché à la release Gitea correspondante.
name: VSCode Release
on:
push:
tags: ['vscode-v*']
permissions:
contents: write
jobs:
package:
name: Package VSIX
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
# Garde-fou : le tag (sans "vscode-v") doit correspondre à la version du manifeste de l'extension.
- name: Verify tag matches extension version
run: |
pkg=$(node -p "require('./packages/vscode/package.json').version")
tag="${GITHUB_REF_NAME#vscode-v}"
if [ "$pkg" != "$tag" ]; then
echo "ERREUR: tag '$tag' != version extension '$pkg'"
exit 1
fi
echo "OK: tag $tag == version $pkg"
# Build du shared puis bundle esbuild de l'extension (typecheck inclus), puis packaging VSIX.
# --no-dependencies : tout est bundlé dans dist/extension.js → pas de node_modules dans le VSIX.
- name: Build & package
run: |
npm run build:vscode
version=$(node -p "require('./packages/vscode/package.json').version")
cd packages/vscode
npx --yes @vscode/vsce package --no-dependencies -o "git-arboretum-${version}.vsix"
# Artefact du run : canal de distribution fiable, indépendant de l'API release.
# upload-artifact@v3 : Gitea Actions ne supporte pas @v4 (@actions/artifact v2+).
- uses: actions/upload-artifact@v3
with:
name: vsix
path: packages/vscode/*.vsix
# Best-effort : attache le VSIX à la release Gitea du tag (crée la release si absente).
# Réutilise le secret NPM_TOKEN (même token Gitea que la publication du daemon — droits
# repository suffisants pour l'API release). Sans lui, l'étape est ignorée sans faire échouer
# le job (continue-on-error) ; le VSIX reste disponible en artefact.
- name: Attach VSIX to Gitea release
continue-on-error: true
env:
RELEASE_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -z "$RELEASE_TOKEN" ]; then
echo "::notice::NPM_TOKEN absent — VSIX disponible en artefact uniquement."
exit 0
fi
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
auth="Authorization: token ${RELEASE_TOKEN}"
version=$(node -p "require('./packages/vscode/package.json').version")
vsix="packages/vscode/git-arboretum-${version}.vsix"
# id de release du tag, sinon création
rid=$(curl -fsSL -H "$auth" "${api}/releases/tags/${GITHUB_REF_NAME}" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).id || ''" || true)
if [ -z "$rid" ]; then
rid=$(curl -fsSL -X POST -H "$auth" -H 'Content-Type: application/json' \
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"Arboretum VSCode ${version}\"}" \
"${api}/releases" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).id || ''")
fi
curl -fsSL -X POST -H "$auth" -F "attachment=@${vsix}" \
"${api}/releases/${rid}/assets?name=git-arboretum-${version}.vsix"
echo "VSIX attaché à la release ${GITHUB_REF_NAME}."

View File

@@ -28,10 +28,11 @@ Un unique daemon Node.js que vous lancez sur votre machine de dev (`npx @johanle
- **Dashboard worktree-first, multi-repo** — chaque worktree de chaque repo enregistré, avec son état git (branche, ahead/behind, fichiers modifiés) *et* l'état de sa session Claude Code (busy / en attente d'entrée / idle / reprenable). - **Dashboard worktree-first, multi-repo** — chaque worktree de chaque repo enregistré, avec son état git (branche, ahead/behind, fichiers modifiés) *et* l'état de sa session Claude Code (busy / en attente d'entrée / idle / reprenable).
- **Cycle de vie complet des worktrees** — créer (avec des hooks post-création par repo : `npm ci`, copie de `.env`…), adopter des worktrees créés à la main, supprimer avec garde-fous, élaguer les orphelins. - **Cycle de vie complet des worktrees** — créer (avec des hooks post-création par repo : `npm ci`, copie de `.env`…), adopter des worktrees créés à la main, supprimer avec garde-fous, élaguer les orphelins.
- **Découverte & reprise de sessions** — les sessions lancées dans votre propre terminal apparaissent automatiquement ; reprenez les sessions mortes, observez ou forkez les vivantes. Ne corrompt jamais une session vivante. - **Découverte & reprise de sessions** — les sessions lancées dans votre propre terminal apparaissent automatiquement ; reprenez les sessions mortes, observez ou forkez les vivantes. Ne corrompt jamais une session vivante. Masquez les anciennes qui encombrent la liste (un clic efface tout l'historique externe ; elles restent reprenables).
- **Terminal web** — terminal xterm.js complet vers chaque session managée, qui survit aux déconnexions du navigateur. - **Terminal web** — terminal xterm.js complet vers chaque session managée, qui survit aux déconnexions du navigateur ; vraiment plein écran, avec l'invite ancrée en bas et tout l'historique défilable au-dessus.
- **Supervision depuis votre téléphone** — PWA installable avec notifications push quand une session vous attend ; répondez à une demande (ses options, ou refusez) sans ouvrir de terminal. - **Supervision depuis votre téléphone** — PWA installable avec notifications push quand une session vous attend ; répondez à une demande (ses options, ou refusez) sans ouvrir de terminal.
- **Groupes de travail** — regroupez des repos liés (ex. une API, son frontend web et sa doc) dans un groupe nommé, puis lancez **une seule session Claude qui les couvre tous à la fois** (via le flag `--add-dir` du CLI) : une conversation unique avec un contexte partagé travaillant à travers chaque repo, plus une vue unifiée de tous leurs worktrees et une grille multi-terminaux côte à côte. Une session de groupe peut d'abord créer le même worktree de branche dans chaque repo, ou tourner directement sur les checkouts principaux. - **Groupes de travail** — regroupez des repos liés (ex. une API, son frontend web et sa doc) dans un groupe nommé, puis lancez **une seule session Claude qui les couvre tous à la fois** (via le flag `--add-dir` du CLI) : une conversation unique avec un contexte partagé travaillant à travers chaque repo, plus une vue unifiée de tous leurs worktrees et une grille multi-terminaux côte à côte. Une session de groupe peut d'abord créer le même worktree de branche dans chaque repo, ou tourner directement sur les checkouts principaux.
- **Extension VS Code** — une extension native (pas un webview) qui amène l'arbre en direct, les terminaux de session natifs, les alertes d'attente et les actions git directement dans votre éditeur. Voir [Extension VS Code](#extension-vs-code).
--- ---
@@ -104,6 +105,24 @@ node packages/server/dist/index.js
4. **Suivez les états en direct.** Chaque session indique si elle est *busy*, *en attente de votre entrée* ou *idle*. Ouvrez le **terminal web** pour interagir directement ; il survit aux déconnexions du navigateur (fermer l'onglet ne tue pas la session). 4. **Suivez les états en direct.** Chaque session indique si elle est *busy*, *en attente de votre entrée* ou *idle*. Ouvrez le **terminal web** pour interagir directement ; il survit aux déconnexions du navigateur (fermer l'onglet ne tue pas la session).
5. **Supervisez depuis votre téléphone.** Installez la PWA, et quand une session bascule en *attente*, vous recevez une notification push. Répondez à la demande — choisissez l'une de ses options ou refusez-la — directement depuis le dashboard, sans terminal. 5. **Supervisez depuis votre téléphone.** Installez la PWA, et quand une session bascule en *attente*, vous recevez une notification push. Répondez à la demande — choisissez l'une de ses options ou refusez-la — directement depuis le dashboard, sans terminal.
## Extension VS Code
Vous préférez rester dans votre éditeur ? Arboretum fournit une **extension VS Code native** (`packages/vscode`) — pas un webview. Elle se connecte au même daemon et l'expose avec les primitives natives de VS Code :
- Un arbre **Repositories** et **Groups** en direct (repos → worktrees → sessions) dans l'Activity Bar, mis à jour en temps réel via le WebSocket du daemon.
- **Terminaux natifs** : attachez-vous (ou observez) n'importe quelle session dans un vrai terminal VS Code — vous bénéficiez du rendu, du scrollback et du copier-coller de VS Code gratuitement.
- Un compteur en **status bar** et des **notifications** natives quand une session attend, avec réponses Oui/Non sans ouvrir de terminal.
- Les mutations git (créer un worktree, commit, push, promouvoir) et la **conscience du workspace** — le worktree de votre dossier ouvert est mis en évidence, avec « démarrer une session / créer un worktree ici » en un clic.
Elle est distribuée en **VSIX privé**. Buildez-la et packagez-la depuis le monorepo :
```bash
npm run build:vscode
cd packages/vscode && npx @vscode/vsce package --no-dependencies # → git-arboretum-0.1.0.vsix
```
Puis installez-la via **Extensions : Installer à partir d'un VSIX…** (ou `code --install-extension git-arboretum-0.1.0.vsix`), lancez **Arboretum: Sign In** et collez un token. Détails complets dans [`packages/vscode/README.md`](packages/vscode/README.md).
## Accès distant depuis votre téléphone ## Accès distant depuis votre téléphone
Arboretum se bind sur `127.0.0.1` par défaut et **refuse** de se binder sur une adresse non-loopback sans dérogation explicite. La façon recommandée (et sûre) de l'atteindre depuis d'autres appareils est **[Tailscale Serve](https://tailscale.com/kb/1242/tailscale-serve)** — HTTPS valide, identité tailnet, aucun port ouvert : Arboretum se bind sur `127.0.0.1` par défaut et **refuse** de se binder sur une adresse non-loopback sans dérogation explicite. La façon recommandée (et sûre) de l'atteindre depuis d'autres appareils est **[Tailscale Serve](https://tailscale.com/kb/1242/tailscale-serve)** — HTTPS valide, identité tailnet, aucun port ouvert :
@@ -235,7 +254,7 @@ Arboretum enveloppe le CLI Claude Code **interactif** dans un PTY — la même c
## Développement ## Développement
Arboretum est un monorepo npm workspaces : `@arboretum/shared` (protocole WS/REST, source de vérité), `@johanleroy/git-arboretum` (le daemon Fastify, le paquet publié) et `@arboretum/web` (la SPA Vue 3). Arboretum est un monorepo npm workspaces : `@arboretum/shared` (protocole WS/REST, source de vérité), `@johanleroy/git-arboretum` (le daemon Fastify, le paquet publié), `@arboretum/web` (la SPA Vue 3) et `git-arboretum` (l'extension VS Code — buildée séparément avec `npm run build:vscode`).
```bash ```bash
npm run build # build shared → server → web (l'ordre compte) npm run build # build shared → server → web (l'ordre compte)

View File

@@ -28,10 +28,11 @@ A single Node.js daemon you run on your dev machine (`npx @johanleroy/git-arbore
- **Worktree-first, multi-repo dashboard** — every worktree of every registered repo, with its git state (branch, ahead/behind, dirty files) *and* the state of its Claude Code session (busy / waiting for input / idle / resumable). - **Worktree-first, multi-repo dashboard** — every worktree of every registered repo, with its git state (branch, ahead/behind, dirty files) *and* the state of its Claude Code session (busy / waiting for input / idle / resumable).
- **Full worktree lifecycle** — create (with per-repo post-create hooks: `npm ci`, copy `.env`…), adopt worktrees created by hand, delete with guardrails, prune orphans. - **Full worktree lifecycle** — create (with per-repo post-create hooks: `npm ci`, copy `.env`…), adopt worktrees created by hand, delete with guardrails, prune orphans.
- **Session discovery & resume** — sessions you launched in your own terminal show up automatically; resume dead ones, observe or fork live ones. Never corrupts a live session. - **Session discovery & resume** — sessions you launched in your own terminal show up automatically; resume dead ones, observe or fork live ones. Never corrupts a live session. Hide the old ones that clutter the list (one click clears the whole external history; they stay resumable).
- **Web terminal** — full xterm.js terminal to every managed session, surviving browser disconnects. - **Web terminal** — full xterm.js terminal to every managed session, surviving browser disconnects; truly fullscreen, with the prompt pinned to the bottom and full scrollback above.
- **Supervision from your phone** — installable PWA with push notifications when a session needs you; answer a prompt (its options, or deny) without opening a terminal. - **Supervision from your phone** — installable PWA with push notifications when a session needs you; answer a prompt (its options, or deny) without opening a terminal.
- **Work groups** — bundle related repos (e.g. an API, its web frontend and its docs) into a named group, then launch **one Claude session that spans all of them at once** (via the CLI's `--add-dir`): a single conversation with one shared context working across every repo, plus a unified view of all their worktrees and a side-by-side multi-terminal grid. Group sessions can either create the same branch worktree in each repo first, or run straight on the main checkouts. - **Work groups** — bundle related repos (e.g. an API, its web frontend and its docs) into a named group, then launch **one Claude session that spans all of them at once** (via the CLI's `--add-dir`): a single conversation with one shared context working across every repo, plus a unified view of all their worktrees and a side-by-side multi-terminal grid. Group sessions can either create the same branch worktree in each repo first, or run straight on the main checkouts.
- **VS Code extension** — a native extension (not a webview) that brings the live tree, native session terminals, waiting alerts and git actions right into your editor. See [VS Code extension](#vs-code-extension).
--- ---
@@ -104,6 +105,24 @@ node packages/server/dist/index.js
4. **Watch the live states.** Each session reports whether it's *busy*, *waiting for your input*, or *idle*. Open the **web terminal** to interact directly; it survives browser disconnects (closing the tab does not kill the session). 4. **Watch the live states.** Each session reports whether it's *busy*, *waiting for your input*, or *idle*. Open the **web terminal** to interact directly; it survives browser disconnects (closing the tab does not kill the session).
5. **Supervise from your phone.** Install the PWA, and when a session flips to *waiting* you get a push notification. Answer the prompt — pick one of its options or deny it — straight from the dashboard, no terminal required. 5. **Supervise from your phone.** Install the PWA, and when a session flips to *waiting* you get a push notification. Answer the prompt — pick one of its options or deny it — straight from the dashboard, no terminal required.
## VS Code extension
Prefer to stay in your editor? Arboretum ships a **native VS Code extension** (`packages/vscode`) — not a webview. It connects to the same daemon and surfaces it with VS Code's own primitives:
- A live **Repositories** and **Groups** tree (repos → worktrees → sessions) in the Activity Bar, updated in real time over the daemon's WebSocket.
- **Native terminals**: attach to (or observe) any session in a real VS Code terminal — you get VS Code's rendering, scrollback and copy/paste for free.
- A **status-bar** counter and native **notifications** when a session is waiting, with Yes/No answers without opening a terminal.
- Git mutations (create worktree, commit, push, promote) and **workspace awareness** — the worktree for your open folder is highlighted, with one-click "start session / create worktree here".
It is distributed as a **private VSIX**. Build and package it from the monorepo:
```bash
npm run build:vscode
cd packages/vscode && npx @vscode/vsce package --no-dependencies # → git-arboretum-0.1.0.vsix
```
Then install it via **Extensions: Install from VSIX…** (or `code --install-extension git-arboretum-0.1.0.vsix`), run **Arboretum: Sign In** and paste a token. Full details in [`packages/vscode/README.md`](packages/vscode/README.md).
## Remote access from your phone ## Remote access from your phone
Arboretum binds to `127.0.0.1` by default and **refuses** to bind to a non-loopback address without an explicit override. The recommended (and safe) way to reach it from other devices is **[Tailscale Serve](https://tailscale.com/kb/1242/tailscale-serve)** — valid HTTPS, tailnet identity, no open ports: Arboretum binds to `127.0.0.1` by default and **refuses** to bind to a non-loopback address without an explicit override. The recommended (and safe) way to reach it from other devices is **[Tailscale Serve](https://tailscale.com/kb/1242/tailscale-serve)** — valid HTTPS, tailnet identity, no open ports:
@@ -235,7 +254,7 @@ Arboretum wraps the **interactive** Claude Code CLI in a PTY — the same thing
## Development ## Development
Arboretum is an npm-workspaces monorepo: `@arboretum/shared` (WS/REST protocol, source of truth), `@johanleroy/git-arboretum` (the Fastify daemon, the published package), and `@arboretum/web` (the Vue 3 SPA). Arboretum is an npm-workspaces monorepo: `@arboretum/shared` (WS/REST protocol, source of truth), `@johanleroy/git-arboretum` (the Fastify daemon, the published package), `@arboretum/web` (the Vue 3 SPA), and `git-arboretum` (the VS Code extension — built separately with `npm run build:vscode`).
```bash ```bash
npm run build # build shared → server → web (order matters) npm run build # build shared → server → web (order matters)

3464
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,9 @@
"dev:web": "npm run dev -w @arboretum/web", "dev:web": "npm run dev -w @arboretum/web",
"build:site": "npm run build -w @arboretum/site", "build:site": "npm run build -w @arboretum/site",
"dev:site": "npm run dev -w @arboretum/site", "dev:site": "npm run dev -w @arboretum/site",
"preview:site": "npm run preview -w @arboretum/site" "preview:site": "npm run preview -w @arboretum/site",
"build:vscode": "npm run build -w @arboretum/shared -w git-arboretum",
"dev:vscode": "npm run dev -w git-arboretum"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.10.0", "@types/node": "^22.10.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@johanleroy/git-arboretum", "name": "@johanleroy/git-arboretum",
"version": "1.6.0", "version": "1.11.0",
"description": "Self-hosted web dashboard for git worktrees and the Claude Code sessions running on them", "description": "Self-hosted web dashboard for git worktrees and the Claude Code sessions running on them",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",

View File

@@ -144,6 +144,37 @@ try {
const out = c.state.outputs.get(att?.channel) ?? ''; const out = c.state.outputs.get(att?.channel) ?? '';
check('resume lance `--resume sid-dead` dans le bon cwd', out.includes('args=[--resume sid-dead]') && out.includes(`cwd=${workDir}`), out.replace(/\s+/g, ' ').slice(0, 120)); check('resume lance `--resume sid-dead` dans le bon cwd', out.includes('args=[--resume sid-dead]') && out.includes(`cwd=${workDir}`), out.replace(/\s+/g, ' ').slice(0, 120));
// --- Régression « Reprendre » : reprise d'une session MANAGÉE morte par son UUID Arboretum ---
// (le bouton web envoie l'UUID managé, pas le claudeSessionId ; le serveur doit le résoudre en DB).
const createManaged = await fetch(`${ORIGIN}/api/v1/sessions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Origin: ORIGIN, Cookie: cookie },
body: JSON.stringify({ cwd: workDir, command: 'claude' }),
});
const managed = (await createManaged.json()).session;
check('création session managée claude → 201 (pid)', createManaged.status === 201 && managed?.pid > 0);
// Simule la capture du claudeSessionId : entrée registre pour le pid du PTY managé (pollée toutes les 400ms).
writeFileSync(
join(sessions, `${managed.pid}.json`),
JSON.stringify({ pid: managed.pid, sessionId: 'sid-managed', cwd: workDir, status: 'idle' }),
);
const captured = await c.waitMsg(
(m) => m.type === 'session_update' && m.session?.id === managed.id && m.session?.claudeSessionId === 'sid-managed',
);
check('claudeSessionId capturé depuis le registre (session managée)', !!captured);
// Fermeture (kill) puis reprise par UUID managé → 201 dans le cwd d'origine (avant le fix : 404).
const killManaged = await fetch(`${ORIGIN}/api/v1/sessions/${managed.id}`, { method: 'DELETE', headers: { Origin: ORIGIN, Cookie: cookie } });
check('kill session managée → 200', killManaged.status === 200);
await sleep(400); // laisse handleExit persister ended_at
const resumeManaged = await postJson(`/api/v1/sessions/${managed.id}/resume`, cookie);
const resumedManaged = (await resumeManaged.json()).session;
check(
'resume dune session MANAGÉE morte par UUID → 201',
resumeManaged.status === 201 && resumedManaged?.command === 'claude' && resumedManaged?.source === 'managed' && resumedManaged?.cwd === workDir,
);
// Broadcast : une nouvelle session découverte est poussée via session_update au rafraîchissement périodique. // Broadcast : une nouvelle session découverte est poussée via session_update au rafraîchissement périodique.
writeJsonl(workDir, 'sid-new'); writeJsonl(workDir, 'sid-new');
const pushed = await c.waitMsg((m) => m.type === 'session_update' && m.session?.id === 'sid-new', 13000); const pushed = await c.waitMsg((m) => m.type === 'session_update' && m.session?.id === 'sid-new', 13000);

View File

@@ -4,7 +4,7 @@
// group_removed sur le topic 'groups', ajout/retrait de repo, et purge CASCADE de la membership // group_removed sur le topic 'groups', ajout/retrait de repo, et purge CASCADE de la membership
// quand le repo est supprimé (PRAGMA foreign_keys = ON). // quand le repo est supprimé (PRAGMA foreign_keys = ON).
import { spawn, execFileSync } from 'node:child_process'; import { spawn, execFileSync } from 'node:child_process';
import { mkdtempSync, rmSync } from 'node:fs'; import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os'; import { tmpdir } from 'node:os';
import { join, dirname } from 'node:path'; import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
@@ -127,9 +127,11 @@ try {
const gsession = gsBody.session; const gsession = gsBody.session;
check('POST /groups/:id/session → 201', gsRes.status === 201 && !!gsession); check('POST /groups/:id/session → 201', gsRes.status === 201 && !!gsession);
check('session de groupe : 2 répertoires couverts', Array.isArray(gsBody.dirs) && gsBody.dirs.length === 2); check('session de groupe : 2 répertoires couverts', Array.isArray(gsBody.dirs) && gsBody.dirs.length === 2);
check('session de groupe : addedDirs (1 dir supplémentaire)', (gsession?.addedDirs?.length ?? 0) === 1); // cwd = parent commun des repos (P6), chaque repo relié en --add-dir → 2 addedDirs.
check('session de groupe : cwd = parent commun des repos', gsession?.cwd === tmp);
check('session de groupe : addedDirs = les 2 repos', (gsession?.addedDirs?.length ?? 0) === 2);
check('session de groupe : groupId posé', gsession?.groupId === group.id); check('session de groupe : groupId posé', gsession?.groupId === group.id);
check('session de groupe : cwd primaire + addedDir = 2 repos', new Set([gsession?.cwd, ...(gsession?.addedDirs ?? [])]).size === 2); check('session de groupe : cwd parent + 2 repos addedDirs = 3 chemins distincts', new Set([gsession?.cwd, ...(gsession?.addedDirs ?? [])]).size === 3);
// La session apparaît dans la liste globale avec son groupId. // La session apparaît dans la liste globale avec son groupId.
const sessList = await (await j('/api/v1/sessions', 'GET', cookie)).json(); const sessList = await (await j('/api/v1/sessions', 'GET', cookie)).json();
@@ -140,6 +142,34 @@ try {
const pushedSession = await c.waitMsg((m) => m.type === 'session_update' && m.session?.id === gsession.id); const pushedSession = await c.waitMsg((m) => m.type === 'session_update' && m.session?.id === gsession.id);
check('broadcast WS session_update (session de groupe)', !!pushedSession); check('broadcast WS session_update (session de groupe)', !!pushedSession);
// ---- Worktree de groupe sur une NOUVELLE branche (scénario corrigé : mode auto, plus de -b raté) ----
const wtA = await j(`/api/v1/repos/${repoSummary.id}/worktrees`, 'POST', cookie, { branch: 'feature/cross', mode: 'auto', startSession: null });
const wtABody = await wtA.json();
check('POST /repos/:id/worktrees (branche neuve) → 201 + action=created', wtA.status === 201 && wtABody.action === 'created');
const wtB = await j(`/api/v1/repos/${repo2Summary.id}/worktrees`, 'POST', cookie, { branch: 'feature/cross', mode: 'auto', startSession: null });
check('POST /repos (2e repo) worktree branche neuve → 201', wtB.status === 201);
// GET /branches : la nouvelle branche apparaît (alimente le sélecteur de base côté UI).
const branchesA = await (await j(`/api/v1/repos/${repoSummary.id}/branches`, 'GET', cookie)).json();
check('GET /repos/:id/branches : feature/cross présente', Array.isArray(branchesA.local) && branchesA.local.includes('feature/cross'));
// session de groupe SUR cette branche → résout les worktrees créés (le cas qui échouait avant).
const gsBranch = await j(`/api/v1/groups/${group.id}/session`, 'POST', cookie, { command: 'bash', branch: 'feature/cross' });
const gsBranchBody = await gsBranch.json();
check('POST /groups/:id/session (branche) → 201 + 2 dirs', gsBranch.status === 201 && gsBranchBody.dirs?.length === 2);
await j(`/api/v1/sessions/${gsBranchBody.session.id}`, 'DELETE', cookie);
// commit : fichier neuf dans le worktree de repo1 puis commit via l'endpoint.
writeFileSync(join(wtABody.worktree.path, 'cross.txt'), 'wip\n');
const commitRes = await j(`/api/v1/repos/${repoSummary.id}/worktrees/commit`, 'POST', cookie, { path: wtABody.worktree.path, message: 'wip cross' });
check('POST /worktrees/commit → 200 + dirty=0', commitRes.status === 200 && (await commitRes.json()).worktree?.git?.dirtyCount === 0);
// promotion « en principal » : feature/cross devient le checkout principal de repo1, worktree supprimé.
const promRes = await j(`/api/v1/repos/${repoSummary.id}/worktrees/promote`, 'POST', cookie, { path: wtABody.worktree.path });
check('POST /worktrees/promote → 200', promRes.status === 200);
const wtsAfter = await (await j(`/api/v1/repos/${repoSummary.id}/worktrees`, 'GET', cookie)).json();
check('promotion : checkout principal désormais sur feature/cross', wtsAfter.worktrees?.find((w) => w.isMain)?.branch === 'feature/cross');
// groupe sans worktree résolu (branche inexistante) → 400. // groupe sans worktree résolu (branche inexistante) → 400.
const gsBad = await j(`/api/v1/groups/${group.id}/session`, 'POST', cookie, { command: 'bash', branch: 'no/such/branch' }); const gsBad = await j(`/api/v1/groups/${group.id}/session`, 'POST', cookie, { command: 'bash', branch: 'no/such/branch' });
check('POST /groups/:id/session branche absente → 400', gsBad.status === 400); check('POST /groups/:id/session branche absente → 400', gsBad.status === 400);

View File

@@ -17,6 +17,7 @@ import { PushService } from './core/push-service.js';
import { loadSecretBox } from './core/secret-box.js'; import { loadSecretBox } from './core/secret-box.js';
import { registerAuthRoutes } from './routes/auth.js'; import { registerAuthRoutes } from './routes/auth.js';
import { registerSessionRoutes } from './routes/sessions.js'; import { registerSessionRoutes } from './routes/sessions.js';
import { registerProjectRoutes } from './routes/projects.js';
import { registerRepoRoutes } from './routes/repos.js'; import { registerRepoRoutes } from './routes/repos.js';
import { registerGroupRoutes } from './routes/groups.js'; import { registerGroupRoutes } from './routes/groups.js';
import { registerWorktreeRoutes } from './routes/worktrees.js'; import { registerWorktreeRoutes } from './routes/worktrees.js';
@@ -84,6 +85,7 @@ export function buildApp(config: Config, db: Db, serverVersion: string): AppBund
const push = new PushService(db, config.vapidContact, undefined, box); const push = new PushService(db, config.vapidContact, undefined, box);
const manager = new PtyManager(db, config.claudeSessionsDir, push); const manager = new PtyManager(db, config.claudeSessionsDir, push);
const discovery = new DiscoveryService({ const discovery = new DiscoveryService({
db,
ptyManager: manager, ptyManager: manager,
projectsDir: config.claudeProjectsDir, projectsDir: config.claudeProjectsDir,
sessionsDir: config.claudeSessionsDir, sessionsDir: config.claudeSessionsDir,
@@ -168,10 +170,11 @@ export function buildApp(config: Config, db: Db, serverVersion: string): AppBund
}); });
registerAuthRoutes(app, auth, limiter, serverVersion, db); registerAuthRoutes(app, auth, limiter, serverVersion, db);
registerSessionRoutes(app, manager, discovery); registerSessionRoutes(app, manager, discovery, db);
registerProjectRoutes(app, manager, db);
registerRepoRoutes(app, worktrees, db); registerRepoRoutes(app, worktrees, db);
registerGroupRoutes(app, groups, db, worktrees, manager); registerGroupRoutes(app, groups, db, worktrees, manager);
registerWorktreeRoutes(app, worktrees); registerWorktreeRoutes(app, worktrees, db);
registerPushRoutes(app, push, db); registerPushRoutes(app, push, db);
registerSettingsRoutes(app, db, config, serverVersion, push); registerSettingsRoutes(app, db, config, serverVersion, push);
registerFsRoutes(app); registerFsRoutes(app);

View File

@@ -122,8 +122,13 @@ function quoteIfNeeded(token: string): string {
return /\s/.test(token) ? `"${token}"` : token; return /\s/.test(token) ? `"${token}"` : token;
} }
export function renderSystemdUnit(input: { exec: string; scriptArgs: string[] }): string { export function renderSystemdUnit(input: { exec: string; scriptArgs: string[]; pathEnv?: string | undefined }): string {
const execStart = [input.exec, ...input.scriptArgs].map(quoteIfNeeded).join(' '); const execStart = [input.exec, ...input.scriptArgs].map(quoteIfNeeded).join(' ');
// Un service systemd user démarre avec un PATH minimal (typiquement /usr/bin:/bin…) qui n'inclut
// PAS ~/.local/bin ni le bin npm/nvm où vit le CLI `claude` → resolveClaudeBin() (`which claude`)
// échouerait. On fige donc le PATH de l'environnement d'installation, où `claude` est résolvable.
// Doubles quotes systemd : tolèrent un chemin du PATH contenant des espaces.
const pathLine = input.pathEnv ? `\nEnvironment="PATH=${input.pathEnv}"` : '';
// KillSignal=SIGTERM + TimeoutStopSec=10 collent au drain de runDaemon (SIGTERM → drain 1s → close). // KillSignal=SIGTERM + TimeoutStopSec=10 collent au drain de runDaemon (SIGTERM → drain 1s → close).
return `[Unit] return `[Unit]
Description=Arboretum — git worktree & Claude Code dashboard Description=Arboretum — git worktree & Claude Code dashboard
@@ -136,7 +141,7 @@ Restart=on-failure
RestartSec=5 RestartSec=5
KillSignal=SIGTERM KillSignal=SIGTERM
TimeoutStopSec=10 TimeoutStopSec=10
Environment=NODE_ENV=production Environment=NODE_ENV=production${pathLine}
[Install] [Install]
WantedBy=default.target WantedBy=default.target
@@ -148,8 +153,14 @@ export function renderLaunchAgentPlist(input: {
programArguments: string[]; programArguments: string[];
stdoutPath: string; stdoutPath: string;
stderrPath: string; stderrPath: string;
pathEnv?: string | undefined;
}): string { }): string {
const args = input.programArguments.map((a) => ` <string>${xmlEscape(a)}</string>`).join('\n'); const args = input.programArguments.map((a) => ` <string>${xmlEscape(a)}</string>`).join('\n');
// launchd démarre un LaunchAgent avec un PATH minimal qui n'inclut pas ~/.local/bin ni le bin
// npm/nvm où vit le CLI `claude` → resolveClaudeBin() échouerait. On fige le PATH d'installation.
const pathEntry = input.pathEnv
? `\n <key>PATH</key>\n <string>${xmlEscape(input.pathEnv)}</string>`
: '';
// KeepAlive/SuccessfulExit=false ≈ Restart=on-failure (ne relance pas après un drain volontaire). // KeepAlive/SuccessfulExit=false ≈ Restart=on-failure (ne relance pas après un drain volontaire).
return `<?xml version="1.0" encoding="UTF-8"?> return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -175,7 +186,7 @@ ${args}
<key>EnvironmentVariables</key> <key>EnvironmentVariables</key>
<dict> <dict>
<key>NODE_ENV</key> <key>NODE_ENV</key>
<string>production</string> <string>production</string>${pathEntry}
</dict> </dict>
</dict> </dict>
</plist> </plist>
@@ -258,9 +269,12 @@ export async function runInstall(argv: string[]): Promise<void> {
const serviceArgs = buildServiceArgs(flags); const serviceArgs = buildServiceArgs(flags);
const { exec, args: binArgs } = resolveBin(flags); const { exec, args: binArgs } = resolveBin(flags);
const scriptArgs = [...binArgs, ...serviceArgs]; const scriptArgs = [...binArgs, ...serviceArgs];
// PATH de l'environnement d'installation (shell interactif où `claude` est résolvable) : on le
// fige dans l'unit/plist car systemd/launchd démarrent le service avec un PATH minimal.
const pathEnv = process.env.PATH;
if (platform === 'linux') { if (platform === 'linux') {
const unit = renderSystemdUnit({ exec, scriptArgs }); const unit = renderSystemdUnit({ exec, scriptArgs, pathEnv });
const unitPath = systemdUnitPath(); const unitPath = systemdUnitPath();
if (flags.dryRun) { if (flags.dryRun) {
console.log(`# ${unitPath}\n${unit}\n# commands:`); console.log(`# ${unitPath}\n${unit}\n# commands:`);
@@ -295,6 +309,7 @@ export async function runInstall(argv: string[]): Promise<void> {
programArguments, programArguments,
stdoutPath: logs.out, stdoutPath: logs.out,
stderrPath: logs.err, stderrPath: logs.err,
pathEnv,
}); });
const plistPath = launchAgentPlistPath(flags.label); const plistPath = launchAgentPlistPath(flags.label);
const uid = process.getuid?.() ?? 0; const uid = process.getuid?.() ?? 0;

View File

@@ -11,6 +11,10 @@ export interface Config {
/** origins supplémentaires autorisées (ex. https://machine.tailnet.ts.net) */ /** origins supplémentaires autorisées (ex. https://machine.tailnet.ts.net) */
allowedOrigins: string[]; allowedOrigins: string[];
printToken: boolean; printToken: boolean;
/** racine effective de l'install Claude (~/.claude par défaut, --claude-home, ou réglage claude_home). */
claudeHome: string;
/** true si --claude-home a été passé explicitement → a priorité sur le réglage claude_home. */
claudeHomeFromFlag: boolean;
/** ~/.claude/projects (transcripts JSONL) — surchargeable via --claude-home (tests). */ /** ~/.claude/projects (transcripts JSONL) — surchargeable via --claude-home (tests). */
claudeProjectsDir: string; claudeProjectsDir: string;
/** ~/.claude/sessions (registre des sessions CLI vivantes). */ /** ~/.claude/sessions (registre des sessions CLI vivantes). */
@@ -61,7 +65,8 @@ export function loadConfig(argv = process.argv.slice(2)): Config {
} catch { } catch {
/* FS sans permissions POSIX : ignoré, cf. avertissement dans db.openDb */ /* FS sans permissions POSIX : ignoré, cf. avertissement dans db.openDb */
} }
const claudeHome = values['claude-home'] ?? join(homedir(), '.claude'); const claudeHomeFlag = values['claude-home'];
const claudeHome = claudeHomeFlag ?? join(homedir(), '.claude');
return { return {
port: Number(values.port), port: Number(values.port),
bind, bind,
@@ -69,6 +74,8 @@ export function loadConfig(argv = process.argv.slice(2)): Config {
dataDir, dataDir,
allowedOrigins: values['allow-origin'] ?? [], allowedOrigins: values['allow-origin'] ?? [],
printToken: values['print-token'] ?? false, printToken: values['print-token'] ?? false,
claudeHome,
claudeHomeFromFlag: claudeHomeFlag !== undefined,
claudeProjectsDir: join(claudeHome, 'projects'), claudeProjectsDir: join(claudeHome, 'projects'),
claudeSessionsDir: join(claudeHome, 'sessions'), claudeSessionsDir: join(claudeHome, 'sessions'),
vapidContact: values['vapid-contact'] ?? 'mailto:arboretum@localhost', vapidContact: values['vapid-contact'] ?? 'mailto:arboretum@localhost',

View File

@@ -1,4 +1,5 @@
import { execFileSync } from 'node:child_process'; import { execFileSync } from 'node:child_process';
import { accessSync, constants } from 'node:fs';
export interface SpawnSpec { export interface SpawnSpec {
file: string; file: string;
@@ -12,22 +13,74 @@ export interface SpawnOptions {
resume?: { claudeSessionId: string; fork?: boolean }; resume?: { claudeSessionId: string; fork?: boolean };
/** répertoires supplémentaires à relier dans une seule session (P6) : `--add-dir <path>` répété. */ /** répertoires supplémentaires à relier dans une seule session (P6) : `--add-dir <path>` répété. */
addDirs?: string[]; addDirs?: string[];
/** chemin explicite du binaire `claude` (réglage UI) ; sinon résolution via PATH (`which`). */
claudeBinPath?: string | null;
}
/** Diagnostic de résolution du binaire `claude` (exposé en lecture dans Réglages). */
export interface ClaudeBinDiagnostic {
/** chemin résolu du binaire, ou null si introuvable. */
path: string | null;
/** 'configured' = réglage explicite ; 'path' = trouvé via PATH ; null = introuvable. */
source: 'configured' | 'path' | null;
/** true si le binaire est présent et exécutable. */
ok: boolean;
} }
let cachedClaudeBin: string | null = null; let cachedClaudeBin: string | null = null;
export function resolveClaudeBin(): string { /** Recherche `claude` dans le PATH (sans throw). null si absent. */
if (cachedClaudeBin) return cachedClaudeBin; function findClaudeOnPath(): string | null {
try { try {
cachedClaudeBin = execFileSync('which', ['claude'], { encoding: 'utf8' }).trim(); return execFileSync('which', ['claude'], { encoding: 'utf8' }).trim() || null;
} catch { } catch {
return null;
}
}
function isExecutable(path: string): boolean {
try {
accessSync(path, constants.X_OK);
return true;
} catch {
return false;
}
}
/**
* Résout le binaire `claude`. Si `configuredPath` est fourni (réglage UI), il est utilisé tel quel
* — validé exécutable, message clair sinon — et JAMAIS mis en cache (modifiable à chaud). Sinon :
* `which claude`, mis en cache. Un service systemd/launchd démarre avec un PATH minimal sans
* ~/.local/bin → `which claude` y échoue ; d'où le réglage de chemin explicite (et le PATH figé par
* `arboretum install`).
*/
export function resolveClaudeBin(configuredPath?: string | null): string {
if (configuredPath) {
if (!isExecutable(configuredPath)) {
throw new Error(`Configured Claude CLI path is not executable: ${configuredPath}`);
}
return configuredPath;
}
if (cachedClaudeBin) return cachedClaudeBin;
const found = findClaudeOnPath();
if (!found) {
throw new Error( throw new Error(
'Claude Code CLI not found in PATH. Install it first: https://code.claude.com/docs/en/quickstart', 'Claude Code CLI not found in PATH. Install it first: https://code.claude.com/docs/en/quickstart',
); );
} }
cachedClaudeBin = found;
return cachedClaudeBin; return cachedClaudeBin;
} }
/** Diagnostic non-throwing pour l'UI (Réglages) : recalculé à chaque appel, jamais caché. */
export function diagnoseClaudeBin(configuredPath?: string | null): ClaudeBinDiagnostic {
if (configuredPath) {
return { path: configuredPath, source: 'configured', ok: isExecutable(configuredPath) };
}
const found = findClaudeOnPath();
return found ? { path: found, source: 'path', ok: true } : { path: null, source: null, ok: false };
}
/** Module volontairement abstrait : le plan B « BYO API key / Agent SDK » se brancherait ici. */ /** Module volontairement abstrait : le plan B « BYO API key / Agent SDK » se brancherait ici. */
export function buildSpawnSpec(opts: SpawnOptions): SpawnSpec { export function buildSpawnSpec(opts: SpawnOptions): SpawnSpec {
const env: NodeJS.ProcessEnv = { const env: NodeJS.ProcessEnv = {
@@ -46,5 +99,5 @@ export function buildSpawnSpec(opts: SpawnOptions): SpawnSpec {
} }
// Session de groupe : relie plusieurs repos/worktrees dans une seule session (P6). // Session de groupe : relie plusieurs repos/worktrees dans une seule session (P6).
for (const dir of opts.addDirs ?? []) args.push('--add-dir', dir); for (const dir of opts.addDirs ?? []) args.push('--add-dir', dir);
return { file: resolveClaudeBin(), args, env }; return { file: resolveClaudeBin(opts.claudeBinPath), args, env };
} }

View File

@@ -0,0 +1,63 @@
// Réglages liés au CLI Claude, persistés dans la table `settings` (clé/valeur), modifiables via
// l'onglet Réglages. Frontière de sécurité identique à scan-settings : clés NON sensibles, écrites
// uniquement via l'allow-list du PATCH /api/v1/settings et les validateurs ci-dessous.
//
// Motivation : un service systemd/launchd démarre avec un PATH minimal qui n'inclut pas ~/.local/bin
// (où vit le binaire `claude`) → `which claude` échoue. Plutôt que de bricoler le PATH du service,
// l'utilisateur peut pointer explicitement le binaire ici (effet : prochaine session, sans redémarrage).
import { accessSync, constants, statSync } from 'node:fs';
import { getSetting } from '../db/index.js';
import type { Db } from '../db/index.js';
import { isSafeAbsolutePath } from './git.js';
/** Chemin explicite du binaire `claude` (override de la résolution via PATH). */
export const CLAUDE_BIN_PATH_KEY = 'claude_bin_path';
/** Override de la racine ~/.claude (transcripts + registre des sessions). */
export const CLAUDE_HOME_KEY = 'claude_home';
/** Chemin configuré du binaire `claude`, ou null si non défini (⇒ auto-détection via PATH). */
export function readClaudeBinPath(db: Db): string | null {
const raw = getSetting(db, CLAUDE_BIN_PATH_KEY)?.trim();
return raw ? raw : null;
}
/** Racine ~/.claude configurée, ou null si non défini (⇒ défaut/flag). */
export function readClaudeHome(db: Db): string | null {
const raw = getSetting(db, CLAUDE_HOME_KEY)?.trim();
return raw ? raw : null;
}
/**
* Valide un chemin de binaire `claude`. Retourne `''` pour réinitialiser (auto-détection), le chemin
* normalisé s'il est absolu ET pointe vers un fichier exécutable, ou `null` si invalide (⇒ 400).
*/
export function normalizeClaudeBinPath(raw: unknown): string | null {
if (typeof raw !== 'string') return null;
const p = raw.trim();
if (p === '') return '';
if (!isSafeAbsolutePath(p)) return null;
try {
if (!statSync(p).isFile()) return null;
accessSync(p, constants.X_OK);
} catch {
return null;
}
return p;
}
/**
* Valide une racine ~/.claude. Retourne `''` pour réinitialiser (défaut), le chemin normalisé s'il
* est absolu ET pointe vers un répertoire existant, ou `null` si invalide (⇒ 400).
*/
export function normalizeClaudeHome(raw: unknown): string | null {
if (typeof raw !== 'string') return null;
const p = raw.trim();
if (p === '') return '';
if (!isSafeAbsolutePath(p)) return null;
try {
if (!statSync(p).isDirectory()) return null;
} catch {
return null;
}
return p;
}

View File

@@ -7,6 +7,7 @@ import { join } from 'node:path';
import type { SessionSummary } from '@arboretum/shared'; import type { SessionSummary } from '@arboretum/shared';
import { scanProjects, type DiscoveredJsonl } from './jsonl-discovery.js'; import { scanProjects, type DiscoveredJsonl } from './jsonl-discovery.js';
import { readRegistry, type RegistryEntry } from './session-registry.js'; import { readRegistry, type RegistryEntry } from './session-registry.js';
import { listHiddenSessionIds, type Db } from '../db/index.js';
import type { PtyManager } from './pty-manager.js'; import type { PtyManager } from './pty-manager.js';
const DEFAULT_REFRESH_MS = 10_000; const DEFAULT_REFRESH_MS = 10_000;
@@ -17,6 +18,7 @@ export interface DiscoveryServiceEvents {
} }
export interface DiscoveryOptions { export interface DiscoveryOptions {
db: Db;
ptyManager: PtyManager; ptyManager: PtyManager;
projectsDir?: string; projectsDir?: string;
sessionsDir?: string; sessionsDir?: string;
@@ -24,6 +26,7 @@ export interface DiscoveryOptions {
} }
export class DiscoveryService extends EventEmitter<DiscoveryServiceEvents> { export class DiscoveryService extends EventEmitter<DiscoveryServiceEvents> {
private readonly db: Db;
private readonly projectsDir: string; private readonly projectsDir: string;
private readonly sessionsDir: string; private readonly sessionsDir: string;
private readonly ptyManager: PtyManager; private readonly ptyManager: PtyManager;
@@ -35,6 +38,7 @@ export class DiscoveryService extends EventEmitter<DiscoveryServiceEvents> {
constructor(opts: DiscoveryOptions) { constructor(opts: DiscoveryOptions) {
super(); super();
this.db = opts.db;
this.ptyManager = opts.ptyManager; this.ptyManager = opts.ptyManager;
this.projectsDir = opts.projectsDir ?? join(homedir(), '.claude', 'projects'); this.projectsDir = opts.projectsDir ?? join(homedir(), '.claude', 'projects');
this.sessionsDir = opts.sessionsDir ?? join(homedir(), '.claude', 'sessions'); this.sessionsDir = opts.sessionsDir ?? join(homedir(), '.claude', 'sessions');
@@ -81,6 +85,9 @@ export class DiscoveryService extends EventEmitter<DiscoveryServiceEvents> {
if (r.claudeSessionId) regBySid.set(r.claudeSessionId, r); if (r.claudeSessionId) regBySid.set(r.claudeSessionId, r);
} }
const known = this.ptyManager.knownClaudeSessionIds(); const known = this.ptyManager.knownClaudeSessionIds();
// Sessions masquées par l'utilisateur : on les garde dans le cache (resume/fork possibles) mais
// marquées `hidden` → la route /sessions les exclut par défaut.
const hiddenIds = listHiddenSessionIds(this.db);
// Dédoublonnage des JSONL par claudeSessionId (on retient le plus récent). // Dédoublonnage des JSONL par claudeSessionId (on retient le plus récent).
const latest = new Map<string, DiscoveredJsonl>(); const latest = new Map<string, DiscoveredJsonl>();
@@ -113,6 +120,7 @@ export class DiscoveryService extends EventEmitter<DiscoveryServiceEvents> {
resumable: !live, // morte → --resume direct ; vivante → fork/observe (jamais resume : corruption) resumable: !live, // morte → --resume direct ; vivante → fork/observe (jamais resume : corruption)
attachable: false, // Arboretum ne tient pas le PTY d'une session externe attachable: false, // Arboretum ne tient pas le PTY d'une session externe
registryStatus: r?.status ?? null, registryStatus: r?.status ?? null,
hidden: hiddenIds.has(d.claudeSessionId),
}); });
} }

View File

@@ -2,9 +2,11 @@
// les chemins/refs utilisateur. Fonctions pures sans état, prenant un cwd déjà validé par l'appelant. // les chemins/refs utilisateur. Fonctions pures sans état, prenant un cwd déjà validé par l'appelant.
import { execFile } from 'node:child_process'; import { execFile } from 'node:child_process';
import { resolve, sep } from 'node:path'; import { resolve, sep } from 'node:path';
import type { WorktreeGitStatus } from '@arboretum/shared'; import type { WorktreeGitStatus, WorktreeBranchAction, WorktreeBranchMode } from '@arboretum/shared';
const GIT_TIMEOUT_MS = 10_000; const GIT_TIMEOUT_MS = 10_000;
// `push` peut dialoguer avec un remote (réseau) : on lui laisse une marge bien plus large.
const GIT_PUSH_TIMEOUT_MS = 120_000;
const GIT_MAX_BUFFER = 8 * 1024 * 1024; const GIT_MAX_BUFFER = 8 * 1024 * 1024;
interface GitError extends Error { interface GitError extends Error {
@@ -12,14 +14,14 @@ interface GitError extends Error {
code?: number | string; code?: number | string;
} }
function git(cwd: string, args: string[]): Promise<string> { function git(cwd: string, args: string[], timeoutMs: number = GIT_TIMEOUT_MS): Promise<string> {
return new Promise((resolveP, reject) => { return new Promise((resolveP, reject) => {
execFile( execFile(
'git', 'git',
args, args,
{ {
cwd, cwd,
timeout: GIT_TIMEOUT_MS, timeout: timeoutMs,
maxBuffer: GIT_MAX_BUFFER, maxBuffer: GIT_MAX_BUFFER,
// GIT_OPTIONAL_LOCKS=0 : pas de prise de verrou par `status` (perf + concurrence avec une // GIT_OPTIONAL_LOCKS=0 : pas de prise de verrou par `status` (perf + concurrence avec une
// session claude active) ; LC_ALL=C : sortie stable pour le parsing. // session claude active) ; LC_ALL=C : sortie stable pour le parsing.
@@ -120,6 +122,11 @@ export function isSafeAbsolutePath(p: string): boolean {
return p.startsWith('/') && resolve(p) === p && !p.split(sep).includes('..'); return p.startsWith('/') && resolve(p) === p && !p.split(sep).includes('..');
} }
/** Initialise un dépôt git dans `dir` (déjà créé et validé par l'appelant). `git init` est idempotent. */
export async function gitInit(dir: string): Promise<void> {
await git(dir, ['init']);
}
/** true si `path` est la racine d'un dépôt git (main worktree) accessible. */ /** true si `path` est la racine d'un dépôt git (main worktree) accessible. */
export async function isRepo(path: string): Promise<boolean> { export async function isRepo(path: string): Promise<boolean> {
try { try {
@@ -140,6 +147,52 @@ export async function defaultBranch(repoPath: string): Promise<string | null> {
} }
} }
/** Branche courante (nom court) du checkout en `repoPath`, ou null si HEAD détaché. */
export async function currentBranch(repoPath: string): Promise<string | null> {
try {
const b = (await git(repoPath, ['rev-parse', '--abbrev-ref', 'HEAD'])).trim();
return b === 'HEAD' ? null : b;
} catch {
return null;
}
}
/** Existence d'une branche, en local (`refs/heads`) et/ou suivie du remote (`refs/remotes/origin`). */
export async function branchExists(repoPath: string, branch: string): Promise<{ local: boolean; remote: boolean }> {
const verify = async (ref: string): Promise<boolean> => {
try {
await git(repoPath, ['rev-parse', '--verify', '--quiet', ref]);
return true;
} catch {
return false;
}
};
const [local, remote] = await Promise.all([verify(`refs/heads/${branch}`), verify(`refs/remotes/origin/${branch}`)]);
return { local, remote };
}
/** Branches locales + suivies de `origin` (noms courts) + branche par défaut — pour un sélecteur de base. */
export async function listBranches(repoPath: string): Promise<{ local: string[]; remote: string[]; default: string | null }> {
const local: string[] = [];
const remote: string[] = [];
try {
const out = await git(repoPath, ['for-each-ref', '--format=%(refname:short)', 'refs/heads', 'refs/remotes/origin']);
for (const line of out.split('\n')) {
const name = line.trim();
if (!name) continue;
if (name.startsWith('origin/')) {
const short = name.slice('origin/'.length);
if (short && short !== 'HEAD') remote.push(short);
} else {
local.push(name);
}
}
} catch {
/* dépôt sans refs encore (premier commit absent) → listes vides */
}
return { local, remote, default: await defaultBranch(repoPath) };
}
export async function listWorktrees(repoPath: string): Promise<ParsedWorktree[]> { export async function listWorktrees(repoPath: string): Promise<ParsedWorktree[]> {
return parseWorktreePorcelain(await git(repoPath, ['worktree', 'list', '--porcelain'])); return parseWorktreePorcelain(await git(repoPath, ['worktree', 'list', '--porcelain']));
} }
@@ -175,19 +228,69 @@ export async function worktreeStatus(worktreePath: string): Promise<WorktreeGitS
return { ahead, behind, dirtyCount, upstream }; return { ahead, behind, dirtyCount, upstream };
} }
/** Point de départ d'une branche créée : `baseRef` explicite, sinon la branche par défaut du dépôt
* (locale ou suivie de `origin`), sinon undefined (git part alors du HEAD courant). */
async function resolveStartPoint(repoPath: string, baseRef?: string): Promise<string | undefined> {
if (baseRef) return baseRef;
const def = await defaultBranch(repoPath);
if (!def) return undefined;
const { local, remote } = await branchExists(repoPath, def);
if (local) return def;
if (remote) return `origin/${def}`;
return undefined;
}
/**
* Crée un worktree en résolvant la branche selon `mode` (voir `WorktreeBranchMode`). Renvoie l'action
* effective. En mode `auto`, on choisit checkout / suivi-remote / création selon l'existence réelle de
* la branche — indispensable pour les groupes hétérogènes (branche présente dans certains dépôts seulement).
*/
export async function addWorktree( export async function addWorktree(
repoPath: string, repoPath: string,
opts: { path: string; branch: string; newBranch: boolean; baseRef?: string }, opts: { path: string; branch: string; mode: WorktreeBranchMode; baseRef?: string },
): Promise<void> { ): Promise<WorktreeBranchAction> {
const { local, remote } = await branchExists(repoPath, opts.branch);
let action: WorktreeBranchAction;
if (opts.mode === 'create') action = 'created';
else if (opts.mode === 'checkout') action = local ? 'reused' : 'tracked';
else action = local ? 'reused' : remote ? 'tracked' : 'created'; // auto
const args = ['worktree', 'add']; const args = ['worktree', 'add'];
if (opts.newBranch) args.push('-b', opts.branch); if (action === 'reused') {
args.push('--', opts.path); args.push('--', opts.path, opts.branch);
if (opts.newBranch) { } else if (action === 'tracked') {
if (opts.baseRef) args.push(opts.baseRef); args.push('--track', '-b', opts.branch, '--', opts.path, `origin/${opts.branch}`);
} else { } else {
args.push(opts.branch); const start = await resolveStartPoint(repoPath, opts.baseRef);
args.push('-b', opts.branch, '--', opts.path);
if (start) args.push(start);
} }
await git(repoPath, args); await git(repoPath, args);
return action;
}
/** `git add -A` puis commit. L'appelant garantit qu'il y a quelque chose à committer. */
export async function commitAll(repoPath: string, message: string): Promise<void> {
await git(repoPath, ['add', '-A']);
await git(repoPath, ['commit', '-m', message]);
}
/** Pousse la branche courante. Si aucun upstream n'est configuré : `git push -u origin <branche>`. */
export async function push(repoPath: string): Promise<void> {
let hasUpstream = false;
try {
await git(repoPath, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}']);
hasUpstream = true;
} catch {
hasUpstream = false;
}
if (hasUpstream) {
await git(repoPath, ['push'], GIT_PUSH_TIMEOUT_MS);
} else {
const branch = await currentBranch(repoPath);
if (!branch) throw new Error('cannot push a detached HEAD');
await git(repoPath, ['push', '-u', 'origin', branch], GIT_PUSH_TIMEOUT_MS);
}
} }
/** /**

View File

@@ -0,0 +1,37 @@
import { parse, resolve, sep } from 'node:path';
/**
* Plus long ancêtre commun d'un ensemble de chemins absolus (par segments, jamais par préfixe
* de chaîne — `/a/bc` n'est PAS un ancêtre de `/a/bcd`). Pour un seul chemin, renvoie ce chemin.
*/
export function commonAncestorDir(paths: string[]): string {
const first = paths[0];
if (first === undefined) throw new Error('commonAncestorDir: empty input');
const firstSegs = resolve(first).split(sep);
let common = firstSegs.length;
for (let i = 1; i < paths.length; i++) {
const segs = resolve(paths[i]!).split(sep);
let k = 0;
while (k < common && k < segs.length && segs[k] === firstSegs[k]) k++;
common = k;
}
const joined = firstSegs.slice(0, common).join(sep);
// `['', 'a', 'b'].slice(0,1).join('/')` === '' → racine POSIX ; rétablir le séparateur racine.
return joined === '' ? parse(resolve(first)).root : joined;
}
/**
* Politique de répertoire de travail d'une session de groupe (P6) : le `cwd` est le PARENT COMMUN
* des répertoires couverts (racine neutre, chemins relatifs cross-repo naturels), chaque répertoire
* étant ensuite relié via `--add-dir` (le dédoublonnage + filtrage du cwd est fait par `PtyManager`).
* Garde-fou : si le parent commun est la racine du FS (repos éparpillés sur des racines différentes),
* on retombe sur le premier répertoire pour ne pas accorder à Claude la permission sur tout le disque.
*/
export function resolveGroupCwd(dirs: string[]): { cwd: string; addDirs: string[] } {
const first = dirs[0];
if (first === undefined) throw new Error('resolveGroupCwd: empty input');
const ancestor = commonAncestorDir(dirs);
const root = parse(resolve(first)).root;
const cwd = ancestor === root ? first : ancestor;
return { cwd, addDirs: dirs };
}

View File

@@ -0,0 +1,33 @@
// Création d'un nouveau projet : un dossier `<root>/<name>` créé sous une racine existante, dans
// lequel on lance ensuite une session. Couche PURE (testable sans fs) — la création réelle du
// dossier, le `git init` et le spawn vivent dans `routes/projects.ts`.
import { join } from 'node:path';
import { isSafeAbsolutePath } from './git.js';
/**
* Valide un nom de projet : UN SEUL segment de dossier. Anti-traversal de base — refuse les noms
* vides, trop longs, `.`/`..`, et tout caractère de séparation (`/`, `\`) ou NUL. La résolution du
* chemin complet (et sa re-validation) est faite par {@link resolveProjectDir}.
*/
export function isSafeProjectName(name: string): boolean {
const n = name.trim();
if (n.length === 0 || n.length > 255) return false;
if (n === '.' || n === '..') return false;
return !/[/\\\0]/.test(n);
}
/**
* Résout le dossier de projet `<root>/<name>`. Suppose `root` déjà validé absolu et existant par
* l'appelant ; re-valide le chemin final via {@link isSafeAbsolutePath} (défense en profondeur).
* Lève si `name` est invalide ou si le chemin résultant échappe l'arborescence.
*/
export function resolveProjectDir(root: string, name: string): string {
if (!isSafeProjectName(name)) {
throw Object.assign(new Error(`Invalid project name: ${name}`), { statusCode: 400 });
}
const dir = join(root, name.trim());
if (!isSafeAbsolutePath(dir)) {
throw Object.assign(new Error(`Unsafe project path: ${dir}`), { statusCode: 400 });
}
return dir;
}

View File

@@ -7,12 +7,15 @@ import pty from '@homebridge/node-pty-prebuilt-multiarch';
import { FLOW, REPLAY_TAIL_BYTES, type SessionActivity, type SessionSummary } from '@arboretum/shared'; import { FLOW, REPLAY_TAIL_BYTES, type SessionActivity, type SessionSummary } from '@arboretum/shared';
import { RingBuffer } from './ring-buffer.js'; import { RingBuffer } from './ring-buffer.js';
import { buildSpawnSpec } from './claude-launcher.js'; import { buildSpawnSpec } from './claude-launcher.js';
import { readClaudeBinPath } from './claude-settings.js';
import { findByPid } from './session-registry.js'; import { findByPid } from './session-registry.js';
import { SessionActivityTracker } from './claude-adapter.js'; import { SessionActivityTracker } from './claude-adapter.js';
import type { PushService } from './push-service.js'; import type { PushService } from './push-service.js';
import type { Db } from '../db/index.js'; import type { Db } from '../db/index.js';
const RING_CAPACITY = 2 * 1024 * 1024; // 4 Mo : conserve assez d'historique pour que le replay (REPLAY_TAIL_BYTES = 1 Mo) reste largement
// dans le ring et qu'on puisse remonter une conversation Claude après ré-attache.
const RING_CAPACITY = 4 * 1024 * 1024;
const KILL_GRACE_MS = 5000; const KILL_GRACE_MS = 5000;
/** Délai avant envoi d'une notif push sur passage en `waiting` : annulé si la session repart (faux positif). */ /** Délai avant envoi d'une notif push sur passage en `waiting` : annulé si la session repart (faux positif). */
const NOTIFY_DEBOUNCE_MS = 1500; const NOTIFY_DEBOUNCE_MS = 1500;
@@ -109,8 +112,11 @@ export class PtyManager extends EventEmitter<PtyManagerEvents> {
} }
// Un resume/fork est toujours une session claude (le cwd d'origine est garanti par l'appelant — S1). // Un resume/fork est toujours une session claude (le cwd d'origine est garanti par l'appelant — S1).
const command = opts.resume ? 'claude' : (opts.command ?? 'claude'); const command = opts.resume ? 'claude' : (opts.command ?? 'claude');
// Override de chemin du binaire claude (réglage UI) lu à chaque spawn → effet sans redémarrage.
const claudeBinPath = command === 'claude' ? readClaudeBinPath(this.db) : null;
const spec = buildSpawnSpec({ const spec = buildSpawnSpec({
command, command,
...(claudeBinPath ? { claudeBinPath } : {}),
...(opts.resume ? { resume: opts.resume } : {}), ...(opts.resume ? { resume: opts.resume } : {}),
...(addedDirs.length ? { addDirs: addedDirs } : {}), ...(addedDirs.length ? { addDirs: addedDirs } : {}),
}); });
@@ -201,6 +207,24 @@ export class PtyManager extends EventEmitter<PtyManagerEvents> {
return { addedDirs: parseAddedDirs(row.added_dirs), groupId: row.group_id }; return { addedDirs: parseAddedDirs(row.added_dirs), groupId: row.group_id };
} }
/**
* Cible de reprise d'une session managée MORTE (P2/P6), résolue par UUID Arboretum : son cwd
* d'origine, son claudeSessionId et son contexte de groupe, lus en DB. null si l'id ne correspond
* pas à une session managée morte, reprenable (claude + claudeSessionId connu).
* Complète `DiscoveryService.getDiscovered`, qui ne couvre QUE les sessions claude EXTERNES
* (une managée connue est justement exclue de la découverte).
*/
resumeTargetById(id: string): { cwd: string; claudeSessionId: string; addedDirs: string[]; groupId: string | null } | null {
if (this.live.has(id)) return null; // vivante : pas de resume direct (fork via le même chemin)
const row = this.db
.prepare(
"SELECT cwd, claude_session_id, added_dirs, group_id FROM sessions WHERE id = ? AND ended_at IS NOT NULL AND claude_session_id IS NOT NULL AND command = 'claude'",
)
.get(id) as { cwd: string; claude_session_id: string; added_dirs: string | null; group_id: string | null } | undefined;
if (!row) return null;
return { cwd: row.cwd, claudeSessionId: row.claude_session_id, addedDirs: parseAddedDirs(row.added_dirs), groupId: row.group_id };
}
/** Session managée VIVANTE portant ce claudeSessionId (garde-fou anti-resume d'une session vivante). */ /** Session managée VIVANTE portant ce claudeSessionId (garde-fou anti-resume d'une session vivante). */
findLiveByClaudeSessionId(claudeSessionId: string): SessionSummary | null { findLiveByClaudeSessionId(claudeSessionId: string): SessionSummary | null {
for (const s of this.live.values()) { for (const s of this.live.values()) {
@@ -383,30 +407,35 @@ export class PtyManager extends EventEmitter<PtyManagerEvents> {
// ---- interne ---- // ---- interne ----
/** /**
* Push P4-B : notifie sur le FRONT MONTANT vers `waiting` uniquement (le tracker réémet * Push P4-B : notifie sur le FRONT MONTANT vers un état qui requiert l'attention — `waiting`
* souvent le même état), avec un debounce annulable — un `waiting` ultra-bref (Claude répond * (un dialogue bloque) ou `idle` atteint depuis `busy` (Claude a terminé sa réponse, la session
* tout seul) ne déclenche pas de notif. Cible tous les abonnements (un seul utilisateur). * redevient disponible). Le tracker réémet souvent le même état → on ne réagit qu'au changement.
* Debounce annulable : un état ultra-bref (Claude repart tout seul) ne déclenche pas de notif —
* à l'échéance on revérifie l'état réel. Cible tous les abonnements (un seul utilisateur).
*/ */
private maybeNotify(s: ManagedSession, next: SessionActivity | null): void { private maybeNotify(s: ManagedSession, next: SessionActivity | null): void {
const prev = s.prevActivity; const prev = s.prevActivity;
s.prevActivity = next; s.prevActivity = next;
if (!this.push) return; if (!this.push) return;
if (next === 'waiting' && prev !== 'waiting') { const notifiable =
(next === 'waiting' && prev !== 'waiting') || (next === 'idle' && prev === 'busy');
if (notifiable) {
const target = next; // 'waiting' | 'idle'
if (s.notifyTimer) clearTimeout(s.notifyTimer); if (s.notifyTimer) clearTimeout(s.notifyTimer);
s.notifyTimer = setTimeout(() => { s.notifyTimer = setTimeout(() => {
s.notifyTimer = null; s.notifyTimer = null;
const act = s.tracker?.snapshot(); const act = s.tracker?.snapshot();
if (s.exited || act?.activity !== 'waiting') return; // faux positif : annulé if (s.exited || act?.activity !== target) return; // faux positif : l'état a déjà changé
void this.push?.notify({ const base = { sessionId: s.id, title: basename(s.cwd) || s.cwd, url: `/sessions/${s.id}` };
sessionId: s.id, void this.push?.notify(
title: basename(s.cwd) || s.cwd, target === 'idle'
body: act.dialog?.waitingFor ?? act.waitingFor ?? 'waiting for your input', ? { ...base, body: 'available for new instructions', kind: null }
kind: act.dialog?.kind ?? null, : { ...base, body: act.dialog?.waitingFor ?? act.waitingFor ?? 'waiting for your input', kind: act.dialog?.kind ?? null },
url: `/sessions/${s.id}`, );
});
}, NOTIFY_DEBOUNCE_MS); }, NOTIFY_DEBOUNCE_MS);
s.notifyTimer.unref(); s.notifyTimer.unref();
} else if (next !== 'waiting' && s.notifyTimer) { } else if (s.notifyTimer && next !== 'waiting' && next !== 'idle') {
// On quitte un état notifiable avant l'échéance (ex. Claude repart en busy) → annule.
clearTimeout(s.notifyTimer); clearTimeout(s.notifyTimer);
s.notifyTimer = null; s.notifyTimer = null;
} }

View File

@@ -12,6 +12,8 @@ import type {
PostCreateHook, PostCreateHook,
RepoSummary, RepoSummary,
SessionSummary, SessionSummary,
WorktreeBranchAction,
WorktreeBranchMode,
WorktreeGitStatus, WorktreeGitStatus,
WorktreeSummary, WorktreeSummary,
} from '@arboretum/shared'; } from '@arboretum/shared';
@@ -22,13 +24,16 @@ import { scanForRepos } from './repo-scanner.js';
import { preTrustProject } from './claude-trust.js'; import { preTrustProject } from './claude-trust.js';
import { import {
addWorktree, addWorktree,
commitAll,
defaultBranch, defaultBranch,
isDirtyWorktreeError, isDirtyWorktreeError,
isRepo, isRepo,
isSafeAbsolutePath, isSafeAbsolutePath,
isValidBranchName, isValidBranchName,
listBranches,
listWorktrees, listWorktrees,
pruneWorktrees, pruneWorktrees,
push,
removeWorktree, removeWorktree,
switchBranch, switchBranch,
worktreeStatus, worktreeStatus,
@@ -245,10 +250,18 @@ export class WorktreeManager extends EventEmitter<WorktreeManagerEvents> {
// ---- worktrees ---- // ---- worktrees ----
/** Sessions (managées + découvertes) dont le cwd correspond à ce chemin de worktree. */ /**
private sessionsForCwd(path: string): SessionSummary[] { * Sessions (managées + découvertes) dont le cwd correspond à ce chemin de worktree.
* Les sessions explicitement masquées (`hidden`) sont exclues — cohérent avec `/api/v1/sessions`
* (sans quoi le masquage était ignoré dans les fiches worktree). Le tri managées/externes est laissé
* au client (interrupteur « afficher les externes »), qui dispose du champ `source`. La garde de
* suppression réclame en revanche TOUTES les sessions vivantes (`includeHidden`) pour rester sûre.
*/
private sessionsForCwd(path: string, opts?: { includeHidden?: boolean }): SessionSummary[] {
const rp = resolve(path); const rp = resolve(path);
return mergeSessions(this.ptyManager.list(), this.discovery.list()).filter((s) => resolve(s.cwd) === rp); return mergeSessions(this.ptyManager.list(), this.discovery.list())
.filter((s) => resolve(s.cwd) === rp)
.filter((s) => opts?.includeHidden || !s.hidden);
} }
private toSummary(repoId: string, repoPath: string, w: ParsedWorktree, status: WorktreeGitStatus): WorktreeSummary { private toSummary(repoId: string, repoPath: string, w: ParsedWorktree, status: WorktreeGitStatus): WorktreeSummary {
@@ -322,8 +335,8 @@ export class WorktreeManager extends EventEmitter<WorktreeManagerEvents> {
async createWorktree( async createWorktree(
repoId: string, repoId: string,
req: { branch: string; newBranch: boolean; baseRef?: string; path?: string; runHooks?: boolean; preTrust?: boolean; startSession?: 'claude' | 'bash' | null }, req: { branch: string; mode?: WorktreeBranchMode; baseRef?: string; path?: string; runHooks?: boolean; preTrust?: boolean; startSession?: 'claude' | 'bash' | null },
): Promise<{ worktree: WorktreeSummary; hookResults: HookRunResult[]; session: SessionSummary | null }> { ): Promise<{ worktree: WorktreeSummary; hookResults: HookRunResult[]; session: SessionSummary | null; action: WorktreeBranchAction }> {
const row = this.getRepoRow(repoId); const row = this.getRepoRow(repoId);
if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id'); if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id');
if (!isValidBranchName(req.branch)) throw httpError(400, 'BAD_BRANCH', `Invalid branch name: ${req.branch}`); if (!isValidBranchName(req.branch)) throw httpError(400, 'BAD_BRANCH', `Invalid branch name: ${req.branch}`);
@@ -332,8 +345,9 @@ export class WorktreeManager extends EventEmitter<WorktreeManagerEvents> {
if (existsSync(path)) throw httpError(409, 'PATH_EXISTS', `Path already exists: ${path}`); if (existsSync(path)) throw httpError(409, 'PATH_EXISTS', `Path already exists: ${path}`);
return this.withLock(repoId, async () => { return this.withLock(repoId, async () => {
let action: WorktreeBranchAction;
try { try {
await addWorktree(row.path, { path, branch: req.branch, newBranch: req.newBranch, ...(req.baseRef ? { baseRef: req.baseRef } : {}) }); action = await addWorktree(row.path, { path, branch: req.branch, mode: req.mode ?? 'auto', ...(req.baseRef ? { baseRef: req.baseRef } : {}) });
} catch (err) { } catch (err) {
throw httpError(400, 'WORKTREE_ADD_FAILED', (err as Error).message); throw httpError(400, 'WORKTREE_ADD_FAILED', (err as Error).message);
} }
@@ -352,7 +366,93 @@ export class WorktreeManager extends EventEmitter<WorktreeManagerEvents> {
if (req.startSession) session = this.ptyManager.spawn({ cwd: path, command: req.startSession }); if (req.startSession) session = this.ptyManager.spawn({ cwd: path, command: req.startSession });
const worktree = (await this.emitWorktree(row, path)) ?? this.toSummary(row.id, row.path, { path, head: null, branch: req.branch, detached: false, locked: false, prunable: false, bare: false }, { ahead: 0, behind: 0, dirtyCount: 0, upstream: null }); const worktree = (await this.emitWorktree(row, path)) ?? this.toSummary(row.id, row.path, { path, head: null, branch: req.branch, detached: false, locked: false, prunable: false, bare: false }, { ahead: 0, behind: 0, dirtyCount: 0, upstream: null });
return { worktree, hookResults, session }; return { worktree, hookResults, session, action };
});
}
/** Branches locales/remote + branche par défaut d'un repo — alimente le sélecteur de base côté UI. */
async listRepoBranches(repoId: string): Promise<{ local: string[]; remote: string[]; default: string | null }> {
const row = this.getRepoRow(repoId);
if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id');
return listBranches(row.path);
}
/** `git add -A` + commit dans le worktree visé (le checkout principal est un worktree valide ici). */
async commitWorktree(repoId: string, path: string, message: string): Promise<WorktreeSummary> {
const row = this.getRepoRow(repoId);
if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id');
const w = await this.findWorktree(row, path);
if (!w) throw httpError(404, 'NOT_FOUND', 'No such worktree under this repo');
return this.withLock(repoId, async () => {
if ((await worktreeStatus(w.path)).dirtyCount === 0) {
throw httpError(409, 'NOTHING_TO_COMMIT', 'Nothing to commit — working tree is clean');
}
try {
await commitAll(w.path, message);
} catch (err) {
throw httpError(400, 'COMMIT_FAILED', (err as Error).message);
}
this.factsCache.delete(repoId);
return (await this.emitWorktree(row, w.path)) as WorktreeSummary;
});
}
/** Pousse la branche du worktree visé (upstream auto si absent). */
async pushWorktree(repoId: string, path: string): Promise<WorktreeSummary> {
const row = this.getRepoRow(repoId);
if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id');
const w = await this.findWorktree(row, path);
if (!w) throw httpError(404, 'NOT_FOUND', 'No such worktree under this repo');
return this.withLock(repoId, async () => {
try {
await push(w.path);
} catch (err) {
throw httpError(400, 'PUSH_FAILED', (err as Error).message);
}
this.factsCache.delete(repoId);
return (await this.emitWorktree(row, w.path)) as WorktreeSummary;
});
}
/**
* « Passer en principal » : la branche du worktree devient le checkout principal du dépôt. Une branche
* ne pouvant être extraite qu'à un seul endroit, on retire d'abord le worktree (libère la branche) puis
* on bascule le checkout principal dessus. Sans merge ni conflit possible. L'ancienne branche principale
* est conservée (jamais supprimée). Garde-fous d'arbre sale outrepassables par `force`.
*/
async promoteWorktree(repoId: string, path: string, force = false): Promise<WorktreeSummary | null> {
const row = this.getRepoRow(repoId);
if (!row) throw httpError(404, 'NOT_FOUND', 'No repo with this id');
const w = await this.findWorktree(row, path);
if (!w) throw httpError(404, 'NOT_FOUND', 'No such worktree under this repo');
if (resolve(w.path) === resolve(row.path)) throw httpError(400, 'IS_MAIN_WORKTREE', 'This is already the main checkout');
if (!w.branch || w.detached) throw httpError(400, 'DETACHED_WORKTREE', 'Worktree has no branch to promote (detached HEAD)');
const branch = w.branch;
return this.withLock(repoId, async () => {
if (!force) {
if ((await worktreeStatus(w.path)).dirtyCount > 0) {
throw httpError(409, 'WORKTREE_DIRTY', 'Worktree has uncommitted changes — commit or pass force');
}
if ((await worktreeStatus(row.path)).dirtyCount > 0) {
throw httpError(409, 'DIRTY_TREE', 'Main checkout has uncommitted changes — commit/stash or pass force');
}
}
try {
await removeWorktree(row.path, w.path, force);
} catch (err) {
if (!force && isDirtyWorktreeError(err)) {
throw httpError(409, 'WORKTREE_DIRTY', 'Worktree has uncommitted changes — pass force to promote anyway');
}
throw httpError(500, 'WORKTREE_REMOVE_FAILED', (err as Error).message);
}
try {
await switchBranch(row.path, { branch, create: false });
} catch (err) {
throw httpError(500, 'SWITCH_FAILED', (err as Error).message);
}
this.factsCache.delete(repoId);
this.emit('worktree_removed', { repoId, path: w.path });
return this.emitWorktree(row, row.path); // le checkout principal est désormais sur `branch`
}); });
} }
@@ -415,7 +515,7 @@ export class WorktreeManager extends EventEmitter<WorktreeManagerEvents> {
if (!w) throw httpError(404, 'NOT_FOUND', 'No such worktree under this repo'); if (!w) throw httpError(404, 'NOT_FOUND', 'No such worktree under this repo');
if (resolve(w.path) === resolve(row.path)) throw httpError(400, 'IS_MAIN_WORKTREE', 'Cannot remove the main worktree'); if (resolve(w.path) === resolve(row.path)) throw httpError(400, 'IS_MAIN_WORKTREE', 'Cannot remove the main worktree');
// garde-fou : une session vivante tourne dans ce worktree → exiger une confirmation explicite. // garde-fou : une session vivante tourne dans ce worktree → exiger une confirmation explicite.
if (!force && this.sessionsForCwd(w.path).some((s) => s.live)) { if (!force && this.sessionsForCwd(w.path, { includeHidden: true }).some((s) => s.live)) {
throw httpError(409, 'SESSION_LIVE_IN_WORKTREE', 'A live session runs in this worktree — pass force to delete anyway'); throw httpError(409, 'SESSION_LIVE_IN_WORKTREE', 'A live session runs in this worktree — pass force to delete anyway');
} }
return this.withLock(repoId, async () => { return this.withLock(repoId, async () => {

View File

@@ -129,6 +129,19 @@ const MIGRATIONS: Array<{ id: number; sql: string }> = [
CREATE INDEX idx_sessions_group_id ON sessions(group_id); CREATE INDEX idx_sessions_group_id ON sessions(group_id);
`, `,
}, },
{
// Masquage des sessions Claude découvertes (lancées en CLI hors Arboretum) qui polluent la liste.
// Calqué sur repos.hidden (#6) : la session masquée reste connue (resume/fork possibles) mais est
// exclue de la liste par défaut, et un re-scan ne la ressuscite pas. Clé = claudeSessionId (stable,
// partagé entre une découverte et sa reprise managée).
id: 9,
sql: `
CREATE TABLE hidden_sessions (
claude_session_id TEXT PRIMARY KEY,
hidden_at TEXT NOT NULL
);
`,
},
]; ];
export type Db = DatabaseSync; export type Db = DatabaseSync;
@@ -185,3 +198,23 @@ export function getSetting(db: Db, key: string): string | null {
export function setSetting(db: Db, key: string, value: string): void { export function setSetting(db: Db, key: string, value: string): void {
db.prepare('INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, value); db.prepare('INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, value);
} }
// ---- Sessions masquées (par claudeSessionId) ----
/** Ensemble des claudeSessionId masqués par l'utilisateur. */
export function listHiddenSessionIds(db: Db): Set<string> {
const rows = db.prepare('SELECT claude_session_id FROM hidden_sessions').all() as Array<{ claude_session_id: string }>;
return new Set(rows.map((r) => r.claude_session_id));
}
/** Masque une session (idempotent). */
export function hideSession(db: Db, claudeSessionId: string): void {
db.prepare(
'INSERT INTO hidden_sessions (claude_session_id, hidden_at) VALUES (?, ?) ON CONFLICT(claude_session_id) DO NOTHING',
).run(claudeSessionId, new Date().toISOString());
}
/** Ré-affiche une session masquée (idempotent). */
export function unhideSession(db: Db, claudeSessionId: string): void {
db.prepare('DELETE FROM hidden_sessions WHERE claude_session_id = ?').run(claudeSessionId);
}

View File

@@ -3,17 +3,33 @@ import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path'; import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { loadConfig, type Config } from './config.js'; import { loadConfig, type Config } from './config.js';
import { openDb } from './db/index.js'; import { openDb, type Db } from './db/index.js';
import { buildApp } from './app.js'; import { buildApp } from './app.js';
import { readClaudeHome } from './core/claude-settings.js';
import { runInstall, runUninstall, runStatus, printUsage, printTokenBanner } from './cli/install.js'; import { runInstall, runUninstall, runStatus, printUsage, printTokenBanner } from './cli/install.js';
const pkg = JSON.parse( const pkg = JSON.parse(
readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'), readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'),
) as { version: string }; ) as { version: string };
/**
* Applique l'override `claude_home` (réglage UI) sur la config runtime, sauf si --claude-home a été
* passé explicitement (le flag gagne). Lu une seule fois au démarrage → un changement via l'UI prend
* effet au redémarrage du daemon (comme l'intervalle de scan). Mute `config`.
*/
function applyClaudeHomeOverride(config: Config, db: Db): void {
if (config.claudeHomeFromFlag) return;
const override = readClaudeHome(db);
if (!override) return;
config.claudeHome = override;
config.claudeProjectsDir = join(override, 'projects');
config.claudeSessionsDir = join(override, 'sessions');
}
/** Démarre le daemon : écoute HTTP, scan des sessions, drain propre au SIGTERM/SIGINT. */ /** Démarre le daemon : écoute HTTP, scan des sessions, drain propre au SIGTERM/SIGINT. */
export async function runDaemon(config: Config): Promise<void> { export async function runDaemon(config: Config): Promise<void> {
const db = openDb(config.dbPath); const db = openDb(config.dbPath);
applyClaudeHomeOverride(config, db); // override claude_home (réglage UI) avant de câbler les services
const { app, auth, manager, discovery, repoDiscovery } = buildApp(config, db, pkg.version); const { app, auth, manager, discovery, repoDiscovery } = buildApp(config, db, pkg.version);
const bootstrapToken = auth.ensureBootstrapToken(); const bootstrapToken = auth.ensureBootstrapToken();

View File

@@ -13,6 +13,7 @@ import type { WorktreeManager } from '../core/worktree-manager.js';
import type { PtyManager } from '../core/pty-manager.js'; import type { PtyManager } from '../core/pty-manager.js';
import type { Db } from '../db/index.js'; import type { Db } from '../db/index.js';
import { recordAudit } from '../core/audit-log.js'; import { recordAudit } from '../core/audit-log.js';
import { resolveGroupCwd } from '../core/group-session.js';
import { sendManagerError } from './repos.js'; import { sendManagerError } from './repos.js';
export function registerGroupRoutes( export function registerGroupRoutes(
@@ -137,13 +138,15 @@ export function registerGroupRoutes(
if (!dirs.includes(match.path)) dirs.push(match.path); if (!dirs.includes(match.path)) dirs.push(match.path);
} }
const [primary, ...rest] = dirs; if (dirs.length === 0) {
if (primary === undefined) { const detail = branch ? `no repo has a worktree on branch "${branch}" (create it first)` : 'no repo has a resolvable main checkout';
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'no directory to span (group has no resolvable worktree)' } }); return reply.status(400).send({ error: { code: 'NO_RESOLVABLE_WORKTREE', message: `Cannot start group session: ${detail}` } });
} }
// cwd = parent commun des repos couverts, chacun relié en --add-dir (P6). Voir resolveGroupCwd.
const { cwd, addDirs } = resolveGroupCwd(dirs);
try { try {
const session = manager.spawn({ cwd: primary, addDirs: rest, command, groupId: id }); const session = manager.spawn({ cwd, addDirs, command, groupId: id });
recordAudit(db, { recordAudit(db, {
actor: req.authContext?.tokenId ?? 'unknown', actor: req.authContext?.tokenId ?? 'unknown',
action: 'group.session.create', action: 'group.session.create',

View File

@@ -0,0 +1,89 @@
import type { FastifyInstance } from 'fastify';
import { mkdir, stat } from 'node:fs/promises';
import type { CreateProjectRequest, CreateProjectResponse } from '@arboretum/shared';
import type { PtyManager } from '../core/pty-manager.js';
import { gitInit, isSafeAbsolutePath } from '../core/git.js';
import { resolveProjectDir } from '../core/project.js';
import { recordAudit } from '../core/audit-log.js';
import type { Db } from '../db/index.js';
/**
* Création d'un nouveau projet : crée le dossier `<root>/<name>` (la SEULE écriture fs autorisée
* côté serveur en dehors du dataDir) puis lance une session dedans. `git init` optionnel.
* Cohérent avec le modèle de sécurité : un client authentifié dispose déjà d'un terminal (RCE par
* conception). On valide tout de même strictement `name` (anti-traversal) et on exige une racine
* EXISTANTE (mkdir non récursif → pas de création d'arborescence arbitraire).
*
* POST /api/v1/projects { root, name, gitInit?, command? } → 201 { session, path, gitInitialized }
*/
export function registerProjectRoutes(app: FastifyInstance, manager: PtyManager, db: Db): void {
app.post('/api/v1/projects', async (req, reply) => {
const body = req.body as Partial<CreateProjectRequest> | null;
if (!body || typeof body.root !== 'string' || !isSafeAbsolutePath(body.root)) {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'root (absolute path) is required' } });
}
if (typeof body.name !== 'string') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'name is required' } });
}
if (body.command !== undefined && body.command !== 'claude' && body.command !== 'bash') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'command must be claude or bash' } });
}
// La racine doit exister et être un répertoire (mkdir non récursif derrière).
try {
const st = await stat(body.root);
if (!st.isDirectory()) {
return reply.status(400).send({ error: { code: 'NOT_A_DIRECTORY', message: `Not a directory: ${body.root}` } });
}
} catch (err) {
const code = (err as NodeJS.ErrnoException).code;
if (code === 'ENOENT') return reply.status(404).send({ error: { code: 'NOT_FOUND', message: `No such directory: ${body.root}` } });
if (code === 'EACCES') return reply.status(403).send({ error: { code: 'FORBIDDEN', message: `Permission denied: ${body.root}` } });
return reply.status(400).send({ error: { code: 'BAD_PATH', message: (err as Error).message } });
}
let dir: string;
try {
dir = resolveProjectDir(body.root, body.name);
} catch (err) {
return reply.status((err as { statusCode?: number }).statusCode ?? 400).send({ error: { code: 'BAD_REQUEST', message: (err as Error).message } });
}
// mkdir non récursif : EEXIST → 409 (on n'écrase jamais un dossier existant).
try {
await mkdir(dir);
} catch (err) {
const code = (err as NodeJS.ErrnoException).code;
if (code === 'EEXIST') return reply.status(409).send({ error: { code: 'PROJECT_EXISTS', message: `Already exists: ${dir}` } });
if (code === 'EACCES') return reply.status(403).send({ error: { code: 'FORBIDDEN', message: `Permission denied: ${dir}` } });
return reply.status(400).send({ error: { code: 'MKDIR_FAILED', message: (err as Error).message } });
}
const wantsGitInit = body.gitInit === true;
let gitInitialized = false;
if (wantsGitInit) {
try {
await gitInit(dir);
gitInitialized = true;
} catch {
// Le dossier est créé et la session démarrera quand même : un échec git n'annule pas le projet.
gitInitialized = false;
}
}
try {
const session = manager.spawn({ cwd: dir, ...(body.command ? { command: body.command } : {}) });
recordAudit(db, {
actor: req.authContext?.tokenId ?? 'unknown',
action: 'project.create',
resourceId: dir,
details: { gitInit: gitInitialized },
});
const res: CreateProjectResponse = { session, path: dir, gitInitialized };
return reply.status(201).send(res);
} catch (err) {
const statusCode = (err as { statusCode?: number }).statusCode ?? 500;
return reply.status(statusCode).send({ error: { code: 'SPAWN_FAILED', message: (err as Error).message } });
}
});
}

View File

@@ -1,13 +1,24 @@
import type { FastifyInstance } from 'fastify'; import type { FastifyInstance } from 'fastify';
import type { CreateSessionRequest, SessionResponse, SessionsListResponse } from '@arboretum/shared'; import type { CreateSessionRequest, HideDiscoveredResponse, SessionResponse, SessionsListResponse } from '@arboretum/shared';
import type { PtyManager } from '../core/pty-manager.js'; import type { PtyManager } from '../core/pty-manager.js';
import { mergeSessions, type DiscoveryService } from '../core/discovery-service.js'; import { mergeSessions, type DiscoveryService } from '../core/discovery-service.js';
import { hideSession, unhideSession, type Db } from '../db/index.js';
import { recordAudit } from '../core/audit-log.js';
export function registerSessionRoutes(app: FastifyInstance, manager: PtyManager, discovery: DiscoveryService): void { export function registerSessionRoutes(app: FastifyInstance, manager: PtyManager, discovery: DiscoveryService, db: Db): void {
app.get('/api/v1/sessions', async (): Promise<SessionsListResponse> => { app.get('/api/v1/sessions', async (req): Promise<SessionsListResponse> => {
return { sessions: mergeSessions(manager.list(), discovery.list()) }; const includeHidden = (req.query as { includeHidden?: string }).includeHidden === 'true';
const all = mergeSessions(manager.list(), discovery.list());
return { sessions: includeHidden ? all : all.filter((s) => !s.hidden) };
}); });
// Résout le claudeSessionId d'un :id de session (managée par UUID, ou découverte dont l'id EST le sid).
const resolveClaudeSid = (id: string): string | null => {
const managed = manager.resumeTargetById(id);
if (managed?.claudeSessionId) return managed.claudeSessionId;
return discovery.getDiscovered(id) ? id : null;
};
app.post('/api/v1/sessions', async (req, reply) => { app.post('/api/v1/sessions', async (req, reply) => {
const body = req.body as Partial<CreateSessionRequest> | null; const body = req.body as Partial<CreateSessionRequest> | null;
if (!body || typeof body.cwd !== 'string' || !body.cwd.startsWith('/')) { if (!body || typeof body.cwd !== 'string' || !body.cwd.startsWith('/')) {
@@ -26,24 +37,29 @@ export function registerSessionRoutes(app: FastifyInstance, manager: PtyManager,
} }
}); });
// Reprise d'une session morte : nouveau PTY managé `--resume <id>` DANS SON CWD D'ORIGINE (spike S1). // Reprise d'une session morte : nouveau PTY managé `--resume <claudeSessionId>` DANS SON CWD D'ORIGINE
// Le cwd n'est jamais fourni par le client : il est lu sur disque via la découverte. // (spike S1). Le cwd n'est JAMAIS fourni par le client. Deux origines d'id possibles :
// - session managée morte (id = UUID Arboretum) → cwd + claudeSessionId + groupe lus en DB ;
// - session claude EXTERNE découverte (id = claudeSessionId) → cwd lu sur disque.
app.post('/api/v1/sessions/:id/resume', async (req, reply) => { app.post('/api/v1/sessions/:id/resume', async (req, reply) => {
const { id } = req.params as { id: string }; const { id } = req.params as { id: string };
const discovered = discovery.getDiscovered(id); const managed = manager.resumeTargetById(id);
if (!discovered) { const discovered = managed ? null : discovery.getDiscovered(id);
if (!managed && !discovered) {
return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No resumable session with this id' } }); return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No resumable session with this id' } });
} }
const cwd = managed ? managed.cwd : discovered!.cwd;
const claudeSessionId = managed ? managed.claudeSessionId : id;
// Garde-fou anti-corruption : jamais de resume direct d'une session vivante (vérif FRAÎCHE). // Garde-fou anti-corruption : jamais de resume direct d'une session vivante (vérif FRAÎCHE).
if (discovery.isClaudeSessionLive(id) || manager.findLiveByClaudeSessionId(id)) { if (discovery.isClaudeSessionLive(claudeSessionId) || manager.findLiveByClaudeSessionId(claudeSessionId)) {
return reply.status(409).send({ error: { code: 'SESSION_LIVE', message: 'Session is live — fork it instead' } }); return reply.status(409).send({ error: { code: 'SESSION_LIVE', message: 'Session is live — fork it instead' } });
} }
try { try {
// Session de groupe (P6) : re-relie les mêmes répertoires (--add-dir) et son groupe au resume. // Session de groupe (P6) : re-relie les mêmes répertoires (--add-dir) et son groupe au resume.
const ctx = manager.groupSessionContext(id); const ctx = managed ? { addedDirs: managed.addedDirs, groupId: managed.groupId } : manager.groupSessionContext(claudeSessionId);
const session = manager.spawn({ const session = manager.spawn({
cwd: discovered.cwd, cwd,
resume: { claudeSessionId: id }, resume: { claudeSessionId },
...(ctx?.addedDirs.length ? { addDirs: ctx.addedDirs } : {}), ...(ctx?.addedDirs.length ? { addDirs: ctx.addedDirs } : {}),
...(ctx?.groupId ? { groupId: ctx.groupId } : {}), ...(ctx?.groupId ? { groupId: ctx.groupId } : {}),
}); });
@@ -56,14 +72,18 @@ export function registerSessionRoutes(app: FastifyInstance, manager: PtyManager,
}); });
// Fork : duplique une session (vivante ou morte) sans la corrompre (`--resume <id> --fork-session`). // Fork : duplique une session (vivante ou morte) sans la corrompre (`--resume <id> --fork-session`).
// Même résolution d'id que /resume (managée morte par UUID, sinon externe découverte par claudeSessionId).
app.post('/api/v1/sessions/:id/fork', async (req, reply) => { app.post('/api/v1/sessions/:id/fork', async (req, reply) => {
const { id } = req.params as { id: string }; const { id } = req.params as { id: string };
const discovered = discovery.getDiscovered(id); const managed = manager.resumeTargetById(id);
if (!discovered) { const discovered = managed ? null : discovery.getDiscovered(id);
if (!managed && !discovered) {
return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No session with this id to fork' } }); return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No session with this id to fork' } });
} }
const cwd = managed ? managed.cwd : discovered!.cwd;
const claudeSessionId = managed ? managed.claudeSessionId : id;
try { try {
const session = manager.spawn({ cwd: discovered.cwd, resume: { claudeSessionId: id, fork: true } }); const session = manager.spawn({ cwd, resume: { claudeSessionId, fork: true } });
const res: SessionResponse = { session }; const res: SessionResponse = { session };
return reply.status(201).send(res); return reply.status(201).send(res);
} catch (err) { } catch (err) {
@@ -72,6 +92,49 @@ export function registerSessionRoutes(app: FastifyInstance, manager: PtyManager,
} }
}); });
// Masque une session découverte (ou managée morte) : exclue de la liste sauf ?includeHidden=true.
// Reste reprenable/forkable — c'est un filtre d'affichage, pas une suppression.
app.post('/api/v1/sessions/:id/hide', async (req, reply) => {
const { id } = req.params as { id: string };
const sid = resolveClaudeSid(id);
if (!sid) {
return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No session with this id to hide' } });
}
hideSession(db, sid);
await discovery.refresh(); // rediffuse l'état (hidden) aux clients
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'session.hide', resourceId: sid });
return reply.send({ ok: true });
});
// Ré-affiche une session masquée.
app.delete('/api/v1/sessions/:id/hide', async (req, reply) => {
const { id } = req.params as { id: string };
const sid = resolveClaudeSid(id);
if (!sid) {
return reply.status(404).send({ error: { code: 'NOT_FOUND', message: 'No session with this id to unhide' } });
}
unhideSession(db, sid);
await discovery.refresh();
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'session.unhide', resourceId: sid });
return reply.send({ ok: true });
});
// Masquage de masse : nettoie d'un coup tout l'historique externe actuellement visible. Les futures
// sessions externes réapparaîtront (sinon --no-discover). Renvoie le nombre de sessions masquées.
app.post('/api/v1/sessions/hide-discovered', async (req, reply) => {
const sids = discovery
.list()
.filter((s) => !s.hidden && s.claudeSessionId)
.map((s) => s.claudeSessionId as string);
for (const sid of sids) hideSession(db, sid);
await discovery.refresh();
if (sids.length > 0) {
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'session.hideDiscovered', resourceId: null, details: { count: sids.length } });
}
const res: HideDiscoveredResponse = { hidden: sids.length };
return reply.send(res);
});
app.delete('/api/v1/sessions/:id', async (req, reply) => { app.delete('/api/v1/sessions/:id', async (req, reply) => {
const { id } = req.params as { id: string }; const { id } = req.params as { id: string };
if (!manager.kill(id)) { if (!manager.kill(id)) {

View File

@@ -7,6 +7,7 @@ import type { Config } from '../config.js';
import { type Db, setSetting } from '../db/index.js'; import { type Db, setSetting } from '../db/index.js';
import type { PushService } from '../core/push-service.js'; import type { PushService } from '../core/push-service.js';
import { recordAudit } from '../core/audit-log.js'; import { recordAudit } from '../core/audit-log.js';
import { diagnoseClaudeBin } from '../core/claude-launcher.js';
import { import {
SCAN_INTERVAL_KEY, SCAN_INTERVAL_KEY,
SCAN_ROOTS_KEY, SCAN_ROOTS_KEY,
@@ -15,6 +16,14 @@ import {
readScanIntervalMin, readScanIntervalMin,
readScanRoots, readScanRoots,
} from '../core/scan-settings.js'; } from '../core/scan-settings.js';
import {
CLAUDE_BIN_PATH_KEY,
CLAUDE_HOME_KEY,
normalizeClaudeBinPath,
normalizeClaudeHome,
readClaudeBinPath,
readClaudeHome,
} from '../core/claude-settings.js';
// Réglages modifiables via l'API (allow-list stricte). Les secrets ne figurent JAMAIS ici. // Réglages modifiables via l'API (allow-list stricte). Les secrets ne figurent JAMAIS ici.
export function registerSettingsRoutes( export function registerSettingsRoutes(
@@ -32,11 +41,16 @@ export function registerSettingsRoutes(
dataDir: config.dataDir, dataDir: config.dataDir,
vapidPublicKey: push.publicKey() || null, vapidPublicKey: push.publicKey() || null,
vapidContact: config.vapidContact, vapidContact: config.vapidContact,
claudeHome: config.claudeHome,
// Diagnostic recalculé à chaque GET : reflète l'état réel (override exécutable ? `which claude` ?).
claudeBin: diagnoseClaudeBin(readClaudeBinPath(db)),
}); });
const snapshot = (): SettingsResponse => ({ const snapshot = (): SettingsResponse => ({
settings: { settings: {
scanRoots: readScanRoots(db), scanRoots: readScanRoots(db),
scanIntervalMin: readScanIntervalMin(db), scanIntervalMin: readScanIntervalMin(db),
claudeBinPath: readClaudeBinPath(db),
claudeHome: readClaudeHome(db),
}, },
server: serverInfo(), server: serverInfo(),
}); });
@@ -59,6 +73,20 @@ export function registerSettingsRoutes(
} }
setSetting(db, SCAN_INTERVAL_KEY, String(interval)); setSetting(db, SCAN_INTERVAL_KEY, String(interval));
} }
if ('claudeBinPath' in body) {
const value = normalizeClaudeBinPath(body.claudeBinPath);
if (value === null) {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'claudeBinPath must be an absolute path to an executable file (or "" to reset)' } });
}
setSetting(db, CLAUDE_BIN_PATH_KEY, value);
}
if ('claudeHome' in body) {
const value = normalizeClaudeHome(body.claudeHome);
if (value === null) {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'claudeHome must be an absolute path to an existing directory (or "" to reset)' } });
}
setSetting(db, CLAUDE_HOME_KEY, value);
}
recordAudit(db, { recordAudit(db, {
actor: req.authContext?.tokenId ?? 'unknown', actor: req.authContext?.tokenId ?? 'unknown',
action: 'settings.update', action: 'settings.update',

View File

@@ -1,17 +1,32 @@
import type { FastifyInstance } from 'fastify'; import type { FastifyInstance } from 'fastify';
import type { import type {
AdoptWorktreeRequest, AdoptWorktreeRequest,
CommitWorktreeRequest,
CreateWorktreeRequest, CreateWorktreeRequest,
CreateWorktreeResponse, CreateWorktreeResponse,
PromoteWorktreeRequest,
PushWorktreeRequest,
RepoBranchesResponse,
SessionResponse, SessionResponse,
StartRepoSessionRequest, StartRepoSessionRequest,
WorktreeBranchMode,
WorktreeResponse, WorktreeResponse,
WorktreesListResponse, WorktreesListResponse,
} from '@arboretum/shared'; } from '@arboretum/shared';
import type { WorktreeManager } from '../core/worktree-manager.js'; import type { WorktreeManager } from '../core/worktree-manager.js';
import type { Db } from '../db/index.js';
import { recordAudit } from '../core/audit-log.js';
import { sendManagerError } from './repos.js'; import { sendManagerError } from './repos.js';
export function registerWorktreeRoutes(app: FastifyInstance, wt: WorktreeManager): void { /** Mappe l'API (mode prioritaire ; `newBranch` déprécié) vers la stratégie de résolution de branche. */
function resolveMode(body: { mode?: unknown; newBranch?: unknown }): WorktreeBranchMode {
if (body.mode === 'auto' || body.mode === 'create' || body.mode === 'checkout') return body.mode;
if (body.newBranch === true) return 'create';
if (body.newBranch === false) return 'checkout';
return 'auto';
}
export function registerWorktreeRoutes(app: FastifyInstance, wt: WorktreeManager, db: Db): void {
app.get('/api/v1/worktrees', async (): Promise<WorktreesListResponse> => ({ worktrees: await wt.listAllWorktrees() })); app.get('/api/v1/worktrees', async (): Promise<WorktreesListResponse> => ({ worktrees: await wt.listAllWorktrees() }));
app.get('/api/v1/repos/:id/worktrees', async (req): Promise<WorktreesListResponse> => { app.get('/api/v1/repos/:id/worktrees', async (req): Promise<WorktreesListResponse> => {
@@ -31,7 +46,7 @@ export function registerWorktreeRoutes(app: FastifyInstance, wt: WorktreeManager
try { try {
const out = await wt.createWorktree(id, { const out = await wt.createWorktree(id, {
branch: body.branch, branch: body.branch,
newBranch: body.newBranch !== false, // défaut : créer la branche mode: resolveMode(body), // défaut : auto (détecte créer / checkout / suivi remote)
...(body.baseRef !== undefined ? { baseRef: body.baseRef } : {}), ...(body.baseRef !== undefined ? { baseRef: body.baseRef } : {}),
...(body.path !== undefined ? { path: body.path } : {}), ...(body.path !== undefined ? { path: body.path } : {}),
...(body.runHooks !== undefined ? { runHooks: body.runHooks } : {}), ...(body.runHooks !== undefined ? { runHooks: body.runHooks } : {}),
@@ -45,6 +60,17 @@ export function registerWorktreeRoutes(app: FastifyInstance, wt: WorktreeManager
} }
}); });
// Branches du repo (locales + suivies de origin + défaut) — alimente le sélecteur de base côté UI.
app.get('/api/v1/repos/:id/branches', async (req, reply) => {
const { id } = req.params as { id: string };
try {
const out = await wt.listRepoBranches(id);
return reply.send(out satisfies RepoBranchesResponse);
} catch (err) {
return sendManagerError(reply, err);
}
});
// Session sur le checkout principal (« bosser sur la branche principale » sans worktree), // Session sur le checkout principal (« bosser sur la branche principale » sans worktree),
// avec création/bascule de branche optionnelle côté serveur. // avec création/bascule de branche optionnelle côté serveur.
app.post('/api/v1/repos/:id/session', async (req, reply) => { app.post('/api/v1/repos/:id/session', async (req, reply) => {
@@ -101,6 +127,57 @@ export function registerWorktreeRoutes(app: FastifyInstance, wt: WorktreeManager
} }
}); });
// Commit (git add -A + commit) dans un worktree (ou le checkout principal).
app.post('/api/v1/repos/:id/worktrees/commit', async (req, reply) => {
const { id } = req.params as { id: string };
const body = req.body as Partial<CommitWorktreeRequest> | null;
if (!body || typeof body.path !== 'string') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'path is required' } });
}
if (typeof body.message !== 'string' || body.message.trim() === '') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'message is required' } });
}
try {
const worktree = await wt.commitWorktree(id, body.path, body.message.trim());
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'worktree.commit', resourceId: id, details: { path: body.path } });
return reply.send({ worktree } satisfies WorktreeResponse);
} catch (err) {
return sendManagerError(reply, err);
}
});
// Push de la branche d'un worktree (upstream auto si absent).
app.post('/api/v1/repos/:id/worktrees/push', async (req, reply) => {
const { id } = req.params as { id: string };
const body = req.body as Partial<PushWorktreeRequest> | null;
if (!body || typeof body.path !== 'string') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'path is required' } });
}
try {
const worktree = await wt.pushWorktree(id, body.path);
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'worktree.push', resourceId: id, details: { path: body.path } });
return reply.send({ worktree } satisfies WorktreeResponse);
} catch (err) {
return sendManagerError(reply, err);
}
});
// Promotion « en principal » : la branche du worktree devient le checkout principal (worktree supprimé).
app.post('/api/v1/repos/:id/worktrees/promote', async (req, reply) => {
const { id } = req.params as { id: string };
const body = req.body as Partial<PromoteWorktreeRequest> | null;
if (!body || typeof body.path !== 'string') {
return reply.status(400).send({ error: { code: 'BAD_REQUEST', message: 'path is required' } });
}
try {
const worktree = await wt.promoteWorktree(id, body.path, body.force === true);
recordAudit(db, { actor: req.authContext?.tokenId ?? 'unknown', action: 'worktree.promote', resourceId: id, details: { path: body.path } });
return reply.send({ worktree });
} catch (err) {
return sendManagerError(reply, err);
}
});
app.delete('/api/v1/repos/:id/worktrees', async (req, reply) => { app.delete('/api/v1/repos/:id/worktrees', async (req, reply) => {
const { id } = req.params as { id: string }; const { id } = req.params as { id: string };
const query = req.query as { path?: string; force?: string }; const query = req.query as { path?: string; force?: string };

View File

@@ -148,6 +148,20 @@ describe('app e2e — auth, origin et sessions', () => {
expect(res.json()).toEqual({ sessions: [] }); expect(res.json()).toEqual({ sessions: [] });
}); });
it('masquage des sessions : hide-discovered (vide), includeHidden, hide dun id inconnu → 404', async () => {
const headers = { authorization: `Bearer ${t.token}` };
const mass = await t.bundle.app.inject({ method: 'POST', url: '/api/v1/sessions/hide-discovered', headers });
expect(mass.statusCode).toBe(200);
expect(mass.json()).toEqual({ hidden: 0 });
const withHidden = await t.bundle.app.inject({ method: 'GET', url: '/api/v1/sessions?includeHidden=true', headers });
expect(withHidden.statusCode).toBe(200);
expect(withHidden.json()).toEqual({ sessions: [] });
const unknown = await t.bundle.app.inject({ method: 'POST', url: '/api/v1/sessions/nope/hide', headers });
expect(unknown.statusCode).toBe(404);
});
it('Origin interdite → 403 même avec un Bearer valide, et même sur la route publique de login', async () => { it('Origin interdite → 403 même avec un Bearer valide, et même sur la route publique de login', async () => {
const res = await t.bundle.app.inject({ const res = await t.bundle.app.inject({
method: 'GET', method: 'GET',

View File

@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import { buildSpawnSpec } from '../src/core/claude-launcher.js'; import { buildSpawnSpec, diagnoseClaudeBin, resolveClaudeBin } from '../src/core/claude-launcher.js';
// resolveClaudeBin() fait `which claude` : on le stub pour ne pas dépendre d'un claude réel en PATH. // resolveClaudeBin() fait `which claude` : on le stub pour ne pas dépendre d'un claude réel en PATH.
vi.mock('node:child_process', () => ({ execFileSync: () => '/usr/bin/claude\n' })); vi.mock('node:child_process', () => ({ execFileSync: () => '/usr/bin/claude\n' }));
@@ -27,3 +27,28 @@ describe('buildSpawnSpec — session de groupe multi-repo (P6)', () => {
expect(spec.args).toEqual(['--norc']); expect(spec.args).toEqual(['--norc']);
}); });
}); });
describe('resolveClaudeBin / diagnoseClaudeBin — override de chemin (réglage UI)', () => {
// process.execPath (node) est un fichier exécutable réel garanti sur la machine de test.
const realBin = process.execPath;
it('buildSpawnSpec utilise le chemin configuré tel quel quand fourni', () => {
const spec = buildSpawnSpec({ command: 'claude', claudeBinPath: realBin });
expect(spec.file).toBe(realBin);
});
it('resolveClaudeBin retombe sur le PATH (which) sans override', () => {
expect(resolveClaudeBin()).toBe('/usr/bin/claude');
expect(resolveClaudeBin(null)).toBe('/usr/bin/claude');
});
it('resolveClaudeBin throw si le chemin configuré nest pas exécutable', () => {
expect(() => resolveClaudeBin('/no/such/claude')).toThrow(/not executable/);
});
it('diagnoseClaudeBin : configuré+exécutable → ok ; configuré absent → !ok ; sinon PATH', () => {
expect(diagnoseClaudeBin(realBin)).toEqual({ path: realBin, source: 'configured', ok: true });
expect(diagnoseClaudeBin('/no/such/claude')).toEqual({ path: '/no/such/claude', source: 'configured', ok: false });
expect(diagnoseClaudeBin()).toEqual({ path: '/usr/bin/claude', source: 'path', ok: true });
});
});

View File

@@ -0,0 +1,89 @@
// Réglages CLI Claude (chemin du binaire + override ~/.claude) : validateurs + lecture/écriture DB.
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { openDb, setSetting, type Db } from '../src/db/index.js';
import {
CLAUDE_BIN_PATH_KEY,
CLAUDE_HOME_KEY,
normalizeClaudeBinPath,
normalizeClaudeHome,
readClaudeBinPath,
readClaudeHome,
} from '../src/core/claude-settings.js';
let dir: string;
let execFile: string;
let plainFile: string;
let subDir: string;
beforeAll(() => {
dir = mkdtempSync(join(tmpdir(), 'arboretum-claude-settings-'));
execFile = join(dir, 'claude');
writeFileSync(execFile, '#!/bin/sh\n');
chmodSync(execFile, 0o755); // exécutable
plainFile = join(dir, 'notexec');
writeFileSync(plainFile, 'x');
chmodSync(plainFile, 0o644); // non exécutable
subDir = join(dir, 'home');
mkdirSync(subDir);
});
afterAll(() => rmSync(dir, { recursive: true, force: true }));
describe('normalizeClaudeBinPath', () => {
it('accepte un chemin absolu vers un fichier exécutable', () => {
expect(normalizeClaudeBinPath(execFile)).toBe(execFile);
});
it('"" = réinitialisation (auto-détection)', () => {
expect(normalizeClaudeBinPath('')).toBe('');
expect(normalizeClaudeBinPath(' ')).toBe('');
});
it('rejette un fichier non exécutable, un répertoire, un chemin relatif ou avec ".." (null)', () => {
expect(normalizeClaudeBinPath(plainFile)).toBeNull();
expect(normalizeClaudeBinPath(subDir)).toBeNull(); // répertoire, pas un fichier
expect(normalizeClaudeBinPath('relative/claude')).toBeNull();
expect(normalizeClaudeBinPath(join(dir, '..', 'x'))).toBeNull();
expect(normalizeClaudeBinPath(join(dir, 'missing'))).toBeNull();
expect(normalizeClaudeBinPath(42)).toBeNull();
});
});
describe('normalizeClaudeHome', () => {
it('accepte un chemin absolu vers un répertoire existant', () => {
expect(normalizeClaudeHome(subDir)).toBe(subDir);
});
it('"" = réinitialisation (défaut)', () => {
expect(normalizeClaudeHome('')).toBe('');
});
it('rejette un fichier, un chemin relatif/inexistant (null)', () => {
expect(normalizeClaudeHome(execFile)).toBeNull(); // fichier, pas un répertoire
expect(normalizeClaudeHome('relative/.claude')).toBeNull();
expect(normalizeClaudeHome(join(dir, 'missing'))).toBeNull();
expect(normalizeClaudeHome(null)).toBeNull();
});
});
describe('readClaudeBinPath / readClaudeHome', () => {
let db: Db;
beforeAll(() => {
db = openDb(join(dir, 'settings.db'));
});
afterAll(() => db.close());
it('null quand non défini', () => {
expect(readClaudeBinPath(db)).toBeNull();
expect(readClaudeHome(db)).toBeNull();
});
it('lit la valeur stockée et traite "" stockée comme null', () => {
setSetting(db, CLAUDE_BIN_PATH_KEY, execFile);
setSetting(db, CLAUDE_HOME_KEY, subDir);
expect(readClaudeBinPath(db)).toBe(execFile);
expect(readClaudeHome(db)).toBe(subDir);
setSetting(db, CLAUDE_BIN_PATH_KEY, ''); // réinitialisé
setSetting(db, CLAUDE_HOME_KEY, '');
expect(readClaudeBinPath(db)).toBeNull();
expect(readClaudeHome(db)).toBeNull();
});
});

View File

@@ -79,6 +79,21 @@ describe('cli install — renderSystemdUnit', () => {
expect(unit).toContain('ExecStart="/path with space/node" /s.js'); expect(unit).toContain('ExecStart="/path with space/node" /s.js');
}); });
it('fige le PATH d\'installation quand fourni (le service systemd a un PATH minimal)', () => {
const unit = renderSystemdUnit({
exec: '/usr/bin/node',
scriptArgs: ['/s.js'],
pathEnv: '/home/me/.local/bin:/usr/bin',
});
// Doubles quotes systemd : un chemin du PATH peut contenir un espace.
expect(unit).toContain('Environment="PATH=/home/me/.local/bin:/usr/bin"');
});
it("n'émet aucune ligne PATH sans pathEnv (rétrocompat)", () => {
const unit = renderSystemdUnit({ exec: '/usr/bin/node', scriptArgs: ['/s.js'] });
expect(unit).not.toContain('PATH=');
});
it('snapshot du unit pour un jeu de flags fixe', () => { it('snapshot du unit pour un jeu de flags fixe', () => {
const unit = renderSystemdUnit({ const unit = renderSystemdUnit({
exec: '/usr/bin/node', exec: '/usr/bin/node',
@@ -133,6 +148,19 @@ describe('cli install — renderLaunchAgentPlist', () => {
expect(plist).toContain('https://a?b&amp;c=d'); expect(plist).toContain('https://a?b&amp;c=d');
expect(plist).not.toContain('b&c=d'); expect(plist).not.toContain('b&c=d');
}); });
it('ajoute la clé PATH dans EnvironmentVariables quand fournie (launchd a un PATH minimal)', () => {
const plist = renderLaunchAgentPlist({ ...base, pathEnv: '/Users/me/.local/bin:/usr/bin' });
expect(plist).toContain('<key>PATH</key>');
expect(plist).toContain('<string>/Users/me/.local/bin:/usr/bin</string>');
// Reste dans le dict EnvironmentVariables, juste après NODE_ENV.
expect(plist.indexOf('<key>PATH</key>')).toBeGreaterThan(plist.indexOf('<key>NODE_ENV</key>'));
});
it("n'ajoute aucune clé PATH sans pathEnv (rétrocompat)", () => {
const plist = renderLaunchAgentPlist(base);
expect(plist).not.toContain('<key>PATH</key>');
});
}); });
describe('cli install — xmlEscape', () => { describe('cli install — xmlEscape', () => {

View File

@@ -7,7 +7,7 @@ import { DiscoveryService, mergeSessions } from '../src/core/discovery-service.j
import { munge } from '../src/core/jsonl-discovery.js'; import { munge } from '../src/core/jsonl-discovery.js';
import { readProcStart } from '../src/core/session-registry.js'; import { readProcStart } from '../src/core/session-registry.js';
import { PtyManager } from '../src/core/pty-manager.js'; import { PtyManager } from '../src/core/pty-manager.js';
import { openDb, type Db } from '../src/db/index.js'; import { openDb, hideSession, unhideSession, listHiddenSessionIds, type Db } from '../src/db/index.js';
function writeJsonl(projectsDir: string, cwd: string, sid: string): void { function writeJsonl(projectsDir: string, cwd: string, sid: string): void {
const dir = join(projectsDir, munge(cwd)); const dir = join(projectsDir, munge(cwd));
@@ -30,7 +30,7 @@ describe('DiscoveryService', () => {
sessionsDir = mkdtempSync(join(tmpdir(), 'arb-sess-')); sessionsDir = mkdtempSync(join(tmpdir(), 'arb-sess-'));
db = openDb(':memory:'); db = openDb(':memory:');
manager = new PtyManager(db, sessionsDir); manager = new PtyManager(db, sessionsDir);
svc = new DiscoveryService({ ptyManager: manager, projectsDir, sessionsDir }); svc = new DiscoveryService({ db, ptyManager: manager, projectsDir, sessionsDir });
}); });
afterEach(() => { afterEach(() => {
svc.stop(); svc.stop();
@@ -71,6 +71,29 @@ describe('DiscoveryService', () => {
expect(svc.list().find((x) => x.id === 'managed-sid')).toBeUndefined(); expect(svc.list().find((x) => x.id === 'managed-sid')).toBeUndefined();
}); });
it('marque hidden une session masquée mais la garde résoluble (resume/fork)', async () => {
writeJsonl(projectsDir, '/home/u/old', 'old-sid');
hideSession(db, 'old-sid');
await svc.refresh();
const s = svc.list().find((x) => x.id === 'old-sid');
expect(s?.hidden).toBe(true);
// toujours connue : la reprise/le fork doivent rester possibles
expect(svc.getDiscovered('old-sid')?.cwd).toBe('/home/u/old');
// ré-affichage
unhideSession(db, 'old-sid');
await svc.refresh();
expect(svc.list().find((x) => x.id === 'old-sid')?.hidden).toBe(false);
});
it('hideSession est idempotent et listHiddenSessionIds reflète létat', () => {
hideSession(db, 'a');
hideSession(db, 'a');
hideSession(db, 'b');
expect(listHiddenSessionIds(db)).toEqual(new Set(['a', 'b']));
unhideSession(db, 'a');
expect(listHiddenSessionIds(db)).toEqual(new Set(['b']));
});
it('émet discovery_update sur changement uniquement', async () => { it('émet discovery_update sur changement uniquement', async () => {
writeJsonl(projectsDir, '/home/u/x', 'sid-x'); writeJsonl(projectsDir, '/home/u/x', 'sid-x');
const seen: SessionSummary[] = []; const seen: SessionSummary[] = [];

View File

@@ -15,6 +15,10 @@ import {
pruneWorktrees, pruneWorktrees,
switchBranch, switchBranch,
isDirtyWorktreeError, isDirtyWorktreeError,
branchExists,
currentBranch,
listBranches,
commitAll,
} from '../src/core/git.js'; } from '../src/core/git.js';
const dirs: string[] = []; const dirs: string[] = [];
@@ -96,7 +100,7 @@ describe('opérations git (repo tmp réel)', () => {
const repo = makeTmpRepo(); const repo = makeTmpRepo();
const wtPath = join(dirname(repo), `${basename(repo)}-wt-feat`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-feat`);
dirs.push(wtPath); dirs.push(wtPath);
await addWorktree(repo, { path: wtPath, branch: 'feat', newBranch: true }); await addWorktree(repo, { path: wtPath, branch: 'feat', mode: 'create' });
const list = await listWorktrees(repo); const list = await listWorktrees(repo);
const wt = list.find((w) => resolve(w.path) === resolve(wtPath)); const wt = list.find((w) => resolve(w.path) === resolve(wtPath));
@@ -136,9 +140,57 @@ describe('opérations git (repo tmp réel)', () => {
it('prune retire un worktree dont le dossier a disparu', async () => { it('prune retire un worktree dont le dossier a disparu', async () => {
const repo = makeTmpRepo(); const repo = makeTmpRepo();
const wtPath = join(dirname(repo), `${basename(repo)}-wt-gone`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-gone`);
await addWorktree(repo, { path: wtPath, branch: 'gone', newBranch: true }); await addWorktree(repo, { path: wtPath, branch: 'gone', mode: 'create' });
rmSync(wtPath, { recursive: true, force: true }); // suppression "à la main" rmSync(wtPath, { recursive: true, force: true }); // suppression "à la main"
await pruneWorktrees(repo); await pruneWorktrees(repo);
expect((await listWorktrees(repo)).some((w) => resolve(w.path) === resolve(wtPath))).toBe(false); expect((await listWorktrees(repo)).some((w) => resolve(w.path) === resolve(wtPath))).toBe(false);
}); });
}); });
describe('branche : existence, liste, courante, commit', () => {
it('branchExists / currentBranch / listBranches', async () => {
const repo = makeTmpRepo();
expect(await currentBranch(repo)).toBe('main');
expect(await branchExists(repo, 'main')).toEqual({ local: true, remote: false });
expect(await branchExists(repo, 'nope')).toEqual({ local: false, remote: false });
execFileSync('git', ['branch', 'dev'], { cwd: repo });
const b = await listBranches(repo);
expect(b.local).toContain('main');
expect(b.local).toContain('dev');
expect(b.remote).toEqual([]);
});
it('commitAll : add -A + commit, fait baisser dirtyCount à 0', async () => {
const repo = makeTmpRepo();
writeFileSync(join(repo, 'new.txt'), 'hello\n');
expect((await worktreeStatus(repo)).dirtyCount).toBeGreaterThan(0);
await commitAll(repo, 'add new.txt');
expect((await worktreeStatus(repo)).dirtyCount).toBe(0);
});
});
describe('addWorktree : résolution auto (créer / réutiliser)', () => {
it('auto crée la branche si absente, la réutilise si présente', async () => {
const repo = makeTmpRepo();
// branche absente → création (renvoie "created")
const wt1 = join(dirname(repo), `${basename(repo)}-wt-feat`);
dirs.push(wt1);
expect(await addWorktree(repo, { path: wt1, branch: 'feat', mode: 'auto' })).toBe('created');
expect((await listWorktrees(repo)).find((w) => resolve(w.path) === resolve(wt1))?.branch).toBe('feat');
// la même branche existe désormais ; un AUTRE worktree dessus → checkout (renvoie "reused")
await removeWorktree(repo, wt1, true); // libère la branche
const wt2 = join(dirname(repo), `${basename(repo)}-wt-feat2`);
dirs.push(wt2);
expect(await addWorktree(repo, { path: wt2, branch: 'feat', mode: 'auto' })).toBe('reused');
});
it('mode create échoue si la branche existe déjà', async () => {
const repo = makeTmpRepo();
execFileSync('git', ['branch', 'dup'], { cwd: repo });
const wt = join(dirname(repo), `${basename(repo)}-wt-dup`);
dirs.push(wt);
await expect(addWorktree(repo, { path: wt, branch: 'dup', mode: 'create' })).rejects.toBeDefined();
});
});

View File

@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import { commonAncestorDir, resolveGroupCwd } from '../src/core/group-session.js';
describe('commonAncestorDir', () => {
it('renvoie le chemin lui-même pour un seul répertoire', () => {
expect(commonAncestorDir(['/home/johan/WebstormProjects/arboretum'])).toBe('/home/johan/WebstormProjects/arboretum');
});
it('renvoie le parent commun de deux siblings', () => {
expect(commonAncestorDir(['/p/a', '/p/b'])).toBe('/p');
});
it('gère un répertoire ancêtre dun autre', () => {
expect(commonAncestorDir(['/p/a', '/p/a/b'])).toBe('/p/a');
});
it('compare par segments, pas par préfixe de chaîne', () => {
// /a/bc n'est PAS un ancêtre de /a/bcd : ancêtre commun = /a
expect(commonAncestorDir(['/a/bc', '/a/bcd'])).toBe('/a');
});
it('renvoie la racine quand aucun segment nest commun', () => {
expect(commonAncestorDir(['/x/a', '/y/b'])).toBe('/');
});
});
describe('resolveGroupCwd', () => {
it('mono-repo : cwd = le repo, addDirs sera filtré à vide par PtyManager', () => {
const { cwd, addDirs } = resolveGroupCwd(['/p/a']);
expect(cwd).toBe('/p/a');
expect(addDirs).toEqual(['/p/a']);
});
it('multi-repos sous un parent commun : cwd = parent, addDirs = tous les repos', () => {
const dirs = ['/home/johan/WebstormProjects/beehelp_lambdas', '/home/johan/WebstormProjects/beehelp_api'];
const { cwd, addDirs } = resolveGroupCwd(dirs);
expect(cwd).toBe('/home/johan/WebstormProjects');
expect(addDirs).toEqual(dirs);
});
it('garde-fou : repos sur des racines différentes → retombe sur le premier répertoire', () => {
const { cwd } = resolveGroupCwd(['/x/a', '/y/b']);
expect(cwd).toBe('/x/a');
});
});

View File

@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import { isSafeProjectName, resolveProjectDir } from '../src/core/project.js';
describe('isSafeProjectName', () => {
it('accepte un segment simple', () => {
expect(isSafeProjectName('mon-projet')).toBe(true);
expect(isSafeProjectName('Projet_42.v2')).toBe(true);
expect(isSafeProjectName(' espaces-trim ')).toBe(true); // trim interne
});
it('refuse vide / espaces seuls', () => {
expect(isSafeProjectName('')).toBe(false);
expect(isSafeProjectName(' ')).toBe(false);
});
it('refuse `.` et `..`', () => {
expect(isSafeProjectName('.')).toBe(false);
expect(isSafeProjectName('..')).toBe(false);
});
it('refuse les séparateurs et le NUL (anti-traversal)', () => {
expect(isSafeProjectName('a/b')).toBe(false);
expect(isSafeProjectName('../evil')).toBe(false);
expect(isSafeProjectName('a\\b')).toBe(false);
expect(isSafeProjectName('a\0b')).toBe(false);
});
it('refuse un nom trop long (> 255)', () => {
expect(isSafeProjectName('x'.repeat(256))).toBe(false);
expect(isSafeProjectName('x'.repeat(255))).toBe(true);
});
});
describe('resolveProjectDir', () => {
it('joint root + name (trim) en chemin absolu', () => {
expect(resolveProjectDir('/home/johan/dev', 'mon-projet')).toBe('/home/johan/dev/mon-projet');
expect(resolveProjectDir('/home/johan/dev', ' mon-projet ')).toBe('/home/johan/dev/mon-projet');
});
it('lève (400) sur un nom invalide', () => {
expect(() => resolveProjectDir('/home/johan/dev', '..')).toThrow();
expect(() => resolveProjectDir('/home/johan/dev', 'a/b')).toThrow();
expect(() => resolveProjectDir('/home/johan/dev', '')).toThrow();
});
});

View File

@@ -0,0 +1,116 @@
import { mkdtempSync, existsSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { buildApp, type AppBundle } from '../src/app.js';
import { openDb, type Db } from '../src/db/index.js';
import type { Config } from '../src/config.js';
import type { CreateProjectResponse } from '@arboretum/shared';
// On NE mocke PAS node:child_process : on veut un vrai `git init` (testé via command:'bash', qui
// n'a pas besoin de résoudre le binaire claude). Seul le PTY est simulé (pas de vrai process en CI).
vi.mock('@homebridge/node-pty-prebuilt-multiarch', () => {
class FakePty {
pid = 424242;
write = vi.fn();
resize = vi.fn();
pause = vi.fn();
resume = vi.fn();
kill = vi.fn();
onData(): { dispose: () => void } {
return { dispose: () => {} };
}
onExit(): { dispose: () => void } {
return { dispose: () => {} };
}
}
return { default: { spawn: (): FakePty => new FakePty() } };
});
process.env.ARBORETUM_LOG = 'silent';
let dir: string;
let root: string;
let bundle: AppBundle;
let db: Db;
let token: string;
const auth = (): { authorization: string } => ({ authorization: `Bearer ${token}` });
beforeAll(() => {
dir = mkdtempSync(join(tmpdir(), 'arboretum-projects-'));
root = dir; // la racine existe déjà
const dbPath = join(dir, 'projects.db');
db = openDb(dbPath);
const config: Config = {
port: 7317,
bind: '127.0.0.1',
dbPath,
dataDir: dir,
allowedOrigins: [],
printToken: false,
claudeProjectsDir: join(dir, 'claude', 'projects'),
claudeSessionsDir: join(dir, 'claude', 'sessions'),
vapidContact: 'mailto:test@localhost',
};
bundle = buildApp(config, db, '0.0.0-test');
const t = bundle.auth.ensureBootstrapToken();
if (!t) throw new Error('bootstrap token attendu sur une base vierge');
token = t;
});
afterAll(async () => {
await bundle.app.close();
db.close();
rmSync(dir, { recursive: true, force: true });
});
describe('POST /api/v1/projects', () => {
it('crée le dossier et lance une session (sans git)', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root, name: 'plain', command: 'bash' } });
expect(res.statusCode).toBe(201);
const body = res.json() as CreateProjectResponse;
expect(body.path).toBe(join(root, 'plain'));
expect(body.gitInitialized).toBe(false);
expect(existsSync(join(root, 'plain'))).toBe(true);
expect(existsSync(join(root, 'plain', '.git'))).toBe(false);
expect(body.session.cwd).toBe(join(root, 'plain'));
});
it('gitInit:true crée un dépôt git', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root, name: 'withgit', gitInit: true, command: 'bash' } });
expect(res.statusCode).toBe(201);
const body = res.json() as CreateProjectResponse;
expect(body.gitInitialized).toBe(true);
expect(existsSync(join(root, 'withgit', '.git'))).toBe(true);
});
it('nom avec `..` ou séparateur → 400 (anti-traversal)', async () => {
for (const name of ['..', 'a/b', '../evil']) {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root, name, command: 'bash' } });
expect(res.statusCode).toBe(400);
}
});
it('dossier déjà existant → 409 PROJECT_EXISTS', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root, name: 'plain', command: 'bash' } });
expect(res.statusCode).toBe(409);
expect(res.json()).toMatchObject({ error: { code: 'PROJECT_EXISTS' } });
});
it('racine inexistante → 404', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root: join(root, 'nope-xyz'), name: 'x', command: 'bash' } });
expect(res.statusCode).toBe(404);
});
it('root relatif → 400', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', headers: auth(), payload: { root: 'relatif/x', name: 'x', command: 'bash' } });
expect(res.statusCode).toBe(400);
});
it('sans authentification → 401', async () => {
const res = await bundle.app.inject({ method: 'POST', url: '/api/v1/projects', payload: { root, name: 'noauth', command: 'bash' } });
expect(res.statusCode).toBe(401);
});
});

View File

@@ -187,6 +187,34 @@ describe('PtyManager (pty mocké)', () => {
expect(listed).toMatchObject({ live: false, resumable: true, claudeSessionId: 'sid-known' }); expect(listed).toMatchObject({ live: false, resumable: true, claudeSessionId: 'sid-known' });
}); });
it('resumeTargetById : session claude morte → cwd + claudeSessionId + groupe ; null sinon', () => {
const d1 = mkdtempSync(join(tmpdir(), 'arb-rt-'));
try {
const summary = manager.spawn({ cwd, command: 'claude', addDirs: [d1], groupId: 'grpR' });
db.prepare('UPDATE sessions SET claude_session_id = ? WHERE id = ?').run('cs-resume', summary.id);
// vivante → null (resume direct interdit ; fork passe par le même chemin)
expect(manager.resumeTargetById(summary.id)).toBeNull();
lastPty().emitExit(0);
// morte avec claudeSessionId connu → cible complète
expect(manager.resumeTargetById(summary.id)).toEqual({
cwd,
claudeSessionId: 'cs-resume',
addedDirs: [d1],
groupId: 'grpR',
});
// id inconnu → null
expect(manager.resumeTargetById('nope')).toBeNull();
} finally {
rmSync(d1, { recursive: true, force: true });
}
});
it('resumeTargetById : session bash morte (sans claudeSessionId) → null', () => {
const { summary, pty } = spawnBash();
pty.emitExit(0);
expect(manager.resumeTargetById(summary.id)).toBeNull();
});
it('capture le claudeSessionId via le registre (poll par pid) → findLiveByClaudeSessionId', () => { it('capture le claudeSessionId via le registre (poll par pid) → findLiveByClaudeSessionId', () => {
vi.useFakeTimers(); vi.useFakeTimers();
const sessDir = mkdtempSync(join(tmpdir(), 'arb-sess-')); const sessDir = mkdtempSync(join(tmpdir(), 'arb-sess-'));
@@ -215,7 +243,11 @@ describe('PtyManager (pty mocké)', () => {
it('resync à lattach = queue du ring (REPLAY_TAIL_BYTES max)', () => { it('resync à lattach = queue du ring (REPLAY_TAIL_BYTES max)', () => {
const { summary, pty } = spawnBash(); const { summary, pty } = spawnBash();
const chunks = ['A', 'B', 'C'].map((c) => c.repeat(100 * 1024)); // on écrit volontairement PLUS que REPLAY_TAIL_BYTES (mais < RING_CAPACITY) pour vérifier
// le plafonnement de la queue rejouée. Tailles dérivées de la constante → robuste aux bumps.
const chunkSize = 256 * 1024;
const chunkCount = Math.ceil(REPLAY_TAIL_BYTES / chunkSize) + 2;
const chunks = Array.from({ length: chunkCount }, (_, i) => String.fromCharCode(65 + (i % 26)).repeat(chunkSize));
for (const c of chunks) pty.emitData(c); for (const c of chunks) pty.emitData(c);
const b = makeBinding('interactive'); const b = makeBinding('interactive');
@@ -382,6 +414,44 @@ describe('PtyManager (pty mocké)', () => {
rmSync(sessDir, { recursive: true, force: true }); rmSync(sessDir, { recursive: true, force: true });
} }
}); });
it('une notif sur le front montant busy→idle (Claude a terminé → disponible), après le debounce', async () => {
const sessDir = mkdtempSync(join(tmpdir(), 'arb-push-idle-'));
const notifies: PushPayload[] = [];
const fakePush = {
notify: async (p: PushPayload) => {
notifies.push(p);
},
} as unknown as PushService;
const m = new PtyManager(db, sessDir, fakePush);
try {
const summary = m.spawn({ cwd, command: 'claude' });
const p = lastPty();
const regFile = join(sessDir, `${p.pid}.json`);
const writeReg = (status: string): void =>
writeFileSync(regFile, JSON.stringify({ pid: p.pid, procStart: '1', sessionId: 'sid', cwd, status }));
// busy d'abord : front montant vers busy, pas de notif
writeReg('busy');
p.emitData('working…');
await sleep(260);
expect(notifies).toHaveLength(0);
// idle : Claude a terminé → front busy→idle → planifie la notif (debounce 1500ms)
writeReg('idle');
p.emitData('\x1b[2J\x1b[HDone.\r\n');
await sleep(260);
expect(notifies).toHaveLength(0); // pas encore : debounce en cours
await sleep(1500); // dépasse le debounce
expect(notifies).toHaveLength(1);
expect(notifies[0]).toMatchObject({ sessionId: summary.id, kind: null, url: `/sessions/${summary.id}` });
expect(notifies[0].body).toMatch(/available/i);
} finally {
m.shutdown();
rmSync(sessDir, { recursive: true, force: true });
}
});
}); });
describe('flow control', () => { describe('flow control', () => {

View File

@@ -48,6 +48,8 @@ beforeAll(() => {
dataDir: dir, dataDir: dir,
allowedOrigins: ['https://host.tailnet.ts.net'], allowedOrigins: ['https://host.tailnet.ts.net'],
printToken: false, printToken: false,
claudeHome: join(dir, 'claude'),
claudeHomeFromFlag: false,
claudeProjectsDir: join(dir, 'claude', 'projects'), claudeProjectsDir: join(dir, 'claude', 'projects'),
claudeSessionsDir: join(dir, 'claude', 'sessions'), claudeSessionsDir: join(dir, 'claude', 'sessions'),
vapidContact: 'mailto:test@localhost', vapidContact: 'mailto:test@localhost',
@@ -77,6 +79,11 @@ describe('GET /api/v1/settings', () => {
// défauts de découverte : AUCUNE racine (clean install → pas de scan) + intervalle 5 min // défauts de découverte : AUCUNE racine (clean install → pas de scan) + intervalle 5 min
expect(body.settings.scanRoots).toEqual([]); expect(body.settings.scanRoots).toEqual([]);
expect(body.settings.scanIntervalMin).toBe(5); expect(body.settings.scanIntervalMin).toBe(5);
// Claude CLI : aucun override par défaut + diagnostic via PATH (execFileSync mocké → /usr/bin/claude).
expect(body.settings.claudeBinPath).toBeNull();
expect(body.settings.claudeHome).toBeNull();
expect(body.server.claudeHome).toBe(join(dir, 'claude'));
expect(body.server.claudeBin).toEqual({ path: '/usr/bin/claude', source: 'path', ok: true });
}); });
it('nexpose AUCUN secret (server_secret, clé privée VAPID)', async () => { it('nexpose AUCUN secret (server_secret, clé privée VAPID)', async () => {
@@ -137,3 +144,46 @@ describe('PATCH /api/v1/settings — découverte des dépôts', () => {
expect(neg.statusCode).toBe(400); expect(neg.statusCode).toBe(400);
}); });
}); });
describe('PATCH /api/v1/settings — Claude CLI', () => {
// process.execPath (node) est un fichier exécutable réel garanti sur la machine de test.
const realBin = process.execPath;
it('enregistre un chemin de binaire exécutable et reflète le diagnostic (source=configured)', async () => {
const res = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeBinPath: realBin } });
expect(res.statusCode).toBe(200);
const body = res.json() as SettingsResponse;
expect(body.settings.claudeBinPath).toBe(realBin);
expect(body.server.claudeBin).toEqual({ path: realBin, source: 'configured', ok: true });
});
it('réinitialise le chemin avec "" (retour à lauto-détection via PATH)', async () => {
await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeBinPath: realBin } });
const res = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeBinPath: '' } });
const body = res.json() as SettingsResponse;
expect(body.settings.claudeBinPath).toBeNull();
expect(body.server.claudeBin.source).toBe('path'); // de nouveau via PATH (mock → /usr/bin/claude)
});
it('rejette un chemin non absolu ou non exécutable (400)', async () => {
for (const claudeBinPath of ['relative/claude', '/a/../b', dir /* répertoire, pas un fichier */]) {
const res = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeBinPath } });
expect(res.statusCode).toBe(400);
}
});
it('enregistre un override claude_home (répertoire existant) et le réinitialise avec ""', async () => {
const set = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeHome: dir } });
expect(set.statusCode).toBe(200);
expect((set.json() as SettingsResponse).settings.claudeHome).toBe(dir);
const reset = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeHome: '' } });
expect((reset.json() as SettingsResponse).settings.claudeHome).toBeNull();
});
it('rejette un claude_home non absolu ou inexistant/fichier (400)', async () => {
for (const claudeHome of ['relative/.claude', join(dir, 'settings.db') /* fichier */, join(dir, 'nope')]) {
const res = await bundle.app.inject({ method: 'PATCH', url: '/api/v1/settings', headers: auth(), payload: { claudeHome } });
expect(res.statusCode).toBe(400);
}
});
});

View File

@@ -69,7 +69,7 @@ describe('WorktreeManager', () => {
claudeHome = mkdtempSync(join(tmpdir(), 'arb-ch-')); claudeHome = mkdtempSync(join(tmpdir(), 'arb-ch-'));
dirs.push(claudeHome); dirs.push(claudeHome);
pty = new PtyManager(db, join(claudeHome, 'sessions')); pty = new PtyManager(db, join(claudeHome, 'sessions'));
discovery = new DiscoveryService({ ptyManager: pty, projectsDir: join(claudeHome, 'projects'), sessionsDir: join(claudeHome, 'sessions') }); discovery = new DiscoveryService({ db, ptyManager: pty, projectsDir: join(claudeHome, 'projects'), sessionsDir: join(claudeHome, 'sessions') });
wt = new WorktreeManager(db, pty, discovery); wt = new WorktreeManager(db, pty, discovery);
}); });
@@ -97,7 +97,8 @@ describe('WorktreeManager', () => {
const wtPath = join(dirname(repo), `${basename(repo)}-wt-feat`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-feat`);
dirs.push(wtPath); dirs.push(wtPath);
const out = await wt.createWorktree(r.id, { branch: 'feat', newBranch: true, runHooks: true }); const out = await wt.createWorktree(r.id, { branch: 'feat', mode: 'create', runHooks: true });
expect(out.action).toBe('created');
expect(resolve(out.worktree.path)).toBe(resolve(wtPath)); expect(resolve(out.worktree.path)).toBe(resolve(wtPath));
expect(out.worktree.branch).toBe('feat'); expect(out.worktree.branch).toBe('feat');
@@ -113,7 +114,7 @@ describe('WorktreeManager', () => {
it('createWorktree : branche invalide → 400', async () => { it('createWorktree : branche invalide → 400', async () => {
const repo = makeTmpRepo(); const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo }); const r = await wt.addRepo({ path: repo });
await expect(wt.createWorktree(r.id, { branch: '../evil', newBranch: true })).rejects.toMatchObject({ statusCode: 400 }); await expect(wt.createWorktree(r.id, { branch: '../evil', mode: 'create' })).rejects.toMatchObject({ statusCode: 400 });
}); });
it('startMainSession : session dans le checkout principal (branche actuelle, sans mutation git)', async () => { it('startMainSession : session dans le checkout principal (branche actuelle, sans mutation git)', async () => {
@@ -163,7 +164,7 @@ describe('WorktreeManager', () => {
const wtPath = join(dirname(repo), `${basename(repo)}-wt-x`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-x`);
dirs.push(wtPath); dirs.push(wtPath);
await wt.createWorktree(r.id, { branch: 'x', newBranch: true, runHooks: false }); await wt.createWorktree(r.id, { branch: 'x', mode: 'create', runHooks: false });
writeFileSync(join(wtPath, 'scratch.txt'), 'wip\n'); // worktree sale writeFileSync(join(wtPath, 'scratch.txt'), 'wip\n'); // worktree sale
await expect(wt.deleteWorktree(r.id, wtPath, false)).rejects.toMatchObject({ statusCode: 409, code: 'WORKTREE_DIRTY' }); await expect(wt.deleteWorktree(r.id, wtPath, false)).rejects.toMatchObject({ statusCode: 409, code: 'WORKTREE_DIRTY' });
@@ -176,7 +177,7 @@ describe('WorktreeManager', () => {
const r = await wt.addRepo({ path: repo }); const r = await wt.addRepo({ path: repo });
const wtPath = join(dirname(repo), `${basename(repo)}-wt-sess`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-sess`);
dirs.push(wtPath); dirs.push(wtPath);
await wt.createWorktree(r.id, { branch: 'sess', newBranch: true, runHooks: false }); await wt.createWorktree(r.id, { branch: 'sess', mode: 'create', runHooks: false });
pty.spawn({ cwd: wtPath, command: 'bash' }); pty.spawn({ cwd: wtPath, command: 'bash' });
const list = await wt.listRepoWorktrees(r.id, true); const list = await wt.listRepoWorktrees(r.id, true);
@@ -190,11 +191,49 @@ describe('WorktreeManager', () => {
const r = await wt.addRepo({ path: repo }); const r = await wt.addRepo({ path: repo });
const wtPath = join(dirname(repo), `${basename(repo)}-wt-busy`); const wtPath = join(dirname(repo), `${basename(repo)}-wt-busy`);
dirs.push(wtPath); dirs.push(wtPath);
await wt.createWorktree(r.id, { branch: 'busy', newBranch: true, runHooks: false }); await wt.createWorktree(r.id, { branch: 'busy', mode: 'create', runHooks: false });
pty.spawn({ cwd: wtPath, command: 'bash' }); pty.spawn({ cwd: wtPath, command: 'bash' });
await expect(wt.deleteWorktree(r.id, wtPath, false)).rejects.toMatchObject({ statusCode: 409, code: 'SESSION_LIVE_IN_WORKTREE' }); await expect(wt.deleteWorktree(r.id, wtPath, false)).rejects.toMatchObject({ statusCode: 409, code: 'SESSION_LIVE_IN_WORKTREE' });
}); });
it('listRepoBranches : renvoie les branches locales (dont main)', async () => {
const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo });
const b = await wt.listRepoBranches(r.id);
expect(b.local).toContain('main');
});
it('commitWorktree : arbre propre → 409 NOTHING_TO_COMMIT ; arbre sale → commit (dirty=0)', async () => {
const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo });
await expect(wt.commitWorktree(r.id, repo, 'noop')).rejects.toMatchObject({ statusCode: 409, code: 'NOTHING_TO_COMMIT' });
writeFileSync(join(repo, 'f.txt'), 'x\n');
const w = await wt.commitWorktree(r.id, repo, 'add f');
expect(w.git.dirtyCount).toBe(0);
});
it('promoteWorktree : la branche du worktree devient le checkout principal, worktree supprimé, ancienne branche conservée', async () => {
const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo });
const wtPath = join(dirname(repo), `${basename(repo)}-wt-prom`);
dirs.push(wtPath);
await wt.createWorktree(r.id, { branch: 'prom', mode: 'create', runHooks: false });
await wt.promoteWorktree(r.id, wtPath);
expect(execFileSync('git', ['branch', '--show-current'], { cwd: repo }).toString().trim()).toBe('prom');
expect((await wt.listRepoWorktrees(r.id, true)).some((w) => resolve(w.path) === resolve(wtPath))).toBe(false);
const branches = await wt.listRepoBranches(r.id);
expect(branches.local).toContain('main'); // ancienne branche principale conservée
expect(branches.local).toContain('prom');
});
it('promoteWorktree : checkout principal refusé (400 IS_MAIN_WORKTREE)', async () => {
const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo });
await expect(wt.promoteWorktree(r.id, repo)).rejects.toMatchObject({ statusCode: 400, code: 'IS_MAIN_WORKTREE' });
});
it('addRepo renvoie hidden:false ; updateRepo({hidden}) bascule et émet repo_update', async () => { it('addRepo renvoie hidden:false ; updateRepo({hidden}) bascule et émet repo_update', async () => {
const repo = makeTmpRepo(); const repo = makeTmpRepo();
const r = await wt.addRepo({ path: repo }); const r = await wt.addRepo({ path: repo });

View File

@@ -47,12 +47,40 @@ export interface CreateSessionRequest {
/** binaire à lancer — défaut "claude" ; "bash" sert aux tests d'acceptation sans quota */ /** binaire à lancer — défaut "claude" ; "bash" sert aux tests d'acceptation sans quota */
command?: 'claude' | 'bash'; command?: 'claude' | 'bash';
} }
/**
* POST /api/v1/projects — crée un NOUVEAU dossier de projet `<root>/<name>` (le serveur ne crée
* jamais de dossier ailleurs) puis y lance une session. Le `git init` est optionnel (case à cocher).
* Réponse : `CreateProjectResponse`.
*/
export interface CreateProjectRequest {
/** racine absolue où créer le projet (doit déjà exister). */
root: string;
/** nom du dossier de projet : un seul segment, sans séparateur ni `..`. */
name: string;
/** true → `git init` dans le nouveau dossier avant la session (défaut false). */
gitInit?: boolean;
/** binaire à lancer — défaut "claude" ; "bash" sert aux tests sans quota. */
command?: 'claude' | 'bash';
}
export interface CreateProjectResponse {
session: SessionSummary;
/** chemin absolu du dossier de projet créé. */
path: string;
/** true si `git init` a réellement été exécuté. */
gitInitialized: boolean;
}
export interface SessionsListResponse { export interface SessionsListResponse {
sessions: SessionSummary[]; sessions: SessionSummary[];
} }
export interface SessionResponse { export interface SessionResponse {
session: SessionSummary; session: SessionSummary;
} }
/** POST /sessions/hide-discovered — masque tout l'historique de sessions externes visible. */
export interface HideDiscoveredResponse {
/** nombre de sessions effectivement masquées. */
hidden: number;
}
// POST /sessions/:id/resume et /sessions/:id/fork (P2) : aucun corps — cwd et command // POST /sessions/:id/resume et /sessions/:id/fork (P2) : aucun corps — cwd et command
// sont TOUJOURS dérivés du :id (lu sur disque), jamais fournis par le client (cf. spike S1). // sont TOUJOURS dérivés du :id (lu sur disque), jamais fournis par le client (cf. spike S1).
@@ -104,11 +132,25 @@ export interface HookRunResult {
output: string; output: string;
durationMs: number; durationMs: number;
} }
/**
* Stratégie de résolution de la branche d'un nouveau worktree :
* - `auto` (défaut) : détecte l'existence de la branche — checkout si elle existe en local, suivi de
* `origin/<branch>` si elle n'existe que sur le remote, sinon création (`-b`). Robuste pour les
* groupes hétérogènes où la branche peut déjà exister dans certains dépôts mais pas d'autres.
* - `create` : force la création (`-b`), échoue si la branche existe déjà.
* - `checkout` : force le checkout d'une branche existante, échoue si elle est absente.
*/
export type WorktreeBranchMode = 'auto' | 'create' | 'checkout';
/** Action réellement effectuée par la résolution `auto` (feedback UI). */
export type WorktreeBranchAction = 'created' | 'reused' | 'tracked';
export interface CreateWorktreeRequest { export interface CreateWorktreeRequest {
branch: string; branch: string;
/** true : créer la branche (`-b`) ; false : checkout d'une branche existante. */ /** stratégie de résolution de la branche (défaut : `auto`). Voir {@link WorktreeBranchMode}. */
newBranch: boolean; mode?: WorktreeBranchMode;
/** point de départ de la nouvelle branche (défaut : HEAD courant du repo). */ /** @deprecated remplacé par `mode` ; mappé : true→create, false→checkout, absent→auto. */
newBranch?: boolean;
/** point de départ d'une branche créée (défaut : branche par défaut du dépôt, sinon HEAD). */
baseRef?: string; baseRef?: string;
/** chemin cible du worktree (défaut : `<parent>/<repo>-wt-<branch>`). */ /** chemin cible du worktree (défaut : `<parent>/<repo>-wt-<branch>`). */
path?: string; path?: string;
@@ -121,6 +163,35 @@ export interface CreateWorktreeResponse {
worktree: WorktreeSummary; worktree: WorktreeSummary;
hookResults: HookRunResult[]; hookResults: HookRunResult[];
session: SessionSummary | null; session: SessionSummary | null;
/** action effective de la résolution de branche (créée / réutilisée / suivie du remote). */
action: WorktreeBranchAction;
}
/** GET /api/v1/repos/:id/branches — branches locales/remote pour alimenter un sélecteur de base. */
export interface RepoBranchesResponse {
local: string[];
remote: string[];
/** branche par défaut du dépôt (origin/HEAD), ou null si indéterminée. */
default: string | null;
}
/** POST /api/v1/repos/:id/worktrees/commit — `git add -A` puis commit dans le worktree visé. */
export interface CommitWorktreeRequest {
path: string;
message: string;
}
/** POST /api/v1/repos/:id/worktrees/push — pousse la branche du worktree (upstream auto si absent). */
export interface PushWorktreeRequest {
path: string;
}
/**
* POST /api/v1/repos/:id/worktrees/promote — « passer en principal » : la branche du worktree devient
* le checkout principal du dépôt (le worktree est supprimé, l'ancienne branche principale est conservée).
*/
export interface PromoteWorktreeRequest {
path: string;
/** outrepasse les garde-fous d'arbre sale (worktree/checkout principal). */
force?: boolean;
} }
export interface AdoptWorktreeRequest { export interface AdoptWorktreeRequest {
path: string; path: string;
@@ -225,6 +296,19 @@ export interface ServerInfo {
/** clé publique VAPID (sûre à exposer) ; null si push indisponible. */ /** clé publique VAPID (sûre à exposer) ; null si push indisponible. */
vapidPublicKey: string | null; vapidPublicKey: string | null;
vapidContact: string; vapidContact: string;
/** racine effective de l'install Claude (~/.claude, --claude-home, ou réglage claude_home). */
claudeHome: string;
/** diagnostic de résolution du binaire `claude` (présence + exécutabilité). */
claudeBin: ClaudeBinDiagnostic;
}
/** Diagnostic de résolution du CLI `claude` exposé en lecture dans les Réglages. */
export interface ClaudeBinDiagnostic {
/** chemin résolu du binaire, ou null si introuvable. */
path: string | null;
/** 'configured' = réglage explicite ; 'path' = trouvé via PATH ; null = introuvable. */
source: 'configured' | 'path' | null;
/** true si le binaire est présent et exécutable. */
ok: boolean;
} }
export interface SettingsResponse { export interface SettingsResponse {
/** réglages modifiables à chaud (allow-list serveur — jamais les secrets). */ /** réglages modifiables à chaud (allow-list serveur — jamais les secrets). */
@@ -233,6 +317,10 @@ export interface SettingsResponse {
scanRoots: string[]; scanRoots: string[];
/** intervalle du re-scan périodique en minutes ; 0 = périodique désactivé. */ /** intervalle du re-scan périodique en minutes ; 0 = périodique désactivé. */
scanIntervalMin: number; scanIntervalMin: number;
/** chemin explicite du binaire `claude` ; null = auto-détection via PATH. Effet : prochaine session. */
claudeBinPath: string | null;
/** override de la racine ~/.claude ; null = défaut. Effet : au redémarrage du daemon. */
claudeHome: string | null;
}; };
server: ServerInfo; server: ServerInfo;
} }
@@ -241,6 +329,10 @@ export interface UpdateSettingsRequest {
scanRoots?: string[]; scanRoots?: string[];
/** intervalle du re-scan périodique en minutes (01440 ; 0 désactive). */ /** intervalle du re-scan périodique en minutes (01440 ; 0 désactive). */
scanIntervalMin?: number; scanIntervalMin?: number;
/** chemin absolu du binaire `claude` (fichier exécutable) ; '' pour réinitialiser à l'auto-détection. */
claudeBinPath?: string;
/** override de la racine ~/.claude (répertoire existant) ; '' pour réinitialiser au défaut. */
claudeHome?: string;
} }
// ---- Journal d'audit (conformité entreprise) ---- // ---- Journal d'audit (conformité entreprise) ----

View File

@@ -51,8 +51,12 @@ export const FLOW = {
LAGGING_BYTES: 2 * 1024 * 1024, LAGGING_BYTES: 2 * 1024 * 1024,
} as const; } as const;
/** Replay à l'attach : reset terminal + queue du ring (l'écran TUI se repeint en continu) */ /**
export const REPLAY_TAIL_BYTES = 256 * 1024; * Replay à l'attach : reset terminal + queue du ring (l'écran TUI se repeint en continu).
* 1 Mo (≈ 1015k lignes) pour permettre de remonter une vraie conversation Claude dans le terminal ;
* reste < LAGGING_BYTES (pas de faux lagging) et bien dans RING_CAPACITY.
*/
export const REPLAY_TAIL_BYTES = 1024 * 1024;
// ---- États de session (sous-ensemble P1 ; étendu en P3) ---- // ---- États de session (sous-ensemble P1 ; étendu en P3) ----
export type SessionRuntimeStatus = export type SessionRuntimeStatus =
@@ -118,6 +122,9 @@ export interface SessionSummary {
addedDirs?: string[]; addedDirs?: string[];
/** groupe propriétaire d'une session de groupe (couvre plusieurs repos) ; null/absent sinon. */ /** groupe propriétaire d'une session de groupe (couvre plusieurs repos) ; null/absent sinon. */
groupId?: string | null; groupId?: string | null;
// ---- Masquage (additif) ----
/** true = session découverte masquée par l'utilisateur (exclue de la liste sauf includeHidden). */
hidden?: boolean;
} }
// ---- Worktrees & repos (P3) ---- // ---- Worktrees & repos (P3) ----

View File

@@ -71,6 +71,20 @@ const { t } = useI18n();
</template> </template>
{{ t('feat8Desc') }} {{ t('feat8Desc') }}
</FeatureCard> </FeatureCard>
<FeatureCard :title="t('feat9Title')">
<template #icon>
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" /></svg>
</template>
{{ t('feat9Desc') }}
</FeatureCard>
<FeatureCard :title="t('feat10Title')">
<template #icon>
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 10v6" /><path d="M9 13h6" /><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" /></svg>
</template>
{{ t('feat10Desc') }}
</FeatureCard>
</div> </div>
</section> </section>
</template> </template>

View File

@@ -96,6 +96,11 @@ const dlgOpts = computed(() => DLG_OPTS[locale.value as AppLocale]);
<span class="font-mono text-[11px] text-zinc-400">claude</span> <span class="font-mono text-[11px] text-zinc-400">claude</span>
</span> </span>
</div> </div>
<!-- actions git de la carte : commit / push (fidèle au WorktreeCard) -->
<div class="mt-1 flex items-center gap-1.5">
<span class="inline-flex items-center rounded border border-zinc-700 bg-zinc-800 px-1.5 py-0.5 text-[11px] font-medium text-zinc-300">{{ t('mCommit') }}</span>
<span class="inline-flex items-center rounded border border-zinc-700 bg-zinc-800 px-1.5 py-0.5 text-[11px] font-medium text-zinc-300">{{ t('mPush') }} 2</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -11,7 +11,7 @@ export const FAQS: Record<AppLocale, FaqItem[]> = {
en: [ en: [
{ {
q: 'How is this different from running Claude Code in a terminal?', q: 'How is this different from running Claude Code in a terminal?',
a: 'It runs the very same interactive claude CLI — Arboretum just wraps it in a managed terminal you reach from a browser. What you gain on top: a worktree-first dashboard across all your repos, live busy / waiting / idle states, a multi-terminal grid, push notifications, and the ability to answer a prompt from your phone. It supervises your sessions; it does not change how Claude Code works.', a: 'It runs the very same interactive claude CLI — Arboretum just wraps it in a managed terminal you reach from a browser. What you gain on top: a worktree-first dashboard across all your repos, live busy / waiting / available states, a multi-terminal grid, push notifications, and the ability to answer a prompt from your phone. It supervises your sessions; it does not change how Claude Code works.',
}, },
{ {
q: 'Does it need the cloud?', q: 'Does it need the cloud?',
@@ -33,7 +33,7 @@ export const FAQS: Record<AppLocale, FaqItem[]> = {
fr: [ fr: [
{ {
q: 'En quoi est-ce différent de lancer Claude Code dans un terminal ?', q: 'En quoi est-ce différent de lancer Claude Code dans un terminal ?',
a: "C'est exactement le même CLI claude interactif — Arboretum l'enveloppe simplement dans un terminal managé accessible depuis un navigateur. Ce que vous gagnez en plus : un dashboard worktree-first sur tous vos repos, les états occupée / en attente / inactive en direct, une grille multi-terminaux, des notifications push, et la possibilité de répondre à une question depuis votre téléphone. Il supervise vos sessions ; il ne change rien au fonctionnement de Claude Code.", a: "C'est exactement le même CLI claude interactif — Arboretum l'enveloppe simplement dans un terminal managé accessible depuis un navigateur. Ce que vous gagnez en plus : un dashboard worktree-first sur tous vos repos, les états occupée / en attente / disponible en direct, une grille multi-terminaux, des notifications push, et la possibilité de répondre à une question depuis votre téléphone. Il supervise vos sessions ; il ne change rien au fonctionnement de Claude Code.",
}, },
{ {
q: 'A-t-il besoin du cloud ?', q: 'A-t-il besoin du cloud ?',

View File

@@ -17,7 +17,7 @@ export default {
featKicker: 'Everything in one view', featKicker: 'Everything in one view',
featTitle: 'Built to supervise agents working in parallel', featTitle: 'Built to supervise agents working in parallel',
feat1Title: 'Worktree-first', feat1Title: 'Worktree-first',
feat1Desc: 'Work on your main branch or spin up an isolated worktree — every session stays pinned to a branch. Branches, not chaos.', feat1Desc: 'Work on your main branch or spin up an isolated worktree — then commit, push or promote a branch to main, without opening a terminal. Branches, not chaos.',
feat2Title: 'Many sessions, one view', feat2Title: 'Many sessions, one view',
feat2Desc: 'Run parallel Claude Code agents side by side in a single live grid.', feat2Desc: 'Run parallel Claude Code agents side by side in a single live grid.',
feat3Title: 'Fine-grained states', feat3Title: 'Fine-grained states',
@@ -32,14 +32,18 @@ export default {
feat7Desc: 'Group repos and run one Claude session across all of them at once.', feat7Desc: 'Group repos and run one Claude session across all of them at once.',
feat8Title: 'Local-first & secure', feat8Title: 'Local-first & secure',
feat8Desc: 'Binds to localhost, hashes tokens, remote access via Tailscale.', feat8Desc: 'Binds to localhost, hashes tokens, remote access via Tailscale.',
feat9Title: 'Native VS Code extension',
feat9Desc: 'Drive worktrees and attach sessions in native terminals, right inside your editor.',
feat10Title: 'New project in one click',
feat10Desc: 'Create a project folder anywhere (optional git init) and start a Claude session in it, from any device.',
scAKicker: 'Worktree-first dashboard', scAKicker: 'Worktree-first dashboard',
scATitle: 'See what needs you — before anything stalls', scATitle: 'See what needs you — before anything stalls',
scABody: scABody:
'A live list of every worktree and its session state. The Needs attention rail floats the agents waiting on a decision to the top, so nothing sits blocked while you are heads-down elsewhere.', 'A live list of every worktree and its session state. The Needs attention rail floats the agents waiting on a decision to the top, so nothing sits blocked while you are heads-down elsewhere. Commit, push or promote a branch to main straight from the card, and hide the noisy history left by past terminal sessions so the list stays actionable.',
scBKicker: 'Multi-terminal grid', scBKicker: 'Multi-terminal grid',
scBTitle: "Every agent's output, streaming live", scBTitle: "Every agent's output, streaming live",
scBBody: scBBody:
'Watch all your sessions at once — real terminal output, color-coded by state, updating in real time. Click any pane to take over, answer a prompt, or stop a run.', 'Watch all your sessions at once — real terminal output, color-coded by state, updating in real time. Click any pane to take over in a fullscreen terminal — prompt pinned to the bottom, full scrollback above — answer a prompt, or stop a run.',
scCKicker: 'On your phone', scCKicker: 'On your phone',
scCTitle: 'Unblock an agent from the kitchen', scCTitle: 'Unblock an agent from the kitchen',
scCBody: scCBody:
@@ -86,13 +90,15 @@ export default {
mAttn: 'Needs attention', mAttn: 'Needs attention',
waiting: 'waiting', waiting: 'waiting',
busy: 'busy', busy: 'busy',
idle: 'idle', idle: 'available',
mPermission: 'Permission', mPermission: 'Permission',
mDeny: 'Deny (Esc)', mDeny: 'Deny (Esc)',
mMain: 'main', mMain: 'main',
mClean: 'clean', mClean: 'clean',
mDirty: '3 changed', mDirty: '3 changed',
mStart: 'Start work', mStart: 'Start work',
mCommit: 'Commit',
mPush: 'Push',
toastTitle: 'Session waiting for you', toastTitle: 'Session waiting for you',
toastBody: 'api · feat/auth needs a decision', toastBody: 'api · feat/auth needs a decision',
dlgQ: 'Apply this change to login.ts?', dlgQ: 'Apply this change to login.ts?',

View File

@@ -17,7 +17,7 @@ export default {
featKicker: 'Tout dans une seule vue', featKicker: 'Tout dans une seule vue',
featTitle: 'Conçu pour superviser des agents qui travaillent en parallèle', featTitle: 'Conçu pour superviser des agents qui travaillent en parallèle',
feat1Title: "Worktree d'abord", feat1Title: "Worktree d'abord",
feat1Desc: 'Travaillez sur votre branche principale ou créez un worktree isolé — chaque session reste rattachée à une branche. Des branches, pas du chaos.', feat1Desc: 'Travaillez sur votre branche principale ou créez un worktree isolé — puis commitez, poussez ou passez une branche en principal, sans ouvrir de terminal. Des branches, pas du chaos.',
feat2Title: 'Plusieurs sessions, une vue', feat2Title: 'Plusieurs sessions, une vue',
feat2Desc: 'Lancez des agents Claude Code en parallèle, côte à côte dans une seule grille en direct.', feat2Desc: 'Lancez des agents Claude Code en parallèle, côte à côte dans une seule grille en direct.',
feat3Title: 'États fins', feat3Title: 'États fins',
@@ -32,14 +32,18 @@ export default {
feat7Desc: 'Regroupez des repos et pilotez-les via une seule session Claude, tous à la fois.', feat7Desc: 'Regroupez des repos et pilotez-les via une seule session Claude, tous à la fois.',
feat8Title: 'Local-first & sécurisé', feat8Title: 'Local-first & sécurisé',
feat8Desc: 'Se lie à localhost, hashe les tokens, accès distant via Tailscale.', feat8Desc: 'Se lie à localhost, hashe les tokens, accès distant via Tailscale.',
feat9Title: 'Extension VS Code native',
feat9Desc: 'Pilotez vos worktrees et attachez vos sessions dans des terminaux natifs, directement dans votre éditeur.',
feat10Title: 'Nouveau projet en un clic',
feat10Desc: "Créez un dossier de projet où vous voulez (git init optionnel) et lancez-y une session Claude, depuis n'importe quel appareil.",
scAKicker: 'Dashboard worktree-first', scAKicker: 'Dashboard worktree-first',
scATitle: 'Voyez ce qui vous attend — avant que ça ne bloque', scATitle: 'Voyez ce qui vous attend — avant que ça ne bloque',
scABody: scABody:
"Une liste en direct de chaque worktree et de l'état de sa session. Le bandeau À traiter fait remonter les agents en attente d'une décision, pour que rien ne reste bloqué pendant que vous êtes concentré ailleurs.", "Une liste en direct de chaque worktree et de l'état de sa session. Le bandeau À traiter fait remonter les agents en attente d'une décision, pour que rien ne reste bloqué pendant que vous êtes concentré ailleurs. Commitez, poussez ou passez une branche en principal directement depuis la carte, et masquez l'historique encombrant laissé par vos anciennes sessions terminal pour garder la liste actionnable.",
scBKicker: 'Grille multi-terminaux', scBKicker: 'Grille multi-terminaux',
scBTitle: 'La sortie de chaque agent, en direct', scBTitle: 'La sortie de chaque agent, en direct',
scBBody: scBBody:
"Surveillez toutes vos sessions en même temps — vraie sortie terminal, couleur selon l'état, mise à jour en temps réel. Cliquez sur un panneau pour reprendre la main, répondre, ou arrêter une exécution.", "Surveillez toutes vos sessions en même temps — vraie sortie terminal, couleur selon l'état, mise à jour en temps réel. Cliquez sur un panneau pour reprendre la main dans un terminal plein écran — invite ancrée en bas, historique défilable au-dessus — répondre, ou arrêter une exécution.",
scCKicker: 'Sur votre téléphone', scCKicker: 'Sur votre téléphone',
scCTitle: 'Débloquez un agent depuis la cuisine', scCTitle: 'Débloquez un agent depuis la cuisine',
scCBody: scCBody:
@@ -68,7 +72,7 @@ export default {
sec3Desc: 'Chaque requête est validée par origine. Pas de surprise cross-site.', sec3Desc: 'Chaque requête est validée par origine. Pas de surprise cross-site.',
sec4Title: 'Distant via Tailscale', sec4Title: 'Distant via Tailscale',
sec4Desc: 'Accédez-y via Tailscale Serve — aucun port public, aucune redirection de port.', sec4Desc: 'Accédez-y via Tailscale Serve — aucun port public, aucune redirection de port.',
faqTitle: 'Vos questions, nos réponses', faqTitle: 'Vos questions, les réponses',
ctaTitle: 'Prenez le commandement de vos agents', ctaTitle: 'Prenez le commandement de vos agents',
ctaBody: 'Une commande pour lancer. Tout superviser depuis un seul endroit.', ctaBody: 'Une commande pour lancer. Tout superviser depuis un seul endroit.',
ctaSource: 'Voir le code sur Gitea', ctaSource: 'Voir le code sur Gitea',
@@ -86,13 +90,15 @@ export default {
mAttn: 'À traiter', mAttn: 'À traiter',
waiting: 'en attente', waiting: 'en attente',
busy: 'occupée', busy: 'occupée',
idle: 'inactive', idle: 'disponible',
mPermission: 'Permission', mPermission: 'Permission',
mDeny: 'Refuser (Échap)', mDeny: 'Refuser (Échap)',
mMain: 'principal', mMain: 'principal',
mClean: 'propre', mClean: 'propre',
mDirty: '3 modifiés', mDirty: '3 modifiés',
mStart: 'Démarrer', mStart: 'Démarrer',
mCommit: 'Commit',
mPush: 'Push',
toastTitle: 'Une session vous attend', toastTitle: 'Une session vous attend',
toastBody: 'api · feat/auth attend une décision', toastBody: 'api · feat/auth attend une décision',
dlgQ: 'Appliquer ce changement à login.ts ?', dlgQ: 'Appliquer ce changement à login.ts ?',

2
packages/vscode/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
dist/
*.vsix

View File

@@ -0,0 +1,9 @@
# Tout est bundlé dans dist/extension.js par esbuild : on n'embarque que le bundle + la meta.
src/**
test/**
node_modules/**
esbuild.mjs
tsconfig.json
.gitignore
**/*.ts
**/*.map

View File

@@ -0,0 +1,16 @@
# Changelog
## 0.1.0
Initial release — native VS Code integration for the Arboretum daemon:
- Real-time **Repositories** and **Groups** trees (repos → worktrees → sessions) over the daemon WebSocket.
- **Native terminals** (`Pseudoterminal`) to attach/observe any session, reusing VS Code's rendering and
scrollback.
- **Status-bar** waiting counter and native **notifications** on the rising edge to `waiting`, with
Yes/No answers via the `answer` command.
- Git mutations from the tree: **create worktree, commit, push, promote**; start session / start group
session; resume / fork / kill / hide.
- **Workspace awareness**: reveal the worktree for the open folder; start a session or create a worktree
for the current folder.
- Token auth via `Authorization: Bearer` (REST + WebSocket), token stored in SecretStorage.

21
packages/vscode/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Johan Leroy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

73
packages/vscode/README.md Normal file
View File

@@ -0,0 +1,73 @@
# Arboretum for VS Code
Pilot your git **worktrees** and **Claude Code sessions** from inside VS Code — a real native
integration on top of the [Arboretum](https://git.lidge.fr/johanleroy/arboretum) daemon, not a webview.
- **Live tree** of Repositories → Worktrees → Sessions (and a Groups view), updated in real time over
the daemon's WebSocket.
- **Native terminals**: attach to any session in a real VS Code terminal (a `Pseudoterminal` bridges the
daemon's PTY) — you get VS Code's own rendering, scrollback, copy/paste and links for free.
- **Waiting alerts**: a status-bar counter and native notifications when a Claude session is waiting for
input — answer **Yes/No** without even opening the terminal (uses the daemon's `answer` command).
- **Git mutations** from the tree: create worktree, commit, push, promote to main.
- **Workspace-aware**: the worktree matching your open folder is highlighted; start a session or create a
worktree for the current folder in one command.
## Requirements
- A running Arboretum daemon (`npx @johanleroy/git-arboretum`, or installed as a user service via
`arboretum install`). The extension is a **client** — it does not start the daemon.
- An access token. The bootstrap token is printed once on first daemon start; you can also create one in
the Arboretum dashboard (**Settings → Tokens**).
## Getting started
1. Start the daemon and copy a token.
2. In VS Code, run **Arboretum: Sign In** (Command Palette) and paste the token. The token is validated
against the daemon and stored in VS Code's encrypted **SecretStorage**.
3. The **Arboretum** view container appears in the Activity Bar with the Repositories and Groups trees.
## Settings
| Setting | Default | Description |
| --- | --- | --- |
| `arboretum.url` | `http://127.0.0.1:7317` | Base URL of the daemon (REST + WebSocket). |
| `arboretum.showExternalSessions` | `false` | Also show Claude sessions started outside Arboretum (CLI). |
| `arboretum.notifyOnWaiting` | `true` | Native notification when a session starts waiting for input. |
The extension authenticates with `Authorization: Bearer <token>` on both REST and the WebSocket upgrade.
For remote access, point `arboretum.url` at your Tailscale Serve URL (`https://…`) — the WebSocket is
derived automatically (`wss://`).
## Building & packaging (private VSIX)
The extension is bundled with esbuild (`@arboretum/shared` is inlined → the VSIX is self-contained).
```bash
# from the monorepo root
npm install
npm run build:vscode # builds @arboretum/shared then bundles the extension
cd packages/vscode && npx @vscode/vsce package --no-dependencies
# → git-arboretum-0.1.0.vsix
```
Install it with **Extensions: Install from VSIX…** in the Command Palette, or:
```bash
code --install-extension git-arboretum-0.1.0.vsix # also: codium / cursor
```
### Other distribution channels (optional)
- **Open VSX** (VSCodium, Cursor, Windsurf): `npx ovsx publish *.vsix -p <token>` after creating an
Open VSX account and namespace.
- **VS Code Marketplace**: create an Azure DevOps publisher + PAT, then `npx @vscode/vsce publish`.
A Gitea Actions workflow packages the VSIX automatically on a `vscode-vX.Y.Z` tag (see
`.gitea/workflows/vscode-release.yml`) and attaches it to the release.
## Security
The extension never weakens the daemon's security model: it speaks the same authenticated protocol as the
web dashboard. A Node client sends no `Origin` header, so it passes the daemon's strict Origin check while
still requiring a valid token.

View File

@@ -0,0 +1,28 @@
// Build de l'extension : un seul bundle CJS `dist/extension.js`.
// esbuild résout `@arboretum/shared` via le symlink workspace et l'inline dans le bundle
// (VSIX 100 % autonome, sans node_modules embarqué) ; seul `vscode` reste externe (fourni par l'hôte).
import esbuild from 'esbuild';
const watch = process.argv.includes('--watch');
/** @type {import('esbuild').BuildOptions} */
const options = {
entryPoints: ['src/extension.ts'],
bundle: true,
platform: 'node',
format: 'cjs',
target: 'node18', // VSCode 1.85 embarque Electron/Node 18
outfile: 'dist/extension.js',
external: ['vscode'], // module fourni par l'hôte VSCode, jamais bundlé
sourcemap: true,
minify: !watch,
logLevel: 'info',
};
if (watch) {
const ctx = await esbuild.context(options);
await ctx.watch();
console.log('[esbuild] watching…');
} else {
await esbuild.build(options);
}

View File

@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 22v-6" />
<path d="M12 16c0-3 2.5-3.5 4-5 1.4-1.4 1.5-3.6 1-5" />
<path d="M12 16c0-3-2.5-3.5-4-5C6.6 9.6 6.5 7.4 7 6" />
<circle cx="12" cy="4" r="1.6" />
<circle cx="17" cy="6" r="1.6" />
<circle cx="7" cy="6" r="1.6" />
</svg>

After

Width:  |  Height:  |  Size: 416 B

View File

@@ -0,0 +1,164 @@
{
"name": "git-arboretum",
"displayName": "Arboretum",
"description": "Pilot your git worktrees and Claude Code sessions from VS Code — native terminals, live tree, waiting alerts.",
"version": "0.1.1",
"private": true,
"publisher": "johanleroy",
"license": "MIT",
"engines": {
"vscode": "^1.85.0"
},
"repository": {
"type": "git",
"url": "https://git.lidge.fr/johanleroy/arboretum"
},
"categories": [
"SCM Providers",
"Other"
],
"keywords": [
"git",
"worktree",
"claude",
"terminal",
"arboretum"
],
"main": "./dist/extension.js",
"activationEvents": [
"onStartupFinished"
],
"contributes": {
"configuration": {
"title": "Arboretum",
"properties": {
"arboretum.url": {
"type": "string",
"default": "http://127.0.0.1:7317",
"markdownDescription": "Base URL of the Arboretum daemon (REST + WebSocket). Defaults to the loopback bind."
},
"arboretum.showExternalSessions": {
"type": "boolean",
"default": false,
"markdownDescription": "Show Claude sessions discovered outside Arboretum (started from the CLI) in the trees. Off by default to avoid clutter."
},
"arboretum.notifyOnWaiting": {
"type": "boolean",
"default": true,
"markdownDescription": "Show a native notification when a Claude session starts waiting for input."
}
}
},
"viewsContainers": {
"activitybar": [
{
"id": "arboretum",
"title": "Arboretum",
"icon": "media/arboretum.svg"
}
]
},
"views": {
"arboretum": [
{
"id": "arboretum.repos",
"name": "Repositories",
"icon": "media/arboretum.svg"
},
{
"id": "arboretum.groups",
"name": "Groups",
"icon": "media/arboretum.svg"
}
]
},
"viewsWelcome": [
{
"view": "arboretum.repos",
"contents": "Not connected to an Arboretum daemon.\n[Sign in](command:arboretum.signIn)\n\nMake sure the daemon is running (`npx @johanleroy/git-arboretum`) and paste a token.",
"when": "!arboretum.connected"
}
],
"commands": [
{ "command": "arboretum.signIn", "title": "Sign In", "category": "Arboretum" },
{ "command": "arboretum.signOut", "title": "Sign Out", "category": "Arboretum" },
{ "command": "arboretum.refresh", "title": "Refresh", "category": "Arboretum", "icon": "$(refresh)" },
{ "command": "arboretum.openDashboard", "title": "Open Dashboard in Browser", "category": "Arboretum", "icon": "$(globe)" },
{ "command": "arboretum.attachSession", "title": "Attach Terminal", "category": "Arboretum", "icon": "$(terminal)" },
{ "command": "arboretum.observeSession", "title": "Observe Terminal (read-only)", "category": "Arboretum", "icon": "$(eye)" },
{ "command": "arboretum.answerSession", "title": "Answer Prompt…", "category": "Arboretum", "icon": "$(comment-discussion)" },
{ "command": "arboretum.killSession", "title": "Kill Session", "category": "Arboretum", "icon": "$(trash)" },
{ "command": "arboretum.hideSession", "title": "Hide Session", "category": "Arboretum", "icon": "$(eye-closed)" },
{ "command": "arboretum.resumeSession", "title": "Resume Session", "category": "Arboretum", "icon": "$(debug-restart)" },
{ "command": "arboretum.forkSession", "title": "Fork Session", "category": "Arboretum", "icon": "$(git-branch)" },
{ "command": "arboretum.createWorktree", "title": "Create Worktree…", "category": "Arboretum", "icon": "$(add)" },
{ "command": "arboretum.commitWorktree", "title": "Commit…", "category": "Arboretum", "icon": "$(git-commit)" },
{ "command": "arboretum.pushWorktree", "title": "Push", "category": "Arboretum", "icon": "$(repo-push)" },
{ "command": "arboretum.promoteWorktree", "title": "Promote to Main", "category": "Arboretum", "icon": "$(arrow-up)" },
{ "command": "arboretum.startSession", "title": "Start Claude Session", "category": "Arboretum", "icon": "$(play)" },
{ "command": "arboretum.startGroupSession", "title": "Start Group Session…", "category": "Arboretum", "icon": "$(play)" },
{ "command": "arboretum.startSessionHere", "title": "Start Session in Current Folder", "category": "Arboretum" },
{ "command": "arboretum.createWorktreeHere", "title": "Create Worktree for Current Folder…", "category": "Arboretum" },
{ "command": "arboretum.revealWorktree", "title": "Reveal Worktree for Current Folder", "category": "Arboretum" }
],
"menus": {
"view/title": [
{ "command": "arboretum.refresh", "when": "view == arboretum.repos || view == arboretum.groups", "group": "navigation" },
{ "command": "arboretum.openDashboard", "when": "view == arboretum.repos", "group": "navigation" },
{ "command": "arboretum.signOut", "when": "view == arboretum.repos && arboretum.connected", "group": "1_auth" },
{ "command": "arboretum.signIn", "when": "view == arboretum.repos && !arboretum.connected", "group": "1_auth" }
],
"view/item/context": [
{ "command": "arboretum.createWorktree", "when": "viewItem == arboretum:repo", "group": "inline" },
{ "command": "arboretum.startSession", "when": "viewItem == arboretum:repo", "group": "1_session" },
{ "command": "arboretum.commitWorktree", "when": "viewItem == arboretum:worktree", "group": "1_git" },
{ "command": "arboretum.pushWorktree", "when": "viewItem == arboretum:worktree", "group": "1_git" },
{ "command": "arboretum.promoteWorktree", "when": "viewItem == arboretum:worktree", "group": "2_git" },
{ "command": "arboretum.startSession", "when": "viewItem == arboretum:worktree", "group": "3_session" },
{ "command": "arboretum.attachSession", "when": "viewItem =~ /arboretum:session:live/", "group": "inline" },
{ "command": "arboretum.observeSession", "when": "viewItem =~ /arboretum:session:live/", "group": "1_term" },
{ "command": "arboretum.answerSession", "when": "viewItem =~ /arboretum:session:live:.*waiting/", "group": "1_term" },
{ "command": "arboretum.killSession", "when": "viewItem =~ /arboretum:session:live/", "group": "9_danger" },
{ "command": "arboretum.resumeSession", "when": "viewItem =~ /arboretum:session:dead/", "group": "inline" },
{ "command": "arboretum.forkSession", "when": "viewItem =~ /arboretum:session/", "group": "2_term" },
{ "command": "arboretum.hideSession", "when": "viewItem =~ /arboretum:session:.*discovered/", "group": "9_danger" },
{ "command": "arboretum.startGroupSession", "when": "viewItem == arboretum:group", "group": "inline" }
],
"commandPalette": [
{ "command": "arboretum.refresh", "when": "arboretum.connected" },
{ "command": "arboretum.signOut", "when": "arboretum.connected" },
{ "command": "arboretum.attachSession", "when": "false" },
{ "command": "arboretum.observeSession", "when": "false" },
{ "command": "arboretum.answerSession", "when": "false" },
{ "command": "arboretum.killSession", "when": "false" },
{ "command": "arboretum.hideSession", "when": "false" },
{ "command": "arboretum.resumeSession", "when": "false" },
{ "command": "arboretum.forkSession", "when": "false" },
{ "command": "arboretum.createWorktree", "when": "false" },
{ "command": "arboretum.commitWorktree", "when": "false" },
{ "command": "arboretum.pushWorktree", "when": "false" },
{ "command": "arboretum.promoteWorktree", "when": "false" },
{ "command": "arboretum.startSession", "when": "false" },
{ "command": "arboretum.startGroupSession", "when": "false" },
{ "command": "arboretum.revealWorktree", "when": "false" }
]
}
},
"scripts": {
"typecheck": "tsc -p . --noEmit",
"build": "npm run typecheck && node esbuild.mjs",
"dev": "node esbuild.mjs --watch",
"vscode:prepublish": "node esbuild.mjs",
"package": "vsce package --no-dependencies"
},
"devDependencies": {
"@arboretum/shared": "0.1.0",
"@types/node": "^22.10.0",
"@types/vscode": "^1.85.0",
"@types/ws": "^8.5.0",
"@vscode/vsce": "^3.2.0",
"esbuild": "^0.21.0",
"typescript": "^5.7.0",
"ws": "^8.18.0"
}
}

View File

@@ -0,0 +1,173 @@
// 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,
GroupSessionResponse,
GroupsListResponse,
MeResponse,
PromoteWorktreeRequest,
PushWorktreeRequest,
RepoBranchesResponse,
ReposListResponse,
SessionResponse,
SessionsListResponse,
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);
}
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);
}
// ---- sessions ----
createSession(body: CreateSessionRequest): Promise<SessionResponse> {
return this.request<SessionResponse>('POST', '/api/v1/sessions', body);
}
listSessions(includeHidden = false): Promise<SessionsListResponse> {
const q = includeHidden ? '?includeHidden=true' : '';
return this.request<SessionsListResponse>('GET', `/api/v1/sessions${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;
}
}

View File

@@ -0,0 +1,425 @@
// Client WebSocket multiplexé Node — portage du client web (packages/web/src/lib/ws-client.ts).
// UNE connexion, plusieurs canaux ; handshake hello/hello_ok, sub des topics, corrélation FIFO des
// 'attached', flow control par ACK (cumul d'octets PAR CANAL, remis à 0 à chaque RESYNC), reconnexion
// avec backoff. Différences vs web :
// - transport injecté (RawSocket) → testable sans réseau ; l'implémentation par défaut utilise `ws`
// avec l'en-tête `Authorization: Bearer` posé à l'upgrade (le navigateur, lui, envoie le cookie).
// - pas de callback de rendu (xterm) : on ACK les octets AU MOMENT où on les remet au sink (onDidWrite
// d'un Pseudoterminal émet de façon synchrone). Un ACK traînant débouncé flushe le reliquat < 64 Ko.
import {
BINARY_FRAME,
FLOW,
PROTOCOL_VERSION,
decodeBinaryFrame,
type ClientMessage,
type ServerMessage,
} from '@arboretum/shared';
import { wsUrlFromBase } from '../config.js';
export type WsStatus = 'idle' | 'connecting' | 'open' | 'reconnecting';
export type DetachReason = 'client' | 'session_exit' | 'replaced';
export type SessionEvent = Extract<ServerMessage, { type: 'session_update' | 'session_exit' }>;
export type WorktreeEvent = Extract<ServerMessage, { type: 'repo_update' | 'repo_removed' | 'worktree_update' | 'worktree_removed' }>;
export type GroupEvent = Extract<ServerMessage, { type: 'group_update' | 'group_removed' }>;
/** Sink d'un canal : reçoit les octets BRUTS (le décodage UTF-8 est délégué au SessionBridge). */
export interface AttachmentSink {
data(payload: Uint8Array): void;
reset(): void;
detached(reason: DetachReason): void;
controlChanged(controlling: boolean): void;
}
export interface AttachOptions {
sessionId: string;
mode: 'interactive' | 'observer';
cols: number;
rows: number;
sink: AttachmentSink;
}
/** Transport minimal — abstrait pour les tests ; l'impl par défaut enveloppe `ws`. */
export interface RawSocket {
send(data: string): void;
close(): void;
onOpen(cb: () => void): void;
onText(cb: (text: string) => void): void;
onBinary(cb: (data: Uint8Array) => void): void;
onClose(cb: () => void): void;
onError(cb: (err: Error) => void): void;
}
export type SocketFactory = (wsUrl: string, token: string) => RawSocket;
const BACKOFF_MIN_MS = 500;
const BACKOFF_MAX_MS = 10_000;
export class Attachment {
channel = -1;
controlling = false;
closed = false;
cols: number;
rows: number;
epoch = 0;
processedBytes = 0;
lastAckBytes = 0;
trailingAckTimer: ReturnType<typeof setTimeout> | null = null;
pending: { resolve: (a: Attachment) => void; reject: (err: Error) => void } | null = null;
constructor(
private readonly client: ArbWsClient,
readonly sessionId: string,
readonly mode: 'interactive' | 'observer',
readonly sink: AttachmentSink,
cols: number,
rows: number,
) {
this.cols = cols;
this.rows = rows;
}
sendStdin(data: string): void {
if (this.closed || this.channel < 0) return;
this.client.sendControl({ type: 'stdin', channel: this.channel, data });
}
/** Répond à un dialogue Claude sans clavier ; le serveur traduit en keystrokes. */
answer(action: 'select' | 'confirm' | 'deny', optionN?: number): void {
if (this.closed || this.channel < 0) return;
this.client.sendControl(
action === 'select' && optionN !== undefined
? { type: 'answer', channel: this.channel, action, optionN }
: { type: 'answer', channel: this.channel, action },
);
}
resize(cols: number, rows: number): void {
this.cols = cols;
this.rows = rows;
if (this.closed || this.channel < 0 || !this.controlling) return;
this.client.sendControl({ type: 'resize', channel: this.channel, cols, rows });
}
detach(): void {
if (this.closed) return;
this.closed = true;
this.pending = null;
this.client.releaseAttachment(this);
}
}
export interface ArbWsClientOptions {
socketFactory: SocketFactory;
onStatus?: (status: WsStatus) => void;
onSession?: (e: SessionEvent) => void;
onWorktree?: (e: WorktreeEvent) => void;
onGroup?: (e: GroupEvent) => void;
/** appelé au premier hello_ok après (re)connexion → re-seed du store via REST. */
onReady?: () => void;
log?: (msg: string) => void;
}
export class ArbWsClient {
status: WsStatus = 'idle';
private baseUrl = '';
private token = '';
private socket: RawSocket | null = null;
private ready = false;
private stopped = true;
private backoffMs = BACKOFF_MIN_MS;
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
private readonly attachments = new Set<Attachment>();
private readonly byChannel = new Map<number, Attachment>();
private awaitingAttached: Attachment[] = [];
constructor(private readonly opts: ArbWsClientOptions) {}
/** (Re)configure l'URL/token ; si la connexion était active, elle est relancée. */
configure(baseUrl: string, token: string): void {
const wasActive = !this.stopped;
this.baseUrl = baseUrl;
this.token = token;
if (wasActive) {
this.hardReset();
this.connect();
}
}
connect(): void {
this.stopped = false;
if (this.socket || this.reconnectTimer) return;
if (!this.token) return; // pas authentifié : on n'ouvre rien
this.setStatus('connecting');
this.openSocket();
}
disconnect(): void {
this.stopped = true;
this.hardReset();
this.setStatus('idle');
}
/** résout sur le prochain 'attached' corrélé ; rejette si la session est introuvable/terminée */
attach(opts: AttachOptions): Promise<Attachment> {
const att = new Attachment(this, opts.sessionId, opts.mode, opts.sink, opts.cols, opts.rows);
const promise = new Promise<Attachment>((resolve, reject) => {
att.pending = { resolve, reject };
});
this.attachments.add(att);
this.connect();
if (this.ready) this.sendAttach(att);
return promise;
}
sendControl(msg: ClientMessage): void {
if (!this.ready || !this.socket) return;
try {
this.socket.send(JSON.stringify(msg));
} catch {
/* socket en cours de fermeture : la reconnexion rejouera */
}
}
releaseAttachment(att: Attachment): void {
this.attachments.delete(att);
if (att.trailingAckTimer) {
clearTimeout(att.trailingAckTimer);
att.trailingAckTimer = null;
}
if (att.channel >= 0) {
this.byChannel.delete(att.channel);
this.sendControl({ type: 'detach', channel: att.channel });
att.channel = -1;
}
}
// ---- interne ----
private setStatus(s: WsStatus): void {
this.status = s;
this.opts.onStatus?.(s);
}
/** ferme la socket courante et invalide tous les états sans toucher au flag stopped. */
private hardReset(): void {
this.clearReconnectTimer();
const socket = this.socket;
this.socket = null;
this.ready = false;
for (const att of this.attachments) {
if (att.trailingAckTimer) {
clearTimeout(att.trailingAckTimer);
att.trailingAckTimer = null;
}
att.pending?.reject(new Error('disconnected'));
att.pending = null;
att.closed = true;
att.sink.detached('client');
}
this.attachments.clear();
this.byChannel.clear();
this.awaitingAttached = [];
socket?.close();
}
private openSocket(): void {
const socket = this.opts.socketFactory(wsUrlFromBase(this.baseUrl), this.token);
this.socket = socket;
socket.onOpen(() => {
const hello: ClientMessage = { type: 'hello', protocol: PROTOCOL_VERSION };
socket.send(JSON.stringify(hello));
});
socket.onText((text) => this.handleText(text));
socket.onBinary((data) => this.handleBinary(data));
socket.onClose(() => this.handleClose(socket));
socket.onError((err) => this.opts.log?.(`ws error: ${err.message}`));
}
private handleClose(socket: RawSocket): void {
if (this.socket !== socket) return;
this.socket = null;
this.ready = false;
this.byChannel.clear();
this.awaitingAttached = [];
for (const att of this.attachments) {
att.channel = -1;
att.epoch += 1;
if (att.trailingAckTimer) {
clearTimeout(att.trailingAckTimer);
att.trailingAckTimer = null;
}
}
if (this.stopped) {
this.setStatus('idle');
return;
}
this.setStatus('reconnecting');
this.scheduleReconnect();
}
private scheduleReconnect(): void {
this.clearReconnectTimer();
this.reconnectTimer = setTimeout(() => {
this.reconnectTimer = null;
if (!this.stopped) this.openSocket();
}, this.backoffMs);
this.backoffMs = Math.min(this.backoffMs * 2, BACKOFF_MAX_MS);
}
private clearReconnectTimer(): void {
if (this.reconnectTimer !== null) {
clearTimeout(this.reconnectTimer);
this.reconnectTimer = null;
}
}
private sendAttach(att: Attachment): void {
this.awaitingAttached.push(att);
this.sendControl({ type: 'attach', sessionId: att.sessionId, mode: att.mode, cols: att.cols, rows: att.rows });
}
private handleText(text: string): void {
let msg: ServerMessage;
try {
msg = JSON.parse(text) as ServerMessage;
} catch {
return;
}
this.handleServerMessage(msg);
}
private handleBinary(data: Uint8Array): void {
if (data.byteLength < BINARY_FRAME.HEADER_BYTES) return;
const frame = decodeBinaryFrame(data);
const att = this.byChannel.get(frame.channel);
if (!att || att.closed) return;
if (frame.type === BINARY_FRAME.RESYNC) {
// le serveur repart de sentBytes=0 : reset terminal, replay, compteurs à zéro (le replay ne compte pas)
att.epoch += 1;
att.processedBytes = 0;
att.lastAckBytes = 0;
att.sink.reset();
if (frame.payload.byteLength > 0) att.sink.data(frame.payload);
this.scheduleTrailingAck(att, att.epoch);
return;
}
if (frame.type !== BINARY_FRAME.OUTPUT) return;
// Émission synchrone vers le sink (onDidWrite) → on ACK directement les octets remis.
const length = frame.payload.byteLength;
att.sink.data(frame.payload);
if (att.channel < 0) return;
att.processedBytes += length;
if (att.processedBytes - att.lastAckBytes >= FLOW.ACK_EVERY_BYTES) {
att.lastAckBytes = att.processedBytes;
this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes });
}
// Filet : flushe le reliquat < ACK_EVERY_BYTES pour que le serveur sorte toujours de pause.
this.scheduleTrailingAck(att, att.epoch);
}
private scheduleTrailingAck(att: Attachment, epoch: number): void {
if (att.trailingAckTimer) clearTimeout(att.trailingAckTimer);
att.trailingAckTimer = setTimeout(() => {
att.trailingAckTimer = null;
if (att.closed || att.epoch !== epoch || att.channel < 0) return;
if (att.processedBytes > att.lastAckBytes) {
att.lastAckBytes = att.processedBytes;
this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes });
}
}, 200);
}
private handleServerMessage(msg: ServerMessage): void {
switch (msg.type) {
case 'hello_ok': {
this.ready = true;
this.backoffMs = BACKOFF_MIN_MS;
this.setStatus('open');
this.sendControl({ type: 'sub', topics: ['sessions', 'worktrees', 'groups'] });
for (const att of this.attachments) {
if (!att.closed) this.sendAttach(att);
}
this.opts.onReady?.();
return;
}
case 'attached': {
const att = this.awaitingAttached.shift();
if (!att) return;
if (att.closed) {
this.sendControl({ type: 'detach', channel: msg.channel });
return;
}
const wasControlling = att.controlling;
att.channel = msg.channel;
att.controlling = msg.controlling;
this.byChannel.set(msg.channel, att);
if (att.pending) {
att.pending.resolve(att);
att.pending = null;
} else if (wasControlling !== msg.controlling) {
att.sink.controlChanged(msg.controlling);
}
return;
}
case 'detached': {
const att = this.byChannel.get(msg.channel);
if (!att) return;
this.byChannel.delete(msg.channel);
att.channel = -1;
if (msg.reason === 'client') return;
att.closed = true;
this.attachments.delete(att);
att.sink.detached(msg.reason);
return;
}
case 'control_changed': {
const att = this.byChannel.get(msg.channel);
if (!att || att.closed) return;
att.controlling = msg.controlling;
att.sink.controlChanged(msg.controlling);
return;
}
case 'session_update':
case 'session_exit':
this.opts.onSession?.(msg);
return;
case 'repo_update':
case 'repo_removed':
case 'worktree_update':
case 'worktree_removed':
this.opts.onWorktree?.(msg);
return;
case 'group_update':
case 'group_removed':
this.opts.onGroup?.(msg);
return;
case 'error': {
if (msg.channel !== undefined) {
this.opts.log?.(`channel ${msg.channel}: ${msg.code}${msg.message}`);
return;
}
if ((msg.code === 'NOT_FOUND' || msg.code === 'SESSION_EXITED') && this.awaitingAttached.length > 0) {
const att = this.awaitingAttached.shift();
if (!att) return;
this.attachments.delete(att);
if (att.pending) {
att.pending.reject(new Error(msg.code));
att.pending = null;
} else if (!att.closed) {
att.closed = true;
att.sink.detached('session_exit');
}
return;
}
this.opts.log?.(`${msg.code}${msg.message}`);
return;
}
case 'pong':
return;
}
}
}

View File

@@ -0,0 +1,33 @@
// Implémentation par défaut du transport RawSocket, basée sur le paquet `ws` (Node).
// L'auth se fait en posant `Authorization: Bearer <token>` dans les en-têtes de l'upgrade HTTP
// (un navigateur enverrait le cookie ; un client Node passe le token ici). Isolé du cœur ws-client
// pour que celui-ci reste injectable et testable sans réseau.
import WebSocket, { type RawData } from 'ws';
import type { RawSocket, SocketFactory } from './ws-client.js';
/** Normalise un RawData (Buffer | ArrayBuffer | Buffer[]) en Uint8Array copiée (offset 0). */
function toUint8(data: RawData): Uint8Array {
if (Array.isArray(data)) return new Uint8Array(Buffer.concat(data));
if (data instanceof ArrayBuffer) return new Uint8Array(data);
// Buffer (sous-classe de Uint8Array) : copie pour ne pas dépendre du buffer poolé réutilisé par ws.
return new Uint8Array(data);
}
export const wsSocketFactory: SocketFactory = (wsUrl: string, token: string): RawSocket => {
const socket = new WebSocket(wsUrl, { headers: { Authorization: `Bearer ${token}` } });
return {
send: (d) => socket.send(d),
close: () => socket.close(),
onOpen: (cb) => socket.on('open', cb),
onText: (cb) =>
socket.on('message', (data: RawData, isBinary: boolean) => {
if (!isBinary) cb(toUint8(data).toString());
}),
onBinary: (cb) =>
socket.on('message', (data: RawData, isBinary: boolean) => {
if (isBinary) cb(toUint8(data));
}),
onClose: (cb) => socket.on('close', () => cb()),
onError: (cb) => socket.on('error', (err: Error) => cb(err)),
};
};

View File

@@ -0,0 +1,22 @@
// Stockage du token dans le SecretStorage de VS Code (chiffré par l'hôte). Les tokens du daemon sont
// stockés hashés côté serveur et le bootstrap ne s'affiche qu'une fois → on ne peut pas « lire » un
// token existant : l'utilisateur le saisit une fois (commande Sign In), on le conserve ici.
import type { SecretStorage } from 'vscode';
const TOKEN_KEY = 'arboretum.token';
export class Auth {
constructor(private readonly secrets: SecretStorage) {}
getToken(): Thenable<string | undefined> {
return this.secrets.get(TOKEN_KEY);
}
storeToken(token: string): Thenable<void> {
return this.secrets.store(TOKEN_KEY, token);
}
clearToken(): Thenable<void> {
return this.secrets.delete(TOKEN_KEY);
}
}

View File

@@ -0,0 +1,299 @@
// Enregistrement de toutes les commandes de l'extension. Les handlers contextuels reçoivent le nœud
// d'arbre cliqué (ou via menu) et narrowent dessus ; les mutations passent par le RestClient et l'état
// se met à jour via les events WS (pas de refetch manuel, sauf hide qui sort la session de la liste).
import * as vscode from 'vscode';
import type { GroupSummary, RepoSummary, SessionSummary, WorktreeSummary } from '@arboretum/shared';
import { RestError, type RestClient } from './api/rest-client.js';
import type { ArbWsClient, AttachmentSink } from './api/ws-client.js';
import type { Store } from './state/store.js';
import type { SessionTerminalManager } from './terminal/session-pty.js';
import type { WorkspaceMapper } from './workspace.js';
import type { AnyNode } from './views/nodes.js';
export interface CommandDeps {
store: Store;
rest: RestClient;
ws: ArbWsClient;
terminals: SessionTerminalManager;
workspace: WorkspaceMapper;
signIn(): Promise<void>;
signOut(): Promise<void>;
reseed(): Promise<void>;
}
// ---- extraction des nœuds ----
function asSession(node: AnyNode | undefined): SessionSummary | undefined {
return node && (node.kind === 'session' || node.kind === 'group-session') ? node.session : undefined;
}
function asWorktree(node: AnyNode | undefined): { repoId: string; worktree: WorktreeSummary } | undefined {
return node?.kind === 'worktree' ? { repoId: node.repoId, worktree: node.worktree } : undefined;
}
function asRepo(node: AnyNode | undefined): RepoSummary | undefined {
return node?.kind === 'repo' ? node.repo : undefined;
}
function asGroup(node: AnyNode | undefined): GroupSummary | undefined {
return node?.kind === 'group' ? node.group : undefined;
}
/** Exécute une action en affichant proprement une erreur REST (code + message serveur). */
async function run(label: string, fn: () => Promise<void>): Promise<void> {
try {
await fn();
} catch (err) {
const msg = err instanceof RestError ? `${err.code}: ${err.message}` : (err as Error).message;
void vscode.window.showErrorMessage(`Arboretum — ${label}: ${msg}`);
}
}
/** Répond à un dialogue : via le terminal ouvert si présent, sinon par une attache éphémère. */
export async function answerSession(
deps: CommandDeps,
session: SessionSummary,
action: 'select' | 'confirm' | 'deny',
optionN?: number,
): Promise<void> {
const open = deps.terminals.getBridge(session.id);
if (open) {
open.answer(action, optionN);
return;
}
const noop: AttachmentSink = { data: () => {}, reset: () => {}, detached: () => {}, controlChanged: () => {} };
const att = await deps.ws.attach({ sessionId: session.id, mode: 'interactive', cols: 80, rows: 24, sink: noop });
att.answer(action, optionN);
setTimeout(() => att.detach(), 600); // laisse le serveur traiter avant de fermer le canal éphémère
}
export function registerCommands(context: vscode.ExtensionContext, deps: CommandDeps): void {
const { store, rest, terminals, workspace } = deps;
const cmd = (id: string, handler: (...args: unknown[]) => unknown): void => {
context.subscriptions.push(vscode.commands.registerCommand(id, handler));
};
// ---- auth / global ----
cmd('arboretum.signIn', () => deps.signIn());
cmd('arboretum.signOut', () => deps.signOut());
cmd('arboretum.refresh', () => run('refresh', () => deps.reseed()));
cmd('arboretum.openDashboard', () => {
void vscode.env.openExternal(vscode.Uri.parse(rest.url));
});
// ---- terminaux (Phase B) ----
cmd('arboretum.attachSession', (node) => {
const s = asSession(node as AnyNode);
if (s) terminals.open(s, 'interactive');
});
cmd('arboretum.observeSession', (node) => {
const s = asSession(node as AnyNode);
if (s) terminals.open(s, 'observer');
});
cmd('arboretum.showWaiting', async () => {
const waiting = store.waitingSessions();
if (waiting.length === 0) {
void vscode.window.showInformationMessage('Arboretum: no session waiting.');
return;
}
const pick = await vscode.window.showQuickPick(
waiting.map((s) => ({ label: s.title?.trim() || s.command, description: s.waitingFor ?? s.cwd, session: s })),
{ placeHolder: 'Sessions waiting for input' },
);
if (pick) terminals.open(pick.session, 'interactive');
});
// ---- answer (Phase C) ----
cmd('arboretum.answerSession', async (node) => {
const s = asSession(node as AnyNode);
if (!s) return;
const dialogOptions = s.dialog?.options ?? [];
if (dialogOptions.length > 0) {
const pick = await vscode.window.showQuickPick(
dialogOptions.map((o) => ({ label: o.label, option: o })),
{ placeHolder: s.dialog?.waitingFor ?? 'Choose an option' },
);
if (pick) await run('answer', () => answerSession(deps, s, 'select', pick.option.n));
return;
}
const pick = await vscode.window.showQuickPick(['Yes', 'No'], { placeHolder: s.waitingFor ?? 'Answer the prompt' });
if (pick) await run('answer', () => answerSession(deps, s, pick === 'Yes' ? 'confirm' : 'deny'));
});
// ---- sessions ----
cmd('arboretum.killSession', async (node) => {
const s = asSession(node as AnyNode);
if (!s) return;
const ok = await vscode.window.showWarningMessage(`Kill session "${s.title?.trim() || s.command}"?`, { modal: true }, 'Kill');
if (ok === 'Kill') await run('kill', async () => void (await rest.killSession(s.id)));
});
cmd('arboretum.hideSession', (node) => {
const s = asSession(node as AnyNode);
if (!s) return;
void run('hide', async () => {
await rest.hideSession(s.id);
await deps.reseed(); // la session masquée sort de la liste (listSessions sans includeHidden)
});
});
cmd('arboretum.resumeSession', (node) => {
const s = asSession(node as AnyNode);
if (!s) return;
void run('resume', async () => {
const res = await rest.resumeSession(s.id);
terminals.open(res.session, 'interactive');
});
});
cmd('arboretum.forkSession', (node) => {
const s = asSession(node as AnyNode);
if (!s) return;
void run('fork', async () => {
const res = await rest.forkSession(s.id);
terminals.open(res.session, 'interactive');
});
});
// ---- worktrees (Phase C) ----
cmd('arboretum.createWorktree', (node) => {
const repo = asRepo(node as AnyNode);
if (repo) void createWorktreeFlow(deps, repo.id);
});
cmd('arboretum.commitWorktree', (node) => {
const wt = asWorktree(node as AnyNode);
if (!wt) return;
void run('commit', async () => {
const message = await vscode.window.showInputBox({ prompt: 'Commit message', placeHolder: 'Describe your changes' });
if (!message) return;
await rest.commitWorktree(wt.repoId, { path: wt.worktree.path, message });
void vscode.window.showInformationMessage('Arboretum: committed.');
});
});
cmd('arboretum.pushWorktree', (node) => {
const wt = asWorktree(node as AnyNode);
if (!wt) return;
void vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: 'Arboretum: pushing…' }, () =>
run('push', async () => {
await rest.pushWorktree(wt.repoId, { path: wt.worktree.path });
void vscode.window.showInformationMessage('Arboretum: pushed.');
}),
);
});
cmd('arboretum.promoteWorktree', (node) => {
const wt = asWorktree(node as AnyNode);
if (wt) void promoteWorktreeFlow(deps, wt.repoId, wt.worktree);
});
// ---- démarrage de session ----
cmd('arboretum.startSession', (node) => {
const wt = asWorktree(node as AnyNode);
if (wt) {
void run('start session', async () => {
const res = await rest.createSession({ cwd: wt.worktree.path, command: 'claude' });
terminals.open(res.session, 'interactive');
});
return;
}
const repo = asRepo(node as AnyNode);
if (repo) {
void run('start session', async () => {
const res = await rest.startRepoSession(repo.id, { command: 'claude' });
terminals.open(res.session, 'interactive');
});
}
});
cmd('arboretum.startGroupSession', (node) => {
const group = asGroup(node as AnyNode);
if (group) void startGroupSessionFlow(deps, group);
});
// ---- conscience du workspace (Phase D) ----
cmd('arboretum.startSessionHere', () => {
const repoId = workspace.currentRepoId();
if (!repoId) {
void vscode.window.showWarningMessage('Arboretum: the current folder is not a known repo/worktree.');
return;
}
const folder = vscode.workspace.workspaceFolders?.[0];
if (!folder) return;
void run('start session', async () => {
const res = await rest.createSession({ cwd: folder.uri.fsPath, command: 'claude' });
terminals.open(res.session, 'interactive');
});
});
cmd('arboretum.createWorktreeHere', () => {
const repoId = workspace.currentRepoId();
if (!repoId) {
void vscode.window.showWarningMessage('Arboretum: the current folder is not a known repo.');
return;
}
void createWorktreeFlow(deps, repoId);
});
cmd('arboretum.revealWorktree', () => workspace.revealCurrent());
}
// ---- flows interactifs ----
async function createWorktreeFlow(deps: CommandDeps, repoId: string): Promise<void> {
await run('create worktree', async () => {
const branches = await deps.rest.getBranches(repoId);
const existing = [...new Set([...branches.local, ...branches.remote.map((b) => b.replace(/^origin\//, ''))])].sort();
const NEW = '$(add) New branch…';
const items = [NEW, ...existing];
const choice = await vscode.window.showQuickPick(items, { placeHolder: 'Branch for the new worktree (auto: checkout if exists, else create)' });
if (!choice) return;
let branch = choice;
if (choice === NEW) {
const input = await vscode.window.showInputBox({ prompt: 'New branch name' });
if (!input) return;
branch = input.trim();
}
if (!branch) return;
const res = await deps.rest.createWorktree(repoId, { branch, mode: 'auto' });
void vscode.window.showInformationMessage(`Arboretum: worktree ${res.action} for "${branch}".`);
});
}
async function promoteWorktreeFlow(deps: CommandDeps, repoId: string, worktree: WorktreeSummary): Promise<void> {
const label = worktree.branch ?? worktree.path;
const confirm = await vscode.window.showWarningMessage(
`Promote "${label}" to the repo's main checkout? The worktree is removed (branch kept).`,
{ modal: true },
'Promote',
);
if (confirm !== 'Promote') return;
try {
await deps.rest.promoteWorktree(repoId, { path: worktree.path });
void vscode.window.showInformationMessage(`Arboretum: "${label}" promoted to main.`);
} catch (err) {
if (err instanceof RestError && err.status === 409) {
const force = await vscode.window.showWarningMessage(
`Arboretum: working tree is dirty (${err.message}). Promote anyway?`,
{ modal: true },
'Force promote',
);
if (force === 'Force promote') {
await run('promote', async () => {
await deps.rest.promoteWorktree(repoId, { path: worktree.path, force: true });
void vscode.window.showInformationMessage(`Arboretum: "${label}" promoted (forced).`);
});
}
return;
}
const msg = err instanceof RestError ? `${err.code}: ${err.message}` : (err as Error).message;
void vscode.window.showErrorMessage(`Arboretum — promote: ${msg}`);
}
}
async function startGroupSessionFlow(deps: CommandDeps, group: GroupSummary): Promise<void> {
await run('start group session', async () => {
const branch = await vscode.window.showInputBox({
prompt: `Branch to cover in each repo of "${group.label}" (leave empty for the main checkouts)`,
placeHolder: 'feature/cross-repo (optional)',
});
if (branch === undefined) return; // annulé (chaîne vide = checkouts principaux)
const body = branch.trim() ? { command: 'claude' as const, branch: branch.trim() } : { command: 'claude' as const };
const res = await deps.rest.createGroupSession(group.id, body);
deps.terminals.open(res.session, 'interactive');
if (res.skipped.length > 0) {
void vscode.window.showWarningMessage(
`Arboretum: ${res.skipped.length} repo(s) skipped — ${res.skipped.map((s) => s.reason).join('; ')}`,
);
}
});
}

View File

@@ -0,0 +1,21 @@
// Lecture des réglages `arboretum.*` — module pur (aucun import vscode) pour rester testable.
// L'extension fournit un `ConfigSnapshot` lu depuis workspace.getConfiguration ; ce module
// normalise/dérive les valeurs (notamment l'URL WebSocket à partir de l'URL HTTP).
export interface ConfigSnapshot {
url: string;
showExternalSessions: boolean;
notifyOnWaiting: boolean;
}
/** Base REST normalisée (sans slash final) ; `http://127.0.0.1:7317` par défaut. */
export function normalizeBaseUrl(url: string): string {
const trimmed = (url || '').trim().replace(/\/+$/, '');
return trimmed || 'http://127.0.0.1:7317';
}
/** Dérive l'URL du endpoint WebSocket `/ws` (http→ws, https→wss). */
export function wsUrlFromBase(baseUrl: string): string {
const base = normalizeBaseUrl(baseUrl);
return `${base.replace(/^http/, 'ws')}/ws`;
}

View File

@@ -0,0 +1,152 @@
// Point d'entrée de l'extension : câble auth ↔ REST ↔ WS ↔ store ↔ surfaces natives (arbres, terminaux,
// status bar, notifications, workspace). C'est le SEUL gros consommateur de l'API vscode avec les vues ;
// toute la logique réutilisable (protocole, état) vit dans des modules purs testables.
import * as vscode from 'vscode';
import { Auth } from './auth/auth.js';
import { RestClient } from './api/rest-client.js';
import { ArbWsClient } from './api/ws-client.js';
import { wsSocketFactory } from './api/ws-socket.js';
import { Store } from './state/store.js';
import { SessionTerminalManager } from './terminal/session-pty.js';
import { ReposTreeProvider } from './views/repos-tree.js';
import { GroupsTreeProvider } from './views/groups-tree.js';
import { StatusBar } from './status-bar.js';
import { WaitingNotifier } from './notifications.js';
import { WorkspaceMapper } from './workspace.js';
import { answerSession, registerCommands } from './commands.js';
function readUrl(): string {
return vscode.workspace.getConfiguration('arboretum').get<string>('url', 'http://127.0.0.1:7317');
}
function readShowExternal(): boolean {
return vscode.workspace.getConfiguration('arboretum').get<boolean>('showExternalSessions', false);
}
function readNotify(): boolean {
return vscode.workspace.getConfiguration('arboretum').get<boolean>('notifyOnWaiting', true);
}
async function setConnectedContext(connected: boolean): Promise<void> {
await vscode.commands.executeCommand('setContext', 'arboretum.connected', connected);
}
export async function activate(context: vscode.ExtensionContext): Promise<void> {
const log = vscode.window.createOutputChannel('Arboretum');
context.subscriptions.push(log);
const auth = new Auth(context.secrets);
const store = new Store();
store.showExternalSessions = readShowExternal();
const rest = new RestClient({ baseUrl: readUrl() });
const reseed = async (): Promise<void> => {
try {
await store.seed(rest);
} catch (err) {
log.appendLine(`seed failed: ${(err as Error).message}`);
}
};
const statusBar = new StatusBar(store);
context.subscriptions.push(statusBar);
const ws = new ArbWsClient({
socketFactory: wsSocketFactory,
onSession: (e) => store.applySession(e),
onWorktree: (e) => store.applyWorktree(e),
onGroup: (e) => store.applyGroup(e),
onReady: () => void reseed(),
onStatus: (s) => {
const connected = s === 'open';
statusBar.setConnected(connected);
void setConnectedContext(connected);
},
log: (m) => log.appendLine(m),
});
const terminals = new SessionTerminalManager(ws);
context.subscriptions.push({ dispose: () => terminals.dispose() });
const reposProvider = new ReposTreeProvider(store);
const groupsProvider = new GroupsTreeProvider(store);
const reposView = vscode.window.createTreeView('arboretum.repos', { treeDataProvider: reposProvider, showCollapseAll: true });
const groupsView = vscode.window.createTreeView('arboretum.groups', { treeDataProvider: groupsProvider, showCollapseAll: true });
context.subscriptions.push(reposView, groupsView);
const workspace = new WorkspaceMapper(store, reposView, reposProvider);
context.subscriptions.push(workspace);
const signIn = async (): Promise<void> => {
const token = await vscode.window.showInputBox({
prompt: `Arboretum token for ${rest.url}`,
password: true,
ignoreFocusOut: true,
placeHolder: 'arb_… (printed once on first daemon start, or created in Settings → Tokens)',
});
if (!token) return;
// valide le token avant de le stocker (sonde isolée pour ne pas polluer le client principal).
const probe = new RestClient({ baseUrl: rest.url, token });
try {
await probe.me();
} catch (err) {
void vscode.window.showErrorMessage(`Arboretum: sign in failed — ${(err as Error).message}`);
return;
}
await auth.storeToken(token);
rest.setToken(token);
ws.configure(rest.url, token);
ws.connect();
void vscode.window.showInformationMessage('Arboretum: connected.');
};
const signOut = async (): Promise<void> => {
await auth.clearToken();
rest.setToken(null);
ws.disconnect();
store.clear();
await setConnectedContext(false);
void vscode.window.showInformationMessage('Arboretum: signed out.');
};
registerCommands(context, { store, rest, ws, terminals, workspace, signIn, signOut, reseed });
// Notifications : ouvrir le terminal ou répondre Yes/No (réutilise le helper transient-attach).
const notifier = new WaitingNotifier(store, {
notifyEnabled: () => readNotify(),
openTerminal: (session) => terminals.open(session, 'interactive'),
answer: (session, action) => {
void answerSession({ store, rest, ws, terminals, workspace, signIn, signOut, reseed }, session, action).catch((err: Error) =>
log.appendLine(`answer failed: ${err.message}`),
);
},
});
context.subscriptions.push(notifier);
// Réglages à chaud : URL (reconfigure REST+WS), sessions externes (refiltre), notif (lu à la volée).
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(async (e) => {
if (e.affectsConfiguration('arboretum.url')) {
rest.setBaseUrl(readUrl());
const token = await auth.getToken();
if (token) ws.configure(rest.url, token);
}
if (e.affectsConfiguration('arboretum.showExternalSessions')) {
store.setShowExternalSessions(readShowExternal());
}
}),
);
// Connexion initiale si un token est déjà mémorisé.
await setConnectedContext(false);
const token = await auth.getToken();
if (token) {
rest.setToken(token);
ws.configure(rest.url, token);
ws.connect();
}
context.subscriptions.push({ dispose: () => ws.disconnect() });
}
export function deactivate(): void {
// tout est enregistré dans context.subscriptions → disposé par VS Code.
}

View File

@@ -0,0 +1,57 @@
// Notifications natives sur front montant d'une session vers `waiting` (doublonne utilement le Web
// Push, ici dans l'éditeur). Suit l'activité précédente par session pour ne notifier qu'à la transition,
// pas à chaque mise à jour. Actions : ouvrir le terminal, ou répondre Yes/No via la commande WS `answer`.
import * as vscode from 'vscode';
import type { SessionSummary } from '@arboretum/shared';
import type { Store } from './state/store.js';
export interface NotificationHooks {
notifyEnabled(): boolean;
openTerminal(session: SessionSummary): void;
answer(session: SessionSummary, action: 'confirm' | 'deny'): void;
}
export class WaitingNotifier implements vscode.Disposable {
/** dernière activité connue par session → détection du front montant vers 'waiting'. */
private readonly lastActivity = new Map<string, string | null | undefined>();
private readonly unsubscribe: () => void;
constructor(
private readonly store: Store,
private readonly hooks: NotificationHooks,
) {
this.unsubscribe = store.onDidChange(() => this.check());
}
private check(): void {
const sessions = this.store.allSessions();
const seen = new Set<string>();
for (const s of sessions) {
seen.add(s.id);
const prev = this.lastActivity.get(s.id);
const cur = s.live ? s.activity : null;
this.lastActivity.set(s.id, cur);
if (cur === 'waiting' && prev !== 'waiting' && prev !== undefined && this.hooks.notifyEnabled()) {
this.notify(s);
}
// prev === undefined : première observation (au seed) → on n'annonce pas l'historique.
}
for (const id of [...this.lastActivity.keys()]) if (!seen.has(id)) this.lastActivity.delete(id);
}
private notify(session: SessionSummary): void {
const title = session.title?.trim() || session.command;
const detail = session.waitingFor ? `${session.waitingFor}` : '';
void vscode.window
.showInformationMessage(`Arboretum: "${title}" is waiting for input${detail}`, 'Open Terminal', 'Yes', 'No')
.then((choice) => {
if (choice === 'Open Terminal') this.hooks.openTerminal(session);
else if (choice === 'Yes') this.hooks.answer(session, 'confirm');
else if (choice === 'No') this.hooks.answer(session, 'deny');
});
}
dispose(): void {
this.unsubscribe();
}
}

View File

@@ -0,0 +1,196 @@
// État mémoire de l'extension — module pur (aucun import vscode), testable.
// Seedé via REST au (re)connect, puis patché par les events WS. Émet onDidChange à chaque mutation ;
// les arbres / status bar / notifications s'y abonnent. Principe « groupe léger » : on ne corrèle pas
// les worktrees aux sessions via la liste embarquée (potentiellement périmée) mais par `cwd`, exactement
// comme `sessionsForCwd` côté serveur.
import type {
GroupSummary,
RepoSummary,
SessionSummary,
WorktreeSummary,
} from '@arboretum/shared';
import type { GroupEvent, SessionEvent, WorktreeEvent } from '../api/ws-client.js';
import type { RestClient } from '../api/rest-client.js';
/** Normalise un chemin absolu pour la corrélation (retire le slash final). */
function normPath(p: string): string {
return p.replace(/\/+$/, '') || '/';
}
export class Store {
private readonly repos = new Map<string, RepoSummary>();
/** worktrees par repo, indexés par chemin (clé stable). */
private readonly worktrees = new Map<string, Map<string, WorktreeSummary>>();
private readonly sessions = new Map<string, SessionSummary>();
private readonly groups = new Map<string, GroupSummary>();
private readonly listeners = new Set<() => void>();
/** affiche aussi les sessions externes (découvertes hors Arboretum). */
showExternalSessions = false;
onDidChange(cb: () => void): () => void {
this.listeners.add(cb);
return () => this.listeners.delete(cb);
}
/** Bascule l'affichage des sessions externes et notifie les abonnés (refiltre les arbres). */
setShowExternalSessions(value: boolean): void {
if (this.showExternalSessions === value) return;
this.showExternalSessions = value;
this.emit();
}
private emit(): void {
for (const cb of this.listeners) cb();
}
/** Charge tout l'état depuis le daemon (au premier hello_ok et à chaque reconnexion). */
async seed(rest: RestClient): Promise<void> {
const [repos, worktrees, sessions, groups] = await Promise.all([
rest.listRepos(),
rest.listWorktrees(),
rest.listSessions(false),
rest.listGroups(),
]);
this.repos.clear();
this.worktrees.clear();
this.sessions.clear();
this.groups.clear();
for (const r of repos.repos) this.repos.set(r.id, r);
for (const w of worktrees.worktrees) this.putWorktree(w);
for (const s of sessions.sessions) this.sessions.set(s.id, s);
for (const g of groups.groups) this.groups.set(g.id, g);
this.emit();
}
clear(): void {
this.repos.clear();
this.worktrees.clear();
this.sessions.clear();
this.groups.clear();
this.emit();
}
private putWorktree(w: WorktreeSummary): void {
let byPath = this.worktrees.get(w.repoId);
if (!byPath) {
byPath = new Map();
this.worktrees.set(w.repoId, byPath);
}
byPath.set(normPath(w.path), w);
// les sessions embarquées dans le worktree alimentent aussi la map sessions (état initial).
for (const s of w.sessions) if (!this.sessions.has(s.id)) this.sessions.set(s.id, s);
}
// ---- réducteurs d'events WS ----
applySession(e: SessionEvent): void {
if (e.type === 'session_update') {
this.sessions.set(e.session.id, e.session);
} else {
// session_exit : marque morte si connue (sinon ignore).
const prev = this.sessions.get(e.sessionId);
if (prev) this.sessions.set(e.sessionId, { ...prev, live: false, status: 'exited', exitCode: e.exitCode });
}
this.emit();
}
applyWorktree(e: WorktreeEvent): void {
switch (e.type) {
case 'repo_update':
this.repos.set(e.repo.id, e.repo);
break;
case 'repo_removed':
this.repos.delete(e.repoId);
this.worktrees.delete(e.repoId);
break;
case 'worktree_update':
this.putWorktree(e.worktree);
break;
case 'worktree_removed':
this.worktrees.get(e.repoId)?.delete(normPath(e.path));
break;
}
this.emit();
}
applyGroup(e: GroupEvent): void {
if (e.type === 'group_update') this.groups.set(e.group.id, e.group);
else this.groups.delete(e.groupId);
this.emit();
}
// ---- lecture ----
listRepos(): RepoSummary[] {
return [...this.repos.values()]
.filter((r) => !r.hidden && r.valid)
.sort((a, b) => a.label.localeCompare(b.label));
}
getRepo(id: string): RepoSummary | undefined {
return this.repos.get(id);
}
listWorktrees(repoId: string): WorktreeSummary[] {
const byPath = this.worktrees.get(repoId);
if (!byPath) return [];
// worktree principal en tête, puis tri par branche/chemin.
return [...byPath.values()].sort((a, b) => {
if (a.isMain !== b.isMain) return a.isMain ? -1 : 1;
return (a.branch ?? a.path).localeCompare(b.branch ?? b.path);
});
}
getWorktree(repoId: string, path: string): WorktreeSummary | undefined {
return this.worktrees.get(repoId)?.get(normPath(path));
}
/** sessions corrélées à un worktree par cwd (comme le serveur) ; filtre les externes selon le réglage. */
sessionsForWorktree(path: string): SessionSummary[] {
const wp = normPath(path);
return [...this.sessions.values()]
.filter((s) => normPath(s.cwd) === wp)
.filter((s) => this.showExternalSessions || s.source === 'managed')
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
}
getSession(id: string): SessionSummary | undefined {
return this.sessions.get(id);
}
listGroups(): GroupSummary[] {
return [...this.groups.values()].sort((a, b) => a.label.localeCompare(b.label));
}
getGroup(id: string): GroupSummary | undefined {
return this.groups.get(id);
}
/** sessions de groupe (couvrant plusieurs repos) attachées à un groupe donné. */
sessionsForGroup(groupId: string): SessionSummary[] {
return [...this.sessions.values()]
.filter((s) => s.groupId === groupId)
.filter((s) => this.showExternalSessions || s.source === 'managed')
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
}
/** sessions en attente d'input (activity === 'waiting') — pour la status bar et les notifications. */
waitingSessions(): SessionSummary[] {
return [...this.sessions.values()].filter((s) => s.live && s.activity === 'waiting');
}
allSessions(): SessionSummary[] {
return [...this.sessions.values()];
}
/** trouve le worktree dont le chemin == folderPath (mapping workspace). */
findWorktreeByPath(folderPath: string): { repoId: string; worktree: WorktreeSummary } | undefined {
const target = normPath(folderPath);
for (const [repoId, byPath] of this.worktrees) {
const wt = byPath.get(target);
if (wt) return { repoId, worktree: wt };
}
return undefined;
}
}

View File

@@ -0,0 +1,40 @@
// Status bar : compteur des sessions Claude en attente d'input (`activity === 'waiting'`).
// Clic → quick-pick des sessions en attente (commande arboretum.showWaiting). Masqué si déconnecté
// ou s'il n'y a rien en attente.
import * as vscode from 'vscode';
import type { Store } from './state/store.js';
export class StatusBar implements vscode.Disposable {
private readonly item: vscode.StatusBarItem;
private connected = false;
private readonly unsubscribe: () => void;
constructor(private readonly store: Store) {
this.item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
this.item.command = 'arboretum.showWaiting';
this.unsubscribe = store.onDidChange(() => this.update());
this.update();
}
setConnected(connected: boolean): void {
this.connected = connected;
this.update();
}
private update(): void {
const count = this.connected ? this.store.waitingSessions().length : 0;
if (count === 0) {
this.item.hide();
return;
}
this.item.text = `$(bell-dot) ${count}`;
this.item.tooltip = `Arboretum: ${count} session(s) waiting for input`;
this.item.color = new vscode.ThemeColor('statusBarItem.warningForeground');
this.item.show();
}
dispose(): void {
this.unsubscribe();
this.item.dispose();
}
}

View File

@@ -0,0 +1,85 @@
// Pont d'une session vers un terminal — module pur (aucun import vscode), testable.
// Le ws-client remet des octets BRUTS (un chunk PTY peut couper un caractère UTF-8 en frontière de
// frame, exactement comme côté web où xterm.write(Uint8Array) gérait le décodage). Ici la cible est
// un Pseudoterminal qui veut des `string` → on décode en streaming avec un TextDecoder, et on recrée
// le décodeur à chaque RESYNC pour ne pas traîner une séquence partielle au-delà d'un reset.
import type { ArbWsClient, Attachment, AttachmentSink, DetachReason } from '../api/ws-client.js';
/** Décodeur UTF-8 incrémental : conserve l'octet partiel d'une frontière de frame jusqu'au suivant. */
export class StreamingUtf8Decoder {
private decoder = new TextDecoder('utf-8');
decode(chunk: Uint8Array): string {
return this.decoder.decode(chunk, { stream: true });
}
/** Vide l'état partiel et repart à neuf (appelé sur RESYNC). */
reset(): void {
this.decoder = new TextDecoder('utf-8');
}
}
export interface SessionBridgeCallbacks {
/** texte décodé à écrire dans le terminal. */
onText(text: string): void;
/** RESYNC reçu : le terminal doit se réinitialiser (le texte de replay suit via onText). */
onReset(): void;
onDetached(reason: DetachReason): void;
onControlChanged(controlling: boolean): void;
}
/**
* Relie une session Arboretum à un terminal via le ws-client. Instancié par l'adaptateur
* Pseudoterminal ; reste pur pour être testable avec un faux ws-client.
*/
export class SessionBridge {
private attachment: Attachment | null = null;
private readonly decoder = new StreamingUtf8Decoder();
private detached = false;
constructor(
private readonly ws: ArbWsClient,
private readonly sessionId: string,
private readonly mode: 'interactive' | 'observer',
private readonly cb: SessionBridgeCallbacks,
) {}
/** Ouvre l'attache ; résout quand le canal est établi. Rejette si la session est introuvable. */
async open(cols: number, rows: number): Promise<void> {
const sink: AttachmentSink = {
data: (payload) => {
if (this.detached) return;
const text = this.decoder.decode(payload);
if (text.length > 0) this.cb.onText(text);
},
reset: () => {
this.decoder.reset();
this.cb.onReset();
},
detached: (reason) => {
this.detached = true;
this.cb.onDetached(reason);
},
controlChanged: (c) => this.cb.onControlChanged(c),
};
this.attachment = await this.ws.attach({ sessionId: this.sessionId, mode: this.mode, cols, rows, sink });
}
sendStdin(data: string): void {
this.attachment?.sendStdin(data);
}
resize(cols: number, rows: number): void {
this.attachment?.resize(cols, rows);
}
answer(action: 'select' | 'confirm' | 'deny', optionN?: number): void {
this.attachment?.answer(action, optionN);
}
close(): void {
this.detached = true;
this.attachment?.detach();
this.attachment = null;
}
}

View File

@@ -0,0 +1,86 @@
// Adaptateur vscode.Pseudoterminal : expose une session Arboretum comme un terminal NATIF de VS Code
// (rendu, scrollback, copier/coller, liens gratuits). C'est la pièce maîtresse de l'intégration —
// pas de xterm-in-webview. Le pont WS/décodage vit dans SessionBridge (pur) ; cet adaptateur ne fait
// que relier les events Pseudoterminal ↔ bridge.
import * as vscode from 'vscode';
import type { SessionSummary } from '@arboretum/shared';
import type { ArbWsClient } from '../api/ws-client.js';
import { SessionBridge } from './session-bridge.js';
const ANSI_RESET = '\x1bc'; // RIS : réinitialisation complète du terminal (avant le replay d'un RESYNC)
export class SessionTerminalManager {
private readonly terminals = new Map<string, vscode.Terminal>();
private readonly bridges = new Map<string, SessionBridge>();
constructor(private readonly ws: ArbWsClient) {}
/** Bridge d'une session si un terminal est ouvert (pour répondre à un dialogue sans ré-attacher). */
getBridge(sessionId: string): SessionBridge | undefined {
return this.bridges.get(sessionId);
}
/** Ouvre (ou ré-affiche) un terminal natif attaché à la session. */
open(session: SessionSummary, mode: 'interactive' | 'observer'): void {
const existing = this.terminals.get(session.id);
if (existing) {
existing.show();
return;
}
const writeEmitter = new vscode.EventEmitter<string>();
const closeEmitter = new vscode.EventEmitter<number | void>();
let bridge: SessionBridge | null = null;
const pty: vscode.Pseudoterminal = {
onDidWrite: writeEmitter.event,
onDidClose: closeEmitter.event,
open: (dims) => {
bridge = new SessionBridge(this.ws, session.id, mode, {
onText: (text) => writeEmitter.fire(text),
onReset: () => writeEmitter.fire(ANSI_RESET),
onDetached: () => {
writeEmitter.fire('\r\n\x1b[2m[arboretum: session ended]\x1b[0m\r\n');
closeEmitter.fire();
},
onControlChanged: (controlling) => {
if (!controlling && mode === 'interactive') {
writeEmitter.fire('\r\n\x1b[33m[arboretum: control lost — now observing]\x1b[0m\r\n');
}
},
});
this.bridges.set(session.id, bridge);
bridge.open(dims?.columns ?? 80, dims?.rows ?? 24).catch((err: Error) => {
writeEmitter.fire(`\r\n\x1b[31m[arboretum: cannot attach — ${err.message}]\x1b[0m\r\n`);
closeEmitter.fire();
});
},
close: () => {
bridge?.close();
this.bridges.delete(session.id);
this.terminals.delete(session.id);
},
handleInput: (data) => {
if (mode === 'interactive') bridge?.sendStdin(data);
},
setDimensions: (dims) => bridge?.resize(dims.columns, dims.rows),
};
const name = this.terminalName(session, mode);
const terminal = vscode.window.createTerminal({ name, pty, iconPath: new vscode.ThemeIcon('comment-discussion') });
this.terminals.set(session.id, terminal);
terminal.show();
}
private terminalName(session: SessionSummary, mode: 'interactive' | 'observer'): string {
const base = session.title?.trim() || session.cwd.split('/').pop() || session.command;
const prefix = mode === 'observer' ? '👁 ' : '';
return `${prefix}${base}`;
}
dispose(): void {
for (const t of this.terminals.values()) t.dispose();
this.terminals.clear();
this.bridges.clear();
}
}

View File

@@ -0,0 +1,64 @@
// Arbre Groups → repos membres → worktrees/sessions, plus les sessions de groupe (multi-repo, --add-dir)
// rattachées directement au groupe. Rafraîchi en temps réel (store.onDidChange).
import * as vscode from 'vscode';
import type { Store } from '../state/store.js';
import type { GroupsNode } from './nodes.js';
import { groupTreeItem, repoTreeItem, sessionTreeItem, worktreeTreeItem } from './tree-items.js';
export class GroupsTreeProvider implements vscode.TreeDataProvider<GroupsNode> {
private readonly changeEmitter = new vscode.EventEmitter<GroupsNode | undefined>();
readonly onDidChangeTreeData = this.changeEmitter.event;
constructor(private readonly store: Store) {
store.onDidChange(() => this.changeEmitter.fire(undefined));
}
getTreeItem(node: GroupsNode): vscode.TreeItem {
switch (node.kind) {
case 'group':
return groupTreeItem(node.group);
case 'repo':
return repoTreeItem(node.repo);
case 'worktree':
return worktreeTreeItem(node.worktree);
case 'group-session':
case 'session': {
const item = sessionTreeItem(node.session);
if (node.session.live) {
item.command = { command: 'arboretum.attachSession', title: 'Attach', arguments: [node] };
}
return item;
}
}
}
getChildren(node?: GroupsNode): GroupsNode[] {
if (!node) {
return this.store.listGroups().map((group) => ({ kind: 'group', group }));
}
if (node.kind === 'group') {
const children: GroupsNode[] = [];
// sessions de groupe (couvrant plusieurs repos) en tête
for (const session of this.store.sessionsForGroup(node.group.id)) {
children.push({ kind: 'group-session', session, groupId: node.group.id });
}
// puis les repos membres
for (const repoId of node.group.repoIds) {
const repo = this.store.getRepo(repoId);
if (repo) children.push({ kind: 'repo', repo });
}
return children;
}
if (node.kind === 'repo') {
return this.store
.listWorktrees(node.repo.id)
.map((worktree) => ({ kind: 'worktree', repoId: node.repo.id, worktree }));
}
if (node.kind === 'worktree') {
return this.store
.sessionsForWorktree(node.worktree.path)
.map((session) => ({ kind: 'session', session, repoId: node.repoId, worktreePath: node.worktree.path }));
}
return [];
}
}

View File

@@ -0,0 +1,33 @@
// Types de nœuds des arbres. Les handlers de commandes reçoivent un nœud (clic ou menu contextuel) et
// narrowent sur `kind`. Volontairement plats (données + discriminant) ; la hiérarchie parent/enfant est
// tenue par les providers (maps indexées) pour que reveal()/getParent fonctionnent.
import type { GroupSummary, RepoSummary, SessionSummary, WorktreeSummary } from '@arboretum/shared';
export interface RepoNode {
kind: 'repo';
repo: RepoSummary;
}
export interface WorktreeNode {
kind: 'worktree';
repoId: string;
worktree: WorktreeSummary;
}
export interface SessionNode {
kind: 'session';
session: SessionSummary;
repoId: string;
worktreePath: string;
}
export interface GroupNode {
kind: 'group';
group: GroupSummary;
}
export interface GroupSessionNode {
kind: 'group-session';
session: SessionSummary;
groupId: string;
}
export type ReposNode = RepoNode | WorktreeNode | SessionNode;
export type GroupsNode = GroupNode | RepoNode | WorktreeNode | SessionNode | GroupSessionNode;
export type AnyNode = ReposNode | GroupsNode;

Binary file not shown.

View File

@@ -0,0 +1,96 @@
// Helpers de construction des TreeItem (icônes d'état, labels, contextValue) partagés par les deux
// arbres (Repositories & Groups). Les `contextValue` pilotent les menus contextuels (cf. package.json) ;
// les regex y matchent des sous-chaînes → format stable `arboretum:session:<live|dead>[:discovered][:waiting]`.
import * as vscode from 'vscode';
import type { GroupSummary, RepoSummary, SessionSummary, WorktreeSummary } from '@arboretum/shared';
export function repoTreeItem(repo: RepoSummary): vscode.TreeItem {
const item = new vscode.TreeItem(repo.label, vscode.TreeItemCollapsibleState.Expanded);
item.id = `repo:${repo.id}`;
item.contextValue = 'arboretum:repo';
item.iconPath = new vscode.ThemeIcon('repo');
item.description = repo.defaultBranch ?? '';
item.tooltip = repo.path;
return item;
}
export function worktreeTreeItem(worktree: WorktreeSummary): vscode.TreeItem {
const label = worktree.branch ?? (worktree.detached ? '(detached)' : worktree.head.slice(0, 8));
const item = new vscode.TreeItem(label, vscode.TreeItemCollapsibleState.Expanded);
item.id = `wt:${worktree.path}`;
item.contextValue = 'arboretum:worktree';
item.iconPath = new vscode.ThemeIcon(worktree.isMain ? 'star-full' : 'git-branch');
item.description = worktreeStatus(worktree);
item.tooltip = worktree.path;
item.resourceUri = vscode.Uri.file(worktree.path);
return item;
}
function worktreeStatus(w: WorktreeSummary): string {
const parts: string[] = [];
if (w.isMain) parts.push('main');
if (w.git.ahead > 0) parts.push(`${w.git.ahead}`);
if (w.git.behind > 0) parts.push(`${w.git.behind}`);
if (w.git.dirtyCount > 0) parts.push(`${w.git.dirtyCount}`);
return parts.join(' ');
}
export function sessionContextValue(s: SessionSummary): string {
let v = `arboretum:session:${s.live ? 'live' : 'dead'}`;
if (s.source === 'discovered') v += ':discovered';
if (s.live && s.activity === 'waiting') v += ':waiting';
return v;
}
export function sessionTreeItem(s: SessionSummary): vscode.TreeItem {
const label = s.title?.trim() || s.command;
const item = new vscode.TreeItem(label, vscode.TreeItemCollapsibleState.None);
item.id = `session:${s.id}`;
item.contextValue = sessionContextValue(s);
item.iconPath = sessionIcon(s);
item.description = sessionDescription(s);
item.tooltip = sessionTooltip(s);
return item;
}
function sessionIcon(s: SessionSummary): vscode.ThemeIcon {
if (!s.live) return new vscode.ThemeIcon('circle-slash');
switch (s.activity) {
case 'waiting':
return new vscode.ThemeIcon('bell-dot', new vscode.ThemeColor('charts.yellow'));
case 'busy':
return new vscode.ThemeIcon('loading~spin');
case 'idle':
return new vscode.ThemeIcon('pass', new vscode.ThemeColor('charts.green'));
default:
return new vscode.ThemeIcon('terminal');
}
}
function sessionDescription(s: SessionSummary): string {
const parts: string[] = [];
// Affiche 'available' pour idle (cohérent avec le libellé web) ; l'enum reste 'idle' côté protocole.
if (s.live && s.activity) parts.push(s.activity === 'idle' ? 'available' : s.activity);
else if (!s.live) parts.push('exited');
if (s.source === 'discovered') parts.push('external');
if (s.groupId) parts.push('group');
if (s.waitingFor) parts.push(`${s.waitingFor}`);
return parts.join(' ');
}
function sessionTooltip(s: SessionSummary): string {
const lines = [`${s.command}${s.cwd}`, `status: ${s.status}${s.live ? ' (live)' : ''}`];
if (s.activity) lines.push(`activity: ${s.activity}`);
if (s.addedDirs && s.addedDirs.length > 0) lines.push(`added dirs: ${s.addedDirs.length}`);
return lines.join('\n');
}
export function groupTreeItem(group: GroupSummary): vscode.TreeItem {
const item = new vscode.TreeItem(group.label, vscode.TreeItemCollapsibleState.Collapsed);
item.id = `group:${group.id}`;
item.contextValue = 'arboretum:group';
item.iconPath = new vscode.ThemeIcon('folder-library');
item.description = `${group.repoIds.length} repos`;
if (group.description) item.tooltip = group.description;
return item;
}

View File

@@ -0,0 +1,57 @@
// Conscience du workspace (Phase D) : mappe les dossiers ouverts dans VS Code aux repos/worktrees
// Arboretum par égalité de chemin, met en évidence le worktree correspondant dans l'arbre, et fournit
// le repoId courant aux commandes contextuelles (« start session here », « create worktree here »).
import * as vscode from 'vscode';
import type { Store } from './state/store.js';
import type { ReposNode } from './views/nodes.js';
import type { ReposTreeProvider } from './views/repos-tree.js';
function normPath(p: string): string {
return p.replace(/\/+$/, '') || '/';
}
export class WorkspaceMapper implements vscode.Disposable {
private readonly disposables: vscode.Disposable[] = [];
constructor(
private readonly store: Store,
private readonly treeView: vscode.TreeView<ReposNode>,
private readonly provider: ReposTreeProvider,
) {
this.disposables.push(vscode.workspace.onDidChangeWorkspaceFolders(() => this.revealCurrent()));
// re-tente après chaque rafraîchissement de l'état (les worktrees arrivent après la connexion).
this.disposables.push({ dispose: store.onDidChange(() => this.revealCurrent()) });
}
/** repoId correspondant à un dossier ouvert (via worktree ou racine de repo), pour les actions contextuelles. */
currentRepoId(): string | undefined {
for (const folder of vscode.workspace.workspaceFolders ?? []) {
const p = normPath(folder.uri.fsPath);
const match = this.store.findWorktreeByPath(p);
if (match) return match.repoId;
const repo = this.store.listRepos().find((r) => normPath(r.path) === p);
if (repo) return repo.id;
}
return undefined;
}
/** Met en évidence dans l'arbre le worktree du premier dossier ouvert qui matche. */
revealCurrent(): void {
if (!this.treeView.visible) return;
for (const folder of vscode.workspace.workspaceFolders ?? []) {
const match = this.store.findWorktreeByPath(normPath(folder.uri.fsPath));
if (!match) continue;
const node = this.provider.worktreeNode(match.repoId, match.worktree.path);
if (node) {
void this.treeView.reveal(node, { select: false, focus: false, expand: true }).then(undefined, () => {
/* reveal est best-effort : un échec (nœud pas encore matérialisé) n'est pas bloquant */
});
return;
}
}
}
dispose(): void {
for (const d of this.disposables) d.dispose();
}
}

View File

@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest';
import { normalizeBaseUrl, wsUrlFromBase } from '../src/config.js';
describe('config', () => {
it('normalise la base URL (slash final, défaut)', () => {
expect(normalizeBaseUrl('http://127.0.0.1:7317/')).toBe('http://127.0.0.1:7317');
expect(normalizeBaseUrl(' http://host:8080// ')).toBe('http://host:8080');
expect(normalizeBaseUrl('')).toBe('http://127.0.0.1:7317');
});
it('dérive lURL WebSocket (/ws, http→ws, https→wss)', () => {
expect(wsUrlFromBase('http://127.0.0.1:7317')).toBe('ws://127.0.0.1:7317/ws');
expect(wsUrlFromBase('https://box.ts.net')).toBe('wss://box.ts.net/ws');
});
});

View File

@@ -0,0 +1,51 @@
import { describe, expect, it, vi } from 'vitest';
import { RestClient, RestError } from '../src/api/rest-client.js';
type Captured = { url: string; init: RequestInit };
function fakeFetch(response: { ok: boolean; status: number; body: unknown }, captured: Captured[]) {
return vi.fn(async (url: string, init: RequestInit) => {
captured.push({ url, init });
return {
ok: response.ok,
status: response.status,
json: async () => response.body,
} as unknown as Response;
}) as unknown as typeof fetch;
}
describe('RestClient', () => {
it('appelle /api/v1/auth/me avec le header Bearer', async () => {
const captured: Captured[] = [];
const rest = new RestClient(
{ baseUrl: 'http://127.0.0.1:7317/', token: 'arb_secret' },
fakeFetch({ ok: true, status: 200, body: { ok: true, tokenId: 't', tokenLabel: 'l', serverVersion: '1.8.0' } }, captured),
);
const me = await rest.me();
expect(me.serverVersion).toBe('1.8.0');
expect(captured[0]?.url).toBe('http://127.0.0.1:7317/api/v1/auth/me');
const headers = captured[0]?.init.headers as Record<string, string>;
expect(headers.Authorization).toBe('Bearer arb_secret');
});
it('normalise les erreurs serveur en RestError (code + status)', async () => {
const rest = new RestClient(
{ baseUrl: 'http://127.0.0.1:7317', token: 'bad' },
fakeFetch({ ok: false, status: 401, body: { error: { code: 'BAD_TOKEN', message: 'invalid token' } } }, []),
);
await expect(rest.me()).rejects.toMatchObject({ code: 'BAD_TOKEN', status: 401 });
await expect(rest.me()).rejects.toBeInstanceOf(RestError);
});
it('encode les ids dans les chemins et envoie le corps JSON', async () => {
const captured: Captured[] = [];
const rest = new RestClient(
{ baseUrl: 'http://h:1', token: 't' },
fakeFetch({ ok: true, status: 200, body: { worktree: {} } }, captured),
);
await rest.commitWorktree('repo id', { path: '/w', message: 'msg' });
expect(captured[0]?.url).toBe('http://h:1/api/v1/repos/repo%20id/worktrees/commit');
expect(captured[0]?.init.method).toBe('POST');
expect(JSON.parse(String(captured[0]?.init.body))).toEqual({ path: '/w', message: 'msg' });
});
});

View File

@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { StreamingUtf8Decoder } from '../src/terminal/session-bridge.js';
describe('StreamingUtf8Decoder', () => {
it('recompose un caractère UTF-8 coupé en frontière de frame', () => {
const dec = new StreamingUtf8Decoder();
// 'é' = 0xC3 0xA9, coupé en deux frames
expect(dec.decode(new Uint8Array([0xc3]))).toBe('');
expect(dec.decode(new Uint8Array([0xa9]))).toBe('é');
});
it('décode lASCII normalement', () => {
const dec = new StreamingUtf8Decoder();
expect(dec.decode(new Uint8Array([0x6c, 0x73, 0x0a]))).toBe('ls\n');
});
it('reset() vide létat partiel', () => {
const dec = new StreamingUtf8Decoder();
expect(dec.decode(new Uint8Array([0xe2, 0x9c]))).toBe(''); // début dun ✓ (3 octets)
dec.reset();
// après reset, loctet partiel est oublié → un nouveau caractère complet décode proprement
expect(dec.decode(new Uint8Array([0x41]))).toBe('A');
});
});

View File

@@ -0,0 +1,103 @@
import { describe, expect, it } from 'vitest';
import type { RepoSummary, SessionSummary, WorktreeSummary } from '@arboretum/shared';
import { Store } from '../src/state/store.js';
function repo(id: string): RepoSummary {
return {
id,
path: `/code/${id}`,
label: id,
defaultBranch: 'main',
postCreateHooks: [],
preTrust: false,
createdAt: '2026-01-01T00:00:00Z',
valid: true,
hidden: false,
};
}
function worktree(repoId: string, path: string, branch: string): WorktreeSummary {
return {
repoId,
path,
branch,
head: 'abcdef0',
detached: false,
locked: false,
prunable: false,
isMain: branch === 'main',
git: { ahead: 0, behind: 0, dirtyCount: 0, upstream: null },
sessions: [],
};
}
function session(id: string, cwd: string, over: Partial<SessionSummary> = {}): SessionSummary {
return {
id,
cwd,
command: 'claude',
title: null,
status: 'running',
live: true,
createdAt: '2026-01-01T00:00:00Z',
endedAt: null,
exitCode: null,
clients: 0,
source: 'managed',
claudeSessionId: null,
pid: 123,
resumable: false,
attachable: true,
registryStatus: null,
...over,
};
}
describe('Store', () => {
it('corrèle les sessions au worktree par cwd et filtre les externes', () => {
const store = new Store();
store.applyWorktree({ type: 'repo_update', repo: repo('app') });
store.applyWorktree({ type: 'worktree_update', repoId: 'app', worktree: worktree('app', '/code/app', 'main') });
store.applySession({ type: 'session_update', session: session('s1', '/code/app') });
store.applySession({ type: 'session_update', session: session('s2', '/code/app', { source: 'discovered' }) });
// externes masquées par défaut
expect(store.sessionsForWorktree('/code/app').map((s) => s.id)).toEqual(['s1']);
store.setShowExternalSessions(true);
expect(store.sessionsForWorktree('/code/app').map((s) => s.id).sort()).toEqual(['s1', 's2']);
});
it('liste les repos visibles, triés', () => {
const store = new Store();
store.applyWorktree({ type: 'repo_update', repo: { ...repo('b'), label: 'beta' } });
store.applyWorktree({ type: 'repo_update', repo: { ...repo('a'), label: 'alpha' } });
store.applyWorktree({ type: 'repo_update', repo: { ...repo('h'), label: 'hidden', hidden: true } });
expect(store.listRepos().map((r) => r.label)).toEqual(['alpha', 'beta']);
});
it('session_exit marque la session morte', () => {
const store = new Store();
store.applySession({ type: 'session_update', session: session('s1', '/x') });
store.applySession({ type: 'session_exit', sessionId: 's1', exitCode: 0, signal: null });
expect(store.getSession('s1')?.live).toBe(false);
expect(store.getSession('s1')?.status).toBe('exited');
});
it('waitingSessions ne retient que les sessions live en attente', () => {
const store = new Store();
store.applySession({ type: 'session_update', session: session('s1', '/x', { activity: 'waiting' }) });
store.applySession({ type: 'session_update', session: session('s2', '/y', { activity: 'busy' }) });
store.applySession({ type: 'session_update', session: session('s3', '/z', { activity: 'waiting', live: false, status: 'exited' }) });
expect(store.waitingSessions().map((s) => s.id)).toEqual(['s1']);
});
it('worktree_removed retire le worktree', () => {
const store = new Store();
store.applyWorktree({ type: 'repo_update', repo: repo('app') });
store.applyWorktree({ type: 'worktree_update', repoId: 'app', worktree: worktree('app', '/code/app-wt', 'feat') });
expect(store.listWorktrees('app')).toHaveLength(1);
store.applyWorktree({ type: 'worktree_removed', repoId: 'app', path: '/code/app-wt' });
expect(store.listWorktrees('app')).toHaveLength(0);
});
});

View File

@@ -0,0 +1,136 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { BINARY_FRAME, FLOW, encodeBinaryFrame, type ClientMessage } from '@arboretum/shared';
import { ArbWsClient, type AttachmentSink, type RawSocket } from '../src/api/ws-client.js';
class FakeSocket implements RawSocket {
sent: string[] = [];
private openCb: (() => void) | null = null;
private textCb: ((t: string) => void) | null = null;
private binaryCb: ((d: Uint8Array) => void) | null = null;
private closeCb: (() => void) | null = null;
send(data: string): void {
this.sent.push(data);
}
close(): void {
this.closeCb?.();
}
onOpen(cb: () => void): void {
this.openCb = cb;
}
onText(cb: (t: string) => void): void {
this.textCb = cb;
}
onBinary(cb: (d: Uint8Array) => void): void {
this.binaryCb = cb;
}
onClose(cb: () => void): void {
this.closeCb = cb;
}
onError(): void {
/* non utilisé dans ces tests */
}
fireOpen(): void {
this.openCb?.();
}
fireText(msg: unknown): void {
this.textCb?.(JSON.stringify(msg));
}
fireBinary(data: Uint8Array): void {
this.binaryCb?.(data);
}
/** messages de contrôle envoyés, parsés et filtrés par type. */
controls<T extends ClientMessage['type']>(type: T): Array<Extract<ClientMessage, { type: T }>> {
return this.sent
.map((s) => JSON.parse(s) as ClientMessage)
.filter((m): m is Extract<ClientMessage, { type: T }> => m.type === type);
}
}
function makeNoopSink(): AttachmentSink {
return { data: () => {}, reset: () => {}, detached: () => {}, controlChanged: () => {} };
}
describe('ArbWsClient', () => {
let fake: FakeSocket;
let client: ArbWsClient;
beforeEach(() => {
vi.useFakeTimers();
fake = new FakeSocket();
client = new ArbWsClient({ socketFactory: () => fake });
client.configure('http://127.0.0.1:7317', 'arb_token');
client.connect();
fake.fireOpen();
fake.fireText({ type: 'hello_ok', protocol: 1, serverVersion: '1.8.0' });
});
afterEach(() => {
vi.useRealTimers();
});
it('envoie hello puis sub après hello_ok', () => {
expect(fake.controls('hello')).toHaveLength(1);
expect(fake.controls('sub')[0]?.topics).toEqual(['sessions', 'worktrees', 'groups']);
});
it('corrèle attach→attached et délivre les OUTPUT au sink', async () => {
const chunks: Uint8Array[] = [];
const sink: AttachmentSink = { ...makeNoopSink(), data: (p) => chunks.push(p) };
const p = client.attach({ sessionId: 'sess', mode: 'interactive', cols: 80, rows: 24, sink });
fake.fireText({ type: 'attached', channel: 1, sessionId: 'sess', mode: 'interactive', controlling: true });
const att = await p;
expect(att.channel).toBe(1);
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.OUTPUT, 1, new Uint8Array([104, 105]))); // "hi"
expect(chunks).toHaveLength(1);
expect([...(chunks[0] ?? [])]).toEqual([104, 105]);
});
it('ACK au seuil ACK_EVERY_BYTES', async () => {
const p = client.attach({ sessionId: 'sess', mode: 'interactive', cols: 80, rows: 24, sink: makeNoopSink() });
fake.fireText({ type: 'attached', channel: 7, sessionId: 'sess', mode: 'interactive', controlling: true });
await p;
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.OUTPUT, 7, new Uint8Array(FLOW.ACK_EVERY_BYTES)));
const acks = fake.controls('ack');
expect(acks).toHaveLength(1);
expect(acks[0]).toMatchObject({ channel: 7, bytes: FLOW.ACK_EVERY_BYTES });
});
it('ACK traînant flushe un reliquat sous le seuil après 200ms', async () => {
const p = client.attach({ sessionId: 'sess', mode: 'interactive', cols: 80, rows: 24, sink: makeNoopSink() });
fake.fireText({ type: 'attached', channel: 2, sessionId: 'sess', mode: 'interactive', controlling: true });
await p;
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.OUTPUT, 2, new Uint8Array(1000)));
expect(fake.controls('ack')).toHaveLength(0); // sous le seuil → pas dACK immédiat
vi.advanceTimersByTime(200);
expect(fake.controls('ack')).toEqual([{ type: 'ack', channel: 2, bytes: 1000 }]);
});
it('RESYNC réinitialise le terminal et les compteurs dACK', async () => {
let resets = 0;
const sink: AttachmentSink = { ...makeNoopSink(), reset: () => (resets += 1) };
const p = client.attach({ sessionId: 'sess', mode: 'interactive', cols: 80, rows: 24, sink });
fake.fireText({ type: 'attached', channel: 3, sessionId: 'sess', mode: 'interactive', controlling: true });
await p;
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.OUTPUT, 3, new Uint8Array(FLOW.ACK_EVERY_BYTES)));
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.RESYNC, 3, new Uint8Array([65]))); // reset + replay "A"
expect(resets).toBe(1);
// après resync, le replay ne compte pas : un nouvel OUTPUT au seuil ré-ACK à partir de 0
fake.fireBinary(encodeBinaryFrame(BINARY_FRAME.OUTPUT, 3, new Uint8Array(FLOW.ACK_EVERY_BYTES)));
const acks = fake.controls('ack');
expect(acks[acks.length - 1]).toMatchObject({ bytes: FLOW.ACK_EVERY_BYTES });
});
it('envoie stdin/resize sur le bon canal', async () => {
const p = client.attach({ sessionId: 'sess', mode: 'interactive', cols: 80, rows: 24, sink: makeNoopSink() });
fake.fireText({ type: 'attached', channel: 5, sessionId: 'sess', mode: 'interactive', controlling: true });
const att = await p;
att.sendStdin('ls\n');
att.resize(120, 40);
expect(fake.controls('stdin')[0]).toEqual({ type: 'stdin', channel: 5, data: 'ls\n' });
expect(fake.controls('resize')[0]).toEqual({ type: 'resize', channel: 5, cols: 120, rows: 40 });
});
});

View File

@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"module": "ESNext",
"moduleResolution": "Bundler",
"verbatimModuleSyntax": false,
"composite": false,
"declaration": false,
"declarationMap": false,
"noEmit": true,
"types": ["node"],
"lib": ["ES2023"]
},
"include": ["src", "test"]
}

View File

@@ -4,18 +4,21 @@
<span class="badge bg-amber-900 text-amber-200">{{ t(`sessions.dialog.kind.${dialog.kind}`) }}</span> <span class="badge bg-amber-900 text-amber-200">{{ t(`sessions.dialog.kind.${dialog.kind}`) }}</span>
<span class="text-sm text-amber-100">{{ dialog.waitingFor ?? t('sessions.dialog.waiting') }}</span> <span class="text-sm text-amber-100">{{ dialog.waitingFor ?? t('sessions.dialog.waiting') }}</span>
</div> </div>
<div class="mt-2 flex flex-wrap gap-2"> <!-- Options empilées verticalement et pleine largeur : un libellé long (ex. AskUserQuestion) wrappe
proprement au lieu d'être tronqué/collé au suivant comme avec un flex-wrap horizontal. -->
<div class="mt-2 flex flex-col gap-1.5">
<button <button
v-for="opt in dialog.options" v-for="opt in dialog.options"
:key="opt.n" :key="opt.n"
class="btn text-xs" class="btn w-full items-start justify-start whitespace-normal break-words text-left text-xs"
:class="opt.selected ? 'border-amber-400 text-amber-200' : ''" :class="opt.selected ? 'border-amber-400 text-amber-200' : ''"
:disabled="busy" :disabled="busy"
@click="respond('select', opt.n)" @click="respond('select', opt.n)"
> >
<span class="font-mono text-amber-400">{{ opt.n }}</span> {{ opt.label }} <span class="font-mono text-amber-400">{{ opt.n }}</span>
<span class="min-w-0 flex-1">{{ opt.label }}</span>
</button> </button>
<button class="btn-danger text-xs" :disabled="busy" @click="respond('deny')"> <button class="btn-danger w-full justify-start text-left text-xs" :disabled="busy" @click="respond('deny')">
{{ t('sessions.dialog.deny') }} {{ t('sessions.dialog.deny') }}
</button> </button>
</div> </div>

View File

@@ -21,21 +21,20 @@
</div> </div>
</div> </div>
<!-- mode feature : branche commune créée dans chaque repo --> <!-- mode feature : branche commune créée (ou réutilisée si déjà présente) dans chaque repo -->
<template v-if="mode === 'feature'"> <template v-if="mode === 'feature'">
<label class="flex flex-col gap-1 text-xs text-zinc-400"> <label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('crossRepo.branchLabel') }} {{ t('crossRepo.branchLabel') }}
<input v-model="branch" class="input font-mono" :placeholder="t('crossRepo.branchPlaceholder')" :required="mode === 'feature'" /> <input v-model="branch" class="input font-mono" :placeholder="t('crossRepo.branchPlaceholder')" :required="mode === 'feature'" />
</label> <span class="text-[11px] text-zinc-500">{{ t('crossRepo.branchHint') }}</span>
<div class="flex flex-wrap items-end gap-3">
<label class="flex items-center gap-1.5 text-xs text-zinc-400">
<input v-model="newBranch" type="checkbox" /> {{ t('crossRepo.newBranch') }}
</label> </label>
<label class="flex flex-col gap-1 text-xs text-zinc-400"> <label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('crossRepo.baseRefLabel') }} {{ t('crossRepo.baseRefLabel') }}
<input v-model="baseRef" class="input font-mono" placeholder="HEAD" /> <input v-model="baseRef" class="input font-mono" list="group-base-branches" :placeholder="t('crossRepo.baseRefPlaceholder')" />
<datalist id="group-base-branches">
<option v-for="b in baseBranchOptions" :key="b" :value="b" />
</datalist>
</label> </label>
</div>
</template> </template>
<label class="flex flex-col gap-1 text-xs text-zinc-400"> <label class="flex flex-col gap-1 text-xs text-zinc-400">
@@ -78,21 +77,43 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import type { RepoSummary } from '@arboretum/shared'; import type { RepoBranchesResponse, RepoSummary } from '@arboretum/shared';
import { useGroupsStore, type CrossRepoResult, type GroupFeatureOutcome } from '../stores/groups'; import { useGroupsStore, type CrossRepoResult, type GroupFeatureOutcome } from '../stores/groups';
import { useWorktreesStore } from '../stores/worktrees';
import { useToastsStore } from '../stores/toasts';
const props = defineProps<{ groupId: string; repos: RepoSummary[] }>(); const props = defineProps<{ groupId: string; repos: RepoSummary[] }>();
const emit = defineEmits<{ close: [] }>(); const emit = defineEmits<{ close: [] }>();
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter();
const groups = useGroupsStore(); const groups = useGroupsStore();
const worktrees = useWorktreesStore();
const toasts = useToastsStore();
const mode = ref<'feature' | 'main'>('feature'); const mode = ref<'feature' | 'main'>('feature');
const branch = ref(''); const branch = ref('');
const newBranch = ref(true);
const baseRef = ref(''); const baseRef = ref('');
// Sélecteur de branche de base : branches du 1er repo du groupe (indicatif ; vide → défaut serveur par repo).
const branches = ref<RepoBranchesResponse | null>(null);
const baseBranchOptions = computed<string[]>(() => {
const b = branches.value;
if (!b) return [];
return Array.from(new Set([...(b.default ? [b.default] : []), ...b.local, ...b.remote]));
});
onMounted(async () => {
const first = props.repos[0];
if (!first) return;
try {
branches.value = await worktrees.fetchBranches(first.id);
} catch {
/* le sélecteur de base est facultatif */
}
});
const command = ref<'claude' | 'bash'>('claude'); const command = ref<'claude' | 'bash'>('claude');
const wtResults = ref<Record<string, CrossRepoResult>>({}); const wtResults = ref<Record<string, CrossRepoResult>>({});
const outcome = ref<GroupFeatureOutcome | null>(null); const outcome = ref<GroupFeatureOutcome | null>(null);
@@ -132,13 +153,21 @@ async function onSubmit(): Promise<void> {
{ {
command: command.value, command: command.value,
...(mode.value === 'feature' ...(mode.value === 'feature'
? { branch: branch.value.trim(), newBranch: newBranch.value, ...(baseRef.value.trim() ? { baseRef: baseRef.value.trim() } : {}) } ? { branch: branch.value.trim(), ...(baseRef.value.trim() ? { baseRef: baseRef.value.trim() } : {}) }
: {}), : {}),
}, },
(result) => { (result) => {
wtResults.value = { ...wtResults.value, [result.repoId]: result }; wtResults.value = { ...wtResults.value, [result.repoId]: result };
}, },
); );
// Session lancée → on redirige vers son terminal plein écran (comme une session individuelle).
// En cas d'échec serveur (session null), on garde le modal ouvert avec le statut d'erreur.
if (outcome.value.session) {
const failed = outcome.value.skipped.length + outcome.value.worktreeResults.filter((r) => r.status !== 'ok').length;
if (failed > 0) toasts.info(t('toast.groupSessionPartial', { n: failed }));
else toasts.success(t('toast.groupSessionLaunched'));
await router.push({ name: 'session', params: { id: outcome.value.session.id } });
}
} catch (err) { } catch (err) {
errorMsg.value = err instanceof Error ? err.message : String(err); errorMsg.value = err instanceof Error ? err.message : String(err);
} finally { } finally {

View File

@@ -0,0 +1,119 @@
<template>
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4" @click.self="emit('close')">
<div class="flex max-h-[90vh] w-full max-w-lg flex-col gap-3 overflow-y-auto rounded-lg border border-zinc-800 bg-zinc-900 p-4">
<header class="flex items-center gap-2">
<h2 class="font-semibold text-zinc-100">{{ t('project.title') }}</h2>
<button class="btn ml-auto text-xs" @click="emit('close')">{{ t('common.cancel') }}</button>
</header>
<p class="text-xs text-zinc-500">{{ t('project.intro') }}</p>
<form class="flex flex-col gap-3" @submit.prevent="onSubmit">
<label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('project.nameLabel') }}
<input v-model="name" class="input font-mono" :placeholder="t('project.namePlaceholder')" required :disabled="creating" />
</label>
<label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('project.rootLabel') }}
<input v-model="root" class="input font-mono" :placeholder="t('project.rootPlaceholder')" required :disabled="creating" />
</label>
<div>
<button type="button" class="btn text-xs" :disabled="creating" @click="showPicker = !showPicker">{{ t('fs.browse') }}</button>
</div>
<DirectoryPicker v-if="showPicker" mode="dir" :initial-path="root" @select="onPickRoot" @close="showPicker = false" />
<label class="flex items-center gap-2 text-xs text-zinc-300">
<input v-model="gitInit" type="checkbox" :disabled="creating" /> {{ t('project.gitInit') }}
</label>
<label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('project.commandLabel') }}
<select v-model="command" class="input" :disabled="creating">
<option value="claude">claude</option>
<option value="bash">bash</option>
</select>
</label>
<p class="font-mono text-[11px] text-zinc-500">{{ previewPath }}</p>
<p v-if="errorMsg" class="text-xs text-red-400">{{ errorMsg }}</p>
<div class="flex items-center gap-2">
<button type="submit" class="btn-primary" :disabled="creating || name.trim() === '' || root.trim() === ''">
{{ creating ? t('project.creating') : t('project.create') }}
</button>
</div>
</form>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useSessionsStore } from '../stores/sessions';
import { useSettingsStore } from '../stores/settings';
import { useToastsStore } from '../stores/toasts';
import DirectoryPicker from './DirectoryPicker.vue';
const emit = defineEmits<{ close: [] }>();
const { t } = useI18n();
const router = useRouter();
const sessions = useSessionsStore();
const settings = useSettingsStore();
const toasts = useToastsStore();
const name = ref('');
// Racine par défaut : la 1ère racine de scan (réglage Découverte) ; modifiable via le picker.
const root = ref('');
const gitInit = ref(false);
const command = ref<'claude' | 'bash'>('claude');
const showPicker = ref(false);
const creating = ref(false);
const errorMsg = ref<string | null>(null);
// Aperçu du chemin final (indicatif ; jointure naïve suffisante pour l'affichage).
const previewPath = computed(() => {
const r = root.value.trim().replace(/\/+$/, '');
const n = name.value.trim();
return r && n ? `${r}/${n}` : '';
});
onMounted(async () => {
if (!settings.loaded) {
try {
await settings.fetch();
} catch {
/* le préremplissage de la racine est facultatif */
}
}
root.value = settings.scanRoots[0] ?? '';
});
function onPickRoot(path: string): void {
root.value = path;
showPicker.value = false;
}
async function onSubmit(): Promise<void> {
if (creating.value || name.value.trim() === '' || root.value.trim() === '') return;
creating.value = true;
errorMsg.value = null;
try {
const res = await sessions.createProject({
root: root.value.trim(),
name: name.value.trim(),
gitInit: gitInit.value,
command: command.value,
});
toasts.success(t('toast.projectCreated'));
emit('close');
await router.push({ name: 'session', params: { id: res.session.id } });
} catch (err) {
errorMsg.value = err instanceof Error ? err.message : String(err);
} finally {
creating.value = false;
}
}
</script>

View File

@@ -27,12 +27,19 @@
</div> </div>
<div class="flex flex-wrap items-end gap-2"> <div class="flex flex-wrap items-end gap-2">
<!-- mode worktree : branche + créer/existante --> <!-- mode worktree : branche (créée si absente, réutilisée si présente) + branche de base + session -->
<template v-if="mode === 'worktree'"> <template v-if="mode === 'worktree'">
<label class="flex flex-1 flex-col gap-1 text-xs text-zinc-400"> <label class="flex flex-1 flex-col gap-1 text-xs text-zinc-400">
{{ t('worktrees.branch') }} {{ t('worktrees.branch') }}
<input v-model="branch" class="input font-mono" placeholder="feature/…" required /> <input v-model="branch" class="input font-mono" placeholder="feature/…" required />
</label> </label>
<label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('worktrees.baseRefLabel') }}
<input v-model="baseRef" class="input font-mono" :list="datalistId" :placeholder="t('worktrees.baseRefPlaceholder')" />
<datalist :id="datalistId">
<option v-for="b in baseBranchOptions" :key="b" :value="b" />
</datalist>
</label>
<label class="flex flex-col gap-1 text-xs text-zinc-400"> <label class="flex flex-col gap-1 text-xs text-zinc-400">
{{ t('worktrees.start') }} {{ t('worktrees.start') }}
<select v-model="startSession" class="input"> <select v-model="startSession" class="input">
@@ -41,7 +48,6 @@
<option value="bash">bash</option> <option value="bash">bash</option>
</select> </select>
</label> </label>
<label class="flex items-center gap-1 text-xs text-zinc-400"><input v-model="newBranch" type="checkbox" /> {{ t('worktrees.newBranch') }}</label>
</template> </template>
<!-- mode branche principale : option git (branche actuelle ou nouvelle branche) + commande --> <!-- mode branche principale : option git (branche actuelle ou nouvelle branche) + commande -->
@@ -81,10 +87,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue'; import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Eye, EyeOff, Plus, Scissors, Trash2 } from '@lucide/vue'; import { Eye, EyeOff, Plus, Scissors, Trash2 } from '@lucide/vue';
import type { RepoSummary } from '@arboretum/shared'; import type { RepoBranchesResponse, RepoSummary } from '@arboretum/shared';
import { useWorktreesStore } from '../stores/worktrees'; import { useWorktreesStore } from '../stores/worktrees';
import { useWorktreeView } from '../composables/useWorktreeView'; import { useWorktreeView } from '../composables/useWorktreeView';
import { useToastsStore } from '../stores/toasts'; import { useToastsStore } from '../stores/toasts';
@@ -103,13 +109,30 @@ const worktrees = computed(() => view.apply(store.worktreesForRepo(props.repo.id
const creating = ref(false); const creating = ref(false);
const mode = ref<'worktree' | 'main'>('worktree'); const mode = ref<'worktree' | 'main'>('worktree');
const branch = ref(''); const branch = ref('');
const newBranch = ref(true); const baseRef = ref('');
const startSession = ref<'claude' | 'bash' | null>(null); const startSession = ref<'claude' | 'bash' | null>(null);
const mainBranchMode = ref<'current' | 'new'>('current'); const mainBranchMode = ref<'current' | 'new'>('current');
const mainCommand = ref<'claude' | 'bash'>('claude'); const mainCommand = ref<'claude' | 'bash'>('claude');
const busy = ref(false); const busy = ref(false);
const error = ref<string | null>(null); const error = ref<string | null>(null);
// Sélecteur de branche de base (chargé paresseusement à l'ouverture du formulaire).
const branches = ref<RepoBranchesResponse | null>(null);
const datalistId = computed(() => `wt-base-branches-${props.repo.id}`);
const baseBranchOptions = computed<string[]>(() => {
const b = branches.value;
if (!b) return [];
return Array.from(new Set([...(b.default ? [b.default] : []), ...b.local, ...b.remote]));
});
watch(creating, async (open) => {
if (!open || branches.value) return;
try {
branches.value = await store.fetchBranches(props.repo.id);
} catch {
/* le sélecteur de base est facultatif */
}
});
// worktree : branche obligatoire ; branche principale + nouvelle branche : branche obligatoire ; sinon OK. // worktree : branche obligatoire ; branche principale + nouvelle branche : branche obligatoire ; sinon OK.
const canSubmit = computed(() => const canSubmit = computed(() =>
mode.value === 'worktree' ? branch.value.trim() !== '' : mainBranchMode.value === 'current' || branch.value.trim() !== '', mode.value === 'worktree' ? branch.value.trim() !== '' : mainBranchMode.value === 'current' || branch.value.trim() !== '',
@@ -120,7 +143,12 @@ async function onCreate(): Promise<void> {
error.value = null; error.value = null;
try { try {
if (mode.value === 'worktree') { if (mode.value === 'worktree') {
await store.createWorktree(props.repo.id, { branch: branch.value.trim(), newBranch: newBranch.value, startSession: startSession.value }); await store.createWorktree(props.repo.id, {
branch: branch.value.trim(),
mode: 'auto', // détecte créer / checkout / suivi remote
...(baseRef.value.trim() ? { baseRef: baseRef.value.trim() } : {}),
startSession: startSession.value,
});
toasts.success(t('toast.worktreeCreated')); toasts.success(t('toast.worktreeCreated'));
} else { } else {
// bosser sur la branche principale : session dans le checkout principal, avec création de branche optionnelle. // bosser sur la branche principale : session dans le checkout principal, avec création de branche optionnelle.
@@ -131,6 +159,7 @@ async function onCreate(): Promise<void> {
toasts.success(t('toast.sessionCreated')); toasts.success(t('toast.sessionCreated'));
} }
branch.value = ''; branch.value = '';
baseRef.value = '';
creating.value = false; creating.value = false;
} catch (err) { } catch (err) {
error.value = err instanceof Error ? err.message : String(err); error.value = err instanceof Error ? err.message : String(err);

View File

@@ -0,0 +1,82 @@
<template>
<!-- Barre de contexte sous l'en-tête : groupe + repos couverts (avec branche). Masquée s'il n'y a
rien d'utile à montrer (session simple dans un dossier non reconnu le cwd du header suffit). -->
<div v-if="shouldShow" class="flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-zinc-800 bg-zinc-900/40 px-3 py-1.5 text-xs">
<RouterLink
v-if="group"
:to="{ name: 'group', params: { id: group.id } }"
class="flex items-center gap-1.5 rounded px-1.5 py-0.5 text-zinc-200 transition-colors hover:bg-zinc-800"
:title="t('terminal.group')"
>
<span class="h-2.5 w-2.5 shrink-0 rounded-full" :style="{ backgroundColor: group.color ?? '#52525b' }" />
<span class="font-medium">{{ group.label }}</span>
<span class="text-zinc-500"></span>
</RouterLink>
<span v-if="group" class="text-zinc-600">{{ t('terminal.covers') }}</span>
<span
v-for="e in entries"
:key="e.dir"
class="flex items-center gap-1.5 rounded bg-zinc-950/60 px-1.5 py-0.5"
:title="e.dir"
>
<span class="font-mono text-zinc-300">{{ e.label }}</span>
<span v-if="e.branch" class="badge bg-zinc-800 font-mono text-zinc-400">{{ e.branch }}</span>
</span>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { SessionSummary } from '@arboretum/shared';
import { useGroupsStore } from '../stores/groups';
import { useWorktreesStore } from '../stores/worktrees';
const props = defineProps<{ session: SessionSummary }>();
const { t } = useI18n();
const groups = useGroupsStore();
const worktrees = useWorktreesStore();
const group = computed(() => (props.session.groupId ? (groups.byId(props.session.groupId) ?? null) : null));
function basename(dir: string): string {
return dir.split('/').filter(Boolean).pop() ?? dir;
}
interface CoverEntry {
dir: string;
label: string;
branch: string | null;
resolved: boolean;
}
// Résout un répertoire couvert vers repo + branche : worktree exact d'abord (branche connue),
// sinon checkout principal d'un repo, sinon dernier segment du chemin (non résolu).
function resolve(dir: string): CoverEntry {
const wt = worktrees.worktrees.find((w) => w.path === dir);
if (wt) {
const repo = worktrees.repos.find((r) => r.id === wt.repoId);
return { dir, label: repo?.label ?? basename(dir), branch: wt.branch, resolved: true };
}
const repo = worktrees.repos.find((r) => r.path === dir);
if (repo) return { dir, label: repo.label, branch: null, resolved: true };
return { dir, label: basename(dir), branch: null, resolved: false };
}
const entries = computed<CoverEntry[]>(() => {
const dirs = [props.session.cwd, ...(props.session.addedDirs ?? [])];
const seen = new Set<string>();
const out: CoverEntry[] = [];
for (const d of dirs) {
if (seen.has(d)) continue;
seen.add(d);
out.push(resolve(d));
}
return out;
});
// Afficher si on est dans un groupe, ou si au moins un répertoire correspond à un repo connu.
const shouldShow = computed(() => group.value !== null || entries.value.some((e) => e.resolved));
</script>

View File

@@ -12,6 +12,22 @@
{{ t('groups.spanBadge', spannedCount) }} {{ t('groups.spanBadge', spannedCount) }}
</span> </span>
<span class="ml-auto shrink-0 font-mono text-[11px] text-zinc-500">{{ session.command }}</span> <span class="ml-auto shrink-0 font-mono text-[11px] text-zinc-500">{{ session.command }}</span>
<button
class="shrink-0 rounded p-0.5 text-zinc-500 transition-colors hover:text-zinc-200"
:aria-label="t('terminal.openFullscreen')"
:title="t('terminal.openFullscreen')"
@click="emit('open-fullscreen')"
>
<Expand class="h-3.5 w-3.5" />
</button>
<button
class="shrink-0 rounded p-0.5 text-zinc-500 transition-colors hover:text-zinc-200"
:aria-label="maximized ? t('terminal.restore') : t('terminal.maximize')"
:title="maximized ? t('terminal.restore') : t('terminal.maximize')"
@click="emit('toggle-maximize')"
>
<component :is="maximized ? Minimize2 : Maximize2" class="h-3.5 w-3.5" />
</button>
</header> </header>
<DialogPrompt v-if="isWaiting" :session="session" class="px-2 pt-2" /> <DialogPrompt v-if="isWaiting" :session="session" class="px-2 pt-2" />
<div class="min-h-0 flex-1"> <div class="min-h-0 flex-1">
@@ -23,13 +39,15 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Expand, Maximize2, Minimize2 } from '@lucide/vue';
import type { SessionSummary } from '@arboretum/shared'; import type { SessionSummary } from '@arboretum/shared';
import { useWorktreesStore } from '../stores/worktrees'; import { useWorktreesStore } from '../stores/worktrees';
import SessionStateBadge from './SessionStateBadge.vue'; import SessionStateBadge from './SessionStateBadge.vue';
import DialogPrompt from './DialogPrompt.vue'; import DialogPrompt from './DialogPrompt.vue';
import TerminalView from './TerminalView.vue'; import TerminalView from './TerminalView.vue';
const props = defineProps<{ session: SessionSummary }>(); const props = defineProps<{ session: SessionSummary; maximized?: boolean }>();
const emit = defineEmits<{ 'toggle-maximize': []; 'open-fullscreen': [] }>();
const worktrees = useWorktreesStore(); const worktrees = useWorktreesStore();
const { t } = useI18n(); const { t } = useI18n();

View File

@@ -2,27 +2,63 @@
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<p v-if="sessions.length === 0" class="text-sm text-zinc-500">{{ t('groups.gridEmpty') }}</p> <p v-if="sessions.length === 0" class="text-sm text-zinc-500">{{ t('groups.gridEmpty') }}</p>
<template v-else> <template v-else>
<p v-if="sessions.length > MAX_CELLS" class="text-xs text-amber-400"> <p v-if="!activeMax && sessions.length > MAX_CELLS" class="text-xs text-amber-400">
{{ t('groups.gridCapped', { shown: MAX_CELLS, total: sessions.length }) }} {{ t('groups.gridCapped', { shown: MAX_CELLS, total: sessions.length }) }}
</p> </p>
<!-- une seule socket WS multiplexe tous les terminaux ; cap dur pour préserver GPU/canaux. <!-- une seule socket WS multiplexe tous les terminaux ; cap dur pour préserver GPU/canaux.
Sur mobile la grille retombe à une colonne (empilement). --> Sur mobile la grille retombe à une colonne (empilement). Hauteur relative au viewport
<div class="grid grid-cols-1 gap-3 lg:grid-cols-2 2xl:grid-cols-3"> (dvh) : terminaux grands sur PC, exploitables sur mobile ; xterm re-fit via ResizeObserver.
<TerminalCell v-for="s in shown" :key="s.id" :session="s" class="h-80" /> Plancher min-h-80 pour les fenêtres courtes. -->
<!-- une cellule maximisée plein cadre ; sinon la grille responsive -->
<div v-if="activeMax" class="grid grid-cols-1">
<TerminalCell
:session="activeMax"
maximized
class="h-[calc(100dvh-8rem)] min-h-80"
@toggle-maximize="toggleMax(activeMax.id)"
@open-fullscreen="openFullscreen(activeMax.id)"
/>
</div>
<div v-else class="grid grid-cols-1 gap-3 lg:grid-cols-2 2xl:grid-cols-3">
<TerminalCell
v-for="s in shown"
:key="s.id"
:session="s"
class="h-[68dvh] min-h-80 lg:h-[calc((100dvh-9rem)/2)]"
@toggle-maximize="toggleMax(s.id)"
@open-fullscreen="openFullscreen(s.id)"
/>
</div> </div>
</template> </template>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import type { SessionSummary } from '@arboretum/shared'; import type { SessionSummary } from '@arboretum/shared';
import TerminalCell from './TerminalCell.vue'; import TerminalCell from './TerminalCell.vue';
const props = defineProps<{ sessions: SessionSummary[] }>(); const props = defineProps<{ sessions: SessionSummary[] }>();
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter();
const MAX_CELLS = 6; const MAX_CELLS = 6;
const shown = computed(() => props.sessions.slice(0, MAX_CELLS)); const shown = computed(() => props.sessions.slice(0, MAX_CELLS));
// ouvrir le terminal choisi en plein écran (page dédiée /sessions/:id), comme depuis la liste des sessions.
function openFullscreen(id: string): void {
void router.push({ name: 'session', params: { id } });
}
// Maximisation d'une cellule au choix (état purement présentation, local à la grille). Si la session
// maximisée disparaît (terminée), on retombe automatiquement sur la grille.
const maximizedId = ref<string | null>(null);
function toggleMax(id: string): void {
maximizedId.value = maximizedId.value === id ? null : id;
}
const activeMax = computed<SessionSummary | null>(() =>
maximizedId.value ? (shown.value.find((s) => s.id === maximizedId.value) ?? null) : null,
);
</script> </script>

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="relative min-h-0 bg-[#09090b]"> <div class="relative h-full min-h-0 bg-[#09090b]">
<div ref="container" class="h-full w-full" /> <div ref="container" class="h-full w-full" />
<div <div
v-if="!controlling && !ended" v-if="!controlling && !ended"
@@ -38,6 +38,8 @@ const ended = ref(false);
let term: Terminal | null = null; let term: Terminal | null = null;
let attachment: Attachment | null = null; let attachment: Attachment | null = null;
let resizeObserver: ResizeObserver | null = null; let resizeObserver: ResizeObserver | null = null;
let intersectionObserver: IntersectionObserver | null = null;
let onVisible: (() => void) | null = null;
let disposed = false; let disposed = false;
onMounted(async () => { onMounted(async () => {
@@ -47,7 +49,7 @@ onMounted(async () => {
cursorBlink: true, cursorBlink: true,
fontSize: 13, fontSize: 13,
fontFamily: "ui-monospace, 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace", fontFamily: "ui-monospace, 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace",
scrollback: 10_000, scrollback: 20_000, // absorbe le replay élargi (REPLAY_TAIL_BYTES = 1 Mo) → on remonte plus loin
theme: { theme: {
background: '#09090b', background: '#09090b',
foreground: '#d4d4d8', foreground: '#d4d4d8',
@@ -58,18 +60,40 @@ onMounted(async () => {
const fit = new FitAddon(); const fit = new FitAddon();
term.loadAddon(fit); term.loadAddon(fit);
term.open(container.value); term.open(container.value);
const activeTerm = term;
try { try {
const { WebglAddon } = await import('@xterm/addon-webgl'); const { WebglAddon } = await import('@xterm/addon-webgl');
const webgl = new WebglAddon(); const webgl = new WebglAddon();
webgl.onContextLoss(() => webgl.dispose()); // perte de contexte GPU : on dispose (retour au renderer DOM) PUIS on repeint — sinon l'écran
// reste figé sur le dernier rendu WebGL jusqu'à la prochaine interaction (« texte qui ne s'affiche
// que si ça bouge »).
webgl.onContextLoss(() => {
webgl.dispose();
activeTerm.refresh(0, activeTerm.rows - 1);
});
term.loadAddon(webgl); term.loadAddon(webgl);
} catch { } catch {
// WebGL indisponible : xterm retombe sur le renderer DOM // WebGL indisponible : xterm retombe sur le renderer DOM
} }
fit.fit(); fit.fit();
const activeTerm = term;
// Re-mesure après stabilisation du layout flex : au `onMounted`, le conteneur peut ne pas avoir sa
// taille finale (la hauteur flex se résout après le 1er paint) → un seul `fit()` donne trop peu de
// lignes et déforme le TUI. On refait donc le calcul en `requestAnimationFrame`, puis on resynchronise
// les dimensions PTY. Sert aussi après un resync (reconnexion) où l'écran est remis à plat.
const refit = (): void => {
try {
fit.fit();
} catch {
/* conteneur sans dimension (démontage en cours) : ignoré */
}
attachment?.resize(activeTerm.cols, activeTerm.rows);
// repaint explicite : le renderer WebGL ne repeint pas toujours une zone non « dirty » (retour
// d'arrière-plan, resync) → on force un rafraîchissement pour éviter un écran figé.
activeTerm.refresh(0, activeTerm.rows - 1);
};
try { try {
attachment = await wsClient.attach({ attachment = await wsClient.attach({
@@ -79,7 +103,10 @@ onMounted(async () => {
rows: activeTerm.rows, rows: activeTerm.rows,
sink: { sink: {
write: (data, callback) => activeTerm.write(data, callback), write: (data, callback) => activeTerm.write(data, callback),
reset: () => activeTerm.reset(), reset: () => {
activeTerm.reset();
requestAnimationFrame(refit);
},
onDetached: (reason) => { onDetached: (reason) => {
if (reason === 'session_exit' || reason === 'replaced') ended.value = true; if (reason === 'session_exit' || reason === 'replaced') ended.value = true;
}, },
@@ -99,19 +126,39 @@ onMounted(async () => {
return; return;
} }
controlling.value = attachment.controlling; controlling.value = attachment.controlling;
requestAnimationFrame(refit); // recale la taille une fois le layout fullbleed stabilisé
activeTerm.onData((data) => attachment?.sendStdin(data)); activeTerm.onData((data) => attachment?.sendStdin(data));
resizeObserver = new ResizeObserver(() => { resizeObserver = new ResizeObserver(refit);
fit.fit();
attachment?.resize(activeTerm.cols, activeTerm.rows);
});
resizeObserver.observe(container.value); resizeObserver.observe(container.value);
// Re-révélation RÉELLE du conteneur : cellule de grille démontée/remontée (maximize↔grille), scroll
// hors/dans le viewport, ou navigation SPA — autant de cas que `visibilitychange` (onglet only) ne
// couvre PAS. Au retour visible, on repeint (le rendu était gelé hors-écran) ET on flushe l'ACK pour
// sortir d'une éventuelle pause serveur (le callback de xterm.write était throttlé tant que caché).
intersectionObserver = new IntersectionObserver((entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
// évite un fit() sur conteneur de taille 0 (remontage transitoire) → déforme le TUI
if (entry.intersectionRect.width === 0 || entry.intersectionRect.height === 0) continue;
refit();
attachment?.flushAck();
}
});
intersectionObserver.observe(container.value);
// au retour en avant-plan, forcer un repaint (le renderer WebGL peut avoir « gelé » l'écran pendant
// que l'onglet était caché) ; le ws-client flushe en parallèle les ACK pour relancer le flux.
onVisible = (): void => {
if (document.visibilityState === 'visible') activeTerm.refresh(0, activeTerm.rows - 1);
};
document.addEventListener('visibilitychange', onVisible);
if (props.mode === 'interactive') activeTerm.focus(); if (props.mode === 'interactive') activeTerm.focus();
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
disposed = true; disposed = true;
resizeObserver?.disconnect(); resizeObserver?.disconnect();
intersectionObserver?.disconnect();
if (onVisible) document.removeEventListener('visibilitychange', onVisible);
attachment?.detach(); attachment?.detach();
term?.dispose(); term?.dispose();
}); });

View File

@@ -16,7 +16,7 @@
<div class="mt-1 flex flex-wrap items-center gap-2"> <div class="mt-1 flex flex-wrap items-center gap-2">
<RouterLink <RouterLink
v-for="s in worktree.sessions" v-for="s in visibleSessions"
:key="s.id" :key="s.id"
:to="{ name: 'session', params: { id: s.id } }" :to="{ name: 'session', params: { id: s.id } }"
class="flex items-center gap-1 rounded bg-zinc-800/60 px-1.5 py-0.5 transition-colors hover:bg-zinc-800" class="flex items-center gap-1 rounded bg-zinc-800/60 px-1.5 py-0.5 transition-colors hover:bg-zinc-800"
@@ -24,7 +24,16 @@
<SessionStateBadge :session="liveSession(s)" /> <SessionStateBadge :session="liveSession(s)" />
<span class="font-mono text-[11px] text-zinc-400">{{ s.command }}</span> <span class="font-mono text-[11px] text-zinc-400">{{ s.command }}</span>
</RouterLink> </RouterLink>
<span v-if="worktree.sessions.length === 0" class="text-xs text-zinc-600">{{ t('worktrees.noSession') }}</span> <!-- sessions externes (lancées hors Arboretum) masquées par défaut : chip de révélation -->
<button
v-if="!store.showExternalSessions && externalCount > 0"
type="button"
class="rounded bg-zinc-800/40 px-1.5 py-0.5 text-[11px] text-zinc-500 transition-colors hover:text-zinc-300"
@click="store.showExternalSessions = true"
>
+{{ externalCount }} {{ t('worktrees.externalSessions') }}
</button>
<span v-if="visibleSessions.length === 0 && externalCount === 0" class="text-xs text-zinc-600">{{ t('worktrees.noSession') }}</span>
<!-- lancement d'une session sur ce worktree ; carte principale = bosser sur la branche principale --> <!-- lancement d'une session sur ce worktree ; carte principale = bosser sur la branche principale -->
<button v-if="hasLiveSession && !showLauncher" class="btn text-xs" @click="showLauncher = true">+ {{ t('worktrees.start') }}</button> <button v-if="hasLiveSession && !showLauncher" class="btn text-xs" @click="showLauncher = true">+ {{ t('worktrees.start') }}</button>
@@ -62,6 +71,41 @@
</div> </div>
</div> </div>
<!-- actions git : commit / push / promotion en principal (sans ouvrir le terminal) -->
<div v-if="canPush || worktree.git.dirtyCount || canPromote" class="mt-1 flex flex-wrap items-center gap-2">
<form v-if="committingOpen" class="flex flex-wrap items-center gap-1" @submit.prevent="onCommit">
<input v-model="commitMessage" class="input w-44 text-xs" :placeholder="t('worktrees.commitPlaceholder')" />
<button type="submit" class="btn-primary text-xs" :disabled="!!gitBusy || commitMessage.trim() === ''">
{{ gitBusy === 'commit' ? t('worktrees.committing') : t('worktrees.commit') }}
</button>
<button type="button" class="btn text-xs" @click="committingOpen = false">{{ t('common.cancel') }}</button>
</form>
<button v-else-if="worktree.git.dirtyCount" class="btn text-xs" :disabled="!!gitBusy" @click="committingOpen = true">
{{ t('worktrees.commit') }}
</button>
<button v-if="canPush" class="btn text-xs" :disabled="!!gitBusy" @click="onPush">
{{ gitBusy === 'push' ? t('worktrees.pushing') : t('worktrees.push') }}<span v-if="worktree.git.ahead"> {{ worktree.git.ahead }}</span>
</button>
<button v-if="canPromote && !promoteConfirming" class="btn text-xs" :disabled="!!gitBusy" @click="promoteConfirming = true">
{{ t('worktrees.promote') }}
</button>
<span v-if="gitError" class="text-xs text-amber-400">{{ gitError }}</span>
</div>
<!-- confirmation explicite de la promotion (action destructive : ce worktree sera supprimé) -->
<div v-if="promoteConfirming" class="mt-1 rounded border border-amber-700/40 bg-amber-950/20 p-2 text-xs text-amber-200">
{{ promoteConfirmText }}
<div class="mt-1 flex items-center gap-2">
<button class="btn-primary text-xs" :disabled="!!gitBusy" @click="onPromote">
{{ gitBusy === 'promote' ? t('worktrees.promoting') : forcePromoteNeeded ? t('worktrees.forcePromote') : t('worktrees.promote') }}
</button>
<button class="btn text-xs" @click="cancelPromote">{{ t('common.cancel') }}</button>
</div>
</div>
<!-- réponse rapide aux dialogues des sessions corrélées en attente (sans ouvrir le terminal) --> <!-- réponse rapide aux dialogues des sessions corrélées en attente (sans ouvrir le terminal) -->
<DialogPrompt v-for="ws in waitingSessions" :key="`dlg-${ws.id}`" :session="ws" class="mt-2" /> <DialogPrompt v-for="ws in waitingSessions" :key="`dlg-${ws.id}`" :session="ws" class="mt-2" />
</div> </div>
@@ -88,6 +132,17 @@ function liveSession(s: SessionSummary): SessionSummary {
return sessions.sessions.find((x) => x.id === s.id) ?? s; return sessions.sessions.find((x) => x.id === s.id) ?? s;
} }
// sessions « liées à l'app » (managées) affichées par défaut ; les externes (découvertes hors
// Arboretum) ne le sont que si l'interrupteur global est activé → évite les listes à rallonge.
const visibleSessions = computed(() =>
store.showExternalSessions
? props.worktree.sessions
: props.worktree.sessions.filter((s) => liveSession(s).source === 'managed'),
);
const externalCount = computed(
() => props.worktree.sessions.filter((s) => liveSession(s).source !== 'managed').length,
);
// sessions corrélées actuellement bloquées sur un dialogue → réponse rapide inline. // sessions corrélées actuellement bloquées sur un dialogue → réponse rapide inline.
const waitingSessions = computed(() => const waitingSessions = computed(() =>
props.worktree.sessions.map(liveSession).filter((s) => s.live && s.activity === 'waiting' && s.dialog), props.worktree.sessions.map(liveSession).filter((s) => s.live && s.activity === 'waiting' && s.dialog),
@@ -135,6 +190,73 @@ const branchLabel = computed(() =>
props.worktree.branch ?? (props.worktree.detached ? `${t('worktrees.detached')} ${props.worktree.head.slice(0, 7)}` : '—'), props.worktree.branch ?? (props.worktree.detached ? `${t('worktrees.detached')} ${props.worktree.head.slice(0, 7)}` : '—'),
); );
// --- actions git : commit / push / promotion en principal ---
const gitBusy = ref<null | 'commit' | 'push' | 'promote'>(null);
const gitError = ref<string | null>(null);
const committingOpen = ref(false);
const commitMessage = ref('');
const promoteConfirming = ref(false);
const forcePromoteNeeded = ref(false);
const canPush = computed(() => !!props.worktree.branch && !props.worktree.detached);
const canPromote = computed(() => !props.worktree.isMain && !!props.worktree.branch && !props.worktree.detached);
const promoteConfirmText = computed(() => t('worktrees.promoteConfirm', { branch: props.worktree.branch ?? '' }));
function gitMsg(err: unknown): string {
return err instanceof Error ? err.message : String(err);
}
function cancelPromote(): void {
promoteConfirming.value = false;
forcePromoteNeeded.value = false;
}
async function onCommit(): Promise<void> {
if (gitBusy.value || commitMessage.value.trim() === '') return;
gitBusy.value = 'commit';
gitError.value = null;
try {
await store.commitWorktree(props.worktree.repoId, props.worktree.path, commitMessage.value.trim());
committingOpen.value = false;
commitMessage.value = '';
} catch (err) {
gitError.value = gitMsg(err);
} finally {
gitBusy.value = null;
}
}
async function onPush(): Promise<void> {
if (gitBusy.value) return;
gitBusy.value = 'push';
gitError.value = null;
try {
await store.pushWorktree(props.worktree.repoId, props.worktree.path);
} catch (err) {
gitError.value = gitMsg(err);
} finally {
gitBusy.value = null;
}
}
async function onPromote(): Promise<void> {
if (gitBusy.value) return;
gitBusy.value = 'promote';
gitError.value = null;
try {
await store.promoteWorktree(props.worktree.repoId, props.worktree.path, forcePromoteNeeded.value);
// succès : la branche est passée en principal et ce worktree est supprimé → la carte se démonte.
} catch (err) {
if (err instanceof ApiError && err.status === 409) {
forcePromoteNeeded.value = true; // arbre modifié → proposer la promotion forcée
gitError.value = err.message;
} else {
gitError.value = gitMsg(err);
}
} finally {
gitBusy.value = null;
}
}
function reset(): void { function reset(): void {
confirming.value = false; confirming.value = false;
forceNeeded.value = false; forceNeeded.value = false;

View File

@@ -2,7 +2,9 @@
<div class="flex min-h-0 w-full flex-1 overflow-hidden"> <div class="flex min-h-0 w-full flex-1 overflow-hidden">
<AppSidebar /> <AppSidebar />
<div class="flex min-h-0 min-w-0 flex-1 flex-col"> <div class="flex min-h-0 min-w-0 flex-1 flex-col">
<main v-if="fullbleed" class="flex min-h-0 flex-1 flex-col pb-14 md:pb-0"> <!-- fullbleed (terminal) : pas de tabbar mobile ni de padding bas terminal réellement plein écran
(la navigation reste accessible via le lien « retour » du header de la vue). -->
<main v-if="fullbleed" class="flex min-h-0 flex-1 flex-col">
<slot /> <slot />
</main> </main>
<main v-else class="flex-1 overflow-y-auto pb-14 md:pb-0"> <main v-else class="flex-1 overflow-y-auto pb-14 md:pb-0">
@@ -10,7 +12,7 @@
<slot /> <slot />
</div> </div>
</main> </main>
<MobileTabBar /> <MobileTabBar v-if="!fullbleed" />
</div> </div>
</div> </div>
</template> </template>

View File

@@ -7,6 +7,15 @@
style="padding-bottom: calc(1rem + env(safe-area-inset-bottom))" style="padding-bottom: calc(1rem + env(safe-area-inset-bottom))"
> >
<div class="mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-700" /> <div class="mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-700" />
<!-- accès recherche/palette : sur mobile la sidebar (et K) est indisponible seul point d'entrée -->
<button
type="button"
class="mb-3 flex w-full items-center gap-2 rounded-lg border border-zinc-800 bg-zinc-950/40 px-3 py-2 text-sm text-zinc-400 transition-colors hover:border-zinc-700 hover:text-zinc-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/50"
@click="openSearch"
>
<Search :size="16" />
<span>{{ t('common.search') }}</span>
</button>
<nav class="mb-3 flex flex-col gap-1"> <nav class="mb-3 flex flex-col gap-1">
<NavItem <NavItem
v-for="item in secondary" v-for="item in secondary"
@@ -31,12 +40,20 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Search } from '@lucide/vue';
import { useNav } from '../../composables/useNav'; import { useNav } from '../../composables/useNav';
import { useCommandPalette } from '../../composables/useCommandPalette';
import NavItem from './NavItem.vue'; import NavItem from './NavItem.vue';
import AppShellFooter from './AppShellFooter.vue'; import AppShellFooter from './AppShellFooter.vue';
import BaseButton from '../ui/BaseButton.vue'; import BaseButton from '../ui/BaseButton.vue';
const { t } = useI18n(); const { t } = useI18n();
const { secondary, isActive } = useNav(); const { secondary, isActive } = useNav();
const palette = useCommandPalette();
const emit = defineEmits<{ close: [] }>(); const emit = defineEmits<{ close: [] }>();
function openSearch(): void {
emit('close');
palette.show();
}
</script> </script>

View File

@@ -1,4 +1,4 @@
import { computed, ref } from 'vue'; import { computed, effectScope, ref } from 'vue';
import type { WorktreeSummary } from '@arboretum/shared'; import type { WorktreeSummary } from '@arboretum/shared';
import type { ListToolbarControls, SortDir } from './useListControls'; import type { ListToolbarControls, SortDir } from './useListControls';
import { useDebouncedRef } from './useDebouncedRef'; import { useDebouncedRef } from './useDebouncedRef';
@@ -29,7 +29,14 @@ function create(): WorktreeView {
const filterDefList = worktreeFilters(); const filterDefList = worktreeFilters();
const filterDefs = computed(() => filterDefList); const filterDefs = computed(() => filterDefList);
const accessor = (w: WorktreeSummary): string => `${w.branch ?? ''} ${w.path}`.toLowerCase(); // label de repo cherchable (en plus de la branche et du chemin) → la recherche couvre le nom du dépôt.
const repoLabelById = computed(() => {
const m = new Map<string, string>();
for (const r of useWorktreesStore().repos) m.set(r.id, r.label);
return m;
});
const accessor = (w: WorktreeSummary): string =>
`${repoLabelById.value.get(w.repoId) ?? ''} ${w.branch ?? ''} ${w.path}`.toLowerCase();
function apply(list: readonly WorktreeSummary[]): WorktreeSummary[] { function apply(list: readonly WorktreeSummary[]): WorktreeSummary[] {
let items = [...list]; let items = [...list];
@@ -98,6 +105,12 @@ function create(): WorktreeView {
} }
export function useWorktreeView(): WorktreeView { export function useWorktreeView(): WorktreeView {
instance ??= create(); // Effets (watch du debounce, computeds) créés dans un scope DÉTACHÉ : sinon ils seraient rattachés
// au scope du premier composant qui appelle ce singleton et stoppés à son démontage (navigation),
// gelant le ref débouncé → la recherche ne filtrerait plus après un aller-retour de route.
if (!instance) {
const scope = effectScope(true);
instance = scope.run(() => create())!;
}
return instance; return instance;
} }

View File

@@ -41,6 +41,12 @@ export default {
live: 'live', live: 'live',
resumable: 'resumable', resumable: 'resumable',
sourceDiscovered: 'discovered', sourceDiscovered: 'discovered',
hide: 'Hide',
unhide: 'Unhide',
hiddenBadge: 'hidden',
hideDiscovered: 'Hide external history',
showHidden: 'Show hidden',
hideHidden: 'Hide hidden',
clients: 'no client | 1 client | {n} clients', clients: 'no client | 1 client | {n} clients',
exitCode: 'exit code {code}', exitCode: 'exit code {code}',
statusLabel: { statusLabel: {
@@ -50,7 +56,7 @@ export default {
}, },
registryStatus: { registryStatus: {
busy: 'busy', busy: 'busy',
idle: 'idle', idle: 'available',
waiting: 'waiting', waiting: 'waiting',
}, },
dialog: { dialog: {
@@ -107,14 +113,15 @@ export default {
modeMain: 'Main checkouts', modeMain: 'Main checkouts',
branchLabel: 'Branch name', branchLabel: 'Branch name',
branchPlaceholder: 'feature/…', branchPlaceholder: 'feature/…',
newBranch: 'create branch', branchHint: 'Created where missing, reused where it already exists in the repo.',
baseRefLabel: 'Base ref (optional)', baseRefLabel: 'Base branch (optional)',
baseRefPlaceholder: "repo's default branch",
commandLabel: 'Session', commandLabel: 'Session',
reposLabel: 'Repos in this session', reposLabel: 'Repos in this session',
launch: 'Launch session', launch: 'Launch session',
launching: 'Launching…', launching: 'Launching…',
close: 'Close', close: 'Close',
ok: 'worktree created', ok: 'worktree ready',
error: 'failed', error: 'failed',
skippedLabel: 'skipped', skippedLabel: 'skipped',
done: 'Group session started.', done: 'Group session started.',
@@ -140,6 +147,8 @@ export default {
creating: 'Creating…', creating: 'Creating…',
branch: 'Branch', branch: 'Branch',
newBranch: 'create branch', newBranch: 'create branch',
baseRefLabel: 'Base branch',
baseRefPlaceholder: 'default branch',
start: 'Start', start: 'Start',
starting: 'Starting…', starting: 'Starting…',
startNone: 'no session', startNone: 'no session',
@@ -155,6 +164,16 @@ export default {
confirmDelete: 'Confirm delete', confirmDelete: 'Confirm delete',
forceDelete: 'Force delete', forceDelete: 'Force delete',
prune: 'Prune', prune: 'Prune',
commit: 'Commit',
commitPlaceholder: 'Commit message',
committing: 'Committing…',
push: 'Push',
pushing: 'Pushing…',
promote: 'Make main',
promoting: 'Promoting…',
promoteConfirm:
'Branch “{branch}” will become the repositorys main checkout; this worktree will be removed (the previous main branch is kept). Continue?',
forcePromote: 'Force (dirty tree)',
main: 'main', main: 'main',
detached: 'detached', detached: 'detached',
locked: 'locked', locked: 'locked',
@@ -162,12 +181,34 @@ export default {
clean: 'clean', clean: 'clean',
dirty: '{n} changed', dirty: '{n} changed',
noSession: 'no session', noSession: 'no session',
externalSessions: 'external',
showExternalSessions: 'Show external sessions ({n})',
},
project: {
new: 'New project',
title: 'New project',
intro: 'Creates a new folder under the chosen root, then starts a session in it.',
nameLabel: 'Project name',
namePlaceholder: 'my-project',
rootLabel: 'Root folder',
rootPlaceholder: '/absolute/path/root',
gitInit: 'Initialize a git repository (git init)',
commandLabel: 'Command',
create: 'Create',
creating: 'Creating…',
}, },
terminal: { terminal: {
observer: 'observer (read-only)', observer: 'observer (read-only)',
sessionEnded: 'Session ended', sessionEnded: 'Session ended',
back: 'Sessions', back: 'Sessions',
notAttachable: 'This session runs outside Arboretum — fork it to interact, or resume it once it has stopped.', notAttachable: 'This session runs outside Arboretum — fork it to interact, or resume it once it has stopped.',
fullscreen: 'Fullscreen',
exitFullscreen: 'Exit fullscreen',
maximize: 'Maximize',
restore: 'Restore',
openFullscreen: 'Open fullscreen',
group: 'Group',
covers: 'covers',
}, },
push: { push: {
enable: 'Enable notifications', enable: 'Enable notifications',
@@ -242,7 +283,7 @@ export default {
live: 'Live', live: 'Live',
waiting: 'Waiting', waiting: 'Waiting',
busy: 'Busy', busy: 'Busy',
idle: 'Idle', idle: 'Available',
exited: 'Exited', exited: 'Exited',
resumable: 'Resumable', resumable: 'Resumable',
}, },
@@ -298,6 +339,9 @@ export default {
sessionKilled: 'Session killed', sessionKilled: 'Session killed',
sessionResumed: 'Session resumed', sessionResumed: 'Session resumed',
sessionForked: 'Session forked', sessionForked: 'Session forked',
sessionHidden: 'Session hidden',
sessionUnhidden: 'Session shown',
sessionsHidden: 'no session hidden | 1 session hidden | {n} sessions hidden',
repoAdded: 'Repository added', repoAdded: 'Repository added',
repoRemoved: 'Repository removed', repoRemoved: 'Repository removed',
worktreeCreated: 'Worktree created', worktreeCreated: 'Worktree created',
@@ -306,6 +350,9 @@ export default {
groupCreated: 'Group created', groupCreated: 'Group created',
groupUpdated: 'Group updated', groupUpdated: 'Group updated',
groupDeleted: 'Group deleted', groupDeleted: 'Group deleted',
groupSessionLaunched: 'Group session started',
groupSessionPartial: 'Group session started ({n} repo(s) skipped)',
projectCreated: 'Project created',
genericError: 'Something went wrong', genericError: 'Something went wrong',
dismiss: 'Dismiss', dismiss: 'Dismiss',
}, },
@@ -366,6 +413,20 @@ export default {
removeRoot: 'Remove', removeRoot: 'Remove',
scanInterval: 'Re-scan interval (minutes)', scanInterval: 'Re-scan interval (minutes)',
scanIntervalHint: '0 disables periodic scanning. Changes apply on the next daemon restart.', scanIntervalHint: '0 disables periodic scanning. Changes apply on the next daemon restart.',
// Claude CLI
claudeCli: 'Claude CLI',
claudeCliHint: 'Where Arboretum finds the `claude` binary and its data. Handy when the daemon runs as a service with a minimal PATH that does not include ~/.local/bin.',
claudeBinStatusOk: 'Detected',
claudeBinStatusNotFound: 'Not found — sessions cannot start until this is resolved.',
claudeBinStatusBadPath: 'The configured path is not an executable file.',
claudeBinSourceConfigured: 'configured',
claudeBinSourcePath: 'PATH',
claudeBinPathLabel: 'Binary path override',
claudeBinPathHint: 'Absolute path to the `claude` executable. Leave empty to auto-detect via PATH. Takes effect on the next session.',
claudeBinPathPlaceholder: 'e.g. /home/you/.local/bin/claude',
claudeHomeLabel: 'Claude home directory',
claudeHomeHint: 'Override the ~/.claude location (transcripts & session registry). Applies on the next daemon restart.',
claudeHomePlaceholder: 'e.g. /home/you/.claude',
// Serveur (lecture seule) // Serveur (lecture seule)
server: 'Server', server: 'Server',
serverHint: 'Set at startup via CLI flags — changing them requires restarting the daemon.', serverHint: 'Set at startup via CLI flags — changing them requires restarting the daemon.',

View File

@@ -43,6 +43,12 @@ const fr: typeof en = {
live: 'en cours', live: 'en cours',
resumable: 'reprenable', resumable: 'reprenable',
sourceDiscovered: 'découverte', sourceDiscovered: 'découverte',
hide: 'Masquer',
unhide: 'Réafficher',
hiddenBadge: 'masquée',
hideDiscovered: 'Masquer lhistorique externe',
showHidden: 'Afficher les masquées',
hideHidden: 'Masquer les masquées',
clients: 'aucun client | 1 client | {n} clients', clients: 'aucun client | 1 client | {n} clients',
exitCode: 'code de sortie {code}', exitCode: 'code de sortie {code}',
statusLabel: { statusLabel: {
@@ -52,7 +58,7 @@ const fr: typeof en = {
}, },
registryStatus: { registryStatus: {
busy: 'occupée', busy: 'occupée',
idle: 'inactive', idle: 'disponible',
waiting: 'en attente', waiting: 'en attente',
}, },
dialog: { dialog: {
@@ -109,14 +115,15 @@ const fr: typeof en = {
modeMain: 'Checkouts principaux', modeMain: 'Checkouts principaux',
branchLabel: 'Nom de branche', branchLabel: 'Nom de branche',
branchPlaceholder: 'feature/…', branchPlaceholder: 'feature/…',
newBranch: 'cer la branche', branchHint: 'Cée si absente, réutilisée si déjà présente dans le dépôt.',
baseRefLabel: 'Réf. de base (optionnel)', baseRefLabel: 'Branche de base (optionnel)',
baseRefPlaceholder: 'branche par défaut du dépôt',
commandLabel: 'Session', commandLabel: 'Session',
reposLabel: 'Dépôts de la session', reposLabel: 'Dépôts de la session',
launch: 'Lancer la session', launch: 'Lancer la session',
launching: 'Lancement…', launching: 'Lancement…',
close: 'Fermer', close: 'Fermer',
ok: 'worktree créé', ok: 'worktree prêt',
error: 'échec', error: 'échec',
skippedLabel: 'ignoré', skippedLabel: 'ignoré',
done: 'Session de groupe démarrée.', done: 'Session de groupe démarrée.',
@@ -142,6 +149,8 @@ const fr: typeof en = {
creating: 'Création…', creating: 'Création…',
branch: 'Branche', branch: 'Branche',
newBranch: 'créer la branche', newBranch: 'créer la branche',
baseRefLabel: 'Branche de base',
baseRefPlaceholder: 'branche par défaut',
start: 'Démarrer', start: 'Démarrer',
starting: 'Démarrage…', starting: 'Démarrage…',
startNone: 'aucune session', startNone: 'aucune session',
@@ -157,6 +166,16 @@ const fr: typeof en = {
confirmDelete: 'Confirmer', confirmDelete: 'Confirmer',
forceDelete: 'Forcer la suppression', forceDelete: 'Forcer la suppression',
prune: 'Élaguer', prune: 'Élaguer',
commit: 'Commit',
commitPlaceholder: 'Message de commit',
committing: 'Commit…',
push: 'Push',
pushing: 'Push…',
promote: 'Passer en principal',
promoting: 'Promotion…',
promoteConfirm:
'La branche « {branch} » deviendra le checkout principal du dépôt ; ce worktree sera supprimé (lancienne branche principale est conservée). Continuer ?',
forcePromote: 'Forcer (arbre modifié)',
main: 'principal', main: 'principal',
detached: 'détaché', detached: 'détaché',
locked: 'verrouillé', locked: 'verrouillé',
@@ -164,6 +183,21 @@ const fr: typeof en = {
clean: 'propre', clean: 'propre',
dirty: '{n} modifié(s)', dirty: '{n} modifié(s)',
noSession: 'aucune session', noSession: 'aucune session',
externalSessions: 'externes',
showExternalSessions: 'Afficher les sessions externes ({n})',
},
project: {
new: 'Nouveau projet',
title: 'Nouveau projet',
intro: 'Crée un nouveau dossier sous la racine choisie, puis y lance une session.',
nameLabel: 'Nom du projet',
namePlaceholder: 'mon-projet',
rootLabel: 'Dossier racine',
rootPlaceholder: '/chemin/absolu/racine',
gitInit: 'Initialiser un dépôt git (git init)',
commandLabel: 'Commande',
create: 'Créer',
creating: 'Création…',
}, },
terminal: { terminal: {
observer: 'observateur (lecture seule)', observer: 'observateur (lecture seule)',
@@ -171,6 +205,13 @@ const fr: typeof en = {
back: 'Sessions', back: 'Sessions',
notAttachable: notAttachable:
'Cette session tourne hors dArboretum — dupliquez-la pour interagir, ou reprenez-la une fois arrêtée.', 'Cette session tourne hors dArboretum — dupliquez-la pour interagir, ou reprenez-la une fois arrêtée.',
fullscreen: 'Plein écran',
exitFullscreen: 'Quitter le plein écran',
maximize: 'Agrandir',
restore: 'Réduire',
openFullscreen: 'Ouvrir en plein écran',
group: 'Groupe',
covers: 'couvre',
}, },
push: { push: {
enable: 'Activer les notifications', enable: 'Activer les notifications',
@@ -245,7 +286,7 @@ const fr: typeof en = {
live: 'Active', live: 'Active',
waiting: 'En attente', waiting: 'En attente',
busy: 'Occupée', busy: 'Occupée',
idle: 'Au repos', idle: 'Disponible',
exited: 'Terminée', exited: 'Terminée',
resumable: 'Reprenable', resumable: 'Reprenable',
}, },
@@ -301,6 +342,9 @@ const fr: typeof en = {
sessionKilled: 'Session tuée', sessionKilled: 'Session tuée',
sessionResumed: 'Session reprise', sessionResumed: 'Session reprise',
sessionForked: 'Session dupliquée', sessionForked: 'Session dupliquée',
sessionHidden: 'Session masquée',
sessionUnhidden: 'Session réaffichée',
sessionsHidden: 'aucune session masquée | 1 session masquée | {n} sessions masquées',
repoAdded: 'Dépôt ajouté', repoAdded: 'Dépôt ajouté',
repoRemoved: 'Dépôt retiré', repoRemoved: 'Dépôt retiré',
worktreeCreated: 'Worktree créé', worktreeCreated: 'Worktree créé',
@@ -309,6 +353,9 @@ const fr: typeof en = {
groupCreated: 'Groupe créé', groupCreated: 'Groupe créé',
groupUpdated: 'Groupe mis à jour', groupUpdated: 'Groupe mis à jour',
groupDeleted: 'Groupe supprimé', groupDeleted: 'Groupe supprimé',
groupSessionLaunched: 'Session de groupe démarrée',
groupSessionPartial: 'Session de groupe démarrée ({n} dépôt(s) ignoré(s))',
projectCreated: 'Projet créé',
genericError: 'Une erreur est survenue', genericError: 'Une erreur est survenue',
dismiss: 'Fermer', dismiss: 'Fermer',
}, },
@@ -369,6 +416,20 @@ const fr: typeof en = {
removeRoot: 'Retirer', removeRoot: 'Retirer',
scanInterval: 'Intervalle de re-scan (minutes)', scanInterval: 'Intervalle de re-scan (minutes)',
scanIntervalHint: '0 désactive le scan périodique. Les changements prennent effet au prochain redémarrage du daemon.', scanIntervalHint: '0 désactive le scan périodique. Les changements prennent effet au prochain redémarrage du daemon.',
// Claude CLI
claudeCli: 'CLI Claude',
claudeCliHint: 'Où Arboretum trouve le binaire `claude` et ses données. Utile quand le daemon tourne en service avec un PATH minimal qui ninclut pas ~/.local/bin.',
claudeBinStatusOk: 'Détecté',
claudeBinStatusNotFound: 'Introuvable — impossible de lancer une session tant que ce nest pas résolu.',
claudeBinStatusBadPath: 'Le chemin configuré nest pas un fichier exécutable.',
claudeBinSourceConfigured: 'configuré',
claudeBinSourcePath: 'PATH',
claudeBinPathLabel: 'Chemin du binaire (override)',
claudeBinPathHint: 'Chemin absolu vers lexécutable `claude`. Laisser vide pour lauto-détection via le PATH. Prend effet à la prochaine session.',
claudeBinPathPlaceholder: 'ex. /home/vous/.local/bin/claude',
claudeHomeLabel: 'Répertoire ~/.claude',
claudeHomeHint: 'Surcharge lemplacement de ~/.claude (transcripts & registre des sessions). Prend effet au redémarrage du daemon.',
claudeHomePlaceholder: 'ex. /home/vous/.claude',
// Serveur (lecture seule) // Serveur (lecture seule)
server: 'Serveur', server: 'Serveur',
serverHint: 'Définis au démarrage via des flags CLI — les modifier nécessite de redémarrer le daemon.', serverHint: 'Définis au démarrage via des flags CLI — les modifier nécessite de redémarrer le daemon.',

View File

@@ -100,6 +100,12 @@ export class Attachment {
this.pending = null; this.pending = null;
this.client.releaseAttachment(this); this.client.releaseAttachment(this);
} }
/** Flush ACK ciblé : relance immédiatement le flux si le serveur avait mis ce PTY en pause
* (ex. retour-visible de la cellule, dont le rendu était gelé hors-écran). N'ACK que du traité. */
flushAck(): void {
this.client.flushAck(this);
}
} }
export class WsClient { export class WsClient {
@@ -108,6 +114,7 @@ export class WsClient {
private socket: WebSocket | null = null; private socket: WebSocket | null = null;
private ready = false; private ready = false;
private stopped = true; private stopped = true;
private visibilityBound = false;
private backoffMs = BACKOFF_MIN_MS; private backoffMs = BACKOFF_MIN_MS;
private reconnectTimer: ReturnType<typeof setTimeout> | null = null; private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
/** terminaux ouverts, ré-attachés à chaque reconnexion (ordre d'insertion = ordre FIFO) */ /** terminaux ouverts, ré-attachés à chaque reconnexion (ordre d'insertion = ordre FIFO) */
@@ -121,6 +128,14 @@ export class WsClient {
connect(): void { connect(): void {
this.stopped = false; this.stopped = false;
// Au retour en avant-plan, le rendu se débloque : on flushe les ACK pour ne pas attendre le
// débounce si le serveur s'était mis en pause pendant que l'onglet/PWA était caché.
if (!this.visibilityBound && typeof document !== 'undefined') {
this.visibilityBound = true;
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') this.flushAcks();
});
}
if (this.socket || this.reconnectTimer) return; if (this.socket || this.reconnectTimer) return;
if (this.status.value === 'idle') this.status.value = 'connecting'; if (this.status.value === 'idle') this.status.value = 'connecting';
this.openSocket(); this.openSocket();
@@ -301,6 +316,9 @@ export class WsClient {
att.lastAckBytes = 0; att.lastAckBytes = 0;
att.sink.reset(); att.sink.reset();
if (frame.payload.byteLength > 0) att.sink.write(frame.payload); if (frame.payload.byteLength > 0) att.sink.write(frame.payload);
// filet anti-stall : le replay ne passe PAS de callback de write → on arme quand même l'ACK
// traînant pour que le flux suivant ne puisse pas rester gelé (serveur en pause).
this.scheduleTrailingAck(att, att.epoch);
return; return;
} }
if (frame.type !== BINARY_FRAME.OUTPUT) return; if (frame.type !== BINARY_FRAME.OUTPUT) return;
@@ -315,8 +333,22 @@ export class WsClient {
att.lastAckBytes = att.processedBytes; att.lastAckBytes = att.processedBytes;
this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes }); this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes });
} }
// ACK traînant débouncé : si le flux s'arrête avec un reliquat non-ACKé, this.scheduleTrailingAck(att, epoch);
// le serveur ne doit jamais rester en pause faute d'ACK suivant. });
// Filet anti-stall, INDÉPENDANT du callback de xterm.write : ce callback est throttlé quand
// l'onglet/PWA passe en arrière-plan (rAF + setTimeout ralentis) → sans cela l'ACK ne partait
// plus, le serveur dépassait HIGH_WATERMARK et mettait le PTY en pause, et la sortie « chargeait
// par à-coups » jusqu'à ce que l'utilisateur bouge. On arme donc l'ACK traînant dès la réception.
this.scheduleTrailingAck(att, epoch);
}
/**
* (Ré)arme l'ACK traînant débouncé : si rien d'autre n'arrive, il envoie le reliquat d'octets
* réellement traités par xterm (`processedBytes`) pour que le serveur sorte toujours de pause.
* Appelé à la fois dans le callback de write ET à la réception d'une frame (le callback peut être
* indéfiniment retardé quand le rendu est gelé). Sémantique inchangée : on n'ACK que du traité.
*/
private scheduleTrailingAck(att: Attachment, epoch: number): void {
if (att.trailingAckTimer) clearTimeout(att.trailingAckTimer); if (att.trailingAckTimer) clearTimeout(att.trailingAckTimer);
att.trailingAckTimer = setTimeout(() => { att.trailingAckTimer = setTimeout(() => {
att.trailingAckTimer = null; att.trailingAckTimer = null;
@@ -326,7 +358,28 @@ export class WsClient {
this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes }); this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes });
} }
}, 200); }, 200);
}); }
/** ACK immédiat du reliquat traité pour tous les terminaux ouverts — au retour en avant-plan,
* pour rattraper sans attendre le débounce un serveur éventuellement en pause. */
private flushAcks(): void {
for (const att of this.attachments) this.flushAttachmentAck(att);
}
/** ACK immédiat du reliquat traité d'UN attachment — n'ACK que du réellement traité (invariant
* préservé). Factorisé : utilisé par flushAcks() et par le flush ciblé flushAck(). */
private flushAttachmentAck(att: Attachment): void {
if (att.closed || att.channel < 0) return;
if (att.processedBytes > att.lastAckBytes) {
att.lastAckBytes = att.processedBytes;
this.sendControl({ type: 'ack', channel: att.channel, bytes: att.processedBytes });
}
}
/** Flush ACK ciblé d'un seul attachment : relance un PTY mis en pause par le serveur quand la
* cellule était cachée (cf. Attachment.flushAck, appelé au retour-visible). */
flushAck(att: Attachment): void {
this.flushAttachmentAck(att);
} }
private handleServerMessage(msg: ServerMessage): void { private handleServerMessage(msg: ServerMessage): void {

View File

@@ -28,9 +28,9 @@ export interface CrossRepoResult {
/** Options de lancement d'une session de groupe (P6). */ /** Options de lancement d'une session de groupe (P6). */
export interface GroupFeatureOptions { export interface GroupFeatureOptions {
command: 'claude' | 'bash'; command: 'claude' | 'bash';
/** présent → crée le worktree de cette branche dans chaque repo puis relie ; absent → checkouts principaux. */ /** présent → crée/réutilise le worktree de cette branche dans chaque repo puis relie ; absent → checkouts principaux. */
branch?: string; branch?: string;
newBranch?: boolean; /** branche de base d'une branche créée (défaut serveur : branche par défaut du dépôt). */
baseRef?: string; baseRef?: string;
} }
@@ -157,7 +157,7 @@ export const useGroupsStore = defineStore('groups', () => {
try { try {
const res = await wt.createWorktree(repoId, { const res = await wt.createWorktree(repoId, {
branch, branch,
newBranch: opts.newBranch ?? true, mode: 'auto', // détecte créer / checkout / suivi remote selon l'existence par dépôt
...(opts.baseRef ? { baseRef: opts.baseRef } : {}), ...(opts.baseRef ? { baseRef: opts.baseRef } : {}),
startSession: null, startSession: null,
}); });
@@ -176,6 +176,11 @@ export const useGroupsStore = defineStore('groups', () => {
}), }),
); );
} }
// Mode feature : si AUCUN worktree n'a pu être créé/résolu, ne pas tenter la session (elle
// échouerait en « no resolvable worktree » et masquerait les vraies erreurs par dépôt).
if (opts.branch && worktreeResults.length > 0 && !worktreeResults.some((r) => r.status === 'ok')) {
return { worktreeResults, session: null, dirs: [], skipped: [] };
}
const res = await createGroupSession(groupId, { const res = await createGroupSession(groupId, {
command: opts.command, command: opts.command,
...(opts.branch ? { branch: opts.branch } : {}), ...(opts.branch ? { branch: opts.branch } : {}),

View File

@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref } from 'vue'; import { ref } from 'vue';
import type { CreateSessionRequest, SessionResponse, SessionSummary, SessionsListResponse } from '@arboretum/shared'; import type { CreateProjectRequest, CreateProjectResponse, CreateSessionRequest, HideDiscoveredResponse, SessionResponse, SessionSummary, SessionsListResponse } from '@arboretum/shared';
import { api } from '../lib/api'; import { api } from '../lib/api';
import { wsClient, type SessionEvent } from '../lib/ws-client'; import { wsClient, type SessionEvent } from '../lib/ws-client';
@@ -8,6 +8,8 @@ export const useSessionsStore = defineStore('sessions', () => {
const sessions = ref<SessionSummary[]>([]); const sessions = ref<SessionSummary[]>([]);
const loading = ref(false); const loading = ref(false);
const loadError = ref<string | null>(null); const loadError = ref<string | null>(null);
// false (défaut) : les sessions masquées sont exclues ; true : on les inclut (mode « afficher les masquées »).
const showHidden = ref(false);
let unsubscribe: (() => void) | null = null; let unsubscribe: (() => void) | null = null;
// vivantes d'abord, puis par date de création décroissante (même ordre que le serveur) // vivantes d'abord, puis par date de création décroissante (même ordre que le serveur)
@@ -15,7 +17,17 @@ export const useSessionsStore = defineStore('sessions', () => {
return [...list].sort((a, b) => Number(b.live) - Number(a.live) || b.createdAt.localeCompare(a.createdAt)); return [...list].sort((a, b) => Number(b.live) - Number(a.live) || b.createdAt.localeCompare(a.createdAt));
} }
function remove(id: string): void {
const idx = sessions.value.findIndex((s) => s.id === id);
if (idx >= 0) sessions.value.splice(idx, 1);
}
function upsert(session: SessionSummary): void { function upsert(session: SessionSummary): void {
// session masquée et mode « afficher les masquées » inactif : on la retire de la liste.
if (session.hidden && !showHidden.value) {
remove(session.id);
return;
}
const idx = sessions.value.findIndex((s) => s.id === session.id); const idx = sessions.value.findIndex((s) => s.id === session.id);
if (idx >= 0) sessions.value.splice(idx, 1, session); if (idx >= 0) sessions.value.splice(idx, 1, session);
else sessions.value.push(session); else sessions.value.push(session);
@@ -43,7 +55,8 @@ export const useSessionsStore = defineStore('sessions', () => {
loading.value = true; loading.value = true;
loadError.value = null; loadError.value = null;
try { try {
const res = await api.get<SessionsListResponse>('/api/v1/sessions'); const url = showHidden.value ? '/api/v1/sessions?includeHidden=true' : '/api/v1/sessions';
const res = await api.get<SessionsListResponse>(url);
sessions.value = sorted(res.sessions); sessions.value = sorted(res.sessions);
} catch (err) { } catch (err) {
loadError.value = err instanceof Error ? err.message : String(err); loadError.value = err instanceof Error ? err.message : String(err);
@@ -52,6 +65,31 @@ export const useSessionsStore = defineStore('sessions', () => {
} }
} }
async function setShowHidden(value: boolean): Promise<void> {
showHidden.value = value;
await fetchSessions();
}
// Masque une session découverte (retrait optimiste si on n'affiche pas les masquées).
async function hideSession(id: string): Promise<void> {
await api.post<{ ok: true }>(`/api/v1/sessions/${id}/hide`);
if (!showHidden.value) remove(id);
}
// Ré-affiche une session masquée.
async function unhideSession(id: string): Promise<void> {
await api.delete<{ ok: true }>(`/api/v1/sessions/${id}/hide`);
}
// Masque tout l'historique de sessions externes visible. Renvoie le nombre masqué.
async function hideDiscovered(): Promise<number> {
const res = await api.post<HideDiscoveredResponse>('/api/v1/sessions/hide-discovered');
if (!showHidden.value) {
sessions.value = sessions.value.filter((s) => !(s.source === 'discovered' && !s.hidden));
}
return res.hidden;
}
function startRealtime(): void { function startRealtime(): void {
unsubscribe ??= wsClient.subscribeSessions(onEvent); unsubscribe ??= wsClient.subscribeSessions(onEvent);
} }
@@ -68,6 +106,13 @@ export const useSessionsStore = defineStore('sessions', () => {
return res.session; return res.session;
} }
// Crée un nouveau dossier de projet `<root>/<name>` côté serveur puis y lance une session.
async function createProject(req: CreateProjectRequest): Promise<CreateProjectResponse> {
const res = await api.post<CreateProjectResponse>('/api/v1/projects', req);
upsert(res.session);
return res;
}
async function killSession(id: string): Promise<void> { async function killSession(id: string): Promise<void> {
await api.delete<{ ok: true }>(`/api/v1/sessions/${id}`); await api.delete<{ ok: true }>(`/api/v1/sessions/${id}`);
} }
@@ -90,12 +135,18 @@ export const useSessionsStore = defineStore('sessions', () => {
sessions, sessions,
loading, loading,
loadError, loadError,
showHidden,
fetchSessions, fetchSessions,
setShowHidden,
startRealtime, startRealtime,
stopRealtime, stopRealtime,
createSession, createSession,
createProject,
killSession, killSession,
resumeSession, resumeSession,
forkSession, forkSession,
hideSession,
unhideSession,
hideDiscovered,
}; };
}); });

View File

@@ -9,6 +9,8 @@ export const useSettingsStore = defineStore('settings', () => {
const server = ref<ServerInfo | null>(null); const server = ref<ServerInfo | null>(null);
const scanRoots = ref<string[]>([]); const scanRoots = ref<string[]>([]);
const scanIntervalMin = ref(0); const scanIntervalMin = ref(0);
const claudeBinPath = ref<string | null>(null);
const claudeHome = ref<string | null>(null);
const loaded = ref(false); const loaded = ref(false);
const saving = ref(false); const saving = ref(false);
@@ -16,6 +18,8 @@ export const useSettingsStore = defineStore('settings', () => {
server.value = res.server; server.value = res.server;
scanRoots.value = res.settings.scanRoots; scanRoots.value = res.settings.scanRoots;
scanIntervalMin.value = res.settings.scanIntervalMin; scanIntervalMin.value = res.settings.scanIntervalMin;
claudeBinPath.value = res.settings.claudeBinPath;
claudeHome.value = res.settings.claudeHome;
loaded.value = true; loaded.value = true;
} }
@@ -32,5 +36,5 @@ export const useSettingsStore = defineStore('settings', () => {
} }
} }
return { server, scanRoots, scanIntervalMin, loaded, saving, fetch, save }; return { server, scanRoots, scanIntervalMin, claudeBinPath, claudeHome, loaded, saving, fetch, save };
}); });

View File

@@ -4,12 +4,14 @@ import type {
CreateWorktreeRequest, CreateWorktreeRequest,
CreateWorktreeResponse, CreateWorktreeResponse,
DiscoverReposResponse, DiscoverReposResponse,
RepoBranchesResponse,
RepoResponse, RepoResponse,
ReposListResponse, ReposListResponse,
RepoSummary, RepoSummary,
SessionResponse, SessionResponse,
SessionSummary, SessionSummary,
StartRepoSessionRequest, StartRepoSessionRequest,
WorktreeResponse,
WorktreeSummary, WorktreeSummary,
WorktreesListResponse, WorktreesListResponse,
} from '@arboretum/shared'; } from '@arboretum/shared';
@@ -21,6 +23,9 @@ export const useWorktreesStore = defineStore('worktrees', () => {
const worktrees = ref<WorktreeSummary[]>([]); const worktrees = ref<WorktreeSummary[]>([]);
const loading = ref(false); const loading = ref(false);
const loadError = ref<string | null>(null); const loadError = ref<string | null>(null);
// Préférence d'affichage (purement client) : révéler les sessions externes (lancées hors Arboretum)
// dans les fiches worktree. Par défaut masquées pour éviter les listes à rallonge.
const showExternalSessions = ref(false);
let unsubscribe: (() => void) | null = null; let unsubscribe: (() => void) | null = null;
function upsertRepo(repo: RepoSummary): void { function upsertRepo(repo: RepoSummary): void {
@@ -127,6 +132,32 @@ export const useWorktreesStore = defineStore('worktrees', () => {
await refreshRepoWorktrees(repoId); await refreshRepoWorktrees(repoId);
} }
/** Branches du repo (locales/remote + défaut) pour le sélecteur de branche de base. */
async function fetchBranches(repoId: string): Promise<RepoBranchesResponse> {
return api.get<RepoBranchesResponse>(`/api/v1/repos/${repoId}/branches`);
}
/** Commit (add -A + commit) dans un worktree ; le worktree mis à jour arrive aussi par WS. */
async function commitWorktree(repoId: string, path: string, message: string): Promise<WorktreeSummary> {
const res = await api.post<WorktreeResponse>(`/api/v1/repos/${repoId}/worktrees/commit`, { path, message });
upsertWorktree(res.worktree);
return res.worktree;
}
/** Push de la branche d'un worktree (upstream auto si absent). */
async function pushWorktree(repoId: string, path: string): Promise<WorktreeSummary> {
const res = await api.post<WorktreeResponse>(`/api/v1/repos/${repoId}/worktrees/push`, { path });
upsertWorktree(res.worktree);
return res.worktree;
}
/** « Passer en principal » : la branche du worktree devient le checkout principal (worktree supprimé). */
async function promoteWorktree(repoId: string, path: string, force = false): Promise<void> {
await api.post<{ worktree: WorktreeSummary | null }>(`/api/v1/repos/${repoId}/worktrees/promote`, { path, force });
removeWorktreeLocal(path);
await refreshRepoWorktrees(repoId);
}
function startRealtime(): void { function startRealtime(): void {
unsubscribe ??= wsClient.subscribeWorktrees(onEvent); unsubscribe ??= wsClient.subscribeWorktrees(onEvent);
} }
@@ -140,6 +171,7 @@ export const useWorktreesStore = defineStore('worktrees', () => {
worktrees, worktrees,
loading, loading,
loadError, loadError,
showExternalSessions,
worktreesForRepo, worktreesForRepo,
fetchAll, fetchAll,
addRepo, addRepo,
@@ -151,6 +183,10 @@ export const useWorktreesStore = defineStore('worktrees', () => {
startMainSession, startMainSession,
deleteWorktree, deleteWorktree,
prune, prune,
fetchBranches,
commitWorktree,
pushWorktree,
promoteWorktree,
startRealtime, startRealtime,
stopRealtime, stopRealtime,
}; };

View File

@@ -39,6 +39,10 @@
<label v-if="hiddenCount > 0" class="flex items-center gap-2 px-1 text-xs text-zinc-400"> <label v-if="hiddenCount > 0" class="flex items-center gap-2 px-1 text-xs text-zinc-400">
<input v-model="showHidden" type="checkbox" /> {{ t('repos.showHidden', { n: hiddenCount }) }} <input v-model="showHidden" type="checkbox" /> {{ t('repos.showHidden', { n: hiddenCount }) }}
</label> </label>
<label v-if="externalSessionCount > 0" class="flex items-center gap-2 px-1 text-xs text-zinc-400">
<input v-model="store.showExternalSessions" type="checkbox" />
{{ t('worktrees.showExternalSessions', { n: externalSessionCount }) }}
</label>
<EmptyState v-if="visibleRepos.length === 0" :icon="Search" :title="t('controls.results', 0)" /> <EmptyState v-if="visibleRepos.length === 0" :icon="Search" :title="t('controls.results', 0)" />
<RepoSection v-for="repo in pagedRepos" :key="repo.id" :repo="repo" /> <RepoSection v-for="repo in pagedRepos" :key="repo.id" :repo="repo" />
<Pagination <Pagination
@@ -82,6 +86,10 @@ const scanning = ref(false);
const showHidden = ref(false); const showHidden = ref(false);
const hiddenCount = computed(() => store.repos.filter((r) => r.hidden).length); const hiddenCount = computed(() => store.repos.filter((r) => r.hidden).length);
// nombre de sessions externes (lancées hors Arboretum) embarquées dans les worktrees → pilote la case.
const externalSessionCount = computed(
() => store.worktrees.reduce((n, w) => n + w.sessions.filter((s) => s.source !== 'managed').length, 0),
);
// repos visibles : les masqués sont exclus sauf si « afficher les masqués » est coché. Triés par libellé ; // repos visibles : les masqués sont exclus sauf si « afficher les masqués » est coché. Triés par libellé ;
// puis masqués quand un filtre/recherche worktree actif ne laisse rien dans le repo. // puis masqués quand un filtre/recherche worktree actif ne laisse rien dans le repo.

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="flex min-h-0 flex-col"> <div ref="root" class="flex min-h-0 flex-1 flex-col bg-[#09090b]">
<header class="flex items-center gap-3 border-b border-zinc-800 bg-zinc-900/60 px-3 py-1.5"> <header class="flex items-center gap-3 border-b border-zinc-800 bg-zinc-900/60 px-3 py-1.5">
<RouterLink :to="{ name: 'sessions' }" class="text-sm text-zinc-400 transition-colors hover:text-zinc-200"> <RouterLink :to="{ name: 'sessions' }" class="text-sm text-zinc-400 transition-colors hover:text-zinc-200">
{{ t('terminal.back') }} {{ t('terminal.back') }}
@@ -8,7 +8,17 @@
<span class="truncate font-mono text-xs text-zinc-500" :title="session?.cwd ?? sessionId"> <span class="truncate font-mono text-xs text-zinc-500" :title="session?.cwd ?? sessionId">
{{ session?.cwd ?? sessionId }} {{ session?.cwd ?? sessionId }}
</span> </span>
<button
type="button"
class="ml-auto shrink-0 rounded p-1 text-zinc-400 transition-colors hover:bg-zinc-800 hover:text-zinc-200"
:title="t(isFullscreen ? 'terminal.exitFullscreen' : 'terminal.fullscreen')"
:aria-label="t(isFullscreen ? 'terminal.exitFullscreen' : 'terminal.fullscreen')"
@click="toggleFullscreen"
>
<component :is="isFullscreen ? Minimize : Maximize" class="h-4 w-4" />
</button>
</header> </header>
<SessionContextBar v-if="session" :session="session" />
<DialogPrompt v-if="session && session.activity === 'waiting'" :session="session" class="m-2" /> <DialogPrompt v-if="session && session.activity === 'waiting'" :session="session" class="m-2" />
<TerminalView v-if="attachable" :key="`${sessionId}:${mode}`" :session-id="sessionId" :mode="mode" class="flex-1" /> <TerminalView v-if="attachable" :key="`${sessionId}:${mode}`" :session-id="sessionId" :mode="mode" class="flex-1" />
<!-- session externe non détenue par Arboretum : pas de terminal interactif (cf. fork/resume). --> <!-- session externe non détenue par Arboretum : pas de terminal interactif (cf. fork/resume). -->
@@ -19,16 +29,22 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted } from 'vue'; import { computed, onBeforeUnmount, onMounted, ref, useTemplateRef } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Maximize, Minimize } from '@lucide/vue';
import { useSessionsStore } from '../stores/sessions'; import { useSessionsStore } from '../stores/sessions';
import { useGroupsStore } from '../stores/groups';
import { useWorktreesStore } from '../stores/worktrees';
import TerminalView from '../components/TerminalView.vue'; import TerminalView from '../components/TerminalView.vue';
import DialogPrompt from '../components/DialogPrompt.vue'; import DialogPrompt from '../components/DialogPrompt.vue';
import SessionContextBar from '../components/SessionContextBar.vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const store = useSessionsStore(); const store = useSessionsStore();
const groups = useGroupsStore();
const worktrees = useWorktreesStore();
const sessionId = computed(() => String(route.params.id)); const sessionId = computed(() => String(route.params.id));
const mode = computed<'interactive' | 'observer'>(() => (route.query.mode === 'observer' ? 'observer' : 'interactive')); const mode = computed<'interactive' | 'observer'>(() => (route.query.mode === 'observer' ? 'observer' : 'interactive'));
@@ -36,8 +52,28 @@ const session = computed(() => store.sessions.find((s) => s.id === sessionId.val
// défaut true : une navigation directe (liste pas encore chargée) tente l'attache d'une session managée. // défaut true : une navigation directe (liste pas encore chargée) tente l'attache d'une session managée.
const attachable = computed(() => session.value?.attachable ?? true); const attachable = computed(() => session.value?.attachable ?? true);
// Vrai plein écran (API Fullscreen) — surtout utile sur mobile pour récupérer la barre d'URL.
// On synchronise `isFullscreen` sur l'événement natif : l'utilisateur peut sortir via Échap.
const root = useTemplateRef<HTMLDivElement>('root');
const isFullscreen = ref(false);
function syncFullscreen(): void {
isFullscreen.value = document.fullscreenElement === root.value;
}
function toggleFullscreen(): void {
if (document.fullscreenElement) void document.exitFullscreen().catch(() => {});
else void root.value?.requestFullscreen().catch(() => {});
}
onMounted(() => { onMounted(() => {
// navigation directe : garantit l'en-tête (cwd/commande) même si l'AppShell n'a pas encore chargé. // navigation directe : garantit l'en-tête (cwd/commande) même si l'AppShell n'a pas encore chargé.
if (store.sessions.length === 0) void store.fetchSessions(); if (store.sessions.length === 0) void store.fetchSessions();
// best-effort : la barre de contexte a besoin des groupes + worktrees pour résoudre repos/branches.
if (groups.groups.length === 0) void groups.fetchGroups();
if (worktrees.repos.length === 0) void worktrees.fetchAll();
document.addEventListener('fullscreenchange', syncFullscreen);
});
onBeforeUnmount(() => {
document.removeEventListener('fullscreenchange', syncFullscreen);
if (document.fullscreenElement === root.value) void document.exitFullscreen().catch(() => {});
}); });
</script> </script>

View File

@@ -1,5 +1,14 @@
<template> <template>
<PageHeader :title="t('nav.sessions')"> <PageHeader :title="t('nav.sessions')">
<BaseButton variant="primary" size="sm" :icon="FolderPlus" @click="showNewProject = true">
{{ t('project.new') }}
</BaseButton>
<BaseButton v-if="hasDiscovered" variant="ghost" size="sm" :icon="EyeOff" :loading="hidingAll" @click="onHideDiscovered">
{{ t('sessions.hideDiscovered') }}
</BaseButton>
<BaseButton variant="ghost" size="sm" :icon="store.showHidden ? EyeOff : Eye" @click="onToggleHidden">
{{ t(store.showHidden ? 'sessions.hideHidden' : 'sessions.showHidden') }}
</BaseButton>
<BaseButton variant="ghost" size="sm" :icon="RefreshCw" :loading="store.loading" @click="store.fetchSessions()"> <BaseButton variant="ghost" size="sm" :icon="RefreshCw" :loading="store.loading" @click="store.fetchSessions()">
{{ t('common.refresh') }} {{ t('common.refresh') }}
</BaseButton> </BaseButton>
@@ -31,6 +40,7 @@
@select="onPickCwd" @select="onPickCwd"
@close="showPicker = false" @close="showPicker = false"
/> />
<NewProjectModal v-if="showNewProject" @close="showNewProject = false" />
<SkeletonRow v-if="store.loading && store.sessions.length === 0" /> <SkeletonRow v-if="store.loading && store.sessions.length === 0" />
<EmptyState v-else-if="store.sessions.length === 0" :icon="TerminalSquare" :title="t('sessions.empty')" /> <EmptyState v-else-if="store.sessions.length === 0" :icon="TerminalSquare" :title="t('sessions.empty')" />
@@ -43,6 +53,7 @@
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="badge bg-zinc-800 font-mono text-zinc-300">{{ s.command }}</span> <span class="badge bg-zinc-800 font-mono text-zinc-300">{{ s.command }}</span>
<BaseBadge v-if="s.source === 'discovered'" tone="sky">{{ t('sessions.sourceDiscovered') }}</BaseBadge> <BaseBadge v-if="s.source === 'discovered'" tone="sky">{{ t('sessions.sourceDiscovered') }}</BaseBadge>
<BaseBadge v-if="s.hidden" tone="zinc">{{ t('sessions.hiddenBadge') }}</BaseBadge>
<SessionStateBadge :session="s" /> <SessionStateBadge :session="s" />
<span class="ml-auto text-xs text-zinc-500">{{ formatDate(s.createdAt) }}</span> <span class="ml-auto text-xs text-zinc-500">{{ formatDate(s.createdAt) }}</span>
</div> </div>
@@ -73,6 +84,9 @@
<BaseButton variant="primary" size="sm" :icon="Play" :loading="actingId === s.id" @click="onResume(s.id)">{{ t('sessions.resume') }}</BaseButton> <BaseButton variant="primary" size="sm" :icon="Play" :loading="actingId === s.id" @click="onResume(s.id)">{{ t('sessions.resume') }}</BaseButton>
<BaseButton size="sm" :icon="GitFork" :loading="actingId === s.id" @click="onFork(s.id)">{{ t('sessions.fork') }}</BaseButton> <BaseButton size="sm" :icon="GitFork" :loading="actingId === s.id" @click="onFork(s.id)">{{ t('sessions.fork') }}</BaseButton>
</template> </template>
<!-- masquage : réafficher une session masquée, ou masquer une session découverte qui pollue la liste -->
<BaseButton v-if="s.hidden" variant="ghost" size="sm" :icon="Eye" :loading="hidingId === s.id" @click="onUnhide(s.id)">{{ t('sessions.unhide') }}</BaseButton>
<BaseButton v-else-if="s.source === 'discovered'" variant="ghost" size="sm" :icon="EyeOff" :loading="hidingId === s.id" @click="onHide(s.id)">{{ t('sessions.hide') }}</BaseButton>
</div> </div>
</div> </div>
</li> </li>
@@ -88,11 +102,11 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import type { SessionSummary } from '@arboretum/shared'; import type { SessionSummary } from '@arboretum/shared';
import { RefreshCw, FolderOpen, Plus, TerminalSquare, SquareTerminal, Eye, Trash2, GitFork, Play, Search } from '@lucide/vue'; import { RefreshCw, FolderOpen, FolderPlus, Plus, TerminalSquare, SquareTerminal, Eye, EyeOff, Trash2, GitFork, Play, Search } from '@lucide/vue';
import { useSessionsStore } from '../stores/sessions'; import { useSessionsStore } from '../stores/sessions';
import { useWorktreesStore } from '../stores/worktrees'; import { useWorktreesStore } from '../stores/worktrees';
import { useToastsStore } from '../stores/toasts'; import { useToastsStore } from '../stores/toasts';
@@ -108,6 +122,7 @@ import Pagination from '../components/Pagination.vue';
import SessionStateBadge from '../components/SessionStateBadge.vue'; import SessionStateBadge from '../components/SessionStateBadge.vue';
import DialogPrompt from '../components/DialogPrompt.vue'; import DialogPrompt from '../components/DialogPrompt.vue';
import DirectoryPicker from '../components/DirectoryPicker.vue'; import DirectoryPicker from '../components/DirectoryPicker.vue';
import NewProjectModal from '../components/NewProjectModal.vue';
const { t, locale } = useI18n(); const { t, locale } = useI18n();
const router = useRouter(); const router = useRouter();
@@ -126,10 +141,15 @@ const controls = useListControls<SessionSummary>({
const newCwd = ref(''); const newCwd = ref('');
const newCommand = ref<'claude' | 'bash'>('claude'); const newCommand = ref<'claude' | 'bash'>('claude');
const showPicker = ref(false); const showPicker = ref(false);
const showNewProject = ref(false);
const creating = ref(false); const creating = ref(false);
const killArmedId = ref<string | null>(null); const killArmedId = ref<string | null>(null);
const killing = ref(false); const killing = ref(false);
const actingId = ref<string | null>(null); const actingId = ref<string | null>(null);
const hidingId = ref<string | null>(null);
const hidingAll = ref(false);
// au moins une session externe visible → propose le masquage de masse
const hasDiscovered = computed(() => store.sessions.some((s) => s.source === 'discovered' && !s.hidden));
onMounted(() => { onMounted(() => {
// navigation directe : garantit la liste même si l'AppShell n'a pas encore chargé. // navigation directe : garantit la liste même si l'AppShell n'a pas encore chargé.
@@ -197,4 +217,48 @@ async function onConfirmKill(id: string): Promise<void> {
killArmedId.value = null; killArmedId.value = null;
} }
} }
async function onHide(id: string): Promise<void> {
hidingId.value = id;
try {
await store.hideSession(id);
toasts.success(t('toast.sessionHidden'));
} catch (err) {
toasts.error(err);
} finally {
hidingId.value = null;
}
}
async function onUnhide(id: string): Promise<void> {
hidingId.value = id;
try {
await store.unhideSession(id);
toasts.success(t('toast.sessionUnhidden'));
} catch (err) {
toasts.error(err);
} finally {
hidingId.value = null;
}
}
async function onHideDiscovered(): Promise<void> {
hidingAll.value = true;
try {
const n = await store.hideDiscovered();
toasts.success(t('toast.sessionsHidden', n));
} catch (err) {
toasts.error(err);
} finally {
hidingAll.value = false;
}
}
async function onToggleHidden(): Promise<void> {
try {
await store.setShowHidden(!store.showHidden);
} catch (err) {
toasts.error(err);
}
}
</script> </script>

View File

@@ -137,6 +137,44 @@
</div> </div>
</section> </section>
<!-- Claude CLI -->
<section class="card flex flex-col gap-3">
<h2 class="flex items-center gap-2 text-sm font-semibold text-zinc-100">
<Terminal :size="16" /> {{ t('settings.claudeCli') }}
</h2>
<p class="text-xs text-zinc-500">{{ t('settings.claudeCliHint') }}</p>
<!-- Diagnostic de détection -->
<div v-if="settings.server" class="card-inset flex flex-wrap items-center gap-x-2 gap-y-1 text-xs">
<component :is="claudeBin.ok ? CheckCircle2 : AlertCircle" :size="15" :class="claudeBin.ok ? 'text-emerald-400' : 'text-rose-400'" />
<span :class="claudeBin.ok ? 'text-zinc-300' : 'text-rose-300'">
{{ claudeBin.ok ? t('settings.claudeBinStatusOk') : (claudeBin.source === 'configured' ? t('settings.claudeBinStatusBadPath') : t('settings.claudeBinStatusNotFound')) }}
</span>
<code v-if="claudeBin.path" class="min-w-0 truncate font-mono text-zinc-200" :title="claudeBin.path">{{ claudeBin.path }}</code>
<span v-if="claudeBin.source" class="badge bg-zinc-700/40 text-zinc-300">
{{ claudeBin.source === 'configured' ? t('settings.claudeBinSourceConfigured') : t('settings.claudeBinSourcePath') }}
</span>
</div>
<label class="flex flex-col gap-1">
<span class="text-xs text-zinc-400">{{ t('settings.claudeBinPathLabel') }}</span>
<input v-model.trim="claudeBinDraft" class="input font-mono" :placeholder="t('settings.claudeBinPathPlaceholder')" />
<span class="text-xs text-zinc-500">{{ t('settings.claudeBinPathHint') }}</span>
</label>
<label class="flex flex-col gap-1">
<span class="text-xs text-zinc-400">{{ t('settings.claudeHomeLabel') }}</span>
<input v-model.trim="claudeHomeDraft" class="input font-mono" :placeholder="t('settings.claudeHomePlaceholder')" />
<span class="text-xs text-zinc-500">{{ t('settings.claudeHomeHint') }}</span>
</label>
<div>
<BaseButton variant="primary" :loading="settings.saving" :disabled="!claudeDirty" @click="saveClaude">
{{ t('settings.save') }}
</BaseButton>
</div>
</section>
<!-- Sécurité & conformité --> <!-- Sécurité & conformité -->
<section class="card flex flex-col gap-3"> <section class="card flex flex-col gap-3">
<h2 class="flex items-center gap-2 text-sm font-semibold text-zinc-100"> <h2 class="flex items-center gap-2 text-sm font-semibold text-zinc-100">
@@ -202,7 +240,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Bell, BellOff, Check, Coffee, Copy, Download, FolderOpen, KeyRound, Plus, RefreshCw, ScanSearch, Send, Server, Shield, SlidersHorizontal, Trash2, X } from '@lucide/vue'; import { AlertCircle, Bell, BellOff, Check, CheckCircle2, Coffee, Copy, Download, FolderOpen, KeyRound, Plus, RefreshCw, ScanSearch, Send, Server, Shield, SlidersHorizontal, Terminal, Trash2, X } from '@lucide/vue';
import type { import type {
AuditLogEntry, AuditLogEntry,
AuditLogsResponse, AuditLogsResponse,
@@ -328,6 +366,27 @@ async function saveDiscovery(): Promise<void> {
} }
} }
// ---- Claude CLI ----
const claudeBinDraft = ref('');
const claudeHomeDraft = ref('');
const claudeBin = computed(() => settings.server?.claudeBin ?? { path: null, source: null, ok: false });
const claudeDirty = computed(
() => claudeBinDraft.value !== (settings.claudeBinPath ?? '') || claudeHomeDraft.value !== (settings.claudeHome ?? ''),
);
function syncClaudeDraft(): void {
claudeBinDraft.value = settings.claudeBinPath ?? '';
claudeHomeDraft.value = settings.claudeHome ?? '';
}
async function saveClaude(): Promise<void> {
try {
await settings.save({ claudeBinPath: claudeBinDraft.value, claudeHome: claudeHomeDraft.value });
syncClaudeDraft();
toasts.success(t('settings.saved'));
} catch (e) {
toasts.error(e);
}
}
// ---- Sécurité & conformité (audit / RGPD) ---- // ---- Sécurité & conformité (audit / RGPD) ----
const audit = ref<AuditLogEntry[]>([]); const audit = ref<AuditLogEntry[]>([]);
const auditing = ref(false); const auditing = ref(false);
@@ -378,6 +437,7 @@ async function deleteMyData(): Promise<void> {
onMounted(async () => { onMounted(async () => {
await Promise.all([loadTokens(), settings.loaded ? Promise.resolve() : settings.fetch()]); await Promise.all([loadTokens(), settings.loaded ? Promise.resolve() : settings.fetch()]);
syncDiscoveryDraft(); syncDiscoveryDraft();
syncClaudeDraft();
void push.refresh(); void push.refresh();
}); });
</script> </script>

Some files were not shown because too many files have changed in this diff Show More