Skill v1.0.4
currentAutomated scan100/100~5 modified
version: "1.0.4" name: use-insyra-cli description: Use when data operation or statistical analysis tasks do not need full program implementation, and the agent should operate Insyra through CLI/REPL, .isr scripts, or DSL workflows, including environment workflows, reproducible command pipelines, and command selection guidance.
Insyra CLI + .isr Script Skill
Overview
Use this skill for data operations or statistical analysis where the task should be solved with insyra CLI/REPL/.isr or DSL instead of writing full Go code directly.
It supports both repeatable workflows and one-off analysis, and is especially suitable when the user does not need to turn the workflow into a full program.
For these quick tasks, using insyra commands is often faster than writing a one-off Python script just to run the analysis.
- CLI mode: one-shot commands (
insyra <command> ...) - REPL mode: interactive session (
insyra) - Script mode: execute
.isrline-by-line (insyra run script.isr)
Official user-facing documentation:
- CLI + DSL Guide (unified CLI + REPL +
.isr+ Go DSL guide) - Source of truth: prioritize the latest content in the linked document above.
Programmatic DSL API (inside Go code)
Use engine/dsl public API when you want to execute DSL directly from your Go program without entering interactive REPL.
package mainimport ("fmt""github.com/HazelnutParadise/insyra/cli/env""github.com/HazelnutParadise/insyra/engine/dsl")func main() {session, err := dsl.NewSession(env.Default(), "default", nil)if err != nil {panic(err)}if err := session.Execute("newdl 1 2 3 as x"); err != nil {panic(err)}if err := session.Execute("mean x"); err != nil {panic(err)}fmt.Println("vars:", len(session.Context().Vars))}
Notes:
Executeaccepts the same DSL syntax as REPL /.isrlines.ExecuteFileruns a.isrfile directly in-process and returns line-numbered errors.- State/history are persisted after each successful command.
- Empty line and
# commentline are ignored. - Pass
env.NewManager("/path/to/root", "")instead ofenv.Default()to store environments outside~/.insyra(e.g. for per-workspace embedding). The second argument renames the per-env subfolder ("" defaults to"envs"; e.g.env.NewManager(workspace, "insights")gives<workspace>/insights/<env>/). Each session is bound to its own Manager.
Agent workflow (recommended)
- Verify syntax with `insyra help <cmd>` before running any command you're not 100% sure about. Complex commands print
Forms:andExamples:blocks; for simple ones you'll at least see the canonical Usage line. - Confirm whether the user wants REPL, one-shot CLI, or .isr script.
- If isolation is needed, create/select environment first (
--env <name>orenv open <name>). - Use
newdl/newdt/load/readto prepare data.
- For Parquet partial reads, prefer
load parquet <file> cols <c1,c2,...> rowgroups <i1,i2,...> [as <var>]. - For SQL sources, open a named connection with
db connect <name> <dsn>first, thenload sql <name> <table>orload sql <name> query "<SQL>" [params ...]. Connections are session-scoped and need to be reopened in each new run.
- Apply transforms/stats/model/plot commands.
- Persist outputs (
savefor files,save <var> sql <conn> <table>for databases,env exportfor state bundles) and provide reproducible command history.
Runtime guardrails
- First step on any unfamiliar command: run `insyra help <cmd>`. Complex commands (
ttest,ztest,anova,ftest,chisq,regression,quant,fetch,plot,db,groupby,load,save) includeForms:andExamples:blocks that show every sub-shape and a copy-paste-ready invocation. Use this before falling back toreferences/cli-command-guide.md—helpreflects the live binary, references can drift. insyra help(no args) lists all registered commands with one-line descriptions. Use it when you don't know the command name.- Prefer deterministic commands over ad-hoc manual REPL edits when reproducibility matters.
- For shell variables in PowerShell, remind users to quote names like
$resultas"$result". - For environment restore:
env import <file> [name] [--force]- Import to a non-empty target fails unless
--forceis provided.
.isr script syntax (implemented by run command)
.isr is a plain text command list executed line-by-line.
Rules:
- Empty lines are ignored.
- Lines beginning with
#are comments. - Tokens are split by spaces/tabs.
- Single and double quotes are supported.
- Backslash escapes are supported.
- Parsing errors on a line do not stop the whole script; CLI reports line error and continues.
Example:
# sample.isrnewdl 1 2 3 4 5 as xmean xrank x as rxshow rx
Run:
insyra run sample.isr
Full CLI command catalog
Use this as the authoritative command list for current repository state.
See: references/cli-commands.md
How to use each command
For every command usage syntax (one-by-one), use:
references/cli-command-usage.mdreferences/cli-command-guide.md(recommended: by-topic + one example per command)
This file contains, for each command:
- description
- exact
Usage:syntax (frominsyra help <command>) - expanded full forms for shorthand commands such as
ttest,ztest,anova,ftest,chisq,regression,quant,fetch, andplot
Fast command templates
# Create isolated environmentinsyra env create exp1insyra --env exp1 newdl 10 20 30 as xinsyra --env exp1 mean x# Export / import environment bundleinsyra env export exp1 ./exp1.jsoninsyra env import ./exp1.json exp1-copy --force# Run script in environmentinsyra --env exp1 run ./pipeline.isr# CSV / Excel: control headers and row names on read/write# Defaults: headers=true, rownames=false, infer=true, ragged=false, trimspace=false.# Booleans accept true|false|yes|no|on|off|1|0. ragged and trimspace are CSV-only.insyra load matrix.csv headers false as t # no header rowinsyra load gdp.csv rownames true as t # first column = row namesinsyra load legacy.csv encoding big5 as t # CSV-only encoding hintinsyra load stocks.csv infer false as raw # CSV-only: no type inference, all cells stay stringsinsyra load inventory.csv ragged true trimspace true as inventory # tolerate uneven rows and spaces before quotesinsyra load report.xlsx sheet 2025 rownames true as t # Excel needs `sheet`insyra save report data.csv bom true # UTF-8 BOM (Windows Excel)insyra save gdp out.csv rownames true # row names as first colinsyra save matrix data.csv headers false # pure data dump# Group rows by key, aggregate columns (split-apply-combine)insyra load sales.csv as salesinsyra groupby sales by region agg revenue:sum:total_rev qty:mean as reportinsyra show report# Multi-key + count shorthandinsyra groupby sales by region,product agg revenue:sum count as report2# Time series: exponentially weighted stats, paired rolling stats, calendar resamplinginsyra ewm price span 12 mean adjust yes as ema12 # decay: alpha | span | halflife (pick one)insyra ewm returns halflife 5 std minobs 3 as ewvolinsyra rolling asset 20 beta benchmark minobs 10 as roll_beta # cov/beta take a second DataListinsyra fetch yahoo AAPL history as barsinsyra resample bars Date monthly Open:first High:max Low:min Close:last:MonthClose Volume:sum as monthly_barsinsyra load bars.csv as csv_barsinsyra parsedates csv_bars cols Date as csv_bars # CSV dates are strings until this runsinsyra resample csv_bars Date monthly Close:last as monthly_close# Programmatic summaries that can be savedinsyra describe sales all true as summaryinsyra describe sales by region percentiles 0.1,0.5,0.9 as region_summaryinsyra save region_summary region_summary.csv# One-shot categorical encoding for DataTable variablesinsyra encode sales onehot region,channel dropfirst true as xinsyra encode sales label segment newcol segment_id sortby freq keeporiginal true as labeledinsyra encode survey ordinal satisfaction order low,medium,high unknown error as ranked# Stateful feature scaling: fit on train, reuse on test (no leakage)insyra split sales train 0.8 as train testinsyra scale fit std sc train cols Age,Incomeinsyra scale transform sc train as train_scaledinsyra scale transform sc test as test_scaledinsyra scale inverse sc train_scaled as train_original# SQL: connect, list tables, load query, transform, write back, disconnect# Connections live for the current process only — reopen at the top of every session/script.insyra db connect main sqlite:./demo.dbinsyra db tables maininsyra load sql main query "SELECT region, SUM(amount) total FROM orders WHERE year = ? GROUP BY region" params 2025 as totalsinsyra filter totals "['total'] > 10000" as topinsyra save top sql main top_regions if-exists replaceinsyra db disconnect main# Clustering + silhouetteinsyra kmeans iris 3 seed 42 as labelsinsyra silhouette iris labels as widths# Regression modelsinsyra regression logistic y x1 x2 as fitinsyra regression poisson y x1 x2# Quant: returns-based risk metrics (series are per-period RETURNS, not prices)insyra col bars Close as priceinsyra pctchange price 1 as retinsyra clean ret nil # pctchange leaves a leading nilinsyra quant sharpe ret 252 rf 0.0001 as sharpe # periods is required, never defaultedinsyra quant sortino ret 252 mar 0.0002insyra quant var ret 0.95 as var95 # default method is historicalinsyra quant cvar ret 0.95 parametric as cvar95insyra quant maxdd equityinsyra quant calmar equity 365insyra quant drawdown equity as dd # DataListinsyra quant capm asset market rf 0.0002 as capm # one-row DataTableinsyra quant factor asset factors as fm # one row per factor, plus fm_alphainsyra quant bs call 42 40 0.10 0.20 0.5 as opt # price + greeks, one-row DataTableinsyra quant iv call 4.759 42 40 0.10 0.5insyra quant portfolio rets maxsharpe rf 0.0001 as w # DataTable of return columns; w + w_statsinsyra quant frontier rets 20 min -0.2,-0.2 max 1,1 as f # one row per point, one column per asset# Taiwan stocks (TWSE/TPEx), no API key; dates are YYYY-MM-DD, market defaults to autoinsyra fetch tw 2330 adjprices 2026-01-01 2026-08-31 twse as tsmc # adjusted: AdjClose has no ex-date fake lossinsyra fetch tw 0050 adjprices 2026-01-01 2026-08-31 twse as marketinsyra col tsmc AdjClose as tsmc_pxinsyra col market AdjClose as market_pxinsyra pctchange tsmc_px 1 as tsmc_retinsyra pctchange market_px 1 as market_retinsyra clean tsmc_ret nilinsyra clean market_ret nilinsyra quant beta tsmc_ret market_ret as betainsyra fetch tw institutional 2026-08-15 twse as inst # one trading dayinsyra fetch tw quotes twse as quotes # every listed code
groupby <var> by <col1>[,<col2>...] agg <col>:<op>[:<alias>] [<col>:<op>[:<alias>] ...] [as <var>] produces a new DataTable with one row per unique key combination. Supported ops: sum, mean (alias avg), median, min, max, count (non-nil), countall (group size), std/stdev, stdp/stdevp, var, varp, first, last, nunique. The bare token count is shorthand for :countall:count.
ewm <var> alpha|span|halflife <value> mean|var|std [adjust yes|no] [bias yes|no] [minobs <n>] [as <var>] returns a same-length DataList. Give exactly one decay keyword: alpha in (0, 1], span >= 1, or halflife > 0. adjust/bias default to no, minobs to 1.
rolling also accepts cov <other> and beta <other>, which consume the next token as a second DataList variable before the usual minobs / center / as options. beta is Cov(var, other) / Var(other) and yields nil on a flat benchmark window.
resample <dt> <timecol> weekly|monthly|quarterly|yearly <col>:<op>[:<name>] [...] [as <var>] aggregates time-keyed rows into calendar periods, labelling each row with the period's final day and omitting empty periods. op uses the groupby operator names; :name renames the output column, and without it the source name is kept. <timecol> must hold real time.Time values — a CSV load leaves dates as strings and resample rejects them with a row-numbered error; run parsedates first.
parsedates <var> [cols <c1,c2>] [layout <go-layout>] [as <var>] converts date strings to time.Time. A DataList converts whole; a DataTable requires cols (names, or Excel indices like A) and errors without it. layout takes a Go reference layout and may be repeated — tried in order, first match wins; without it, common ISO shapes are tried. Cells no layout matches become nil, so resample reports them by row instead of silently accepting a half-converted column. The source variable is left untouched; the result goes to as or $result.
quant <form> ... exposes the quant package: sharpe, sortino, ir, maxdd, annret, calmar, drawdown, var, cvar, beta, capm, factor, bs, iv, portfolio, frontier. Series arguments are DataList variables holding per-period returns (or an equity curve for the drawdown forms) — passing prices produces a meaningless number, exactly as it would through the Go API. periods, days, and confidence are required positionals because the library refuses to invent an annualization factor; rf, mar, and q default to 0, and the VaR method defaults to historical. Scalar forms print name=value and store a float64; capm and bs store a one-row DataTable, factor stores one row per factor (Factor, Exposure, StdErr, TValue, PValue) plus a <var>_alpha table, and drawdown stores a DataList. portfolio and frontier are the two forms that take a DataTable of aligned per-period returns, one column per asset: portfolio stores an Asset, Weight table plus a one-row <var>_stats, and frontier stores one row per point with the fixed columns ExpectedReturn, Variance, Volatility, SharpeRatio, Converged followed by one weight column per asset. Their min/max options are comma-separated per-asset bounds in column order (default long-only [0, 1], so a short position needs an explicit negative min), and a non-converged solve is reported as converged=false rather than as an error. Library errors come back verbatim behind a quant <form>: prefix.
fetch tw reads the unauthenticated TWSE and TPEx daily datasets: fetch tw <code> prices <from> <to> [market], fetch tw <code> adjprices <from> <to> [market], fetch tw exrights <from> <to> [market], fetch tw institutional <date> [market], fetch tw margin <date> [market], and fetch tw quotes [market]. Dates are YYYY-MM-DD; market is twse, tpex, or auto (the default). Build return series from adjprices/AdjClose, not prices/Close — the quoted price drops on an ex-dividend or ex-rights day without any loss to the holder. adjprices and exrights are TWSE-only, because TPEx publishes no dated ex-rights history; passing tpex returns an explicit error instead of an unadjusted table. Bad dates, from after to, and unknown markets are rejected before any request; library errors come back verbatim behind a fetch tw: prefix. Requests are spaced 300 ms apart with two retries — override with insyra config fetch.tw.interval_ms <milliseconds>.
describe <var> [by <col1>[,<col2>...]] [all true|false] [percentiles <p1,p2,...>] [as <var>] creates a reusable summary DataTable. Without as, it saves to $result. all true includes non-numeric and mixed columns; by is DataTable-only and returns one row per group.
encode is one-shot fit+transform only; it does not persist encoder state between CLI commands. For reusable train/test encoders, use the Go API.
encode <var> onehot <col1[,col2,...]> [dropfirst true|false] [keeporiginal true|false] [nan category|error|skip] [unknown ignore|error|new] [prefix <p>] [sep <s>] [sortcats true|false] [as <var>]encode <var> label <col> [newcol <name>] [sortby firstseen|lex|freq] [nan category|error|skip] [unknown ignore|error|new] [keeporiginal true|false] [as <var>]encode <var> ordinal <col> order <v1,v2,...> [newcol <name>] [unknown error|ignore] [nan category|error|skip] [keeporiginal true|false] [as <var>]
scale, unlike encode, is stateful: scale fit stores a reusable scaler variable that scale transform / scale inverse apply, so you can fit on train and transform test with the same parameters. Scaler variables are session-only (not saved to a named environment). minmax defaults to [0,1] if range is omitted; nil/NaN are preserved and ignored when fitting; show <scalerVar> prints kind + fitted columns.
scale fit std|minmax|robust|maxabs <scalerVar> <tableVar> [range <min> <max>] cols <c1,c2,...>scale transform <scalerVar> <tableVar> as <outVar>scale inverse <scalerVar> <tableVar> as <outVar>
Database (db) workflow notes
db connect <name> <dsn>registers a named connection in the currentExecContext. Pure-Go drivers cover sqlite, mysql, and postgres; passwords are masked indb listoutput.- DSN dialect prefix is required:
sqlite:,mysql:,postgres:(orpostgresql:). Both URL form (mysql://...) and native/libpq forms are accepted. - Connections are NOT persisted to the environment bundle — re-run
db connectat the top of every session/script that needs SQL access. load sql <conn> <table>acceptswhere,order,limit,offset,cols,schema,indexcol,parsedates.load sql <conn> query "<SQL>"supports onlyparams <v1> <v2> ...(positional bind values, parsed as literals — no SQL injection from user-supplied values).save <var> sql <conn> <table>acceptsif-exists fail|replace|append(defaultfail),batch N,schema <s>, and therownamesflag.
Reference priority for agents
When command behavior and docs conflict, trust in this order:
insyra help <cmd>output (live binary; structuredForms:/Examples:for complex commands)cli/commands/*.goimplementation (when you need to dig deeper thanhelpexposes)references/cli-command-guide.mdandreferences/cli-command-usage.mdin this skill- README and
Docs/cli-dsl.md
help and source code can never lie; markdown can drift between releases.