# Scripts

> Read, author and validate indicator scripts.

Source: https://kcq.nebutra.com/docs/agent/tools/scripts


<Callout>
  Generated from the pinned chart source (

  [`04d191a`](https://github.com/TsekaLuk/KLineChartQuant/blob/04d191a78fa3bb2ab80f408c1995a1816c00645d/packages/core/src/foundation/agent/chartToolRegistry.ts)

  ). Descriptions are the exact text the model receives.
</Callout>

script_reference_query [#script_reference_query]

<ToolMeta label="Query script reference" safety="read-only" safetyLabel="Read-only" origin="Chart core" source="https://github.com/TsekaLuk/KLineChartQuant/blob/04d191a78fa3bb2ab80f408c1995a1816c00645d/packages/core/src/features/agent/tools/impl/scripts.ts#L17" sourceLabel="Source" />

Read the indicator script reference before writing or changing a script. topic="guide" is the authoring guide: skeleton, series semantics, inputs, cross-bar state and common errors. Other topics list signatures, options and enum values.

**Parameters**

| Name               | Type              | Required | Constraints                                                              | Description         |
| ------------------ | ----------------- | -------- | ------------------------------------------------------------------------ | ------------------- |
| <code>topic</code> | <code>enum</code> | Yes      | one of <code>"guide", "runtime", "plot", "drawing", "ta", "enums"</code> | Reference topic id. |

**Minimal input** · Required fields only; placeholders are derived from the schema.

```json
{
  "topic": "guide"
}
```

<ToolSchema name="script_reference_query" label="JSON Schema" />

scripts_read [#scripts_read]

<ToolMeta label="Read user scripts" safety="read-only" safetyLabel="Read-only" origin="Chart core" source="https://github.com/TsekaLuk/KLineChartQuant/blob/04d191a78fa3bb2ab80f408c1995a1816c00645d/packages/core/src/features/agent/tools/impl/scripts.ts#L25" sourceLabel="Source" />

List or read user indicator scripts. Without scriptId it returns \{ scripts: \[\{ id, name }], folders: \[\{ path }] }. With scriptId it returns \{ script: \{ id, name, source } }. Built-in scripts and user libraries are not listed. Read the exact source before scripts\_write update; never reconstruct a script from memory.

**Parameters**

| Name                  | Type                | Required | Constraints               | Description                                                                                      |
| --------------------- | ------------------- | -------- | ------------------------- | ------------------------------------------------------------------------------------------------ |
| <code>scriptId</code> | <code>string</code> | —        | min length <code>1</code> | Script id from scripts\_read. Omit to list every user indicator script and the writable folders. |

**Minimal input** · Required fields only; placeholders are derived from the schema.

```json
{}
```

<ToolSchema name="scripts_read" label="JSON Schema" />

scripts_write [#scripts_write]

<ToolMeta label="Edit user scripts" safety="destructive" safetyLabel="Modifies the chart" origin="Chart core" source="https://github.com/TsekaLuk/KLineChartQuant/blob/04d191a78fa3bb2ab80f408c1995a1816c00645d/packages/core/src/features/agent/tools/impl/scripts.ts#L34" sourceLabel="Source" />

Create, update or delete a user indicator script. create: source plus an optional folder from scripts\_read; the source is compiled and registered immediately, so a compile error is returned verbatim. update: scriptId plus the COMPLETE source; partial patches are not supported, so call scripts\_read first. delete: scriptId; the chart instances of that script are removed with it. The source is the single source of truth: it must declare defineIndicator, the current indicator API version (version: 2), its name and position. Only indicator scripts are accepted; defineLibrary is rejected. A created script is registered but not added to the chart; call indicators\_write add with its name afterwards.

**Parameters**

| Name                  | Type                | Required | Constraints                                      | Description                                                                                             |
| --------------------- | ------------------- | -------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| <code>action</code>   | <code>enum</code>   | Yes      | one of <code>"create", "update", "delete"</code> |                                                                                                         |
| <code>scriptId</code> | <code>string</code> | —        | min length <code>1</code>                        | update and delete: id returned by scripts\_read.                                                        |
| <code>folder</code>   | <code>string</code> | —        | —                                                | create only: folder path from scripts\_read. Omit to place the script at the indicator root.            |
| <code>source</code>   | <code>string</code> | —        | min length <code>1</code>                        | create and update: the COMPLETE script source, including defineIndicator and the indicator API version. |

**Minimal input** · Required fields only; placeholders are derived from the schema.

```json
{
  "action": "create"
}
```

<ToolSchema name="scripts_write" label="JSON Schema" />
