-
Notifications
You must be signed in to change notification settings - Fork 377
Add dotnet-fsi-interactive (REPL) skill #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| name: dotnet-fsi-interactive | ||
| description: "Run and test .NET code interactively without creating files. Explore .NET APIs, verify runtime behavior, experiment with code in a persistent REPL (Read-Eval-Print Loop) session via dotnet fsi. Also for data analysis and inspecting stateful objects." | ||
| --- | ||
|
|
||
| # F# Interactive REPL | ||
|
|
||
| `dotnet fsi` — a REPL (Read-Eval-Print Loop) for .NET. **Single persistent process**: start once, send submissions repeatedly, state accumulates. | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Input | Required | Description | | ||
| |-------|----------|-------------| | ||
| | .NET SDK | Yes | Any version with `dotnet fsi` | | ||
|
|
||
| ## Sweet spots | ||
|
|
||
| - **API exploration** — reflect on types, list members, try overloads, `#help` for inline docs | ||
| - **Runtime behavior verification** — test type assignability, generic variance, serialization edge cases | ||
| - **Database inspection** — connect once, query without reconnecting | ||
| - **Iterative analysis of slow-to-retrieve data** — fetch once, slice and explore from different angles | ||
| - **NuGet experimentation** — `#r "nuget: Pkg"` to pull in any package on the fly | ||
|
|
||
| ## When not to use | ||
|
|
||
| - Single script run (`dotnet fsi file.fsx`) suffices | ||
| - Task needs a full project with multiple files | ||
|
|
||
| ## Workflow | ||
|
|
||
| ### Step 1: Start session | ||
|
|
||
| ```bash | ||
| dotnet fsi --nologo | ||
| ``` | ||
|
|
||
| Launch as async/background process, wait for `>`. `--nologo` suppresses banner noise. **Keep this process running for all subsequent steps.** | ||
|
|
||
| ### Step 2: Send submissions, read results | ||
|
|
||
| A submission ends with `;;` and can contain **multiple expressions and let-bindings**. Batch related work into a single submission to minimize round-trips — every read echoes the full session, so fewer submissions = less token overhead. | ||
|
|
||
| ```fsharp | ||
| open System;; | ||
| let minDate = DateTime.MinValue;; | ||
| printfn "MinValue: %A, DayOfWeek: %A" minDate minDate.DayOfWeek;; | ||
| DateTime(2025, 12, 31).DayOfYear;; | ||
| ``` | ||
|
|
||
| All results come back in one read. Send follow-up submissions to the **same session** — previous bindings are still alive. | ||
|
|
||
| ### Step 3: End session | ||
|
|
||
| Terminate the process. | ||
|
|
||
| ## Example: Exploring System.Console API | ||
|
|
||
| Single `dotnet fsi --nologo` session: | ||
|
|
||
| ```fsharp | ||
| open System.Reflection;; | ||
| let methods = typeof<System.Console>.GetMethods(BindingFlags.Public ||| BindingFlags.Static);; | ||
| methods |> Array.map (fun m -> m.Name) |> Array.distinct |> Array.sort;; | ||
| ``` | ||
|
|
||
| Then drill into a specific method in the same session: | ||
|
|
||
| ```fsharp | ||
| methods | ||
| |> Array.filter (fun m -> m.Name = "Beep") | ||
| |> Array.iter (fun m -> | ||
| let ps = m.GetParameters() |> Array.map (fun p -> sprintf "%s: %s" p.Name (p.ParameterType.Name)) | ||
| printfn "%s(%s)" m.Name (String.concat ", " ps));; | ||
| ``` | ||
| Outputs: | ||
| ``` | ||
| Beep() | ||
| Beep(frequency: Int32, duration: Int32) | ||
| ``` | ||
|
|
||
| ## Directives | ||
|
|
||
| | Directive | Purpose | | ||
| |---|---| | ||
| | `#r "nuget: Pkg";;` | Pull in a NuGet package on the fly | | ||
| | `#time "on";;` | Elapsed time, CPU, GC stats per eval | | ||
| | `#help List.map;;` | Inline docs for any function | | ||
| | `#r "path.dll";;` | Reference local assembly | | ||
| | `#load "file.fsx";;` | Load and run script | | ||
| | `#quit;;` | Exit session | | ||
|
|
||
| ## Pitfalls | ||
|
|
||
| | Pitfall | Fix | | ||
| |---------|-----| | ||
| | Forgetting `;;` | FSI shows `-` prompt, waiting. Send `;;` alone to flush. | | ||
| | New process per submission | **Don't.** Reuse same session — state lost on restart. | | ||
| | One expression per submission | A single `;;`-terminated submission can contain multiple `let` bindings, `open` statements, and expressions. Batch them. | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| scenarios: | ||
| - name: "Explore System.IO.Path edge cases at runtime" | ||
| prompt: > | ||
| I need to understand some edge cases in .NET's System.IO.Path API. Can you | ||
| verify these at runtime: | ||
| (1) What does Path.GetExtension return for ".gitignore" — is it empty or ".gitignore"? | ||
| (2) What does Path.Combine("/usr", "/etc/passwd") return — does it concatenate or | ||
| does the second absolute path replace the first? | ||
| (3) How does Path.Join differ from Path.Combine on the same inputs? | ||
| (4) What does Path.GetFileNameWithoutExtension(".gitignore") return? | ||
| Don't guess — these have surprising answers. Run .NET code to check. | ||
| assertions: | ||
| - type: "exit_success" | ||
| - type: "output_contains" | ||
| value: ".gitignore" | ||
| - type: "output_matches" | ||
| pattern: "(Combine|Join)" | ||
| - type: "output_matches" | ||
| pattern: "(/etc/passwd|replace)" | ||
|
T-Gro marked this conversation as resolved.
|
||
| expect_tools: ["bash"] | ||
| max_turns: 10 | ||
| rubric: | ||
| - "The agent correctly reports that Path.GetExtension('.gitignore') returns '.gitignore' (the whole filename is treated as extension)" | ||
| - "The agent correctly reports that Path.Combine('/usr', '/etc/passwd') returns '/etc/passwd' — the second absolute path replaces the first" | ||
| - "The agent correctly reports that Path.Join('/usr', '/etc/passwd') returns '/usr/etc/passwd' — it concatenates without replacing" | ||
| - "The agent verifies the answers by executing .NET code at runtime" | ||
|
T-Gro marked this conversation as resolved.
|
||
| timeout: 120 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F# code specifically, right? it should say that to avoid loading in C# context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any .NET code - it is ephemeral from users perspective ("without file"), for verification and analysis that benefits from keeping state around (like having to load a lot of DB or web API data to do an iterative analysis)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I meant -- someone could have installed this plugin -- want to write some temporary code, but prefer it being in C# because they aren't familar with F#. I have nothign against F#. If I misunderstood, disregard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not creating a file users will see in their diff, it's similar to how agents generate and execute powershell or python for temporal tasks all the time, and this is transparent to the user (because no file is ever created, its just for analysis/research/finding stuff out).
dotnet fsi is that, but for .NET apis and stateful exploration.