pine_get_source
Read the current Pine Editor source code from TradingView. The Pine Editor must be open to fetch the script content.
Instructions
Read the current Pine Editor source code. Pine Editor must be open.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/pine.ts:25-38 (handler)Handler function for pine_get_source tool. Delegates to page.getPineSource() and wraps errors in ToolExecutionError.
export async function pineGetSource( _input: z.infer<typeof pineGetSourceInput>, page: TradingViewPage, ): Promise<z.infer<typeof pineGetSourceOutput>> { try { return await page.getPineSource(); } catch (cause) { throw new ToolExecutionError( 'pine_get_source', 'Failed to read Pine source. Is the Pine Editor open?', cause, ); } } - src/tools/pine.ts:18-23 (schema)Zod schemas for pine_get_source input (empty) and output (code, scriptName, pineVersion).
export const pineGetSourceInput = z.object({}).strict(); export const pineGetSourceOutput = z.object({ code: z.string(), scriptName: z.string().nullable(), pineVersion: z.string().nullable(), }); - src/tools/index.ts:110-117 (registration)Registration entry for pine_get_source in the TOOLS registry, linking name, description, schemas, and handler.
{ name: 'pine_get_source', description: 'Read the current Pine Editor source code. Pine Editor must be open.', input: pineGetSourceInput, output: pineGetSourceOutput, handler: pineGetSource, }, - src/connection/tradingview.ts:42-48 (helper)Type definition for the PineSource object returned by getPineSource().
export interface PineSource { code: string; /** Script name parsed from `//@title <name>` comment, if present. */ scriptName: string | null; /** Pine version parsed from `//@version=<n>` directive, if present. */ pineVersion: string | null; } - Helper method on TradingViewPage that uses CDP evaluation to read Pine Editor source from the Monaco editor in TradingView.
async getPineSource(): Promise<PineSource> { const expr = ` (() => { const editor = ${TradingViewPage.LOCATE_PINE_EDITOR_JS}; if (!editor) return { error: 'Pine Editor not found — is it open?' }; const code = editor.getValue(); const titleMatch = code.match(/\\/\\/\\s*@title\\s+(.+)/); const versionMatch = code.match(/\\/\\/\\s*@version\\s*=\\s*(\\d+)/); return { code, scriptName: titleMatch ? titleMatch[1].trim() : null, pineVersion: versionMatch ? versionMatch[1] : null, }; })() `; const r = await this.cdp.evaluate<{ error?: string } & PineSource>(expr); if (r.error) throw new ChartStateError(r.error); return { code: r.code, scriptName: r.scriptName, pineVersion: r.pineVersion, }; }