Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
15c3392
feat: foundation for the dbt Power User features
hkaltai Nov 13, 2026
4328fc3
fix: harden the dbt Power User feature wiring
hkaltai Nov 13, 2026
6f6c89e
fix: read valid shell lines the dbt command parser refused
hkaltai Nov 13, 2026
2b31340
fix: read a here-string inside a substitution as text, not a heredoc
hkaltai Nov 14, 2026
b36cbe6
fix: read a heredoc that follows an escaped < inside a substitution
hkaltai Nov 14, 2026
f681699
fix: invocation offsets skip prefix words, status parts clear per ses…
hkaltai Nov 15, 2026
c3ffdd8
Merge origin/main into feat/pu-mods-foundation
hkaltai Nov 17, 2026
3fa4834
Harden the dbt command parser, feature phases and tool chain
hkaltai Nov 17, 2026
7f472f5
Test that a status line that cannot be drawn does not stop session start
hkaltai Nov 17, 2026
9409397
Describe the settings by what they control
hkaltai Nov 17, 2026
e243a67
Keep backslashes the shell keeps in quoted values; test the write rou…
hkaltai Nov 17, 2026
830e784
Report no literal for a word the shell expands; launcher help runs no…
hkaltai Nov 17, 2026
176e8b5
Say once, beside the phase deadline, what it means for a gate
hkaltai Nov 17, 2026
4c8add5
Merge main and preserve integration regression coverage
hkaltai Nov 17, 2026
2c494ec
fix: an expanded assignment ahead of a prefix word marks the call dyn…
hkaltai Nov 17, 2026
ac0d379
fix: read only each prefix's and launcher's own options; reword unuse…
hkaltai Nov 17, 2026
2c98769
fix: exec -c clears dbt's environment, so it is not read; per-launche…
hkaltai Nov 17, 2026
d563dce
Merge remote-tracking branch 'origin/main' into feat/pu-mods-foundation
hkaltai Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion plugins/altimate-code/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,39 @@
"databricks",
"column-lineage"
],
"types": "./types/index.d.ts"
"types": "./types/index.d.ts",
"userConfig": {
"maxScanBytes": {
"type": "number",
"title": "Largest BigQuery scan without asking (not used yet)",
"description": "Not used yet: the BigQuery scan check isn't in this version, so no run is held. When it ships, a dbt run, build or show that BigQuery estimates would scan more bytes than this waits for your approval (0 never waits; other warehouses are never held).",
"default": 10737418240,
"min": 0
},
"healthBlocksPush": {
"type": "boolean",
"title": "Project health blocks git push (not used yet)",
"description": "Not used yet: the project health check isn't in this version, so git push is never refused. When it ships, on refuses a push while the check finds new issues in the models you changed; off only shows them.",
"default": false
},
"healthConfigPath": {
"type": "string",
"title": "Project health check config",
"description": "Not used yet: the project health check isn't in this version. Path to a DataPilot health check config file, relative to the dbt project. Empty uses the default checks.",
"default": ""
},
"commentsPollSeconds": {
"type": "number",
"title": "Team comments refresh (seconds)",
"description": "Not used yet: team comments aren't in this version. How often the team's comments on shared docs are fetched again.",
"default": 900,
"min": 30
},
"commentsInContext": {
"type": "boolean",
"title": "Team comments in Claude's context",
"description": "Not used yet: team comments aren't in this version. When on, the open comments on a model Claude reads or edits are added to its context. Off keeps them out of Claude's context.",
"default": true
}
}
}
12 changes: 12 additions & 0 deletions plugins/altimate-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ Rule drafting uses altimate-code's own model (sign in to the Altimate LLM Gatewa
- **The per-turn hooks never block**: they hand off to altimate-code in the background. Session start makes one bounded synchronous call (at most 15 seconds). All of them run only in a linked folder (or below it), as recorded in altimate-code's link cache in your own state directory: nothing in the repository turns them on.
- **`ALTIMATE_LEARN=0`** turns all of it off: the hooks start nothing.

## Settings

The plugin has five settings, shown when you enable it (`userConfig` in `.claude-plugin/plugin.json`). None is used yet: the features that read them are not in this version, so changing one changes nothing. The table says what each will control.

| Setting | Default | What it controls |
| --- | --- | --- |
| `maxScanBytes` | 10 GiB | The largest BigQuery scan a dbt run, build or show may make before it waits for your approval (0 never waits; at least 0). Other warehouses are never held. |
| `healthBlocksPush` | off | When on, `git push` is refused while the project health check finds new issues in the models you changed. Off, the issues are only shown. |
| `healthConfigPath` | empty | The DataPilot health check config file, relative to the dbt project. Empty uses the default checks. |
| `commentsPollSeconds` | 900 | How often the team's comments on shared docs are fetched again (at least 30). |
| `commentsInContext` | on | Whether the open comments on a model Claude reads or edits are added to its context. |

## Example prompts

Once installed, try these in Claude Code (or prefix any of them with `/altimate-code:altimate`):
Expand Down
74 changes: 74 additions & 0 deletions plugins/altimate-code/hooks/altimate-cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { expect, test } from 'claude-code/testing'

import { runTool, within } from './altimate-cli'

/** A stand-in for `$` whose CLI answers every call and whose MCP connection attempts go through `connect`. */
function standIn(connect: () => unknown, now = 0) {
const argvs: string[][] = []
let mcpCalls = 0
const $: any = {
process: {
run: async (argv: string[]) => {
argvs.push(argv)
return { exitCode: 0, stdout: JSON.stringify({ status: 'ok', output: 'done', metadata: { n: 1 } }) }
},
},
mcp: {
connect: async () => connect(),
// No answer: a call that does reach the server falls back to the CLI.
call: async () => (mcpCalls++, null),
},
// A deadline that never fires, so the fallback is the no-answer one.
clock: { now: async () => now, after: () => {} },
}
return { $, argvs, mcpCalls: () => mcpCalls }
}

test('a read call goes without --allow-write; a write call goes through the CLI with it', async () => {
const { $, argvs } = standIn(() => null)
expect(await runTool($, 'dbt_manifest', { a: 1 })).toEqual({ metadata: { n: 1 }, text: 'done', ok: true })
expect(await runTool($, 'dbt_manifest', { a: 1 }, { write: true })).toEqual({ metadata: { n: 1 }, text: 'done', ok: true })
expect(argvs.map(argv => argv.slice(1))).toEqual([
['tool', 'run', 'dbt_manifest', '--args', '{"a":1}', '--json'],
['tool', 'run', 'dbt_manifest', '--args', '{"a":1}', '--json', '--allow-write'],
])
})

test('a write call never asks the MCP server, even when one is connected', async () => {
let connects = 0
const { $, argvs, mcpCalls } = standIn(() => {
connects++
return { isConnected: true, server: 'altimate-code' }
}, 10 * 60_000)
await runTool($, 'dbt_manifest', {}, { write: true })
expect(connects).toBe(0)
expect(argvs).toHaveLength(1)
// The same call without `write` does ask the server: the test above can fail. It gets no answer, so
// it goes through the CLI without --allow-write.
await runTool($, 'dbt_manifest', {})
expect(connects).toBe(1)
expect(mcpCalls()).toBe(1)
expect(argvs.map(argv => argv.slice(1))[1]).toEqual(['tool', 'run', 'dbt_manifest', '--args', '{}', '--json'])
})

test('within handles the work\'s rejection before it sets the deadline, so a throwing clock leaves none unhandled', async () => {
let handled = false
// A work that rejects, recording when a rejection handler is attached.
const rejected = Promise.reject(new Error('rewrite failed'))
const work = {
then: (ok: (v: string) => unknown, failed?: (e: unknown) => unknown) => {
handled = typeof failed === 'function'
return rejected.then(ok, failed)
},
} as unknown as Promise<string>
const $: any = {
clock: {
after: () => {
expect(handled).toBe(true)
throw new Error('clock failed')
},
},
}
await expect(within($, 10, work)).rejects.toThrow('clock failed')
expect(handled).toBe(true)
})
133 changes: 133 additions & 0 deletions plugins/altimate-code/hooks/altimate-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,136 @@ export function later($: EngineInterface, work: () => Promise<unknown>) {
})
})
}

// The plugin's own MCP server, by its key in .mcp.json.
const SERVER_KEY = 'altimate-code'
const TOOL_TIMEOUT_MS = 60_000

/** Resolves with the work's value, or null once `ms` pass or it fails. */
export function within<T>($: EngineInterface, ms: number, work: Promise<T>): Promise<T | null> {
return new Promise(resolve => {
let settled = false
const settle = (value: T | null) => {
if (settled) return
settled = true
resolve(value)
}
// The work's rejection is handled first, so a deadline that throws leaves none unhandled.
work.then(settle, () => settle(null))
$.clock.after(ms, () => settle(null))
})
}

let serverName: string | null = null
let connectFailedAt = -Infinity
const CONNECT_RETRY_MS = 60_000

/** The plugin's MCP server as $.mcp.call names it, or null when it is not connected (CLI mode); a failure is retried after a minute. */
async function mcpServer($: EngineInterface): Promise<string | null> {
if (serverName) return serverName
const now = await $.clock.now()
if (now - connectFailedAt < CONNECT_RETRY_MS) return null
const connected = await $.mcp.connect(SERVER_KEY).catch(() => null)
serverName = connected?.isConnected ? connected.server : null
if (!serverName) connectFailedAt = now
return serverName
}

export function textOf(content: unknown): string {
if (typeof content === 'string') return content
const blocks = Array.isArray(content) ? content : Array.isArray((content as any)?.content) ? (content as any).content : []
return blocks
.filter((block: any) => block?.type === 'text' && typeof block.text === 'string')
.map((block: any) => block.text)
.join('\n')
}

/**
* The file a `<persisted-output>` preview says holds the whole answer: null when the text is no such
* preview, undefined when it is one but names no file.
*/
export function persistedPath(text: string): string | null | undefined {
if (!/^\s*(?:<|&lt;)persisted-output(?:>|&gt;)/.test(text)) return null
return /Full output saved to: ([^\n]+?)\s*$/m.exec(text)?.[1]
}

/** A file:// URI as a filesystem path; a Windows drive path keeps no leading slash. */
function fileUriPath(uri: string): string {
const path = decodeURIComponent(new URL(uri).pathname)
return /^\/[A-Za-z]:/.test(path) ? path.slice(1) : path
}

export type RunToolOptions = {
/** Straight to the CLI, whose --json carries the whole metadata. */
cliOnly?: boolean
/** A deadline on the engine's clock: nothing starts once it has passed, and the CLI is stopped at it. */
until?: number
/**
* The tool needs write permission (it starts the dbt adapter, or changes something): the call goes
* through the CLI with `--allow-write`, since the plugin's MCP server runs read-only. runTool asks
* nobody: a caller sets it only once the user has said yes to this write (README, "How it works",
* item 4), as the skill does before it adds `--allow-write`.
*/
write?: boolean
}

/**
* Runs one altimate-code data tool: through the plugin's MCP server when it is connected (no
* permission prompt, structured content when the build sends it), else `altimate tool run --json`.
* `cliOnly` goes straight to the CLI, whose --json carries the whole metadata; a structured result
* the server left out for size is fetched that way too.
*/
export async function runTool($: EngineInterface, name: string, args: Record<string, unknown>, options: RunToolOptions = {}) {
const { until, write = false } = options
const cliOnly = options.cliOnly === true || write
// With a deadline, nothing starts once it has passed, and the CLI is stopped at it.
const left = async () => {
const ms = until === undefined ? TOOL_TIMEOUT_MS : until - (await $.clock.now())
if (ms <= 0) throw new Error('out of time')
return ms
}
const server = cliOnly ? null : await mcpServer($)
if (server) {
const ms = await left()
try {
// The engine's MCP call has no timeout of its own: one that never answers is given up on, so a
// shared trace does not hold every later edit of that column, and the CLI is tried instead.
const result = await within($, ms, $.mcp.call(server, name, args))
if (!result) throw new Error('altimate-code did not answer over MCP')
let text = textOf(result.content)
// A long result comes back as a preview plus a link to the full text.
const link = result.content.find((block: any) => block?.type === 'resource_link' && String(block.uri).startsWith('file://')) as
| { uri: string }
| undefined
// Claude Code (2.1.319) swaps an answer of about 49 KB or more for a preview that names the file it
// saved the whole answer to, with no link block: the answer is that file.
const saved = link ? null : persistedPath(text)
if (!link && saved === undefined) throw new Error('a cut-off preview with no file named')
// An unreadable link or file leaves only the preview: fetch the whole answer through the CLI instead.
const full = link ? await $.fs.read(fileUriPath(link.uri)).catch(() => null) : saved ? await $.fs.read(saved).catch(() => null) : text
if (full === null) throw new Error('the full result could not be read')
text = full
// Claude Code hands a tool's structured content over as one JSON text block in place of the
// text; the structured content carries the text report as `report`.
const structured = (result.structuredContent ?? (text.trim().startsWith('{') ? parseJson(text) : null)) as any
if (structured?.truncated !== true) {
return { metadata: structured, text: typeof structured?.report === 'string' ? structured.report : text, ok: !result.isError }
}
} catch {
// Fall through to the CLI: the server may have gone away mid-session, so the next call reconnects.
serverName = null
}
}
const argv = ['tool', 'run', name, '--args', JSON.stringify(args), '--json', ...(write ? ['--allow-write'] : [])]
Comment thread
hkaltai marked this conversation as resolved.
Resolved
const result = await runAltimate($, argv, await left())
if ((result as { isStdoutTruncated?: boolean }).isStdoutTruncated) {
return { metadata: null as any, text: `${name}'s answer was larger than the 4 MiB a plugin can read`, ok: false }
}
const data = parseJson<{ status?: string; output?: string; metadata?: unknown }>(result.stdout)
// Anything but the CLI's answer object (an altimate-code that exits before a pipe drains cuts it off) is a
// failure to report and ask again, not "no such model".
if (result.exitCode === 0 && (!data || typeof data !== 'object' || typeof data.status !== 'string')) {
return { metadata: null as any, text: 'the answer could not be read', ok: false }
}
return { metadata: (data?.metadata ?? null) as any, text: data?.output ?? '', ok: result.exitCode === 0 && data?.status !== 'error' }
}
Loading
Loading