A Databricks pane that follows the databricks CLI: browse workspace, Unity Catalog, compute, jobs, pipelines, apps and dashboards, and see what Claude reads or…

<img src="media/bg42-11-4.png" alt="" width="800">
<h1 align="center">power-bi-agentic-development</h1>
The best source for Power BI AI skills and agentic development resources in one marketplace <br></br> <i> Teach AI agents like Claude Code or GitHub Copilot Power BI and Microsoft Fabric </i>
<img src="https://img.shields.io/badge/version-26.40.7-blue" alt="Version"> <img src="https://img.shields.io/badge/Power_BI-F2C811?logo=powerbi&logoColor=000" alt="Power BI"> <img src="https://img.shields.io/badge/Microsoft_Fabric-008272" alt="Microsoft Fabric"> <img src="https://img.shields.io/badge/Tabular_Editor-2E7D32" alt="Tabular Editor"> <img src="https://img.shields.io/badge/license-GPL--3.0-green" alt="License">
[!WARNING] These skills are under active development with a weekly release cadence, so expect regular renaming and restructuring.
Versions 26.26 through 26.38 are a deliberate breaking transition. Skills may be consolidated, renamed, removed, or made less automatic between weekly releases in this range. Pin 26.25 or earlier if you need the pre-transition skill structure and behavior; do not assume compatibility from one transition release to the next.
Here's how you get started in Claude Code; run this in the terminal to get the marketplace:
claude plugin marketplace add data-goblin/power-bi-agentic-development
Click here for a YouTube walkthrough
Add the marketplace, then install plugins via /plugin and navigating to the installed marketplace.
<table> <tr> <td align="center"><img src="media/marketplace-ui.png" alt="Marketplace UI" width="400"></td> <td align="center"><img src="media/marketplace-auto-update.png" alt="Marketplace auto-update" width="400"></td> </tr> <tr> <td align="center"><em>Install plugins from the marketplace</em></td> <td align="center"><em>Enable marketplace auto-update</em></td> </tr> </table>
Alternative; add plugins via command line:
claude plugin install goblin-mode@power-bi-agentic-development
claude plugin install tabular-editor@power-bi-agentic-development
claude plugin install pbi-desktop@power-bi-agentic-development
claude plugin install pbip@power-bi-agentic-development
claude plugin install semantic-models@power-bi-agentic-development
claude plugin install reports@power-bi-agentic-development
claude plugin install paginated-reports@power-bi-agentic-development
claude plugin install custom-visuals@power-bi-agentic-development
claude plugin install fabric-cli@power-bi-agentic-development
claude plugin install fabric-admin@power-bi-agentic-development
claude plugin install databricks-cli@power-bi-agentic-development
claude plugin install fabric-data-app@power-bi-agentic-development
claude plugin install etl@power-bi-agentic-development
claude plugin install dashboards@power-bi-agentic-development
The standalone Copilot CLI supports plugin installation from GitHub repos. Copilot CLI reads the same .claude-plugin/marketplace.json manifest this repo uses, so the marketplace and child-plugin layout works without modification.
TMDL files have a problem with repository-relative paths over 260 characters. Windows' legacy MAX_PATH blocks git clone from writing them unless long path support is enabled at both the OS and git level. Without this, copilot plugin install aborts with Filename too long.
Check useful-stuff/agent-scripts/enable-windows-longpaths.ps1 as an example of a script you can run from an elevated ps environment to enable long paths; there are other routes to do this that you can find online, too... just ask Copilot. A reboot is recommended after the registry change. This is a Windows OS limitation, documented at Maximum Path Length Limitation.
See also the below git config command:
git config --system core.longpaths true
This repository is an Anthropic-format plugin marketplace (a set of plugins), not a single distributable plugin, so the root .claude-plugin/ contains only marketplace.json. Two documented install paths work:
1. Register the marketplace once, then install named child plugins. Example:
copilot plugin marketplace add data-goblin/power-bi-agentic-development
copilot plugin install tabular-editor@power-bi-agentic-development
2. Or install a single plugin directly from its subdirectory, no marketplace registration needed. Example:
copilot plugin install data-goblin/power-bi-agentic-development:plugins/pbip
Both forms are documented in the Copilot CLI plugin reference and the plugins how-to. Inside an interactive Copilot session, /plugin install PLUGIN-NAME@MARKETPLACE-NAME is the equivalent of (1). The bare copilot plugin install data-goblin/power-bi-agentic-development (no qualifier) will not install anything useful, because the root is a marketplace catalog, not a plugin.
Inside Copilot CLI:
/env # Loaded instructions, MCP servers, skills, agents, plugins, LSPs, extensions
/plugin list # Installed plugins
/skills list # Available skills
/skills info pbip # Details for a specific skill
/agent # Browse installed agents
skills/<name>/SKILL.md.*.agent.md extension required by Copilot CLI's documented convention. Claude Code matches any *.md file in agents/, so the dual extension works in both tools..mcp.json (plugin root) or .github/mcp.json. The plugins in this repo do not currently ship MCP servers.hooks/hooks.json (with per-hook if path filters). Copilot CLI reads .github/plugin/plugin.json, which points it at hooks/copilot-hooks.json: the same scripts, wired with explicit bash and powershell commands so a Windows host without Git Bash on PATH gets a clean no-op instead of a failed launch. Copilot has no if filter and denies a tool call on any non-zero PreToolUse exit, so every script also re-applies its own path and command filters and exits 0 on anything unrelated. Requires Copilot CLI >= 1.0.26 (2026-04-14) for CLAUDE_PLUGIN_ROOT (changelog); older builds skip the hooks rather than fail. Native Windows bash users may also hit a separate path-format bug tracked upstream at claude-code#11984.~/.copilot/installed-plugins/ and their hooks run in every session on the machine. There is no per-project install, so the "prefer project scope" advice below applies to Claude Code only; in Copilot, install a plugin only while you need it./plugin rm or copilot plugin uninstall can fail with Access is denied. (os error 5). This is an open Copilot CLI bug, not a plugin problem: the installer swaps the plugin folder by renaming it, and Windows refuses the rename while another process holds a handle on it. VS Code's Copilot extension keeps directory watchers on every installed plugin's hooks/, agents/ and skills/ folders, and a second Copilot CLI session does the same. Tracked at github/copilot-cli#4095 and #4151.
%USERPROFILE%\.copilot\installed-plugins\ (or %COPILOT_HOME%\installed-plugins\) and restart Copilot CLI.hooks folder from that same location.The repo contains skills, agents, and hooks.
/skill-name. In Claude Code, skills and commands have coalesced; commands are simply more prescriptive skill workflows.Hook checks can be individually toggled via config files. Set any check to false to disable it:
plugins/pbip/hooks/config.yaml -- PBIR, TMDL, and report binding validationplugins/pbi-desktop/hooks/config.yaml -- DAX references, measure metadata, referential integrity, metadata cache[!WARNING] Don't install every plugin. Each skill competes for the agent's attention and context window, so install a plugin only when you need it and remove it when you don't. Prefer installing plugins scoped to a project rather than to your user, so each project carries only the skills it actually uses.
| Type | Name | Description |
|---|---|---|
| Skill | help-me-get-started | A slow, friendly, jargon-free guide to agentic development for people new to agents; talks through what you want to do, feels out your role and access, teaches the five pillars (model, context, prompt, tools, environment) with local interactive explainers, and checks and installs what you need (Windows/macOS commands). Adapts pace: full tutorial or a fast install run |
| Skill | improve-my-agent-setup | Setup-wide health check with modes (shallow/deep/ultra/yolo): skills, memory, tools, STT, model independence, other clients, harness config, git, permission/isolation, network and autonomous-agent exposure, safety enforcement, secrets and PII hygiene, and workflow habits; then offers to fix what's weak. Absorbs the old /audit-context |
| Type | Name | Description |
|---|---|---|
| Skill | bpa-rules | Create and improve Best Practice Analyzer rules for models |
| Skill | c-sharp-scripting | C# scripting and macros for TE |
| Skill | te-cli | Cross-platform Tabular Editor CLI (te, preview) for semantic models from the terminal |
| Skill | te2-cli | Tabular Editor 2 CLI usage and automation (not TE3) |
| Skill | te-docs | Tabular Editor documentation search, TE3 config files. Uses pbi-search CLI |
| Command | /suggest-rule | Generate BPA rules from descriptions |
| Agent | bpa-expression-helper | Debug and improve BPA rule expressions |
| Type | Name | Description |
|---|---|---|
| Skill | connect-pbid | Explore, query, and modify a model in Power BI Desktop, and reload/screenshot the report canvas via the Desktop Bridge |
| Agent | query-listener | Capture DAX queries from Power BI Desktop visuals in real time |
| Hook | DAX reference validation | Validates table, column, and measure references against the connected model; suggests corrections |
| Hook | Measure metadata enforcement | Blocks adding measures without DisplayFolder, Description, and FormatString |
| Hook | Referential integrity check | Reports unmatched many-side keys after relationship or column changes |
| Hook | Metadata cache refresh | Auto-snapshots model metadata on TOM connect or model modification |
| Hook | Compatibility level check | Reports features available by upgrading; optional auto-upgrade |
| Type | Name | Description |
|---|---|---|
| Skill | pbip | Power BI Project (PBIP) format, structure, and file types |
| Skill | tmdl | Author and edit TMDL files directly |
| Skill | pbir-format | Author and edit PBIR metadata files directly (visual.json, report.json, themes, filters, report extensions, visual calculations) |
| Agent | pbip-validator | Validate PBIP project structure, TMDL syntax, and PBIR schemas |
| Hook | PBIR validation | Validates PBIR structure, required fields, naming conventions, and schema URLs |
| Hook | Report binding validation | Validates semantic model binding (byPath directory exists; byConnection model exists via fab exists) |
| Hook | TMDL validation | Validates TMDL structural syntax |
| Type | Name | Description |
|---|---|---|
| Skill | create-pbi-report | Step-by-step workflow for building a complete report from scratch via the pbir CLI: model discovery, pages, theme, visuals, field binding, filtering, formatting, validation, publishing |
| Skill | pbi-report-design | The Power BI report design canon: design identity, visual hierarchy, layout, color discipline, chart selection, KPI/table design, accessibility. Shared reference used by the other report skills |
| Skill | modifying-theme-json | Design, enforce, audit, and validate report themes through the pbir CLI |
| Skill | review-report | Actionable feedback on report quality, usage, and effectiveness; usage analysis, health checks |
| Skill | pbir-cli | Programmatic report manipulation via the pbir CLI, including live Power BI Desktop refresh and page screenshots |
| Mod | /report-pane | Report pane: pages, visuals, bookmarks, filters and report measures of the .Report folder as a tree that follows pbir, with live highlights of what Claude reads or changes. Optional arg: a path to a .Report folder. Icons: FabricSymbols NF |
| Agent | deneb-reviewer | Review Deneb visual specs for Vega/Vega-Lite syntax and conventions |
| Agent | svg-reviewer | Review SVG DAX measures for syntax and design quality |
| Agent | r-reviewer | Review R visual scripts (ggplot2) for Power BI conventions |
| Agent | python-reviewer | Review Python visual scripts (matplotlib/seaborn) for Power BI conventions |
| Type | Name | Description |
|---|---|---|
| Skill | paginated-report | Author, validate, publish, and test Power BI paginated reports in RDL format (Report Builder, PBIRS/SSRS-compatible); connect to a semantic model, render to PDF/Excel |
| Hook | RDL validation | Validates .rdl structure after Write/Edit and on Bash commands touching .rdl files; blocks on structural errors only |
| Type | Name | Description |
|---|---|---|
| Skill | deneb-visuals | Deneb visual creation, Vega/Vega-Lite spec authoring, Deneb best practices for PBIR reports |
| Skill | r-visuals | Custom R visuals (ggplot2) for Power BI reports |
| Skill | python-visuals | Custom Python visuals (matplotlib/seaborn) for Power BI reports |
| Skill | svg-visuals | SVG generation via DAX measures and extension measures for inline chart visualizations (sparklines, bullet charts, KPI indicators, and more) |
| Skill | powerbi-custom-visuals | Power BI developer custom visual (.pbiviz) development with the pbiviz toolchain and its MCP server: scaffold, build, debug, package, certify, publish to AppSource |
Reviewer agents for these visual types (deneb-reviewer, svg-reviewer, r-reviewer, python-reviewer) ship in the reports plugin above.
| Type | Name | Description |
|---|---|---|
| Skill | semantic-model | Design, build, refresh, and review semantic models through a te-first tool cascade |
| Skill | organize-semantic-model | Organize a model end to end: names, folders, hierarchies, descriptions, formats, UDFs, perspectives, translations, roles |
| Skill | refresh-semantic-model | Trigger or troubleshoot refreshes |
| Skill | lineage-analysis | Trace downstream reports from a semantic model across workspaces |
| Skill | power-query | Write M expressions, debug query folding, execute M locally or via Fabric API |
| Skill | dax | Write, debug, and optimize DAX in semantic models. Contributed by Justin Martin |
| Agent | semantic-model-auditor | Audit semantic models for quality, memory, DAX, and design issues |
| Type | Name | Description |
|---|---|---|
| Skill | fabric-cli | Fabric CLI (fab) for any remote operation in Power BI or Fabric (works fully on Pro, PPU; Fabric not required) |
| Command | /migrating-fabric-trial-capacities | Migrate workspaces from trial to production capacity |
| Mod | /fabric-pane | Fabric pane: workspaces and items as a tree that follows fab, with live highlights, copy of fab paths, open in Fabric, and open semantic models in te. Optional arg: a workspace to reveal. Icons: FabricSymbols NF |
| Type | Name | Description |
|---|---|---|
| Skill | audit-tenant-settings | Audit Fabric and Power BI tenant settings, delegated overrides, and Entra security group membership |
| Type | Name | Description |
|---|---|---|
| Mod | /databricks-pane | Databricks pane: workspace, Unity Catalog, compute, jobs, pipelines, apps and dashboards as a tree that follows databricks, with live highlights, profile switching (-p or DATABRICKS_CONFIG_PROFILE), copy of CLI arguments, and open in Databricks. Optional arg: a profile. Icons: DatabricksSymbols NF |
| Type | Name | Description |
|---|
| Mod | /fabric-app-pane | Fabric app pane: every Fabric App (rayfin/rayfin.yml) under the working directory with its data sources, deploy s
hooks/register.tsx 1218 lines1import type { EngineInterface, Register, Timer } from 'claude-code'
2import { openCommand } from './open'
3
4import type { Explorer, Onboard, Target, TreeNode, Work } from '../types'
5import { glyph, titleGlyph as dbTitle, type Tier } from './icons'
6import type { RowSpec, RowsProps, Seg } from './rows'
7import { UI_SVG } from './svg-data'
8import type { ZoneProps } from './zone'
9import { ancestors, EMPTY, empty, emptyMark, isLoaded, merge, type Row, visible } from './tree'
10import { chainOf, children, hostFrom, listCalls, PLACEHOLDER, roots } from './databricks'
11import { DB_TONE, dbKind, dbProfile, dbTargets, type Invocation, invocations, positionals, posix, tokenize, useDrives } from './parse'
12
13const STATE = { plugin: 'databricks-cli', key: 'explorer' } as const
14const NODES = { plugin: 'databricks-cli', key: 'nodes' } as const
15const PANE = 'databricks-pane'
16const TITLE = 'Databricks'
17const TITLE_COLOR = '#ff3621'
18const HINT = 'waiting for a databricks command, or /databricks-pane'
19const SORT = false
20const WINDOW = 400
21const DETAIL_ROWS = 12
22const HEADER = '#header'
23const MEMBER_VERBS = /^(create|delete|import|import-dir|mkdirs|rm|mv|rename|restore|deploy|destroy)/
24const BUSY_MAX_MS = 600_000
25const FLASH_MS = 2700
26const DOUBLE_MS = 450
27const SHIMMER = ['#f97316', '#fb923c', '#fdba74', '#ffedd5']
28const TONES: Record<string, { bright: string[]; dim: string[] }> = {
29 orange: { bright: SHIMMER, dim: ['#8a4316', '#a3562a', '#bd7444', '#d29267'] },
30 teal: { bright: ['#14b8a6', '#2dd4bf', '#5eead4', '#ccfbf1'], dim: ['#0f5e57', '#16786f', '#2a9488', '#4fb3a8'] },
31 pink: { bright: ['#ec4899', '#f472b6', '#f9a8d4', '#fce7f3'], dim: ['#831843', '#9d174d', '#b8406f', '#cf6f93'] },
32 purple: { bright: ['#a855f7', '#c084fc', '#d8b4fe', '#f3e8ff'], dim: ['#581c87', '#6b21a8', '#8b47c4', '#a874d6'] },
33}
34const MUTED = '#6e6e7a'
35const PROPS = 'props:toggle'
36const ROW_PX = 24
37const SVG_NS = 'http://www.w3.org/2000/svg'
38const NOTE_LABEL: Record<string, string> = { notebook: 'Language', catalog: 'Type', table: 'Type', view: 'Type', volume: 'Type', cluster: 'State', warehouse: 'State', pipeline: 'State', app: 'State' }
39const TONE_RANK = ['orange', 'pink', 'teal', 'purple']
40const ACCENT = '#5b9bd5'
41const LOGIN = 'databricks auth login --host <your workspace URL>'
42const UNREACHABLE =
43 /dial tcp|no such host|connection refused|connection reset|network is unreachable|no route to host|i\/o timeout|tls handshake timeout|context deadline exceeded|client\.timeout|proxyconnect|proxy error|timed? ?out|temporary failure in name resolution|could not resolve host|getaddrinfo|econnrefused|econnreset|etimedout|enotfound/i
44const SIGNED_OUT =
45 /(?:status|code|http)\W{0,3}401\b|\b401 unauthorized|\bunauthorized\b|unauthenticated|not authenticated|not logged in|no credentials|cannot configure default credentials|cannot get access token|(?:invalid|expired) (?:access |refresh |oauth )?token|token (?:is |has )?(?:invalid|expired|not set)|credential was not sent|has no \S+ profile configured|no configuration file found|no profiles configured|cannot load databricks config|databricks auth login/i
46const FONT_SCRIPT =
47 'f=; command -v fc-list >/dev/null 2>&1 && f=$(fc-list ":charset=$1" file 2>/dev/null | head -n1 | cut -d: -f1); ' +
48 '[ -n "$f" ] || f=$(ls "$HOME"/Library/Fonts/*"$2"* /Library/Fonts/*"$2"* "$HOME"/.local/share/fonts/*"$2"* 2>/dev/null | head -n1); ' +
49 '[ -n "$f" ] || { echo missing; exit 0; }; m=$(stat -c %Z "$f" 2>/dev/null || stat -f %c "$f"); p=$PPID; ' +
50 'while [ -n "$p" ] && [ "$p" -gt 1 ]; do c=$(ps -o comm= -p "$p" 2>/dev/null); c=$(basename "$c" 2>/dev/null | tr -d " "); case "$c" in ' +
51 'ghostty|kitty|alacritty|Alacritty|foot|footclient|wezterm-gui|konsole|gnome-terminal-|xterm|urxvt|st|Terminal|iTerm2) ' +
52 'e=$(ps -o etime= -p "$p" 2>/dev/null | awk -F\'[-:]\' \'{n=NF; s=$n+60*$(n-1); if (n>2) s+=3600*$(n-2); if (n>3) s+=86400*$(n-3); print s}\'); [ -n "$e" ] && [ $(( $(date +%s) - e )) -lt "$m" ] && echo stale || echo ok; exit 0;; esac; ' +
53 'p=$(ps -o ppid= -p "$p" 2>/dev/null | tr -d " "); done; echo ok'
54
55let lastPress = { key: '', at: 0 }
56const views = new Map<string, { from: number; max: number }>()
57let detected: Tier = 'nerd'
58let glyphSetting = 'auto'
59let fontHint = true
60let hinted = false
61let fellBack = false
62let follow = true
63let blink: Timer | null = null
64let generation = 0
65let closed = false
66let noDock = false
67let inflight: Promise<void> | null = null
68let queued: Promise<void> | null = null
69let platform: Promise<'linux' | 'darwin' | 'win32'> | null = null
70let propsOpen = false
71let nativeScroll = false
72const hosts = new Map<string, string>()
73
74function osName($: EngineInterface): Promise<'linux' | 'darwin' | 'win32'> {
75 platform ??= (async () => {
76 if ((await $.env.get('OS')) === 'Windows_NT') return 'win32'
77 try {
78 return (await $.process.run(['uname', '-s'], { timeoutMs: 3_000 })).stdout.trim() === 'Darwin' ? 'darwin' : 'linux'
79 } catch {
80 return 'linux'
81 }
82 })()
83 return platform
84}
85
86async function openPane($: EngineInterface, args: { id: string; title: string; focus?: true }): Promise<void> {
87 if (noDock && !args.focus) return
88 await $.ui.open(args)
89}
90
91async function cwdOf($: EngineInterface): Promise<string> {
92 return posix(await $.session.cwd())
93}
94
95function jumpTo(ex: Explorer, query: string): Partial<Explorer> {
96 const q = query.trim().toLowerCase()
97 const hits = q ? ex.nodes.filter(n => n.name.toLowerCase().includes(q) || n.note.toLowerCase().includes(q)).slice(0, 10) : []
98 const open = new Set(ex.expanded)
99 for (const n of hits) for (const a of ancestors(ex.nodes, n.id)) open.add(a)
100 return { query: '', expanded: [...open], cursor: hits[0]?.id ?? ex.cursor, scroll: null }
101}
102
103async function copyOf($: EngineInterface, text: string, surface?: string): Promise<void> {
104 const done = await $.ui.copy({ text, ...(surface ? { surface: surface as 'terminal' } : {}) })
105 $.ui.toast(done.isCopied ? `Copied ${text}` : 'Could not copy')
106}
107
108function clean(segs: Seg[]): Seg[] {
109 for (const seg of segs) for (const k of Object.keys(seg) as (keyof Seg)[]) if (seg[k] === undefined) delete seg[k]
110 return segs
111}
112
113const slots = { busy: 0, queue: [] as (() => void)[] }
114
115async function limited<T>(fn: () => Promise<T>): Promise<T> {
116 if (slots.busy < 4) slots.busy++
117 else await new Promise<void>(resolve => slots.queue.push(resolve))
118 try {
119 return await fn()
120 } finally {
121 const next = slots.queue.shift()
122 if (next) next()
123 else slots.busy--
124 }
125}
126
127async function openUrl($: EngineInterface, url: string): Promise<void> {
128 const { argv, init } = openCommand(await osName($), url)
129 try {
130 const run = await $.process.run(argv, init)
131 if (run.exitCode !== 0) $.ui.toast(`could not open ${url} with ${argv[0]}: ${run.stderr.trim().split('\n')[0] || `exit ${run.exitCode}`}`)
132 } catch {
133 $.ui.toast(`could not open ${url} with ${argv[0]}`)
134 }
135}
136
137async function fontState($: EngineInterface, charset: string, name: string): Promise<'ok' | 'stale' | 'missing'> {
138 try {
139 const out = (await $.process.run(['sh', '-c', FONT_SCRIPT, 'sh', charset, name], { timeoutMs: 5_000 })).stdout.trim()
140 return out === 'stale' || out === 'missing' ? out : 'ok'
141 } catch {
142 return 'missing'
143 }
144}
145
146function quiet(p: Promise<unknown>): void {
147 void p.catch(() => undefined)
148}
149
150async function detectGlyphs($: EngineInterface): Promise<void> {
151 if ((await $.env.get('SSH_CONNECTION')) || (await $.env.get('SSH_TTY'))) {
152 detected = 'nerd'
153 return
154 }
155 const nerd = (await fontState($, 'f04eb', 'Nerd')) === 'ok'
156 detected = nerd && (await fontState($, 'f3000', 'DatabricksSymbols')) === 'ok' ? 'databricks' : nerd ? 'nerd' : 'plain'
157}
158
159function fontNote(): string {
160 if (!fontHint || hinted || !fellBack) return ''
161 hinted = true
162 return 'Tell user once: Databricks pane icons need github.com/data-goblin/databricks-nf plus a Nerd Font. Plugin option fontHint=off disables this.'
163}
164
165function tierFor(surface: string): Tier {
166 if (glyphSetting === 'databricks' || glyphSetting === 'nerd' || glyphSetting === 'plain') return glyphSetting
167 return surface === 'desktop' ? 'plain' : detected
168}
169
170function titleGlyph(tier: Tier): string {
171 return dbTitle(tier)
172}
173
174function label(target: Target | null): string {
175 return target?.profile ? `${TITLE} · ${target.profile}` : TITLE
176}
177function titleFor(target: Target | null): string {
178 return `${titleGlyph(tierFor('terminal'))} ${label(target)}`
179}
180async function get($: EngineInterface): Promise<Explorer> {
181 const [view, tree] = await Promise.all([$.state.get(STATE), $.state.get(NODES)])
182 return { ...empty(), ...view.value, nodes: tree.value ?? [] }
183}
184
185async function put($: EngineInterface, fn: (ex: Explorer) => Explorer): Promise<void> {
186 for (let i = 0; ; i++) {
187 if (i >= 50) throw new Error('pane state is busy; try again')
188 const [view, tree] = await Promise.all([$.state.get(STATE), $.state.get(NODES)])
189 const cur: Explorer = { ...empty(), ...view.value, nodes: tree.value ?? [] }
190 const next = anchored(cur, fn(cur))
191 if (next.nodes !== cur.nodes) {
192 const done = await $.state.set(NODES, next.nodes, { ifVersion: tree.version })
193 if (!done.isSet) continue
194 }
195 const keys = Object.keys(next) as (keyof Explorer)[]
196 if (!keys.some(k => k !== 'nodes' && next[k] !== cur[k])) return
197 const { nodes: _nodes, ...rest } = next
198 const done = await $.state.set(STATE, { ...rest, nodes: [] }, { ifVersion: view.version })
199 if (done.isSet) return
200 }
201}
202
203function patch($: EngineInterface, fn: (ex: Explorer) => Partial<Explorer>) {
204 return put($, ex => ({ ...ex, ...fn(ex) }))
205}
206
207async function patchView($: EngineInterface, fn: (ex: Explorer) => Partial<Explorer>): Promise<void> {
208 for (let i = 0; ; i++) {
209 if (i >= 50) throw new Error('pane state is busy; try again')
210 const view = await $.state.get(STATE)
211 const cur: Explorer = { ...empty(), ...view.value, nodes: [] }
212 const change = fn(cur)
213 if (Object.keys(change).length === 0) return
214 const done = await $.state.set(STATE, { ...cur, ...change, nodes: [] }, { ifVersion: view.version })
215 if (done.isSet) return
216 }
217}
218
219const sameTarget = (a: Target | null, b: Target | null) => JSON.stringify(a) === JSON.stringify(b)
220
221function refresh($: EngineInterface): Promise<void> {
222 if (inflight) {
223 const rerun = () => {
224 queued = null
225 return refresh($)
226 }
227 queued ??= inflight.then(rerun, rerun)
228 return queued
229 }
230 inflight = doRefresh($).finally(() => {
231 inflight = null
232 })
233 return inflight
234}
235
236function live(work: Work | null, now: number): work is Work {
237 if (!work) return false
238 return work.until === null ? now - work.since < BUSY_MAX_MS : now < work.until
239}
240
241async function startWork($: EngineInterface, ids: string[], tone: string): Promise<number> {
242 const mine = ++generation
243 blink?.cancel()
244 blink = null
245 const at = await $.clock.now()
246 await patchView($, cur => {
247 const prior = live(cur.work, at) ? cur.work : null
248 const lit = [...new Set([...(prior?.lit ?? []), ...ids])]
249 return { work: { tone, lit, dim: (prior?.dim ?? []).filter(id => !lit.includes(id)), since: at, until: null } }
250 })
251 return mine
252}
253
254async function finishWork($: EngineInterface, mine: number, tone: string, ids: string[] = [], alsoLit: string[] = []): Promise<void> {
255 const unique = [...new Set(ids)]
256 const own = () => generation === mine
257 const ex = await get($)
258 const at = await $.clock.now()
259 await patch($, cur => {
260 const byId = new Map(cur.nodes.map(n => [n.id, n]))
261 const open = new Set(cur.expanded)
262 const dim = new Set(alsoLit)
263 for (const id of unique) {
264 const chain = ancestors(cur.nodes, id, byId)
265 if (!chain.some(a => !open.has(a))) continue
266 for (const a of chain) {
267 if (!open.has(a)) dim.add(a)
268 open.add(a)
269 }
270 }
271 for (const id of unique) dim.delete(id)
272 const prior = live(cur.work, at) ? cur.work : null
273 const work: Work | null = own()
274 ? unique.length
275 ? { tone, lit: unique, dim: [...dim], since: prior?.since ?? at, until: at + FLASH_MS }
276 : null
277 : prior && unique.length
278 ? { ...prior, lit: [...new Set([...prior.lit, ...unique])], dim: [...new Set([...prior.dim, ...dim])].filter(id => !unique.includes(id) && !prior.lit.includes(id)) }
279 : cur.work
280 if (unique.length === 0) return { work }
281 const root = rootOf(cur)
282 const away = follow && root !== '' && unique.some(id => id !== root && !ancestors(cur.nodes, id, byId).includes(root))
283 return { work, expanded: [...open], ...(follow ? { scroll: null } : {}), ...(away ? { root: '' } : {}) }
284 })
285 if (!own() || unique.length === 0) return
286 blink = $.clock.after(FLASH_MS, () => {
287 if (!own()) return
288 blink = null
289 quiet(patchView($, () => (own() ? { work: null } : {})))
290 })
291 if (ex.target && !closed) await openPane($, { id: PANE, title: titleFor(ex.target) })
292}
293
294type Mark = { ids: string[]; tone: string }
295
296function rootOf(ex: Explorer): string {
297 return ex.root && ex.nodes.some(n => n.id === ex.root) ? ex.root : ''
298}
299
300function anchored(cur: Explorer, next: Explorer): Explorer {
301 if (follow || cur.scroll === null || next.scroll !== cur.scroll || (next.nodes === cur.nodes && next.expanded === cur.expanded)) return next
302 const top = visible(cur, SORT, rootOf(cur))[cur.scroll]?.node.id
303 const at = top ? visible(next, SORT, rootOf(next)).findIndex(row => row.node.id === top) : -1
304 return at < 0 || at === cur.scroll ? next : { ...next, scroll: at }
305}
306
307
308async function markBusy($: EngineInterface, marks: Mark[]): Promise<void> {
309 if (marks.every(m => m.ids.length === 0)) return
310 const at = await $.clock.now()
311 await patchView($, cur => {
312 const map = { ...cur.busy }
313 for (const { ids, tone } of marks) for (const id of ids) map[id] = { tone, n: (map[id]?.n ?? 0) + 1, at }
314 return { busy: map }
315 })
316}
317
318async function clearBusy($: EngineInterface, marks: Mark[]): Promise<void> {
319 if (marks.every(m => m.ids.length === 0)) return
320 await patchView($, cur => {
321 const map = { ...cur.busy }
322 for (const { ids } of marks) {
323 for (const id of ids) {
324 const left = (map[id]?.n ?? 1) - 1
325 const entry = map[id]
326 if (left > 0 && entry) map[id] = { ...entry, n: left }
327 else delete map[id]
328 }
329 }
330 return { busy: map }
331 })
332}
333
334async function point($: EngineInterface, target: Target | null, opened: 'asked' | 'unasked', fresh = false): Promise<boolean> {
335 const moved = !sameTarget((await get($)).target, target)
336 activeProfile = target?.profile ?? ''
337 if (moved) {
338 treeGen++
339 hosts.clear()
340 await put($, () => ({ ...empty(), target }))
341 }
342 else if (fresh) await patchView($, () => ({ expanded: [], query: '', selected: '', detail: [], cursor: '' }))
343 if (opened === 'asked' || (moved && target)) {
344 const title = titleFor(target)
345 if (opened === 'asked') {
346 closed = false
347 await openPane($, { id: PANE, title, focus: true })
348 } else if (!closed) await openPane($, { id: PANE, title })
349 }
350 return moved
351}
352
353async function navigate($: EngineInterface, n: TreeNode): Promise<void> {
354 await patch($, cur => ({ root: n.id, cursor: n.id, scroll: null, expanded: [...new Set([...cur.expanded, n.id, ...ancestors(cur.nodes, n.id)])] }))
355 if (await expandNode($, n)) await expandOpen($, n.id)
356}
357
358async function goUp($: EngineInterface): Promise<void> {
359 await patch($, cur => {
360 const n = cur.nodes.find(x => x.id === cur.root)
361 return { root: n?.parent ?? '', cursor: n?.id ?? cur.cursor, scroll: null }
362 })
363}
364
365async function goHome($: EngineInterface): Promise<void> {
366 await patchView($, () => ({ root: '', scroll: null }))
367}
368
369async function press($: EngineInterface, n: TreeNode): Promise<void> {
370 const now = Date.now()
371 const isDouble = lastPress.key === n.id && now - lastPress.at < DOUBLE_MS
372 lastPress = { key: isDouble ? '' : n.id, at: now }
373 const ex = await get($)
374 if (isDouble && webUrl(ex, n)) await openWeb($, ex, n)
375 else if (isDouble && ex.nodes.some(c => c.parent === n.id)) await navigate($, n)
376 else if (!isDouble) await select($, n)
377}
378
379function guides(depth: number): string {
380 const lines = Array.from({ length: depth }, (_, i) => `<rect x="${i * 16 + 7.5}" y="0" width="1" height="${ROW_PX}" fill="#34343c"/>`).join('')
381 return `<svg xmlns="${SVG_NS}" width="${depth * 16}" height="${ROW_PX}" viewBox="0 0 ${depth * 16} ${ROW_PX}">${lines}</svg>`
382}
383
384async function openWeb($: EngineInterface, ex: Explorer, n: TreeNode): Promise<void> {
385 const url = webUrl(ex, n)
386 if (url) await openUrl($, url)
387 else $.ui.toast('no Databricks link: set host in ~/.databrickscfg or DATABRICKS_HOST')
388}
389
390async function hostOf($: EngineInterface, profile: string): Promise<string> {
391 const known = hosts.get(profile)
392 if (known !== undefined) return known
393 let host = profile ? '' : ((await $.env.get('DATABRICKS_HOST')) ?? '').trim().replace(/\/+$/, '')
394 const home = (await $.env.get('HOME')) || (await $.env.get('USERPROFILE')) || ''
395 const file = (await $.env.get('DATABRICKS_CONFIG_FILE')) || `${posix(home).replace(/\/+$/, '')}/.databrickscfg`
396 if (!host) {
397 try {
398 host = hostFrom(String(await $.fs.read(posix(file))), profile)
399 } catch {
400 host = ''
401 }
402 }
403 if (host && !/^https?:\/\//.test(host)) host = `https://${host}`
404 hosts.set(profile, host)
405 return host
406}
407type Trouble = Onboard['kind'] | ''
408
409class CliError extends Error {
410 constructor(
411 message: string,
412 readonly trouble: Trouble,
413 ) {
414 super(message)
415 }
416}
417
418function troubleOf(text: string): Trouble {
419 return UNREACHABLE.test(text) ? 'unreachable' : SIGNED_OUT.test(text) ? 'signedOut' : ''
420}
421
422async function dbRun($: EngineInterface, tail: string[], profile: string): Promise<string> {
423 const argv = ['databricks', ...tail, '-o', 'json', ...(profile ? ['-p', profile] : [])]
424 let run: Awaited<ReturnType<EngineInterface['process']['run']>>
425 try {
426 run = await limited(() => $.process.run(argv, { timeoutMs: 60_000 }))
427 } catch (err) {
428 const text = (err instanceof Error ? err.message : String(err)).trim()
429 throw new CliError(text.split('\n')[0] || 'databricks did not start', /timed? ?out/i.test(text) ? 'unreachable' : 'missing')
430 }
431 if (run.exitCode !== 0) {
432 const text = (run.stderr || run.stdout).trim()
433 throw new CliError(text.split('\n')[0] || `databricks ${tail.join(' ')} failed`, run.exitCode === 127 ? 'missing' : troubleOf(text))
434 }
435 if (run.isStdoutTruncated) throw new Error(`databricks ${tail.slice(0, 2).join(' ')}: too much output to show`)
436 return run.stdout
437}
438
439async function implicitProfile($: EngineInterface): Promise<string> {
440 return ((await $.env.get('DATABRICKS_CONFIG_PROFILE')) ?? '').trim()
441}
442
443const loading = new Map<string, Promise<boolean>>()
444let treeGen = 0
445let statusOwner = ''
446let activeProfile = ''
447
448function errorText(err: unknown): string {
449 return `error: ${err instanceof Error ? err.message : String(err)}`
450}
451
452async function pool<T>(items: T[], fn: (item: T) => Promise<unknown>, size = 4): Promise<void> {
453 const queue = [...items]
454 await Promise.all(
455 Array.from({ length: Math.min(size, queue.length) }, async () => {
456 for (let item = queue.shift(); item !== undefined; item = queue.shift()) await fn(item)
457 }),
458 )
459}
460
461async function expandOpen($: EngineInterface, root = ''): Promise<void> {
462 const failed = new Set<string>()
463 for (let pass = 0; pass < 8; pass++) {
464 const ex = await get($)
465 const open = new Set(ex.expanded)
466 const pending = new Set(ex.nodes.filter(c => c.kind === PLACEHOLDER).map(c => c.parent))
467 const byId = new Map(ex.nodes.map(n => [n.id, n]))
468 const todo = ex.nodes.filter(n => {
469 if (!open.has(n.id) || !pending.has(n.id) || failed.has(n.id)) return false
470 const chain = ancestors(ex.nodes, n.id, byId)
471 return chain.every(a => open.has(a)) && (!root || chain.includes(root))
472 })
473 if (todo.length === 0) return
474 await pool(todo, async n => {
475 if (!(await expandNode($, n))) failed.add(n.id)
476 })
477 }
478}
479function onboardOf(err: unknown): Onboard | null {
480 return err instanceof CliError && err.trouble ? { kind: err.trouble, line: err.message } : null
481}
482
483function failed(cur: Explorer, target: Target | null, err: unknown): Partial<Explorer> {
484 if (!sameTarget(cur.target, target)) return {}
485 const onboard = onboardOf(err)
486 return onboard ? { onboard } : { status: errorText(err) }
487}
488
489async function probe($: EngineInterface, profile: string): Promise<Onboard | null> {
490 try {
491 await dbRun($, ['current-user', 'me'], profile)
492 return null
493 } catch (err) {
494 return onboardOf(err)
495 }
496}
497
498async function doRefresh($: EngineInterface): Promise<void> {
499 const target = (await get($)).target
500 if (!target) return
501 await patchView($, () => ({ status: 'loading' }))
502 treeGen++
503 hosts.clear()
504 const onboard = await probe($, target.profile)
505 if (onboard) {
506 await patchView($, cur => (sameTarget(cur.target, target) ? { onboard, status: '' } : {}))
507 return
508 }
509 try {
510 await patch($, cur => (sameTarget(cur.target, target) ? { nodes: roots(), expanded: cur.nodes.length ? cur.expanded : [], status: '', onboard: null } : {}))
511 await expandOpen($)
512 } catch (err) {
513 await patch($, cur => failed(cur, target, err))
514 }
515}
516async function listChildren($: EngineInterface, n: TreeNode, profile: string): Promise<TreeNode[]> {
517 const outputs = await Promise.all(listCalls(n).map(tail => dbRun($, tail, profile)))
518 return children(n, outputs, await hostOf($, profile || (await implicitProfile($))))
519}
520
521const rerun = new Map<string, Promise<boolean>>()
522
523function reloadNode($: EngineInterface, id: string): Promise<boolean> {
524 const key = `${activeProfile}|reload:${id}`
525 const running = loading.get(key)
526 if (running) {
527 const next =
528 rerun.get(key) ??
529 running.then(
530 () => {
531 rerun.delete(key)
532 return reloadNode($, id)
533 },
534 () => {
535 rerun.delete(key)
536 return reloadNode($, id)
537 },
538 )
539 rerun.set(key, next)
540 return next
541 }
542 const job = (async () => {
543 const pending = loading.get(`${activeProfile}|${id}`)
544 if (pending) await pending.catch(() => false)
545 const ex = await get($)
546 const target = ex.target
547 const n = ex.nodes.find(x => x.id === id)
548 if (!n || !isLoaded(ex.nodes, n.id)) return true
549 const gen = treeGen
550 try {
551 const kids = await listChildren($, n, target?.profile ?? '')
552 const owned = statusOwner === n.id
553 if (owned) statusOwner = ''
554 await patch($, cur => (gen === treeGen && sameTarget(cur.target, target) && cur.nodes.some(x => x.id === n.id) ? { nodes: merge(cur.nodes, n.id, kids), ...(owned ? { status: '' } : {}), ...(cur.onboard ? { onboard: null } : {}) } : {}))
555 } catch (err) {
556 statusOwner = n.id
557 await patchView($, cur => failed(cur, target, err))
558 return false
559 }
560 await expandOpen($, n.id)
561 return true
562 })().finally(() => loading.delete(key))
563 loading.set(key, job)
564 return job
565}
566
567function expandNode($: EngineInterface, n: TreeNode): Promise<boolean> {
568 const key = `${activeProfile}|${n.id}`
569 const running = loading.get(key)
570 if (running) return running
571 const job = (async () => {
572 const ex = await get($)
573 const target = ex.target
574 if (!ex.nodes.some(c => c.parent === n.id && c.kind === PLACEHOLDER)) return true
575 const gen = treeGen
576 try {
577 const kids = await listChildren($, n, target?.profile ?? '')
578 const owned = statusOwner === n.id
579 if (owned) statusOwner = ''
580 await patch($, cur => {
581 if (gen !== treeGen || !sameTarget(cur.target, target)) return {}
582 const ok = { ...(owned ? { status: '' } : {}), ...(cur.onboard ? { onboard: null } : {}) }
583 if (!cur.nodes.some(x => x.parent === n.id && x.kind === PLACEHOLDER)) return ok
584 return { nodes: cur.nodes.flatMap(x => (x.parent === n.id && x.kind === PLACEHOLDER ? (kids.length ? kids : [emptyMark(n.id)]) : [x])), ...ok }
585 })
586 return true
587 } catch (err) {
588 statusOwner = n.id
589 await patchView($, cur => failed(cur, target, err))
590 return false
591 }
592 })().finally(() => loading.delete(key))
593 loading.set(key, job)
594 return job
595}
596
597async function reveal($: EngineInterface, chain: string[]): Promise<void> {
598 for (const id of chain) {
599 const n = (await get($)).nodes.find(x => x.id === id)
600 if (!n) return
601 await patch($, cur => ({ expanded: [...new Set([...cur.expanded, n.id])] }))
602 await expandNode($, n)
603 }
604}
605function webUrl(_ex: Explorer, n: TreeNode): string {
606 return n.url || ''
607}
608
609async function openLocal($: EngineInterface, ex: Explorer, n: TreeNode): Promise<void> {
610 if (webUrl(ex, n)) await openUrl($, webUrl(ex, n))
611}
612async function select($: EngineInterface, n: TreeNode): Promise<void> {
613 if (n.kind === PLACEHOLDER || n.kind === EMPTY) return
614 const ex = await get($)
615 const isLeaf = !ex.nodes.some(c => c.parent === n.id)
616 await patch($, cur => {
617 const open = new Set(cur.expanded)
618 if (!isLeaf) open.has(n.id) ? open.delete(n.id) : open.add(n.id)
619 return { expanded: [...open], cursor: n.id, selected: n.path ? n.id : cur.selected }
620 })
621 if (!isLeaf && (await expandNode($, n))) await expandOpen($, n.id)
622 const kind = n.kind.replace(/^section-/, '').replace(/_/g, ' ')
623 const detail = [`${kind} ${n.name}`, `Type: ${kind}`, ...(n.note ? [`${NOTE_LABEL[n.kind] ?? 'Note'}: ${n.note}`] : []), ...(n.path ? [`Path: ${n.path}`] : []), ...(n.url ? [`URL: ${n.url}`] : [])]
624 await patchView($, cur => (cur.cursor === n.id ? { detail } : {}))
625}
626function contextFor(ex: Explorer, n: TreeNode): string {
627 return [
628 'The user has this Databricks object selected in the Databricks pane; "this", "it" or "the selected" in the prompt likely refers to it.',
629 `${n.kind.replace(/_/g, ' ')}: ${n.name}`,
630 ...(n.path ? [`databricks CLI argument: ${n.path}`] : []),
631 ...(ex.target?.profile ? [`profile: ${ex.target.profile}`] : []),
632 ...(n.url ? [`url: ${n.url}`] : []),
633 ].join('\n')
634}
635const STATUS_GROUPS = new Set(['clusters', 'warehouses', 'apps', 'pipelines'])
636const waiting = new Map<string, () => Promise<void>>()
637
638function backgroundOf(result: unknown): string {
639 if (!result || typeof result !== 'object') return ''
640 const id = (result as { backgroundTaskId?: unknown }).backgroundTaskId
641 return typeof id === 'string' ? id : ''
642}
643
644type Call = { inv: Invocation; kind: NonNullable<ReturnType<typeof dbKind>> }
645
646type Lit = { touched: string[]; opened: string[] }
647
648async function afterDb($: EngineInterface, calls: Call[], stale: Set<string>, succeeded: boolean): Promise<Lit> {
649 const none: Lit = { touched: [], opened: [] }
650 const fallback = await implicitProfile($)
651 const canon = (p: string) => p || fallback || 'DEFAULT'
652 const resolved = (inv: Invocation) => dbProfile(inv) || inv.env.DATABRICKS_CONFIG_PROFILE || ''
653 const own = calls.filter(c => !c.inv.env.DATABRICKS_HOST && !c.inv.env.DATABRICKS_TOKEN)
654 const first = own[0]
655 if (!first) return none
656 const current = (await get($)).target
657 const want = resolved(first.inv)
658 const profile = current && canon(current.profile) === canon(want) ? current.profile : want
659 const moved = await point($, { kind: 'databricks', profile }, 'unasked')
660 const shown = await get($)
661 if (moved || shown.nodes.length === 0 || shown.onboard) await refresh($)
662 if ((await get($)).onboard) return none
663 const mine = own.filter(c => canon(resolved(c.inv)) === canon(profile))
664 const prior = await get($)
665 const before = new Set(prior.expanded)
666 const targets = [...new Set(mine.flatMap(c => dbTargets(c.inv)))]
667 await pool(targets, id => reveal($, chainOf(id)))
668 const reloads = new Set<string>()
669 for (const c of mine) {
670 if (c.kind !== 'modify' && c.kind !== 'upload') continue
671 if (!changesMembers(c.inv.args) && !STATUS_GROUPS.has(positionals(c.inv.args)[0] ?? '')) continue
672 for (const id of dbTargets(c.inv)) {
673 const chain = chainOf(id)
674 const parent = chain[chain.length - 1]
675 if (parent) reloads.add(parent)
676 if (id.startsWith('S:')) reloads.add(id)
677 }
678 }
679 await pool([...reloads].filter(id => isLoaded(prior.nodes, id) || stale.has(`${activeProfile}|${id}`)), id => reloadNode($, id))
680 const fresh = await get($)
681 const present = new Set(fresh.nodes.map(n => n.id))
682 if (!succeeded) return none
683 const touched = mine.flatMap(c => dbTargets(c.inv)).filter(id => present.has(id))
684 return { touched, opened: touched.flatMap(id => chainOf(id)).filter(id => !before.has(id) && present.has(id)) }
685}
686
687function toneOf(calls: Call[]): string {
688 const tones = new Set(calls.map(c => DB_TONE[c.kind]))
689 return TONE_RANK.find(t => tones.has(t)) ?? 'orange'
690}
691
692type Line = { icon: [string, string]; title: string } | { text: string; dim?: true } | { label: string; cmd: string }
693
694function onboardBlocks(o: Onboard): Line[][] {
695 const signIn: [string, string] = ['\u{f0342}', '→']
696 if (o.kind === 'missing') {
697 return [
698 [{ icon: ['\u{f05d6}', '⚠'], title: 'Databricks CLI not found' }, { text: 'This pane needs the Databricks CLI (databricks).' }],
699 [
700 { icon: ['\u{f01da}', '↓'], title: 'Install it' },
701 { label: 'macOS or Linux: ', cmd: 'brew tap databricks/tap && brew install databricks' },
702 { label: 'Windows: ', cmd: 'winget install Databricks.DatabricksCLI' },
703 ],
704 [{ icon: signIn, title: 'Then sign in to your workspace' }, { label: '', cmd: LOGIN }],
705 [{ text: "Press ↻ when you're done. Or ask Claude to set it up for you.", dim: true }],
706 ]
707 }
708 if (o.kind === 'signedOut') {
709 return [
710 [{ icon: ['\u{f0306}', '⚿'], title: 'Not signed in to Databricks' }, { label: '', cmd: LOGIN }],
711 [{ text: "Press ↻ when you're done. Several workspaces? Pick one with -p <profile>.", dim: true }],
712 ]
713 }
714 return [[{ icon: ['\u{f0164}', '⊘'], title: "Can't reach Databricks" }, { text: o.line, dim: true }, { text: 'Check your network or proxy, then press ↻.', dim: true }]]
715}
716
717function changesMembers(args: string[]): boolean {
718 const [group = '', verb = ''] = positionals(args)
719 if (group === 'fs') return false
720 if (group === 'sync') return true
721 return MEMBER_VERBS.test(verb) || (verb === 'update' && args.some(a => a.startsWith('--new-name')))
722}
723
724export const register: Register = (on, options) => {
725 glyphSetting = typeof options?.glyphs === 'string' ? options.glyphs : 'auto'
726 follow = options?.follow !== 'off'
727 fontHint = options?.fontHint !== 'off'
728
729 on('session.start', async ($, e, next) => {
730 useDrives((await $.env.get('OS')) === 'Windows_NT')
731 hinted = false
732 fellBack = false
733 quiet(detectGlyphs($).then(() => $.ui.invalidate('ui.render')))
734 await patchView($, () => ({ work: null, busy: {} }))
735 await $.command.register({ name: PANE, description: 'Open the Databricks pane; args: [profile]' })
736 const ex = await get($)
737 activeProfile = ex.target?.profile ?? ''
738 if (ex.target) quiet(openPane($, { id: PANE, title: titleFor(ex.target) }))
739 return next(e)
740 })
741
742 on('command.run', { command: PANE }, async ($, e) => {
743 const terminalOnly = !(await $.session.surfaces().catch(() => ['terminal'])).some(x => x !== 'terminal')
744 if (terminalOnly && e.presentation && !e.presentation.isFullscreen) return { text: 'The Databricks pane shows in the sidebar, which needs the fullscreen layout. Run /tui fullscreen, then /databricks-pane.' }
745 if (terminalOnly && e.presentation && e.presentation.columns < 110) return { text: 'The Databricks pane shows in the sidebar, which needs a terminal at least 110 columns wide. Widen it, then run /databricks-pane.' }
746 noDock = false
747 fellBack = false
748 quiet(detectGlyphs($).then(() => $.ui.invalidate('ui.render')))
749 const [profile = ''] = tokenize(e.args ?? '')
750 await point($, { kind: 'databricks', profile }, 'asked', true)
751 await refresh($)
752 return { text: profile ? `Databricks pane on profile ${profile}.` : 'Databricks pane open.' }
753 })
754
755 on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
756 const command = e.tool === 'Bash' ? e.command : ''
757 if (!/\bdatabricks\b/.test(command)) return next(e)
758 const calls = invocations(command, await cwdOf($)).flatMap(inv => {
759 const kind = dbKind(inv)
760 return kind ? [{ inv, kind }] : []
761 })
762 if (calls.length === 0) return next(e)
763 if (closed || noDock) return next(e)
764 const ex = await get($)
765 const have = new Set(ex.nodes.map(n => n.id))
766 const marks: Mark[] = calls.map(c => ({ ids: [HEADER, ...dbTargets(c.inv).filter(id => have.has(id))], tone: DB_TONE[c.kind] }))
767 const tone = toneOf(calls)
768 await markBusy($, marks)
769 const mine = await startWork($, [...new Set(marks.flatMap(m => m.ids.filter(id => id !== HEADER)))], tone)
770 let result: Awaited<ReturnType<typeof next>>
771 try {
772 result = await next(e)
773 } catch (err) {
774 await clearBusy($, marks)
775 await finishWork($, mine, tone)
776 throw err
777 }
778 const task = result.deny ? '' : backgroundOf(result.result)
779 const stale = new Set(loading.keys())
780 const settle = async () => {
781 await clearBusy($, marks)
782 let lit: Lit = { touched: [], opened: [] }
783 try {
784 if (!result.deny && !closed && !noDock) lit = await afterDb($, calls, stale, !result.isError)
785 } finally {
786 await finishWork($, mine, tone, lit.touched, lit.opened)
787 }
788 }
789 if (task) waiting.set(task, settle)
790 else void settle().catch(() => undefined)
791 return result
792 })
793
794 on('ui.close', async ($, e, next) => {
795 const result = await next(e)
796 if (e.id === PANE && e.origin.kind === 'person') closed = true
797 return result
798 })
799
800 on('ui.message', async ($, e, next) => {
801 if (e.requestId === PANE && typeof e.element === 'string' && e.element.startsWith('onboard-') && e.data && typeof e.data === 'object') {
802 const data = e.data as { press?: unknown; copy?: unknown }
803 const text = typeof data.press === 'string' ? data.press : typeof data.copy === 'string' ? data.copy : ''
804 if (text) await copyOf($, text, e.surface)
805 return {}
806 }
807 if (e.requestId === PANE && e.element.startsWith('z:') && e.data && typeof e.data === 'object') {
808 const data = e.data as { zone?: unknown; ctrl?: unknown }
809 const id = typeof data.zone === 'string' ? data.zone : ''
810 if (id === PROPS) {
811 propsOpen = !propsOpen
812 $.ui.invalidate('ui.render')
813 return {}
814 }
815 const ex = await get($)
816 const n = ex.nodes.find(x => x.id === id)
817 if (n && data.ctrl) quiet(openWeb($, ex, n))
818 else if (n) quiet(press($, n))
819 return {}
820 }
821 if (e.requestId !== PANE || e.element !== 'rows' || !e.data || typeof e.data !== 'object') return next(e)
822 const view = views.get(e.surface) ?? { from: 0, max: 0 }
823 const data = e.data as { press?: unknown; key?: unknown; ctrl?: unknown; shift?: unknown; scrollTo?: unknown; copy?: unknown }
824 const ex = await get($)
825 if (typeof data.scrollTo === 'number') {
826 const to = Math.round(Math.max(0, Math.min(1, data.scrollTo)) * view.max)
827 if (to !== ex.scroll) await patchView($, () => ({ scroll: to }))
828 return {}
829 }
830 if (typeof data.copy === 'string') {
831 const n = ex.nodes.find(x => x.id === data.copy)
832 if (n) await copyOf($, n.path || n.name, e.surface)
833 return {}
834 }
835 if (typeof data.press === 'string') {
836 const n = ex.nodes.find(x => x.id === data.press)
837 if (!n) return {}
838 if (ex.scroll === null) await patchView($, () => ({ scroll: view.from }))
839 if (data.ctrl) await openWeb($, ex, n)
840 else if (data.shift) await openLocal($, ex, n)
841 else await press($, n)
842 return {}
843 }
844 if (typeof data.key !== 'string') return {}
845 const rows = visible(ex, SORT, rootOf(ex))
846 const at = rows.findIndex(r => r.node.id === ex.cursor)
847 const cur = rows[at]
848 const move = (d: number) => {
849 const target = rows[Math.max(0, Math.min(rows.length - 1, (at < 0 ? 0 : at) + d))]
850 return target ? patchView($, () => ({ cursor: target.node.id, scroll: null })) : Promise.resolve()
851 }
852 if (data.key === 'up' || data.key === 'k') await move(-1)
853 else if (data.key === 'down' || data.key === 'j') await move(1)
854 else if (data.key === 'pageup') await move(-10)
855 else if (data.key === 'pagedown') await move(10)
856 else if (data.key === 'home') await move(-rows.length)
857 else if (data.key === 'end') await move(rows.length)
858 else if (cur && (data.key === 'y' || data.key === 'Y')) await copyOf($, cur.node.path || cur.node.name, e.surface)
859 else if (cur && (data.key === 'right' || data.key === 'l') && !cur.leaf && !cur.open) await select($, cur.node)
860 else if (cur && (data.key === 'left' || data.key === 'h')) {
861 if (!cur.leaf && cur.open) await patchView($, x => ({ expanded: x.expanded.filter(id => id !== cur.node.id) }))
862 else if (cur.node.parent) await patchView($, () => ({ cursor: cur.node.parent }))
863 } else if (cur && (data.key === ' ' || data.key === 'return')) await (data.key === 'return' && cur.leaf ? openLocal($, ex, cur.node) : select($, cur.node))
864 return {}
865 })
866
867 on('ui.scroll', { component: 'Pane', requestId: PANE }, async ($, e, next) => {
868 if (nativeScroll) return next(e)
869 const view = views.get('terminal') ?? views.get('desktop') ?? { from: 0, max: 0 }
870 const ex = await get($)
871 const to = Math.max(0, Math.min(view.max, (ex.scroll ?? view.from) + Math.sign(e.by) * Math.max(3, Math.abs(e.by))))
872 if (to !== ex.scroll) await patchView($, () => ({ scroll: to }))
873 return {}
874 })
875
876 on('prompt.submit', async ($, e, next) => {
877 if (e.origin?.kind === 'task-notification') {
878 for (const [task, settle] of waiting) {
879 if (!e.text.includes(task)) continue
880 waiting.delete(task)
881 void settle().catch(() => undefined)
882 }
883 }
884 const ex = await get($)
885 const n = ex.nodes.find(x => x.id === ex.selected)
886 if (!ex.target || closed || noDock) return next(e)
887 const hint = fontNote()
888 const context = [...(e.context ?? []), ...(n ? [contextFor(ex, n)] : []), ...(hint ? [hint] : [])]
889 return context.length === (e.context ?? []).length ? next(e) : next({ ...e, context })
890 })
891
892 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e, next) => {
893 if (e.surface !== 'terminal' && e.surface !== 'desktop') return next(e)
894 if (e.surface === 'terminal' && e.props.placement === 'inline') {
895 noDock = true
896 void $.ui.close({ id: PANE }).catch(() => undefined)
897 const { Box: Empty } = $.ui.resolve(e)
898 return <Empty />
899 }
900 const tier = tierFor(e.surface)
901 if (e.surface === 'terminal' && tier === 'plain' && glyphSetting === 'auto') fellBack = true
902 const table = $.ui.resolve(e)
903 const { Box, Text, Button, Input, Client } = table
904 const Svg = 'Svg' in table ? table.Svg : undefined
905 const native = e.surface === 'desktop' && Boolean(Svg)
906 nativeScroll = native
907 const ex = await get($)
908 const now = await $.clock.now()
909 const busyTone = (id: string) => {
910 const b = ex.busy[id]
911 return b && now - b.at < BUSY_MAX_MS ? b.tone : ''
912 }
913 const work = live(ex.work, now) ? ex.work : null
914 const working = work !== null || busyTone(HEADER) !== ''
915 const brightSet = new Set(work?.lit ?? [])
916 const dimSet = new Set(work?.dim ?? [])
917 const width = Math.max(20, e.props.bodyColumns)
918 const rows = visible(ex, SORT, rootOf(ex))
919 const shownNode = ex.nodes.find(n => n.id === ex.cursor && ex.detail.length > 0) ?? ex.nodes.find(n => n.id === ex.selected)
920 const detail = !ex.onboard && shownNode ? ex.detail : []
921 const empty = !ex.onboard && ex.nodes.length === 0 ? (ex.target ? 'nothing loaded yet' : HINT) : ''
922 const detailRows = detail.length ? Math.min(detail.length, DETAIL_ROWS) + 4 : 0
923 const room = Math.max(5, Math.min(WINDOW, (e.props.scroll?.bodyRows ?? 40) - 4 - detailRows - (empty ? 1 : 0)))
924 const focusId = follow && work && work.lit.length ? (work.lit[work.lit.length - 1] ?? ex.cursor) : ex.cursor
925 const at = Math.max(0, rows.findIndex(r => r.node.id === focusId))
926 const isLit = (id: string) => brightSet.has(id) || dimSet.has(id)
927 const lit = follow && work ? rows.findIndex(r => isLit(r.node.id)) : -1
928 const fits = lit >= 0 && at - lit < room - 2
929 const base = Math.max(0, Math.min(Math.max(0, rows.findIndex(r => r.node.id === ex.cursor)) - Math.floor(room / 2), rows.length - room))
930 const inView = lit >= base && at < base + room
931 const flashing = lit >= 0 && !inView
932 const nearBottom = (span: number) => Math.max(0, Math.min(fits ? Math.min(Math.max(0, lit - 1), at - span + 3) : at - span + 3, rows.length - span))
933 let from = flashing ? nearBottom(room) : base
934 const cap = Math.max(1, Math.floor(room / 3))
935 const chain = new Set(flashing ? ancestors(ex.nodes, focusId) : [])
936 const keep = (id: string) => chain.has(id) || isLit(id)
937 let pinned = flashing ? rows.slice(0, from).filter(r => keep(r.node.id)).slice(-cap) : []
938 if (pinned.length) {
939 from = nearBottom(Math.max(3, room - pinned.length - 1))
940 pinned = rows.slice(0, from).filter(r => keep(r.node.id)).slice(-cap)
941 }
942 const max = Math.max(0, rows.length - room)
943 if (ex.scroll !== null) {
944 from = Math.max(0, Math.min(ex.scroll, max))
945 pinned = []
946 }
947 if (!native) views.set(e.surface, { from, max })
948 const shown = rows.slice(from, from + room - pinned.length)
949 const clip = (s: string, max = width) => (s.length > max ? s.slice(0, max - 1) + '…' : s)
950 const loadingRow = (n: TreeNode) => n.kind === PLACEHOLDER && n.name === 'loading…'
951 const rowSpec = (r: Row): RowSpec => {
952 const n = r.node
953 const g = glyph(n, tier)
954 const arrow = r.leaf ? ' ' : tier === 'plain' ? (r.open ? '▾ ' : '▸ ') : r.open ? '\u{f47c} ' : '\u{f460} '
955 const note = n.note ? ` ${n.note}` : ''
956 const cols = Math.max(4, width - r.depth * 2 - 6 - note.length)
957 const busy = busyTone(n.id)
958 const isBright = brightSet.has(n.id) || busy !== ''
959 const isDim = !isBright && dimSet.has(n.id)
960 const name = clip(n.name, cols)
961 const faded = n.hidden || n.kind === PLACEHOLDER || n.kind === EMPTY
962 const tone = busy || work?.tone || 'orange'
963 const left: Seg[] = [
964 { t: ' '.repeat(r.depth) },
965 { t: arrow, c: '#7a7a86' },
966 ...(loadingRow(n) ? [{ t: '', spin: true }, { t: ' ' }] : [isBright || isDim ? { t: g.char + ' ', sh: tone, dim: isDim, one: true } : { t: g.char + ' ', c: faded ? MUTED : g.color }]),
967 isBright || isDim ? { t: name, sh: tone, dim: isDim, b: isBright } : { t: name, c: faded ? MUTED : g.label, b: n.id === ex.selected },
968 ]
969 return { id: n.kind === PLACEHOLDER || n.kind === EMPTY ? '' : n.id, left: clean(left), right: note ? [{ t: note, c: MUTED }] : [] }
970 }
971 const note = (text: string): RowSpec => ({ id: '', left: [{ t: text, c: MUTED }], right: [] })
972 const specs: RowSpec[] = [...pinned.map(rowSpec), ...(pinned.length > 0 ? [note(' ⋮')] : []), ...shown.map(rowSpec)]
973 const barSize = Math.max(1, Math.round((specs.length * shown.length) / Math.max(1, rows.length)))
974 const bar =
975 rows.length > shown.length + pinned.length
976 ? { pos: max ? Math.round((from / max) * (specs.length - barSize)) : 0, size: barSize, thumb: '#5b9bd5', track: '#4a4a56' }
977 : undefined
978 const icon = (nerd: string, fallback: string) => (tier === 'plain' ? fallback : nerd)
979 const rootNode = ex.nodes.find(n => n.id === rootOf(ex))
980 const headName = rootNode ? rootNode.name : label(ex.target)
981 const head: RowSpec = {
982 id: '',
983 left: clean([{ t: `${titleGlyph(tier)} `, c: TITLE_COLOR }, { t: headName, b: true }, ...(ex.status ? [{ t: ` ${ex.status}`, c: MUTED }] : [])]),
984 right: [],
985 }
986 const icon16 = (source: string | undefined, alt: string, fallback: Seg, key: string) =>
987 native && Svg && source ? <Svg key={key} source={source} alt={alt} width={16} height={16} /> : <Text key={key} color={fallback.c}>{fallback.t}</Text>
988 const rule = (key: string) => <Text key={key} color="#2e2e34" wrap="truncate-end">{'─'.repeat(width)}</Text>
989 const details = detail.slice(1, DETAIL_ROWS).map(l => {
990 const cut = l.indexOf(': ')
991 return { key: cut > 0 ? l.slice(0, cut) : '', value: (cut > 0 ? l.slice(cut + 2) : l).replace(/\s+/g, ' ') }
992 })
993 type Action = { key: string; svg: string; nerd: string; plain: string; label: string; run: (surface: string) => void }
994 const actions: Action[] = shownNode
995 ? [
996 ...(webUrl(ex, shownNode) ? [{ key: 'web', svg: 'ui:open', nerd: '\u{f0379}', plain: '↗', label: 'Open in Databricks', run: () => quiet(openWeb($, ex, shownNode)) }] : []),
997 ...(shownNode.path ? [{ key: 'copy', svg: 'ui:copy', nerd: '\u{f018f}', plain: '⧉', label: 'Copy path', run: (surface: string) => quiet(copyOf($, shownNode.path, surface)) }] : []),
998 ]
999 : []
1000 const actionRow = (
1001 <Box flexDirection="row" alignItems="center" gap={2}>
1002 {actions.map(a => (
1003 <Box key={`a:${a.key}`} flexDirection="row" alignItems="center" gap={1}>
1004 {native ? icon16(UI_SVG[a.svg], a.label, { t: '', c: MUTED }, `ai:${a.key}`) : null}
1005 <Button key={a.key} plain label={native ? a.label : `${icon(a.nerd, a.plain)} ${a.label}`} onPress={p => a.run(p.surface)} />
1006 </Box>
1007 ))}
1008 </Box>
1009 )
1010 const toggles = (
1011 <Box flexDirection="row" alignItems="center" gap={native ? 1 : 2}>
1012 {rootNode && <Button key="up" plain dimColor label={icon('\u{f005d}', '↑')} onPress={() => quiet(goUp($))} />}
1013 {rootNode && <Button key="home" plain dimColor label={icon('\u{f02dc}', '⌂')} onPress={() => quiet(goHome($))} />}
1014 <Button key="refresh" plain dimColor label={icon('\u{f0450}', '↻')} onPress={() => quiet(refresh($))} />
1015 <Button key="collapse" plain dimColor label={icon('\u{eac5}', '⊟')} onPress={() => quiet(patchView($, () => ({ expanded: [] })))} />
1016 <Text> </Text>
1017 </Box>
1018 )
1019 const search = (focus: boolean) => (
1020 <Input
1021 key="q"
1022 placeholder="Filter, or Enter to jump"
1023 {...(focus ? { autoFocus: true as const } : {})}
1024 value={ex.query}
1025 onInput={(v: string) => quiet(patchView($, () => ({ query: v })))}
1026 onSubmit={(v: string) => quiet(patch($, cur => jumpTo(cur, v)))}
1027 />
1028 )
1029 const onboard = ex.onboard ? (
1030 <Box flexDirection="column" marginTop={1}>
1031 {onboardBlocks(ex.onboard).map((block, b) => (
1032 <Box key={`block-${b}`} flexDirection="column" marginTop={b > 0 ? 1 : 0}>
1033 {block.map((line, i) =>
1034 'title' in line ? (
1035 <Text key={`line-${i}`} wrap="wrap">
1036 <Text color={TITLE_COLOR}>{`${icon(line.icon[0], line.icon[1])} `}</Text>
1037 <Text bold>{line.title}</Text>
1038 </Text>
1039 ) : 'cmd' in line ? (
1040 <Box key={`line-${i}`} marginLeft={2}>
1041 <Client
1042 key={`onboard-${b}-${i}`}
1043 module="./rows.tsx"
1044 props={{ rows: [{ id: line.cmd, left: [...(line.label ? [{ t: line.label }] : []), { t: line.cmd, c: ACCENT }], right: [] }], active: '', activeBg: '', hoverBg: '#2d2f33', tones: TONES } satisfies RowsProps}
1045 />
1046 </Box>
1047 ) : (
1048 <Box key={`line-${i}`} marginLeft={2}>
1049 <Text wrap="wrap" dimColor={line.dim}>
1050 {line.text}
1051 </Text>
1052 </Box>
1053 ),
1054 )}
1055 </Box>
1056 ))}
1057 </Box>
1058 ) : null
1059 if (native) {
1060 const body = Math.max(10, e.props.scroll?.bodyRows ?? 30)
1061 const lead = (d: number, key: string) => (Svg && d > 0 ? <Svg key={key} source={guides(d)} alt={`level ${d}`} width={d * 16} height={ROW_PX} /> : <Box key={key} width={d * 2} />)
1062 const nativeRow = (r: Row) => {
1063 const n = r.node
1064 const g = glyph(n, 'plain')
1065 const faded = n.hidden || n.kind === PLACEHOLDER || n.kind === EMPTY
1066 const label = clip(n.name, Math.max(4, width - r.depth * 2 - 8 - n.note.length))
1067 const lit = brightSet.has(n.id) || dimSet.has(n.id) || busyTone(n.id) !== ''
1068 return (
1069 <Box key={`n:${n.id}`} position="relative" height={1} overflow="hidden" flexDirection="row" alignItems="center" backgroundColor={n.id === ex.cursor ? '#2a2d34' : undefined} hover={{ backgroundColor: '#232529' }}>
1070 {lead(r.depth, `g:${n.id}`)}
1071 <Box width={2} flexShrink={0} flexDirection="row" alignItems="center">
1072 {r.leaf ? null : icon16(UI_SVG[r.open ? 'ui:chevron-down' : 'ui:chevron-right'], r.open ? 'collapse' : 'expand', { t: r.open ? '⌄' : '›', c: MUTED }, `c:${n.id}`)}
1073 </Box>
1074 <Box flexDirection="row" alignItems="center" gap={1} flexShrink={1}>
1075 {loadingRow(n) ? (
1076 <Client key={`ph:${n.id}`} module="./rows.tsx" props={{ rows: [{ id: '', left: [{ t: '', spin: true }, { t: ' Loading…', c: MUTED }], right: [] }], active: '', activeBg: '', hoverBg: '', tones: TONES } satisfies RowsProps} />
1077 ) : (
1078 <Text key={`i:${n.id}`} color={g.color}>{g.char}</Text>
1079 )}
1080 {loadingRow(n) ? null : (
1081 <Text color={faded ? MUTED : lit ? TONES[work?.tone ?? 'orange']?.bright[1] : undefined} bold={n.id === ex.selected} wrap="truncate-end">
1082 {label}
1083 </Text>
1084 )}
1085 </Box>
1086 <Box flexGrow={1} />
1087 {n.note ? <Text color={MUTED}>{n.note}</Text> : null}
1088 {faded ? null : (
1089 <Box position="absolute" top={0} left={0} right={0} bottom={0}>
1090 <Client key={`z:${n.id}`} module="./zone.tsx" props={{ id: n.id } satisfies ZoneProps} width="100%" height="100%" />
1091 </Box>
1092 )}
1093 </Box>
1094 )
1095 }
1096 const atSel = shownNode ? rows.findIndex(r => r.node.id === shownNode.id) : -1
1097 const depth = atSel >= 0 ? (rows[atSel]?.depth ?? 0) + 1 : 1
1098 const propRow = (key: string, d: number, child: unknown) => (
1099 <Box key={key} height={1} overflow="hidden" flexDirection="row" alignItems="center" gap={1}>
1100 {lead(d, `${key}:g`)}
1101 {child as never}
1102 </Box>
1103 )
1104 const propLines =
1105 detail.length > 0
1106 ? [
1107 <Box key="pr:head" position="relative" height={1} overflow="hidden" flexDirection="row" alignItems="center" gap={1} hover={{ backgroundColor: '#232529' }}>
1108 {lead(depth, 'pr:head:g')}
1109 {icon16(UI_SVG[propsOpen ? 'ui:chevron-down' : 'ui:chevron-right'], propsOpen ? 'collapse' : 'expand', { t: propsOpen ? '⌄' : '›', c: MUTED }, 'pr:chev')}
1110 {icon16(UI_SVG['tenant settings'], 'Properties', { t: '⚙', c: MUTED }, 'pr:icon')}
1111 <Text color={MUTED}>Properties</Text>
1112 <Box position="absolute" top={0} left={0} right={0} bottom={0}>
1113 <Client key={`z:${PROPS}`} module="./zone.tsx" props={{ id: PROPS } satisfies ZoneProps} width="100%" height="100%" />
1114 </Box>
1115 </Box>,
1116 ...(propsOpen
1117 ? [
1118 ...details.map((d, i) =>
1119 propRow(
1120 `pr:p:${i}`,
1121 depth + 1,
1122 <Box flexDirection="row" gap={1} flexGrow={1} flexShrink={1}>
1123 <Box width={12} flexShrink={0}>
1124 <Text color={MUTED}>{d.key}</Text>
1125 </Box>
1126 <Box flexShrink={1}>
1127 <Text wrap="truncate-end">{d.value}</Text>
1128 </Box>
1129 </Box>,
1130 ),
1131 ),
1132 ...(actions.length ? [propRow('pr:actions', depth + 1, actionRow)] : []),
1133 ]
1134 : []),
1135 ]
1136 : []
1137 const headRows = 4 + (empty ? 1 : 0)
1138 const lines = atSel >= 0 ? rows.flatMap((r, i) => (i === atSel ? [nativeRow(r), ...propLines] : [nativeRow(r)])) : rows.map(nativeRow)
1139 const offset = e.props.scroll?.offset ?? 0
1140 const first = Math.max(0, offset - headRows - body)
1141 const last = Math.min(lines.length, offset - headRows + body * 2)
1142 return (
1143 <Box flexDirection="column">
1144 <Box key="desk-head" height={1} flexDirection="row" alignItems="center">
1145 <Box flexGrow={1} flexShrink={1} flexDirection="row" alignItems="center" gap={1}>
1146 <Text color={TITLE_COLOR}>{titleGlyph(tier)}</Text>
1147 <Text bold wrap="truncate-end">{headName}</Text>
1148 {ex.status ? <Text color={MUTED} wrap="truncate-end">{ex.status}</Text> : null}
1149 </Box>
1150 {toggles}
1151 </Box>
1152 <Box height={3} flexDirection="row" alignItems="center" gap={1} overflow="hidden">
1153 <Box flexGrow={1} flexShrink={1} width="100%">
1154 {search(false)}
1155 </Box>
1156 {ex.query ? <Button key="clearq" plain dimColor label="×" onPress={() => quiet(patchView($, () => ({ query: '' })))} /> : null}
1157 </Box>
1158 {empty ? (
1159 <Box height={1}>
1160 <Text color={MUTED}>{empty}</Text>
1161 </Box>
1162 ) : null}
1163 {onboard ?? (
1164 <Box key="tree" flexDirection="column">
1165 {first > 0 ? <Box key="above" height={first} /> : null}
1166 {lines.slice(first, Math.max(first, last))}
1167 {last < lines.length ? <Box key="below" height={lines.length - Math.max(first, last)} /> : null}
1168 </Box>
1169 )}
1170 </Box>
1171 )
1172 }
1173 return (
1174 <Box flexDirection="column" minHeight={Math.max(1, e.props.scroll?.bodyRows ?? 1)}>
1175 <Client key="head" module="./rows.tsx" props={{ rows: [head], active: '', activeBg: '', hoverBg: '', tones: TONES } satisfies RowsProps} />
1176 <Box flexDirection="row" alignItems="center" marginTop={1} marginBottom={1} gap={1}>
1177 <Box flexGrow={1} flexShrink={1} width="100%">
1178 {working && !ex.query ? (
1179 <Client key="working" module="./rows.tsx" props={{ rows: [{ id: '', left: [{ t: '', spin: true }, { t: ' ' }, { t: tier === 'plain' ? '*' : '\u{ec82}', claude: true }, { t: ' Claude is working in Databricks...', sh: 'orange' }], right: [] }], active: '', activeBg: '', hoverBg: '', tones: TONES } satisfies RowsProps} />
1180 ) : (
1181 search(true)
1182 )}
1183 </Box>
1184 {ex.query ? <Button key="clearq" plain dimColor label={icon('\u{f0156}', '×')} onPress={() => quiet(patchView($, () => ({ query: '' })))} /> : null}
1185 {toggles}
1186 </Box>
1187 {onboard}
1188 {empty ? <Text color={MUTED}>{empty}</Text> : null}
1189 {!ex.onboard && <Client key="rows" module="./rows.tsx" props={{ rows: specs, active: ex.cursor, activeBg: '#3e4451', hoverBg: '#2d2f33', tones: TONES, ...(bar ? { bar } : {}) } satisfies RowsProps} />}
1190 <Box flexGrow={1} />
1191 {shownNode && detail.length > 0 && (
1192 <Box key="details" flexDirection="column">
1193 {rule('rule-top')}
1194 <Box flexDirection="row" alignItems="center" gap={1} marginBottom={1}>
1195 <Text color={glyph(shownNode, tier).color}>{glyph(shownNode, tier).char}</Text>
1196 <Text bold wrap="truncate-end">{shownNode.name}</Text>
1197 <Box flexGrow={1} />
1198 <Button key="clear" plain dimColor label={icon('\u{f0156}', '✕')} onPress={() => quiet(patchView($, () => ({ selected: '', detail: [] })))} />
1199 </Box>
1200 {details.map((d, i) => (hooks/open.ts 41 lines1export const LINUX_LAUNCH = 'setsid -f -w "$@" </dev/null >/dev/null 2>&1 & p=$!; sleep 1; kill -0 "$p" 2>/dev/null && exit 0; wait "$p"'
2
3export const LINUX_OPEN = [
4 'set -f',
5 'f=$1',
6 'if command -v gio >/dev/null; then',
7 ' if [ -f "$f" ] && command -v file >/dev/null && encoding=$(file -b --mime-encoding -- "$f") && [ -n "$encoding" ] && [ "$encoding" != binary ]; then',
8 ' case $(gio info -a standard::content-type -- "$f" | sed -n \'s/.*standard::content-type: //p\') in',
9 ' video/* | audio/*)',
10 ' app=$(xdg-mime query default text/plain)',
11 ' IFS=:',
12 ' for dir in "${XDG_DATA_HOME:-$HOME/.local/share}" ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do',
13 ' [ -n "$app" ] && [ -f "$dir/applications/$app" ] && exec gio launch "$dir/applications/$app" "$f"',
14 ' done',
15 ' echo "No text/plain desktop application found for $f" >&2',
16 ' exit 1',
17 ' ;;',
18 ' esac',
19 ' fi',
20 ' if (exec gio open "$f"); then exit 0; fi',
21 'fi',
22 'exec xdg-open "$f"',
23].join('\n')
24
25const WIN_OPEN = "$ErrorActionPreference = 'Stop'; [Diagnostics.Process]::Start([Diagnostics.ProcessStartInfo]@{ FileName = $env:PANE_OPEN_TARGET; UseShellExecute = $true }) | Out-Null"
26
27export function openCommand(os: 'linux' | 'darwin' | 'win32', target: string) {
28 const argv = os === 'linux'
29 ? ['sh', '-c', LINUX_LAUNCH, 'sh', 'sh', '-c', LINUX_OPEN, 'sh', target]
30 : os === 'darwin'
31 ? ['open', '--', target]
32 : ['powershell', '-NoProfile', '-NonInteractive', '-Command', WIN_OPEN]
33 return {
34 argv,
35 init: {
36 timeoutMs: 10_000,
37 ...(os === 'win32' ? { env: { PANE_OPEN_TARGET: /^[a-z][a-z0-9+.-]*:\/\//i.test(target) ? target : target.replace(/\//g, '\\') } } : {}),
38 },
39 }
40}
41hooks/icons.ts 68 lines1import type { TreeNode } from '../types'
2import { DB_CODEPOINTS } from './icon-data'
3
4type Rgb = [number, number, number]
5type Icon = { db: string; nerd: string; rgb: Rgb; plain: string }
6export type Tier = 'databricks' | 'nerd' | 'plain'
7export type Glyph = { char: string; color: string | undefined; label?: string }
8
9const RED: Rgb = [255, 54, 33]
10const SLATE: Rgb = [148, 163, 184]
11const ICONS: Record<string, Icon> = {
12 'section-workspace': { db: 'ui_workspace', nerd: '\u{f0b9f}', rgb: RED, plain: '▣' },
13 'section-catalog': { db: 'ui_catalog_section', nerd: '\u{f05da}', rgb: RED, plain: '▣' },
14 'section-compute': { db: 'ui_compute', nerd: '\u{f048b}', rgb: RED, plain: '▣' },
15 'section-jobs': { db: 'ui_jobs', nerd: '\u{f0bb4}', rgb: RED, plain: '▣' },
16 'section-pipelines': { db: 'pipeline', nerd: '\u{f07e5}', rgb: RED, plain: '▣' },
17 'section-apps': { db: 'ui_apps', nerd: '\u{f003b}', rgb: RED, plain: '▣' },
18 'section-dashboards': { db: 'ui_dashboard', nerd: '\u{f056e}', rgb: RED, plain: '▣' },
19 folder: { db: 'ui_folder', nerd: '\u{f024b}', rgb: [184, 175, 137], plain: '■' },
20 repo: { db: 'ui_repo', nerd: '\u{f02a2}', rgb: [240, 80, 50], plain: '⑂' },
21 notebook: { db: 'ui_notebook', nerd: '\u{f082e}', rgb: [96, 165, 250], plain: '▤' },
22 file: { db: 'file', nerd: '\u{f0214}', rgb: SLATE, plain: '·' },
23 library: { db: 'file_code', nerd: '\u{f03d7}', rgb: SLATE, plain: '·' },
24 dashboard: { db: 'ui_dashboard', nerd: '\u{f056e}', rgb: [251, 191, 36], plain: '▦' },
25 catalog: { db: 'ui_catalog', nerd: '\u{f05da}', rgb: [167, 139, 250], plain: '◆' },
26 schema: { db: 'ui_schema', nerd: '\u{f01bc}', rgb: [129, 140, 248], plain: '◇' },
27 table: { db: 'ui_table', nerd: '\u{f04eb}', rgb: [74, 222, 128], plain: '▦' },
28 view: { db: 'view', nerd: '\u{f0208}', rgb: [45, 212, 191], plain: '▧' },
29 materialized_view: { db: 'materialized_view', nerd: '\u{f0208}', rgb: [45, 212, 191], plain: '▧' },
30 streaming_table: { db: 'streaming_table', nerd: '\u{f04eb}', rgb: [52, 211, 153], plain: '▦' },
31 metric_view: { db: 'ui_metric_view', nerd: '\u{f04eb}', rgb: [167, 139, 250], plain: '▦' },
32 catalog_system: { db: 'ui_catalog_system', nerd: '\u{f05da}', rgb: [148, 163, 184], plain: '◆' },
33 catalog_shared: { db: 'ui_catalog_shared', nerd: '\u{f05da}', rgb: [45, 212, 191], plain: '◆' },
34 catalog_workspace: { db: 'ui_catalog_workspace', nerd: '\u{f05da}', rgb: [167, 139, 250], plain: '◆' },
35 folder_users: { db: 'ui_folder_users', nerd: '\u{f0849}', rgb: [184, 175, 137], plain: '■' },
36 folder_shared: { db: 'ui_folder_shared', nerd: '\u{f024b}', rgb: [184, 175, 137], plain: '■' },
37 volume: { db: 'volume', nerd: '\u{f02ca}', rgb: [251, 146, 60], plain: '◎' },
38 cluster: { db: 'ui_compute', nerd: '\u{f048b}', rgb: [56, 189, 248], plain: '◉' },
39 warehouse: { db: 'ui_warehouse', nerd: '\u{f140b}', rgb: [250, 204, 21], plain: '◉' },
40 job: { db: 'ui_jobs', nerd: '\u{f0bb4}', rgb: [244, 114, 182], plain: '▶' },
41 pipeline: { db: 'pipeline', nerd: '\u{f07e5}', rgb: [52, 211, 153], plain: '⇶' },
42 app: { db: 'ui_apps', nerd: '\u{f003b}', rgb: [251, 113, 133], plain: '◈' },
43 placeholder: { db: '', nerd: '\u{f0453}', rgb: [110, 110, 122], plain: '…' },
44 empty: { db: '', nerd: '∅', rgb: [110, 110, 122], plain: '∅' },
45}
46const FALLBACK: Icon = { db: 'file', nerd: '\u{f0214}', rgb: SLATE, plain: '·' }
47
48const hex = (c: Rgb) => `#${c.map(v => v.toString(16).padStart(2, '0')).join('')}`
49
50function variant(n: TreeNode): string {
51 if (n.kind === 'catalog') return n.note === 'system' && n.name === 'system' ? 'catalog_system' : n.note === 'system' || n.note === 'deltasharing' ? 'catalog_shared' : n.name === 'workspace' ? 'catalog_workspace' : 'catalog'
52 if (n.kind === 'folder' && n.path === '/Users') return 'folder_users'
53 if (n.kind === 'folder' && n.path === '/Shared') return 'folder_shared'
54 return n.kind
55}
56
57export function glyph(n: TreeNode, tier: Tier): Glyph {
58 const icon = ICONS[variant(n)] ?? ICONS[n.kind] ?? FALLBACK
59 const cp = DB_CODEPOINTS[icon.db]
60 const char = tier === 'databricks' && cp ? String.fromCodePoint(cp) : tier === 'plain' ? icon.plain : icon.nerd
61 return { char, color: hex(icon.rgb) }
62}
63
64export function titleGlyph(tier: Tier): string {
65 const cp = DB_CODEPOINTS.ui_logo
66 return tier === 'databricks' && cp ? String.fromCodePoint(cp) : tier === 'plain' ? '◈' : '\u{f0b9f}'
67}
68hooks/rows.tsx 165 lines1import type { ClientModule } from 'claude-code'
2
3export type Seg = { t: string; c?: string; b?: boolean; s?: boolean; i?: boolean; sh?: string; dim?: boolean; one?: boolean; spin?: boolean; claude?: boolean; bg?: string; tab?: string }
4export type RowSpec = { id: string; left: Seg[]; right: Seg[] }
5export type RowsProps = {
6 rows: RowSpec[]
7 active: string
8 activeBg: string
9 hoverBg: string
10 tones: Record<string, { bright: string[]; dim: string[] }>
11 pointer?: boolean
12 bar?: { pos: number; size: number; thumb: string; track: string }
13}
14type Local = { hover: number; phase: number; drag: boolean; ref: { stop?: () => void; unpoint?: () => void } }
15
16const TICK_MS = 90
17const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
18const GRADIENT = ['#5eead4', '#67e8f9', '#7dd3fc', '#93c5fd', '#a5b4fc', '#c4b5fd', '#d8b4fe', '#f0abfc', '#d8b4fe', '#c4b5fd', '#a5b4fc', '#93c5fd', '#7dd3fc', '#67e8f9']
19
20function shimmer(i: number, phase: number, len: number, palette: string[]): string {
21 const band = ((phase * 1.6) % (len + 8)) - 4
22 const d = Math.abs(i - band)
23 return palette[d < 0.8 ? 3 : d < 1.8 ? 2 : d < 2.8 ? 1 : 0] ?? palette[0] ?? '#f97316'
24}
25
26const Rows: ClientModule<RowsProps, Local> = (props, surface) => {
27 const { Box, Text } = surface.elements
28 let state = surface.state
29 if (state === undefined) {
30 state = { hover: -1, phase: 0, drag: false, ref: {} }
31 surface.setState(state)
32 }
33 const lit = props.rows.some(r => r.left.some(s => s.sh || s.spin || s.claude) || r.right.some(s => s.sh || s.spin || s.claude))
34 if (lit && !state.ref.stop) {
35 state.ref.stop = surface.every(TICK_MS, () => {
36 const cur = surface.state
37 if (cur) surface.setState({ ...cur, phase: cur.phase + 1 })
38 })
39 } else if (!lit && state.ref.stop) {
40 state.ref.stop()
41 state.ref.stop = undefined
42 }
43 if (props.pointer === false) {
44 state.ref.unpoint?.()
45 state.ref.unpoint = undefined
46 } else state.ref.unpoint = surface.onPointer(e => {
47 const cur = surface.state ?? state
48 const span = Math.max(1, props.rows.length - 1)
49 const onBar = Boolean(props.bar) && e.x >= surface.columns - 1
50 if (props.bar && (cur.drag || (onBar && e.type === 'down' && (e.button ?? 'left') === 'left'))) {
51 if (e.type === 'up' || e.type === 'leave') {
52 surface.setState({ ...cur, drag: false })
53 return
54 }
55 if (e.type === 'down' || e.type === 'move') {
56 if (!cur.drag) surface.setState({ ...cur, drag: true, hover: -1 })
57 surface.post({ scrollTo: Math.max(0, Math.min(1, e.y / span)) })
58 return
59 }
60 }
61 if (e.type === 'leave' || e.y < 0 || e.y >= props.rows.length) {
62 if (cur.hover !== -1) surface.setState({ ...cur, hover: -1 })
63 return
64 }
65 if (e.type === 'move' && !e.button && cur.hover !== e.y) surface.setState({ ...cur, hover: e.y })
66 const row = props.rows[e.y]
67 if (e.type === 'down' && e.button === 'right' && row?.id) {
68 surface.post({ copy: row.id, shift: Boolean(e.shift) })
69 return
70 }
71 if (e.type !== 'down' || (e.button ?? 'left') !== 'left' || !row) return
72 const wide = (seg: Seg) => [...seg.t].length + (seg.spin ? 1 : 0)
73 let x = 0
74 for (const seg of row.left) {
75 const w = wide(seg)
76 if (seg.tab && e.x >= x && e.x < x + w) {
77 surface.post({ tab: seg.tab })
78 return
79 }
80 x += w
81 }
82 x = surface.columns - (props.bar ? 1 : 0) - row.right.reduce((n, seg) => n + wide(seg), 0)
83 for (const seg of row.right) {
84 const w = wide(seg)
85 if (seg.tab && e.x >= x && e.x < x + w) {
86 surface.post({ tab: seg.tab })
87 return
88 }
89 x += w
90 }
91 if (row.id) surface.post({ press: row.id, ctrl: Boolean(e.ctrl), shift: Boolean(e.shift) })
92 })
93 surface.onKey(e => surface.post({ key: e.key, ctrl: Boolean(e.ctrl), shift: Boolean(e.shift) }))
94 const draw = (s: Seg, k: number) => {
95 if (s.claude) {
96 const shut = Math.floor(state.phase / 3) % 12 === 11
97 return (
98 <Text key={String(k)} color={shut ? '#7a4535' : '#d97757'} bold={!shut}>
99 {s.t}
100 </Text>
101 )
102 }
103 if (s.spin) {
104 const frame = FRAMES[state.phase % FRAMES.length] ?? ''
105 return (
106 <Text key={String(k)} bold={s.b}>
107 {s.t ? <Text color={s.c}>{s.t}</Text> : null}
108 <Text color={GRADIENT[state.phase % GRADIENT.length]} bold>
109 {frame}
110 </Text>
111 </Text>
112 )
113 }
114 const palette = s.sh ? (s.dim ? props.tones[s.sh]?.dim : props.tones[s.sh]?.bright) : undefined
115 if (!palette) {
116 return (
117 <Text key={String(k)} color={s.c} backgroundColor={s.bg} bold={s.b} strikethrough={s.s} italic={s.i}>
118 {s.t}
119 </Text>
120 )
121 }
122 if (s.one) {
123 return (
124 <Text key={String(k)} color={shimmer(-1, state.phase, s.t.length, palette)}>
125 {s.t}
126 </Text>
127 )
128 }
129 const chars = [...s.t]
130 return (
131 <Text key={String(k)} bold={s.b}>
132 {chars.map((ch, i) => (
133 <Text key={String(i)} color={shimmer(i, state.phase, chars.length, palette)}>{ch}</Text>
134 ))}
135 </Text>
136 )
137 }
138 return (
139 <Box flexDirection="column">
140 {props.rows.map((r, i) => (
141 <Box
142 key={r.id || `row-${i}`}
143 flexDirection="row"
144 height={1}
145 overflow="hidden"
146 backgroundColor={r.id && r.id === props.active ? props.activeBg : r.id && i === state.hover ? props.hoverBg : undefined}
147 >
148 <Box flexShrink={1} overflow="hidden">
149 {r.left.map(draw)}
150 </Box>
151 <Box flexGrow={1} />
152 {r.right.map(draw)}
153 {props.bar && (
154 <Text color={i >= props.bar.pos && i < props.bar.pos + props.bar.size ? props.bar.thumb : props.bar.track}>
155 {i >= props.bar.pos && i < props.bar.pos + props.bar.size ? '┃' : '│'}
156 </Text>
157 )}
158 </Box>
159 ))}
160 </Box>
161 )
162}
163
164export default Rows
165hooks/svg-data.ts 2 lines1export const UI_SVG: Record<string, string> = {"ui:open":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"20\" height=\"20\" fill=\"#c5c5d0\"><path d=\"M6 4a2 2 0 0 0-2 2v8c0 1.1.9 2 2 2h8a2 2 0 0 0 2-2v-2.5a.5.5 0 0 1 1 0V14a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h2.5a.5.5 0 0 1 0 1H6Zm5-.5c0-.28.22-.5.5-.5h5c.28 0 .5.22.5.5v5a.5.5 0 0 1-1 0V4.7l-4.15 4.15a.5.5 0 0 1-.7-.7L15.29 4H11.5a.5.5 0 0 1-.5-.5Z\"/></svg>","ui:copy":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"20\" height=\"20\" fill=\"#c5c5d0\"><path d=\"M8 2a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h6a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8ZM7 4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V4ZM4 6a2 2 0 0 1 1-1.73V14.5A2.5 2.5 0 0 0 7.5 17h6.23A2 2 0 0 1 12 18H7.5A3.5 3.5 0 0 1 4 14.5V6Z\"/></svg>","ui:chevron-right":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"16\" height=\"16\" fill=\"#8b8b96\"><path d=\"M7.65 4.15c.2-.2.5-.2.7 0l5.49 5.46c.21.22.21.57 0 .78l-5.49 5.46a.5.5 0 0 1-.7-.7L12.8 10 7.65 4.85a.5.5 0 0 1 0-.7Z\"/></svg>","ui:chevron-down":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"16\" height=\"16\" fill=\"#8b8b96\"><path d=\"M15.85 7.65c.2.2.2.5 0 .7l-5.46 5.49a.55.55 0 0 1-.78 0L4.15 8.35a.5.5 0 1 1 .7-.7L10 12.8l5.15-5.16c.2-.2.5-.2.7 0Z\"/></svg>","tenant settings":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" width=\"20\" height=\"20\" fill=\"#c5c5d0\"><path d=\"M1.91 7.38A8.5 8.5 0 0 1 3.7 4.3a.5.5 0 0 1 .54-.13l1.92.68a1 1 0 0 0 1.32-.76l.36-2a.5.5 0 0 1 .4-.4 8.53 8.53 0 0 1 3.55 0c.2.04.35.2.38.4l.37 2a1 1 0 0 0 1.32.76l1.92-.68a.5.5 0 0 1 .54.13 8.5 8.5 0 0 1 1.78 3.08c.06.2 0 .4-.15.54l-1.56 1.32a1 1 0 0 0 0 1.52l1.56 1.32a.5.5 0 0 1 .15.54 8.5 8.5 0 0 1-1.78 3.08.5.5 0 0 1-.54.13l-1.92-.68a1 1 0 0 0-1.32.76l-.37 2a.5.5 0 0 1-.38.4 8.53 8.53 0 0 1-3.56 0 .5.5 0 0 1-.39-.4l-.36-2a1 1 0 0 0-1.32-.76l-1.92.68a.5.5 0 0 1-.54-.13 8.5 8.5 0 0 1-1.78-3.08.5.5 0 0 1 .15-.54l1.56-1.32a1 1 0 0 0 0-1.52L2.06 7.92a.5.5 0 0 1-.15-.54Zm1.06 0 1.3 1.1a2 2 0 0 1 0 3.04l-1.3 1.1c.3.79.72 1.51 1.25 2.16l1.6-.58a2 2 0 0 1 2.63 1.53l.3 1.67a7.56 7.56 0 0 0 2.5 0l.3-1.67a2 2 0 0 1 2.64-1.53l1.6.58a7.5 7.5 0 0 0 1.24-2.16l-1.3-1.1a2 2 0 0 1 0-3.04l1.3-1.1a7.5 7.5 0 0 0-1.25-2.16l-1.6.58a2 2 0 0 1-2.63-1.53l-.3-1.67a7.55 7.55 0 0 0-2.5 0l-.3 1.67A2 2 0 0 1 5.81 5.8l-1.6-.58a7.5 7.5 0 0 0-1.24 2.16ZM7.5 10a2.5 2.5 0 1 1 5 0 2.5 2.5 0 0 1-5 0Zm1 0a1.5 1.5 0 1 0 3 0 1.5 1.5 0 0 0-3 0Z\"/></svg>"}
2hooks/zone.tsx 22 lines1import type { ClientModule } from 'claude-code'
2
3export type ZoneProps = { id: string }
4type Local = { ref: { unpoint?: () => void; id: string } }
5
6const Zone: ClientModule<ZoneProps, Local> = (props, surface) => {
7 const { Box } = surface.elements
8 let state = surface.state
9 if (state === undefined) {
10 state = { ref: { id: props.id } }
11 surface.setState(state)
12 }
13 const ref = state.ref
14 ref.id = props.id
15 ref.unpoint ??= surface.onPointer(e => {
16 if (e.type === 'up' && (e.button ?? 'left') === 'left') surface.post({ zone: ref.id, shift: Boolean(e.shift), ctrl: Boolean(e.ctrl) })
17 })
18 return <Box width="100%" height="100%" />
19}
20
21export default Zone
22hooks/tree.ts 130 lines1import type { Explorer, TreeNode } from '../types'
2
3export type Row = { node: TreeNode; depth: number; open: boolean; leaf: boolean }
4
5export function empty(): Explorer {
6 return {
7 target: null,
8 nodes: [],
9 expanded: [],
10 query: '',
11 cursor: '',
12 selected: '',
13 detail: [],
14 status: '',
15 work: null,
16 onboard: null,
17 busy: {},
18 scroll: null,
19 root: '',
20 }
21}
22
23function childrenOf(nodes: TreeNode[]): Map<string, TreeNode[]> {
24 const kids = new Map<string, TreeNode[]>()
25 for (const n of nodes) {
26 const list = kids.get(n.parent)
27 if (list) list.push(n)
28 else kids.set(n.parent, [n])
29 }
30 return kids
31}
32
33export const EMPTY = 'empty'
34
35export function emptyMark(parent: string): TreeNode {
36 return { id: `${parent}/∅`, parent, kind: EMPTY, name: 'empty', path: '', hidden: false, sig: '', note: '' }
37}
38
39export function isLoaded(nodes: TreeNode[], id: string): boolean {
40 let any = false
41 for (const n of nodes) {
42 if (n.parent !== id) continue
43 if (n.kind === 'placeholder') return false
44 any = true
45 }
46 return any
47}
48
49export function merge(nodes: TreeNode[], parent: string, kids: TreeNode[]): TreeNode[] {
50 const under = childrenOf(nodes)
51 const subtree = (id: string, out: TreeNode[] = []): TreeNode[] => {
52 for (const c of under.get(id) ?? []) {
53 out.push(c)
54 subtree(c.id, out)
55 }
56 return out
57 }
58 const known = new Map(nodes.map(n => [n.id, n]))
59 const loaded = (id: string) => {
60 const cs = under.get(id) ?? []
61 return cs.length > 0 && !cs.some(c => c.kind === 'placeholder')
62 }
63 const same = (k: TreeNode) => {
64 const old = known.get(k.id)
65 return Boolean(old) && old?.kind === k.kind && old?.sig === k.sig
66 }
67 const keep = new Set(kids.filter(k => k.kind !== 'placeholder' && same(k) && loaded(k.id)).map(k => k.id))
68 const gone = new Set(subtree(parent).map(n => n.id))
69 const out = nodes.filter(n => !gone.has(n.id))
70 for (const k of kids) {
71 if (k.kind === 'placeholder' && keep.has(k.parent)) continue
72 out.push(k)
73 if (keep.has(k.id)) subtree(k.id, out)
74 }
75 if (kids.length === 0) out.push(emptyMark(parent))
76 return out
77}
78
79export function ancestors(nodes: TreeNode[], id: string, byId?: Map<string, TreeNode>): string[] {
80 const map = byId ?? new Map(nodes.map(n => [n.id, n]))
81 const out: string[] = []
82 let cur = map.get(id)
83 while (cur && cur.parent) {
84 out.push(cur.parent)
85 cur = map.get(cur.parent)
86 }
87 return out
88}
89
90const RANK: Record<string, number> = { folder: 0, group: 3 }
91const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
92
93function sorted(list: TreeNode[]): TreeNode[] {
94 return [...list].sort(
95 (a, b) => (RANK[a.kind] ?? 2) - (RANK[b.kind] ?? 2) || collator.compare(a.name, b.name),
96 )
97}
98
99export function visible(ex: Explorer, sort = false, root = ''): Row[] {
100 const kids = childrenOf(ex.nodes)
101 const q = ex.query.trim().toLowerCase()
102 let keep: Set<string> | null = null
103 if (q) {
104 keep = new Set()
105 const byId = new Map(ex.nodes.map(n => [n.id, n]))
106 for (const n of ex.nodes) {
107 if (!n.name.toLowerCase().includes(q) && !n.note.toLowerCase().includes(q)) continue
108 let cur: TreeNode | undefined = n
109 while (cur && !keep.has(cur.id)) {
110 keep.add(cur.id)
111 cur = byId.get(cur.parent)
112 }
113 }
114 }
115 const open = new Set(ex.expanded)
116 const rows: Row[] = []
117 const walk = (parent: string, depth: number) => {
118 const list = kids.get(parent) ?? []
119 for (const n of sort ? sorted(list) : list) {
120 if (keep && !keep.has(n.id)) continue
121 const leaf = !kids.has(n.id)
122 const isOpen = !leaf && (keep ? true : open.has(n.id))
123 rows.push({ node: n, depth, open: isOpen, leaf })
124 if (isOpen) walk(n.id, depth + 1)
125 }
126 }
127 walk(root, 0)
128 return rows
129}
130hooks/databricks.ts 241 lines1import type { TreeNode } from '../types'
2
3export const PLACEHOLDER = 'placeholder'
4
5export const SECTIONS = [
6 { id: 'S:workspace', name: 'Workspace', kind: 'section-workspace' },
7 { id: 'S:catalog', name: 'Catalog', kind: 'section-catalog' },
8 { id: 'S:compute', name: 'Compute', kind: 'section-compute' },
9 { id: 'S:jobs', name: 'Jobs', kind: 'section-jobs' },
10 { id: 'S:pipelines', name: 'Pipelines', kind: 'section-pipelines' },
11 { id: 'S:apps', name: 'Apps', kind: 'section-apps' },
12 { id: 'S:dashboards', name: 'Dashboards', kind: 'section-dashboards' },
13] as const
14
15type Rec = Record<string, unknown>
16
17function node(id: string, parent: string, kind: string, name: string, path: string, extra: Partial<TreeNode> = {}): TreeNode {
18 return { id, parent, kind, name, path, hidden: false, sig: '', note: '', ...extra }
19}
20
21export function stub(parent: string): TreeNode {
22 return node(`${parent}/…`, parent, PLACEHOLDER, 'loading…', '')
23}
24
25export function roots(): TreeNode[] {
26 return SECTIONS.flatMap(s => [node(s.id, '', s.kind, s.name, ''), stub(s.id)])
27}
28
29function str(v: unknown): string {
30 return typeof v === 'string' ? v : typeof v === 'number' ? String(v) : ''
31}
32
33function at(rec: Rec, ...keys: string[]): string {
34 let cur: unknown = rec
35 for (const k of keys) cur = cur && typeof cur === 'object' ? (cur as Rec)[k] : undefined
36 return str(cur)
37}
38
39export function records(stdout: string): Rec[] {
40 const start = stdout.search(/[[{]/)
41 if (start < 0) return []
42 const parsed: unknown = JSON.parse(stdout.slice(start))
43 const list = Array.isArray(parsed) ? parsed : parsed && typeof parsed === 'object' ? Object.values(parsed).find(Array.isArray) : undefined
44 return (list ?? []).filter((r): r is Rec => Boolean(r) && typeof r === 'object')
45}
46
47export function listCalls(n: TreeNode): string[][] {
48 const [cat = '', sch = ''] = n.path.split('.')
49 switch (n.kind) {
50 case 'section-workspace':
51 return [['workspace', 'list', '/']]
52 case 'folder':
53 case 'repo':
54 return [['workspace', 'list', n.path]]
55 case 'section-catalog':
56 return [['catalogs', 'list']]
57 case 'catalog':
58 return [['schemas', 'list', cat]]
59 case 'schema':
60 return [
61 ['tables', 'list', cat, sch, '--omit-columns', '--omit-properties', '--omit-username'],
62 ['volumes', 'list', cat, sch],
63 ]
64 case 'section-compute':
65 return [['clusters', 'list'], ['warehouses', 'list']]
66 case 'section-jobs':
67 return [['jobs', 'list']]
68 case 'section-pipelines':
69 return [['pipelines', 'list-pipelines']]
70 case 'section-apps':
71 return [['apps', 'list']]
72 case 'section-dashboards':
73 return [['lakeview', 'list']]
74 default:
75 return []
76 }
77}
78
79const OBJECT_KIND: Record<string, string> = { DIRECTORY: 'folder', NOTEBOOK: 'notebook', FILE: 'file', REPO: 'repo', DASHBOARD: 'dashboard', LIBRARY: 'library' }
80
81function base(path: string): string {
82 return path.replace(/\/+$/, '').split('/').pop() || path
83}
84
85export function children(n: TreeNode, outputs: string[], host: string): TreeNode[] {
86 const out: TreeNode[] = []
87 const push = (child: TreeNode, open: boolean) => {
88 child.url = urlFor(child, host)
89 out.push(child)
90 if (open) out.push(stub(child.id))
91 }
92 const [o0 = '', o1 = ''] = outputs
93 switch (n.kind) {
94 case 'section-workspace':
95 case 'folder':
96 case 'repo':
97 for (const r of records(o0)) {
98 const path = at(r, 'path')
99 if (!path) continue
100 const kind = OBJECT_KIND[at(r, 'object_type')] ?? 'file'
101 push(node(`WS:${path}`, n.id, kind, base(path), path, { sig: at(r, 'object_id'), note: kind === 'notebook' ? at(r, 'language').toLowerCase() : '' }), kind === 'folder' || kind === 'repo')
102 const dash = kind === 'dashboard' ? at(r, 'resource_id') : ''
103 const made = out[out.length - 1]
104 if (made && host) made.url = dash ? `${host}/dashboardsv3/${encodeURIComponent(dash)}/published` : kind === 'dashboard' ? `${host}/#workspace${path.split('/').map(encodeURIComponent).join('/')}` : made.url
105 }
106 break
107 case 'section-catalog':
108 for (const r of records(o0)) {
109 const name = at(r, 'name')
110 if (name) push(node(`UC:${name}`, n.id, 'catalog', name, name, { sig: at(r, 'created_at'), note: at(r, 'catalog_type').toLowerCase().replace(/_catalog$/, '') }), true)
111 }
112 break
113 case 'catalog':
114 for (const r of records(o0)) {
115 const name = at(r, 'name')
116 if (name) push(node(`UC:${n.path}.${name}`, n.id, 'schema', name, at(r, 'full_name') || `${n.path}.${name}`, { sig: at(r, 'created_at') }), true)
117 }
118 break
119 case 'schema':
120 for (const r of records(o0)) {
121 const name = at(r, 'name')
122 const type = at(r, 'table_type')
123 const kind = type === 'METRIC_VIEW' ? 'metric_view' : type === 'MATERIALIZED_VIEW' ? 'materialized_view' : type === 'STREAMING_TABLE' ? 'streaming_table' : type === 'VIEW' ? 'view' : 'table'
124 if (name) push(node(`UC:${n.path}.${name}`, n.id, kind, name, at(r, 'full_name') || `${n.path}.${name}`, { note: type.toLowerCase().replace(/_/g, ' ') }), false)
125 }
126 for (const r of records(o1)) {
127 const name = at(r, 'name')
128 if (name) push(node(`UV:${n.path}.${name}`, n.id, 'volume', name, at(r, 'full_name') || `${n.path}.${name}`, { note: 'volume' }), false)
129 }
130 break
131 case 'section-compute':
132 for (const r of records(o0)) {
133 const id = at(r, 'cluster_id')
134 if (id) push(node(`CL:${id}`, n.id, 'cluster', at(r, 'cluster_name') || id, id, { note: at(r, 'state').toLowerCase() }), false)
135 }
136 for (const r of records(o1)) {
137 const id = at(r, 'id')
138 if (id) push(node(`SW:${id}`, n.id, 'warehouse', at(r, 'name') || id, id, { note: at(r, 'state').toLowerCase() }), false)
139 }
140 break
141 case 'section-jobs':
142 for (const r of records(o0)) {
143 const id = at(r, 'job_id')
144 if (id) push(node(`J:${id}`, n.id, 'job', at(r, 'settings', 'name') || id, id), false)
145 }
146 break
147 case 'section-pipelines':
148 for (const r of records(o0)) {
149 const id = at(r, 'pipeline_id')
150 if (id) push(node(`P:${id}`, n.id, 'pipeline', at(r, 'name') || id, id, { note: at(r, 'state').toLowerCase() }), false)
151 }
152 break
153 case 'section-apps':
154 for (const r of records(o0)) {
155 const name = at(r, 'name')
156 if (name) push(node(`A:${name}`, n.id, 'app', name, name, { note: (at(r, 'app_status', 'state') || at(r, 'compute_status', 'state')).toLowerCase() }), false)
157 }
158 break
159 case 'section-dashboards':
160 for (const r of records(o0)) {
161 const id = at(r, 'dashboard_id')
162 if (id) push(node(`D:${id}`, n.id, 'dashboard', at(r, 'display_name') || id, id), false)
163 }
164 break
165 }
166 return out
167}
168
169export function urlFor(n: TreeNode, host: string): string {
170 if (!host) return ''
171 const [c = '', s = '', t = ''] = n.path.split('.')
172 const enc = (v: string) => encodeURIComponent(v)
173 switch (n.kind) {
174 case 'folder':
175 case 'notebook':
176 case 'file':
177 case 'repo':
178 case 'library':
179 return `${host}/#workspace${n.path.split('/').map(enc).join('/')}`
180 case 'catalog':
181 return `${host}/explore/data/${enc(c)}`
182 case 'schema':
183 return `${host}/explore/data/${enc(c)}/${enc(s)}`
184 case 'table':
185 case 'view':
186 case 'metric_view':
187 case 'materialized_view':
188 case 'streaming_table':
189 return `${host}/explore/data/${enc(c)}/${enc(s)}/${enc(t)}`
190 case 'volume':
191 return `${host}/explore/data/volumes/${enc(c)}/${enc(s)}/${enc(t)}`
192 case 'cluster':
193 return `${host}/compute/clusters/${enc(n.path)}`
194 case 'warehouse':
195 return `${host}/sql/warehouses/${enc(n.path)}`
196 case 'job':
197 return `${host}/jobs/${enc(n.path)}`
198 case 'pipeline':
199 return `${host}/pipelines/${enc(n.path)}`
200 case 'app':
201 return `${host}/apps/${enc(n.path)}`
202 case 'dashboard':
203 return `${host}/dashboardsv3/${enc(n.path)}/published`
204 default:
205 return host
206 }
207}
208
209export function chainOf(id: string): string[] {
210 if (id.startsWith('WS:')) {
211 const parts = id.slice(3).split('/').filter(Boolean)
212 return ['S:workspace', ...parts.slice(0, -1).map((_, i) => `WS:/${parts.slice(0, i + 1).join('/')}`)]
213 }
214 if (id.startsWith('UC:') || id.startsWith('UV:')) {
215 const parts = id.slice(3).split('.')
216 const out = ['S:catalog']
217 if (parts.length >= 2) out.push(`UC:${parts[0]}`)
218 if (parts.length >= 3) out.push(`UC:${parts[0]}.${parts[1]}`)
219 return out
220 }
221 const prefix = id.split(':')[0]
222 const section: Record<string, string> = { CL: 'S:compute', SW: 'S:compute', J: 'S:jobs', P: 'S:pipelines', A: 'S:apps', D: 'S:dashboards' }
223 return prefix && section[prefix] ? [section[prefix]] : []
224}
225
226export function hostFrom(cfg: string, profile: string): string {
227 const want = profile || 'DEFAULT'
228 let section = ''
229 for (const raw of cfg.split(/\r?\n/)) {
230 const line = raw.trim()
231 const head = /^\[(.+)\]$/.exec(line)
232 if (head) {
233 section = head[1]?.trim() ?? ''
234 continue
235 }
236 const kv = /^host\s*=\s*(.+)$/i.exec(line)
237 if (kv && section === want) return (kv[1] ?? '').trim().replace(/\/+$/, '')
238 }
239 return ''
240}
241hooks/parse.ts 502 lines1export type Invocation = { tool: string; bin: string; args: string[]; cwd: string; env: Record<string, string> }
2
3const SEPARATORS = new Set(['&&', '||', ';', '|', '&', '\n', '(', ')', '`'])
4const PREFIXES = new Set(['do', 'then', 'else', 'elif', 'if', '!', 'time', '{', 'env', 'command', 'builtin', 'exec', 'nohup', 'sudo', 'nice', 'xargs', 'uvx', 'pipx', 'timeout', 'while', 'until'])
5const PREFIX_VALUED: Record<string, Set<string>> = {
6 sudo: new Set(['-u', '-g', '-C', '-h', '-p', '-U', '-r', '-t', '-D']),
7 timeout: new Set(['-k', '-s', '--kill-after', '--signal']),
8 xargs: new Set(['-n', '-I', '-P', '-L', '-s', '-d', '-E', '-a']),
9 env: new Set(['-u', '-C', '-S', '--unset', '--chdir']),
10 nice: new Set(['-n']),
11 exec: new Set(['-a']),
12 uvx: new Set(['--from', '--with', '-p', '--python']),
13 uv: new Set(['--from', '--with', '-p', '--python', '--project', '--directory']),
14 pipx: new Set(['--spec', '--python']),
15}
16const MAX_CALLS = 50
17const REDIRECT = /^(\d*>>?|\d*<|\d*>&\d*|&>>?)$/
18
19let drives = false
20
21export function useDrives(on: boolean): void {
22 drives = on
23}
24
25export function posix(path: string): string {
26 if (!drives) return path
27 return path.replace(/\\/g, '/').replace(/^\/([A-Za-z])(\/|$)/, (_, d: string) => `${d.toUpperCase()}:/`)
28}
29
30export function isAbsolute(path: string): boolean {
31 return path.startsWith('/') || (drives && /^[A-Za-z]:\//.test(path))
32}
33
34export function tokenize(command: string, subs: { at: number; body: string }[] = []): string[] {
35 const out: string[] = []
36 let cur = ''
37 let quote = ''
38 let has = false
39 for (let i = 0; i < command.length; i++) {
40 const ch = command[i] ?? ''
41 if (!quote && ch === '#' && !has && !cur) {
42 while (i + 1 < command.length && command[i + 1] !== '\n') i++
43 continue
44 }
45 if (quote) {
46 if (ch === quote) quote = ''
47 else if (ch === '\\' && quote === '"' && i + 1 < command.length) cur += command[++i] ?? ''
48 else if (quote === '"' && ((ch === '$' && command[i + 1] === '(') || ch === '`')) {
49 const end = closing(command, i)
50 if (end < 0) cur += ch
51 else {
52 subs.push({ at: out.length, body: command.slice(ch === '`' ? i + 1 : i + 2, end) })
53 cur += command.slice(i, end + 1)
54 i = end
55 }
56 } else cur += ch
57 continue
58 }
59 if (ch === '"' || ch === "'") {
60 quote = ch
61 has = true
62 } else if (ch === '\\' && i + 1 < command.length) {
63 cur += command[++i] ?? ''
64 has = true
65 } else if (ch === '\n') {
66 if (has || cur) out.push(cur)
67 cur = ''
68 has = false
69 out.push('\n')
70 } else if (/\s/.test(ch)) {
71 if (has || cur) out.push(cur)
72 cur = ''
73 has = false
74 } else if (ch === '>' || ch === '<') {
75 let op = /^\d+$/.test(cur) || (cur === '&' && !has) ? cur : ''
76 if (!op && (has || cur)) out.push(cur)
77 op += ch
78 while (command[i + 1] === '>' || command[i + 1] === '&' || /\d/.test(command[i + 1] ?? '')) {
79 if (command[i + 1] === '&' && op.endsWith('&')) break
80 op += command[++i]
81 }
82 out.push(op)
83 cur = ''
84 has = false
85 } else if (ch === '(' || ch === ')' || ch === '`') {
86 if (has || cur) out.push(cur)
87 cur = ''
88 has = false
89 out.push(ch)
90 } else if (ch === ';' || ch === '|' || ch === '&') {
91 if (ch === '&' && command[i + 1] === '>') {
92 if (has || cur) out.push(cur)
93 cur = '&'
94 has = false
95 continue
96 }
97 if (has || cur) out.push(cur)
98 cur = ''
99 has = false
100 const two = command.slice(i, i + 2)
101 if (two === '&&' || two === '||') {
102 out.push(two)
103 i++
104 } else out.push(ch)
105 } else {
106 cur += ch
107 has = true
108 }
109 }
110 if (has || cur) out.push(cur)
111 if (!quote) return out
112 return command
113 .split(/(&&|\|\||[;|\n])/)
114 .flatMap(part => (/^(&&|\|\||[;|\n])$/.test(part) ? [part] : part.trim().split(/\s+/).filter(Boolean)))
115}
116
117export function join(base: string, raw: string): string {
118 const path = posix(raw)
119 if (isAbsolute(path)) return path
120 if (path.startsWith('~/')) return path
121 const parts = base.split('/')
122 for (const seg of path.split('/')) {
123 if (seg === '' || seg === '.') continue
124 if (seg === '..') parts.pop()
125 else parts.push(seg)
126 }
127 return parts.join('/') || '/'
128}
129
130function operators(line: string): { word: string; tabs: boolean; expand: boolean }[] {
131 const found: { word: string; tabs: boolean; expand: boolean }[] = []
132 const outer: boolean[] = []
133 let single = false
134 let double = false
135 for (let i = 0; i < line.length; i++) {
136 const ch = line[i]
137 if (single) {
138 if (ch === "'") single = false
139 continue
140 }
141 if (ch === '\\') {
142 i++
143 continue
144 }
145 if (ch === '$' && line[i + 1] === '(') {
146 outer.push(double)
147 double = false
148 i++
149 continue
150 }
151 if (ch === ')' && outer.length && !double) {
152 double = outer.pop() ?? false
153 continue
154 }
155 if (ch === '"') {
156 double = !double
157 continue
158 }
159 if (double) continue
160 if (ch === "'") {
161 single = true
162 continue
163 }
164 if (ch === '#' && (i === 0 || /\s/.test(line[i - 1] ?? ''))) break
165 if (ch === '<' && line[i + 1] === '<' && line[i + 2] !== '<') {
166 const m = line.slice(i).match(/^<<(-?)\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\2/)
167 if (m) {
168 found.push({ word: m[3] ?? '', tabs: m[1] === '-', expand: !m[2] })
169 i += m[0].length - 1
170 }
171 }
172 }
173 return found
174}
175
176function heredocless(command: string): string {
177 const out: string[] = []
178 const pending: { word: string; tabs: boolean; expand: boolean }[] = []
179 for (const line of command.split('\n')) {
180 const head = pending[0]
181 if (head) {
182 if ((head.tabs ? line.replace(/^\t+/, '') : line) === head.word) pending.shift()
183 else if (head.expand) out.push(...substitutions(line))
184 continue
185 }
186 out.push(line)
187 pending.push(...operators(line))
188 }
189 return out.join('\n')
190}
191
192function closing(command: string, i: number): number {
193 if (command[i] === '`') {
194 let j = i + 1
195 while (j < command.length && command[j] !== '`') j += command[j] === '\\' ? 2 : 1
196 return j < command.length ? j : -1
197 }
198 let depth = 0
199 for (let j = i + 1; j < command.length; j++) {
200 if (command[j] === '(') depth++
201 else if (command[j] === ')' && --depth === 0) return j
202 }
203 return -1
204}
205
206function substitutions(command: string): string[] {
207 const out: string[] = []
208 let single = false
209 let double = false
210 for (let i = 0; i < command.length; i++) {
211 const ch = command[i]
212 if (single) {
213 if (ch === "'") single = false
214 continue
215 }
216 if (ch === '\\') {
217 i++
218 continue
219 }
220 if (ch === "'" && !double) {
221 single = true
222 continue
223 }
224 if (ch === '"') {
225 double = !double
226 continue
227 }
228 if (ch === '#' && !double && (i === 0 || /\s/.test(command[i - 1] ?? ''))) {
229 while (i + 1 < command.length && command[i + 1] !== '\n') i++
230 continue
231 }
232 if ((ch === '$' && command[i + 1] === '(') || ch === '`') {
233 const end = closing(command, i)
234 if (end < 0) continue
235 out.push(command.slice(ch === '`' ? i + 1 : i + 2, end))
236 i = end
237 }
238 }
239 return out
240}
241
242function expand(args: string[], loops: { name: string; words: string[] }[]): string[][] {
243 let out = [args]
244 for (const { name, words } of loops) {
245 if (!name) continue
246 const source = `\\$\\{${name}\\}|\\$${name}(?![A-Za-z0-9_])`
247 const used = new RegExp(source)
248 const ref = new RegExp(source, 'g')
249 if (!out.some(a => a.some(x => used.test(x)))) continue
250 out = out.flatMap(a => words.map(w => a.map(x => x.replace(ref, w)))).slice(0, MAX_CALLS)
251 }
252 return out
253}
254
255function skipFlags(toks: string[], j: number, word: string): number {
256 const valued = PREFIX_VALUED[word]
257 while (j < toks.length && (toks[j] ?? '').startsWith('-') && !SEPARATORS.has(toks[j] ?? '')) j += valued?.has(toks[j] ?? '') ? 2 : 1
258 return j
259}
260
261export function invocations(command: string, sessionCwd: string, base: Record<string, string> = {}, tools: readonly string[] = ['databricks']): Invocation[] {
262 const subs: { at: number; body: string }[] = []
263 const toks = tokenize(heredocless(command), subs)
264 const found: Invocation[] = []
265 const loops: { name: string; words: string[] }[] = []
266 const exported: Record<string, string> = { ...base }
267 let cwd = sessionCwd
268 let start = true
269 for (let i = 0; i < toks.length && found.length < MAX_CALLS; i++) {
270 const t = toks[i] ?? ''
271 if (SEPARATORS.has(t)) {
272 start = true
273 continue
274 }
275 if (!start) continue
276 start = false
277 let end = i
278 while (end < toks.length && !SEPARATORS.has(toks[end] ?? '')) end++
279 for (let sub = subs[0]; sub && sub.at < end; sub = subs[0]) {
280 subs.shift()
281 found.push(...invocations(sub.body, cwd, exported, tools).slice(0, MAX_CALLS - found.length))
282 }
283 const env: Record<string, string> = {}
284 let j = i
285 for (;;) {
286 const tok = toks[j] ?? ''
287 const assign = tok.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s)
288 const word = tok.split('/').pop() ?? ''
289 if (assign) {
290 env[assign[1] ?? ''] = assign[2] ?? ''
291 j++
292 } else if (word === 'uv' && toks[j + 1] === 'run') j = skipFlags(toks, j + 2, 'uv')
293 else if (word === 'timeout') {
294 j = skipFlags(toks, j + 1, word)
295 if (/^\d/.test(toks[j] ?? '')) j++
296 } else if (word === 'while' || word === 'until') {
297 loops.push({ name: '', words: [] })
298 j++
299 } else if (word === 'command' && /^-[A-Za-z]*[vV]/.test(toks[j + 1] ?? '')) break
300 else if (PREFIXES.has(word)) j = skipFlags(toks, j + 1, word)
301 else break
302 }
303 const head = toks[j]?.split('/').pop()
304 const dir = toks[j + 1]
305 if (head === 'export') {
306 for (let k = j + 1; k < toks.length && !SEPARATORS.has(toks[k] ?? ''); k++) {
307 const m = (toks[k] ?? '').match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s)
308 if (m) exported[m[1] ?? ''] = m[2] ?? ''
309 }
310 continue
311 }
312 if (head === 'for' && toks[j + 2] === 'in' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(dir ?? '')) {
313 const words: string[] = []
314 for (let k = j + 3; k < toks.length && !SEPARATORS.has(toks[k] ?? '') && toks[k] !== 'do'; k++) words.push(toks[k] ?? '')
315 loops.push({ name: dir ?? '', words: words.slice(0, 20) })
316 continue
317 }
318 if (head === 'for' || head === 'select') {
319 loops.push({ name: '', words: [] })
320 continue
321 }
322 if (head === 'done') {
323 loops.pop()
324 continue
325 }
326 if (head === 'cd' && dir && !SEPARATORS.has(dir)) {
327 cwd = join(cwd, dir)
328 continue
329 }
330 if (!head || !tools.includes(head)) continue
331 const args: string[] = []
332 let k = j + 1
333 while (k < toks.length && !SEPARATORS.has(toks[k] ?? '')) {
334 const tok = toks[k++] ?? ''
335 if (REDIRECT.test(tok)) {
336 if (!/&\d*$/.test(tok) || tok.startsWith('&')) k++
337 continue
338 }
339 args.push(tok)
340 }
341 for (const each of expand(args, loops)) if (found.length < MAX_CALLS) found.push({ tool: head, bin: toks[j] ?? head, args: each, cwd, env: { ...exported, ...env } })
342 i = k - 1
343 }
344 for (const sub of subs) found.push(...invocations(sub.body, cwd, exported, tools).slice(0, MAX_CALLS - found.length))
345 return found
346}
347
348export type DbKind = 'read' | 'download' | 'upload' | 'modify'
349
350const IGNORED = new Set(['auth', 'configure', 'completion', 'help', 'version', 'cache', 'labs', 'quickstart', 'psql', 'ssh', 'aitools'])
351const VALUE_FLAGS = new Set(['--limit', '--path', '--page-size', '--max-num-clusters', '--min-num-clusters', '--cluster-size', '--warehouse-type', '--spark-version', '--node-type-id', '--num-workers', '--description', '--owner', '--filter', '--source-dir', '--target-dir', '--key', '--scope', '--string-value', '-p', '--profile', '-o', '--output', '--file', '--format', '--language', '--json', '-t', '--target', '--var', '--cluster-id', '--job-id', '--run-id', '--warehouse-id', '--pipeline-id', '--catalog-name', '--schema-name', '--max-results', '--page-token', '--timeout', '--log-level', '--log-file', '--log-format', '--name', '--comment', '--storage-root', '--source-code-path'])
352const READ_VERBS = new Set(['get', 'list', 'describe', 'summary', 'status', 'exists', 'read', 'search', 'ls', 'cat', 'me', 'validate', 'show'])
353const REMOTE = /^(dbfs:|\/Volumes\/)/i
354const UC_NAME = /^[^\s./:]+\.[^\s./:]+\.[^\s./:]+$/
355const UC_GROUPS = new Set(['tables', 'functions', 'registered-models', 'model-versions', 'volumes', 'grants', 'online-tables', 'quality-monitors', 'lakehouse-monitors', 'table-constraints', 'artifact-allowlists', 'temporary-table-credentials', 'vector-search-indexes'])
356
357export function positionals(args: string[]): string[] {
358 const out: string[] = []
359 for (let i = 0; i < args.length; i++) {
360 const a = args[i] ?? ''
361 if (a.startsWith('-')) {
362 if (VALUE_FLAGS.has(a)) i++
363 continue
364 }
365 out.push(a)
366 }
367 return out
368}
369
370function flag(args: string[], ...names: string[]): string {
371 for (let i = 0; i < args.length; i++) {
372 const a = args[i] ?? ''
373 for (const n of names) {
374 if (a === n) return args[i + 1] ?? ''
375 if (a.startsWith(`${n}=`)) return a.slice(n.length + 1)
376 }
377 }
378 return ''
379}
380
381export function dbProfile(inv: Invocation): string {
382 return flag(inv.args, '-p', '--profile')
383}
384
385export function dbKind(inv: Invocation): DbKind | null {
386 const pos = positionals(inv.args)
387 const [group = '', verb = ''] = pos
388 if (!group || IGNORED.has(group)) return null
389 if (group === 'fs') {
390 if (verb === 'ls' || verb === 'cat') return 'read'
391 if (verb === 'cp') {
392 const rest = pos.slice(2)
393 const src = rest[0] ?? ''
394 const dst = rest[rest.length - 1] ?? ''
395 if (REMOTE.test(src) && !REMOTE.test(dst)) return 'download'
396 if (!REMOTE.test(src) && REMOTE.test(dst)) return 'upload'
397 }
398 return 'modify'
399 }
400 if (group === 'workspace') {
401 if (verb === 'export' || verb === 'export-dir') return 'download'
402 if (verb === 'import' || verb === 'import-dir') return 'upload'
403 }
404 if (group === 'bundle') return verb === 'deploy' ? 'upload' : READ_VERBS.has(verb) || verb === 'generate' ? 'read' : 'modify'
405 if (group === 'sync') return 'upload'
406 if (group === 'api') return verb.toLowerCase() === 'get' || /\/sql\/statements/.test(pos[2] ?? '') ? 'read' : 'modify'
407 if (group === 'current-user') return 'read'
408 if (verb === 'export' || verb === 'export-run') return 'download'
409 if (READ_VERBS.has(verb) || verb.startsWith('list-') || verb.startsWith('get-')) return 'read'
410 return 'modify'
411}
412
413function workspacePath(p: string): string {
414 return p.replace(/^\/Workspace(?=\/)/, '').replace(/\/+$/, '') || '/'
415}
416
417function volumeOf(p: string): string {
418 const m = p.replace(/^dbfs:/i, '').match(/^\/Volumes\/([^/]+)\/([^/]+)\/([^/]+)/)
419 return m ? `UV:${m[1]}.${m[2]}.${m[3]}` : ''
420}
421
422export function dbTargets(inv: Invocation): string[] {
423 const pos = positionals(inv.args)
424 const [group = '', verb = '', ...rest] = pos
425 const a0 = rest[0] ?? ''
426 const a1 = rest[1] ?? ''
427 const out: string[] = []
428 const id = (prefix: string, value: string) => value && out.push(`${prefix}:${value}`)
429 switch (group) {
430 case 'workspace':
431 if (verb === 'import-dir') id('WS', a1 && workspacePath(a1))
432 else if (a0.startsWith('/')) id('WS', workspacePath(a0))
433 else if (verb === 'list') out.push('S:workspace')
434 break
435 case 'fs':
436 for (const p of rest) if (volumeOf(p)) out.push(volumeOf(p))
437 break
438 case 'catalogs':
439 if (verb === 'list') out.push('S:catalog')
440 else id('UC', a0)
441 break
442 case 'schemas':
443 id('UC', verb === 'create' && a1 ? `${a1}.${a0}` : a0)
444 break
445 case 'tables':
446 case 'functions':
447 case 'registered-models':
448 if (verb === 'list' || verb === 'list-summaries') id('UC', a0 && a1 ? `${a0}.${a1}` : flag(inv.args, '--catalog-name') && flag(inv.args, '--schema-name') ? `${flag(inv.args, '--catalog-name')}.${flag(inv.args, '--schema-name')}` : '')
449 else if (group === 'tables' && verb === 'create' && a1 && rest[2]) id('UC', `${a1}.${rest[2]}.${a0}`)
450 else id('UC', a0)
451 break
452 case 'volumes':
453 if (verb === 'list') id('UC', a0 && a1 ? `${a0}.${a1}` : '')
454 else if (verb === 'create') id('UV', a0 && a1 && rest[2] ? `${a0}.${a1}.${rest[2]}` : '')
455 else id('UV', a0)
456 break
457 case 'clusters':
458 if (verb === 'list') out.push('S:compute')
459 else id('CL', flag(inv.args, '--cluster-id') || a0)
460 break
461 case 'warehouses':
462 if (verb === 'list') out.push('S:compute')
463 else id('SW', flag(inv.args, '--warehouse-id') || a0)
464 break
465 case 'jobs':
466 if (verb === 'list') out.push('S:jobs')
467 else id('J', flag(inv.args, '--job-id') || (/run/.test(verb) && verb !== 'run-now' ? '' : /^\d+$/.test(a0) ? a0 : ''))
468 break
469 case 'api': {
470 if (!/\/sql\/statements/.test(a0)) break
471 const body = flag(inv.args, '--json')
472 const wh = body.match(/"warehouse_id"\s*:\s*"([^"]+)"/)?.[1]
473 if (wh) out.push(`SW:${wh}`)
474 break
475 }
476 case 'bundle':
477 if (verb === 'deploy' || verb === 'destroy') out.push('S:jobs', 'S:pipelines', 'S:dashboards', 'S:apps', 'S:workspace')
478 break
479 case 'sync':
480 out.push('S:workspace')
481 break
482 case 'pipelines':
483 if (verb === 'list-pipelines') out.push('S:pipelines')
484 else id('P', flag(inv.args, '--pipeline-id') || a0)
485 break
486 case 'apps':
487 if (verb === 'list') out.push('S:apps')
488 else id('A', a0)
489 break
490 case 'lakeview':
491 if (verb === 'list') out.push('S:dashboards')
492 else id('D', a0)
493 break
494 }
495 const SECTION: Record<string, string> = { jobs: 'S:jobs', pipelines: 'S:pipelines', apps: 'S:apps', lakeview: 'S:dashboards', clusters: 'S:compute', warehouses: 'S:compute', catalogs: 'S:catalog' }
496 if (out.length === 0 && (verb === 'create' || verb.startsWith('create-') || verb === 'import') && SECTION[group]) out.push(SECTION[group] ?? '')
497 if (UC_GROUPS.has(group)) for (const p of rest) if (UC_NAME.test(p) && !out.includes(`UC:${p}`) && !out.includes(`UV:${p}`)) out.push(`UC:${p}`)
498 return out
499}
500
501export const DB_TONE: Record<DbKind, string> = { read: 'purple', download: 'teal', upload: 'pink', modify: 'orange' }
502hooks/icon-data.ts 90 lines1export const DB_CODEPOINTS: Record<string, number> = {
2 "workspace": 0xf3000,
3 "folder": 0xf3001,
4 "folder_open": 0xf3002,
5 "folder_home": 0xf3003,
6 "notebook": 0xf3004,
7 "file": 0xf3005,
8 "file_code": 0xf3006,
9 "repo": 0xf3007,
10 "repo_open": 0xf3008,
11 "branch": 0xf3009,
12 "catalog": 0xf300a,
13 "catalog_shared": 0xf300b,
14 "schema": 0xf300c,
15 "database": 0xf300d,
16 "table": 0xf300e,
17 "view": 0xf300f,
18 "materialized_view": 0xf3010,
19 "streaming_table": 0xf3011,
20 "volume": 0xf3012,
21 "volume_open": 0xf3013,
22 "function": 0xf3014,
23 "model": 0xf3015,
24 "serving_endpoint": 0xf3016,
25 "cluster": 0xf3017,
26 "warehouse": 0xf3018,
27 "job": 0xf3019,
28 "pipeline": 0xf301a,
29 "dashboard": 0xf301b,
30 "query": 0xf301c,
31 "sql": 0xf301d,
32 "alert": 0xf301e,
33 "app": 0xf301f,
34 "experiment": 0xf3020,
35 "secret": 0xf3021,
36 "user": 0xf3022,
37 "group": 0xf3023,
38 "dbfs": 0xf3024,
39 "vector_search": 0xf3025,
40 "lakebase": 0xf3026,
41 "genie": 0xf3027,
42 "refresh": 0xf3028,
43 "eye": 0xf3029,
44 "eye_off": 0xf302a,
45 "collapse": 0xf302b,
46 "expand": 0xf302c,
47 "home": 0xf302d,
48 "up": 0xf302e,
49 "search": 0xf302f,
50 "chevron_right": 0xf3030,
51 "chevron_down": 0xf3031,
52 "check": 0xf3032,
53 "warning": 0xf3033,
54 "danger": 0xf3034,
55 "loading": 0xf3035,
56 "play": 0xf3036,
57 "stop": 0xf3037,
58 "trash": 0xf3038,
59 "link": 0xf3039,
60 "lock": 0xf303a,
61 "gear": 0xf303b,
62 "clock": 0xf303c,
63 "sync": 0xf303d,
64 "ui_logo": 0xf3040,
65 "ui_workspace": 0xf3041,
66 "ui_folder": 0xf3042,
67 "ui_folder_users": 0xf3043,
68 "ui_repo": 0xf3044,
69 "ui_folder_shared": 0xf3045,
70 "ui_notebook": 0xf3046,
71 "ui_dashboard": 0xf3047,
72 "ui_catalog_section": 0xf3048,
73 "ui_catalog": 0xf3049,
74 "ui_catalog_workspace": 0xf304a,
75 "ui_catalog_system": 0xf304b,
76 "ui_catalog_shared": 0xf304c,
77 "ui_schema": 0xf304d,
78 "ui_table": 0xf304e,
79 "ui_metric_view": 0xf304f,
80 "ui_jobs": 0xf3050,
81 "ui_compute": 0xf3051,
82 "ui_warehouse": 0xf3052,
83 "ui_apps": 0xf3053,
84 "ui_genie": 0xf3054,
85 "ui_models": 0xf3055,
86 "ui_serving": 0xf3056,
87 "ui_queries": 0xf3057,
88 "ui_alerts": 0xf3058,
89}
90types/index.d.ts 43 lines1export type Target = { kind: 'databricks'; profile: string }
2
3export type TreeNode = {
4 id: string
5 parent: string
6 kind: string
7 name: string
8 path: string
9 hidden: boolean
10 sig: string
11 note: string
12 url?: string
13}
14
15export type Work = { tone: string; lit: string[]; dim: string[]; since: number; until: number | null }
16
17export type Onboard = { kind: 'missing' | 'signedOut' | 'unreachable'; line: string }
18
19export type Explorer = {
20 target: Target | null
21 nodes: TreeNode[]
22 expanded: string[]
23 query: string
24 cursor: string
25 selected: string
26 detail: string[]
27 status: string
28 work: Work | null
29 onboard: Onboard | null
30 busy: Record<string, { tone: string; n: number; at: number }>
31 scroll: number | null
32 root: string
33}
34
35declare module 'claude-code' {
36 interface PluginState {
37 'databricks-cli': {
38 explorer: Explorer
39 nodes: TreeNode[]
40 }
41 }
42}
43