moonscratch 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.agents/skills/moonbit-agent-guide/LICENSE +202 -0
  2. package/.agents/skills/moonbit-agent-guide/SKILL.mbt.md +1126 -0
  3. package/.agents/skills/moonbit-agent-guide/SKILL.md +1126 -0
  4. package/.agents/skills/moonbit-agent-guide/ide.md +116 -0
  5. package/.agents/skills/moonbit-agent-guide/references/advanced-moonbit-build.md +106 -0
  6. package/.agents/skills/moonbit-agent-guide/references/moonbit-language-fundamentals.mbt.md +422 -0
  7. package/.agents/skills/moonbit-agent-guide/references/moonbit-language-fundamentals.md +422 -0
  8. package/.agents/skills/moonbit-practice/SKILL.md +258 -0
  9. package/.agents/skills/moonbit-practice/assets/ci.yaml +25 -0
  10. package/.agents/skills/moonbit-practice/reference/agents.md +1469 -0
  11. package/.agents/skills/moonbit-practice/reference/configuration.md +228 -0
  12. package/.agents/skills/moonbit-practice/reference/ffi.md +229 -0
  13. package/.agents/skills/moonbit-practice/reference/ide.md +189 -0
  14. package/.agents/skills/moonbit-practice/reference/performance.md +217 -0
  15. package/.agents/skills/moonbit-practice/reference/refactor.md +154 -0
  16. package/.agents/skills/moonbit-practice/reference/stdlib.md +351 -0
  17. package/.agents/skills/moonbit-practice/reference/testing.md +228 -0
  18. package/.agents/skills/moonbit-refactoring/LICENSE +21 -0
  19. package/.agents/skills/moonbit-refactoring/SKILL.md +323 -0
  20. package/.githooks/README.md +23 -0
  21. package/.githooks/pre-commit +3 -0
  22. package/.github/workflows/copilot-setup-steps.yml +40 -0
  23. package/.turbo/turbo-typecheck.log +2 -0
  24. package/AGENTS.md +91 -0
  25. package/LICENSE +21 -0
  26. package/PLAN.md +64 -0
  27. package/README.mbt.md +77 -0
  28. package/README.md +84 -0
  29. package/TODO.md +120 -0
  30. package/a.png +0 -0
  31. package/benchmarks/calc.bench.ts +144 -0
  32. package/benchmarks/draw.bench.ts +215 -0
  33. package/benchmarks/load.bench.ts +28 -0
  34. package/benchmarks/render.bench.ts +53 -0
  35. package/benchmarks/run.bench.ts +8 -0
  36. package/benchmarks/types.d.ts +15 -0
  37. package/docs/scratch-vm-specs/eventloop.md +103 -0
  38. package/docs/scratch-vm-specs/moonscratch-time-separation.md +50 -0
  39. package/index.html +91 -0
  40. package/js/AGENTS.md +5 -0
  41. package/js/a.ts +52 -0
  42. package/js/assets/AGENTS.md +5 -0
  43. package/js/assets/base64.test.ts +14 -0
  44. package/js/assets/base64.ts +21 -0
  45. package/js/assets/build-asset.test.ts +26 -0
  46. package/js/assets/build-asset.ts +28 -0
  47. package/js/assets/create.test.ts +142 -0
  48. package/js/assets/create.ts +122 -0
  49. package/js/assets/index.test.ts +15 -0
  50. package/js/assets/index.ts +2 -0
  51. package/js/assets/types.ts +26 -0
  52. package/js/assets/validation.test.ts +34 -0
  53. package/js/assets/validation.ts +25 -0
  54. package/js/assets.test.ts +14 -0
  55. package/js/assets.ts +1 -0
  56. package/js/index.test.ts +26 -0
  57. package/js/index.ts +3 -0
  58. package/js/render/index.test.ts +65 -0
  59. package/js/render/index.ts +13 -0
  60. package/js/render/sharp.ts +87 -0
  61. package/js/render/svg.ts +68 -0
  62. package/js/render/types.ts +35 -0
  63. package/js/render/utils.ts +108 -0
  64. package/js/render/webgl.ts +274 -0
  65. package/js/sharp-optional.d.ts +16 -0
  66. package/js/test/helpers.ts +116 -0
  67. package/js/test/hikkaku-sample.test.ts +37 -0
  68. package/js/test/rubik-components.input-motion.test.ts +60 -0
  69. package/js/test/rubik-components.lists.test.ts +49 -0
  70. package/js/test/rubik-components.operators.test.ts +104 -0
  71. package/js/test/rubik-components.pen.test.ts +112 -0
  72. package/js/test/rubik-components.procedures-loops.test.ts +72 -0
  73. package/js/test/rubik-components.variables-branches.test.ts +57 -0
  74. package/js/test/rubik-components.visibility-entry.test.ts +31 -0
  75. package/js/test/test-projects.ts +598 -0
  76. package/js/test/variable.ts +200 -0
  77. package/js/test/warp.test.ts +59 -0
  78. package/js/vm/AGENTS.md +6 -0
  79. package/js/vm/README.md +183 -0
  80. package/js/vm/bindings.test.ts +13 -0
  81. package/js/vm/bindings.ts +5 -0
  82. package/js/vm/compare-operators.test.ts +145 -0
  83. package/js/vm/constants.test.ts +11 -0
  84. package/js/vm/constants.ts +4 -0
  85. package/js/vm/effect-guards.test.ts +68 -0
  86. package/js/vm/effect-guards.ts +44 -0
  87. package/js/vm/factory.test.ts +486 -0
  88. package/js/vm/factory.ts +615 -0
  89. package/js/vm/headless-vm.test.ts +131 -0
  90. package/js/vm/headless-vm.ts +342 -0
  91. package/js/vm/index.test.ts +28 -0
  92. package/js/vm/index.ts +5 -0
  93. package/js/vm/internal-types.ts +32 -0
  94. package/js/vm/json.test.ts +40 -0
  95. package/js/vm/json.ts +273 -0
  96. package/js/vm/normalize.test.ts +48 -0
  97. package/js/vm/normalize.ts +65 -0
  98. package/js/vm/options.test.ts +30 -0
  99. package/js/vm/options.ts +55 -0
  100. package/js/vm/pen-transparency.test.ts +115 -0
  101. package/js/vm/program-wasm.ts +322 -0
  102. package/js/vm/scheduler-render.test.ts +401 -0
  103. package/js/vm/scratch-assets.test.ts +136 -0
  104. package/js/vm/scratch-assets.ts +202 -0
  105. package/js/vm/types.ts +358 -0
  106. package/js/vm/value-guards.test.ts +25 -0
  107. package/js/vm/value-guards.ts +18 -0
  108. package/moon.mod.json +10 -0
  109. package/package.json +33 -0
  110. package/scripts/preinstall.ts +4 -0
  111. package/src/AGENTS.md +6 -0
  112. package/src/api.mbt +161 -0
  113. package/src/api_aot_commands.mbt +184 -0
  114. package/src/api_effects_json.mbt +72 -0
  115. package/src/api_options.mbt +60 -0
  116. package/src/api_program_wasm.mbt +1647 -0
  117. package/src/api_program_wat.mbt +2206 -0
  118. package/src/api_snapshot_json.mbt +44 -0
  119. package/src/cmd/AGENTS.md +5 -0
  120. package/src/cmd/main/AGENTS.md +5 -0
  121. package/src/cmd/main/main.mbt +29 -0
  122. package/src/cmd/main/moon.pkg +7 -0
  123. package/src/cmd/main/pkg.generated.mbti +13 -0
  124. package/src/json_helpers.mbt +176 -0
  125. package/src/moon.pkg +65 -0
  126. package/src/moonscratch.mbt +3 -0
  127. package/src/moonscratch_wbtest.mbt +40 -0
  128. package/src/parser_sb3.mbt +890 -0
  129. package/src/pkg.generated.mbti +479 -0
  130. package/src/runtime_eval.mbt +2844 -0
  131. package/src/runtime_exec.mbt +3850 -0
  132. package/src/runtime_render.mbt +2550 -0
  133. package/src/runtime_state.mbt +870 -0
  134. package/src/test/AGENTS.md +3 -0
  135. package/src/test/projects/AGENTS.md +6 -0
  136. package/src/test/projects/moon.pkg +4 -0
  137. package/src/test/projects/moonscratch_compat_test.mbt +642 -0
  138. package/src/test/projects/moonscratch_core_test.mbt +1332 -0
  139. package/src/test/projects/moonscratch_runtime_test.mbt +1087 -0
  140. package/src/test/projects/pkg.generated.mbti +13 -0
  141. package/src/test/projects/test_support.mbt +35 -0
  142. package/src/types_effects.mbt +20 -0
  143. package/src/types_error.mbt +4 -0
  144. package/src/types_options.mbt +31 -0
  145. package/src/types_runtime_structs.mbt +254 -0
  146. package/src/types_vm.mbt +109 -0
  147. package/tsconfig.json +29 -0
  148. package/viewer/index.ts +399 -0
  149. package/viewer/vite.d.ts +1 -0
  150. package/viewer/worker.ts +161 -0
  151. package/vite.config.ts +11 -0
@@ -0,0 +1,228 @@
1
+ ---
2
+ title: 'MoonBit Configuration Reference'
3
+ ---
4
+
5
+ # MoonBit Configuration Reference
6
+
7
+ ## File Structure
8
+
9
+ ```
10
+ my-project/
11
+ ├── moon.mod.json # Module configuration (project-wide)
12
+ └── src/
13
+ ├── moon.pkg # Package configuration (new format)
14
+ └── main.mbt
15
+ ```
16
+
17
+ ## Migrating from moon.pkg.json to moon.pkg
18
+
19
+ `moon.pkg.json` is being migrated to the custom syntax `moon.pkg`. Convert with:
20
+
21
+ ```bash
22
+ NEW_MOON_PKG=1 moon fmt
23
+ ```
24
+
25
+ This converts `moon.pkg.json` to `moon.pkg`.
26
+
27
+ ## moon.pkg (New Format)
28
+
29
+ Compared to JSON: supports comments, trailing commas, and more concise syntax.
30
+
31
+ ### Imports
32
+
33
+ ```moonbit
34
+ // Basic import
35
+ import {
36
+ "moonbitlang/async/io",
37
+ "path/to/pkg" as @alias,
38
+ }
39
+
40
+ // Test imports
41
+ import "test" {
42
+ "path/to/pkg5",
43
+ }
44
+
45
+ // White-box test imports
46
+ import "wbtest" {
47
+ "path/to/pkg7",
48
+ }
49
+ ```
50
+
51
+ ### Options
52
+
53
+ ```moonbit
54
+ options(
55
+ "is-main": true,
56
+ "bin-name": "name",
57
+ link: { "native": { "cc": "gcc" } },
58
+ )
59
+ ```
60
+
61
+ ### Comparison with JSON
62
+
63
+ | Feature | JSON Format | moon.pkg Format |
64
+ | -------------- | ---------------- | --------------- |
65
+ | Comments | ❌ Not supported | ✅ Supported |
66
+ | Trailing comma | ❌ Not supported | ✅ Supported |
67
+ | Readability | Low (verbose) | High (concise) |
68
+
69
+ ## moon.mod.json (Module Configuration)
70
+
71
+ ### Required Fields
72
+
73
+ ```json
74
+ {
75
+ "name": "username/project-name",
76
+ "version": "0.1.0"
77
+ }
78
+ ```
79
+
80
+ ### Dependencies
81
+
82
+ ```json
83
+ {
84
+ "deps": {
85
+ "moonbitlang/x": "0.4.6",
86
+ "username/other": { "path": "../other" }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Metadata
92
+
93
+ ```json
94
+ {
95
+ "license": "MIT",
96
+ "repository": "https://github.com/...",
97
+ "description": "...",
98
+ "keywords": ["example", "test"]
99
+ }
100
+ ```
101
+
102
+ ### Source Directory
103
+
104
+ ```json
105
+ {
106
+ "source": "src"
107
+ }
108
+ ```
109
+
110
+ ### Target Specification
111
+
112
+ ```json
113
+ {
114
+ "preferred-target": "js"
115
+ }
116
+ ```
117
+
118
+ ### Warning Configuration
119
+
120
+ ```json
121
+ {
122
+ "warn-list": "-2-4",
123
+ "alert-list": "-alert_1"
124
+ }
125
+ ```
126
+
127
+ ## moon.pkg.json (Package Configuration)
128
+
129
+ ### Main Package
130
+
131
+ ```json
132
+ {
133
+ "is-main": true
134
+ }
135
+ ```
136
+
137
+ ### Dependencies
138
+
139
+ ```json
140
+ {
141
+ "import": [
142
+ "moonbitlang/quickcheck",
143
+ { "path": "moonbitlang/x/encoding", "alias": "lib" }
144
+ ],
145
+ "test-import": [...],
146
+ "wbtest-import": [...]
147
+ }
148
+ ```
149
+
150
+ ### Conditional Compilation
151
+
152
+ ```json
153
+ {
154
+ "targets": {
155
+ "only_js.mbt": ["js"],
156
+ "only_wasm.mbt": ["wasm"],
157
+ "not_js.mbt": ["not", "js"],
158
+ "debug_only.mbt": ["debug"],
159
+ "js_release.mbt": ["and", ["js"], ["release"]]
160
+ }
161
+ }
162
+ ```
163
+
164
+ Conditions: `wasm`, `wasm-gc`, `js`, `debug`, `release`
165
+ Operators: `and`, `or`, `not`
166
+
167
+ ### Link Options
168
+
169
+ #### JS Backend
170
+
171
+ ```json
172
+ {
173
+ "link": {
174
+ "js": {
175
+ "exports": ["hello", "foo:bar"],
176
+ "format": "esm"
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ format: `esm` (default), `cjs`, `iife`
183
+
184
+ #### Wasm Backend
185
+
186
+ ```json
187
+ {
188
+ "link": {
189
+ "wasm-gc": {
190
+ "exports": ["hello"],
191
+ "use-js-builtin-string": true
192
+ }
193
+ }
194
+ }
195
+ ```
196
+
197
+ ### Pre-build
198
+
199
+ ```json
200
+ {
201
+ "pre-build": [
202
+ {
203
+ "input": "a.txt",
204
+ "output": "a.mbt",
205
+ "command": ":embed -i $input -o $output"
206
+ }
207
+ ]
208
+ }
209
+ ```
210
+
211
+ `:embed` converts files to MoonBit source (`--text` or `--binary`)
212
+
213
+ ## Warning Numbers
214
+
215
+ Common ones:
216
+
217
+ - `1` Unused function
218
+ - `2` Unused variable
219
+ - `11` Partial pattern matching
220
+ - `12` Unreachable code
221
+ - `27` Deprecated syntax
222
+
223
+ Check all: `moonc build-package -warn-help`
224
+
225
+ ## References
226
+
227
+ - Module: https://docs.moonbitlang.com/en/stable/toolchain/moon/module
228
+ - Package: https://docs.moonbitlang.com/en/stable/toolchain/moon/package
@@ -0,0 +1,229 @@
1
+ ---
2
+ title: 'MoonBit FFI Reference'
3
+ ---
4
+
5
+ # MoonBit FFI Reference
6
+
7
+ ## External Type Declaration
8
+
9
+ ```moonbit
10
+ #external
11
+ type ExternalRef
12
+ ```
13
+
14
+ - Wasm: `externref`
15
+ - JS: `any`
16
+ - C: `void*`
17
+
18
+ ## External Function Declaration
19
+
20
+ ### JavaScript Backend
21
+
22
+ ```moonbit
23
+ ///| Module.function format
24
+ fn cos(d : Double) -> Double = "Math" "cos"
25
+
26
+ ///| Inline JavaScript
27
+ extern "js" fn cos(d : Double) -> Double =
28
+ #|(d) => Math.cos(d)
29
+
30
+ ///| Multi-line
31
+ extern "js" fn fetch_json(url : String) -> Value =
32
+ #|(url) => fetch(url).then(r => r.json())
33
+ ```
34
+
35
+ ### Wasm Backend
36
+
37
+ ```moonbit
38
+ ///| Import from host
39
+ fn cos(d : Double) -> Double = "math" "cos"
40
+
41
+ ///| Inline Wasm
42
+ extern "wasm" fn identity(d : Double) -> Double =
43
+ #|(func (param f64) (result f64))
44
+ ```
45
+
46
+ ### C Backend
47
+
48
+ ```moonbit
49
+ extern "C" fn put_char(ch : UInt) = "putchar"
50
+ ```
51
+
52
+ ## Type Mapping
53
+
54
+ ### JavaScript
55
+
56
+ | MoonBit | JavaScript |
57
+ | ---------------- | ------------ |
58
+ | `String` | `string` |
59
+ | `Bool` | `boolean` |
60
+ | `Int`, `Double` | `number` |
61
+ | `BigInt` | `bigint` |
62
+ | `Bytes` | `Uint8Array` |
63
+ | `Array[T]` | `T[]` |
64
+ | `#external type` | `any` |
65
+
66
+ ### Wasm
67
+
68
+ | MoonBit | Wasm |
69
+ | ---------------- | ----------- |
70
+ | `Bool`, `Int` | `i32` |
71
+ | `Int64` | `i64` |
72
+ | `Float` | `f32` |
73
+ | `Double` | `f64` |
74
+ | `#external type` | `externref` |
75
+
76
+ ## JavaScript FFI Patterns
77
+
78
+ ### Handling undefined/null
79
+
80
+ ```moonbit
81
+ #external
82
+ pub type Value
83
+
84
+ extern "js" fn Value::undefined() -> Value = "() => undefined"
85
+ extern "js" fn Value::null() -> Value = "() => null"
86
+ extern "js" fn Value::is_undefined(self : Value) -> Bool =
87
+ #|(n) => Object.is(n, undefined)
88
+ ```
89
+
90
+ ### Type Cast (%identity)
91
+
92
+ ```moonbit
93
+ fn[T] Value::cast_from(value : T) -> Value = "%identity"
94
+ fn[T] Value::cast(self : Value) -> T = "%identity"
95
+ ```
96
+
97
+ ### Error Handling
98
+
99
+ ```moonbit
100
+ extern "js" fn wrap_ffi(
101
+ op : () -> Value,
102
+ on_ok : (Value) -> Unit,
103
+ on_error : (Value) -> Unit,
104
+ ) -> Unit =
105
+ #|(op, on_ok, on_error) => {
106
+ #| try { on_ok(op()); }
107
+ #| catch (e) { on_error(e); }
108
+ #|}
109
+ ```
110
+
111
+ ### Loading Node.js Modules
112
+
113
+ ```moonbit
114
+ extern "js" fn require_ffi(path : String) -> Value =
115
+ #|(path) => require(path)
116
+
117
+ // Usage
118
+ let path_module = require_ffi("node:path")
119
+ ```
120
+
121
+ ### ESM Import with #module (Recommended)
122
+
123
+ The `#module` attribute generates ESM `import` statements in the output JavaScript.
124
+
125
+ ```moonbit
126
+ #module("node:fs")
127
+ extern "js" fn readFileSync(path : String, encoding : String) -> String = "readFileSync"
128
+
129
+ #module("node:path")
130
+ extern "js" fn basename(path : String) -> String = "basename"
131
+ extern "js" fn dirname(path : String) -> String = "dirname"
132
+ ```
133
+
134
+ This generates:
135
+
136
+ ```javascript
137
+ import { readFileSync } from 'node:fs'
138
+ import { basename, dirname } from 'node:path'
139
+ ```
140
+
141
+ #### Default Export
142
+
143
+ Use `default` as the function name to import the default export:
144
+
145
+ ```moonbit
146
+ #module("lodash")
147
+ extern "js" fn lodash() -> Value = "default"
148
+ ```
149
+
150
+ Generates:
151
+
152
+ ```javascript
153
+ import lodash from 'lodash'
154
+ ```
155
+
156
+ #### npm Packages
157
+
158
+ Works with any npm package:
159
+
160
+ ```moonbit
161
+ #module("zod")
162
+ extern "js" fn z() -> Value = "z"
163
+
164
+ #module("marked")
165
+ extern "js" fn marked(input : String) -> String = "marked"
166
+ ```
167
+
168
+ #### Requirements
169
+
170
+ - Must use `"format": "esm"` in `moon.pkg.json` link config
171
+ - Target must be JavaScript backend (`--target js`)
172
+
173
+ #### Limitations
174
+
175
+ - **Only functions can be imported** - classes and objects cannot be directly imported via `#module`
176
+ - To use classes or objects, import them through a wrapper function:
177
+
178
+ ```moonbit
179
+ #module("some-lib")
180
+ extern "js" fn get_some_class() -> Value = "SomeClass"
181
+
182
+ // Then use it via Value operations
183
+ let cls = get_some_class()
184
+ ```
185
+
186
+ ## Exporting Functions
187
+
188
+ Configure in `moon.pkg.json`:
189
+
190
+ ```json
191
+ {
192
+ "link": {
193
+ "js": {
194
+ "exports": ["add", "fib:fibonacci"],
195
+ "format": "esm"
196
+ }
197
+ }
198
+ }
199
+ ```
200
+
201
+ ## Callbacks
202
+
203
+ ### FuncRef (No Closures)
204
+
205
+ ```moonbit
206
+ ///| Only functions without free variables
207
+ fn register(callback : FuncRef[() -> Unit]) -> Unit
208
+ ```
209
+
210
+ ### Regular Closures
211
+
212
+ In JavaScript, closures are handled automatically.
213
+
214
+ ## Custom Enum Values
215
+
216
+ ```moonbit
217
+ enum Flags {
218
+ Read = 1
219
+ Write = 2
220
+ ReadWrite = 3
221
+ }
222
+ ```
223
+
224
+ Useful for compatibility with C library flags.
225
+
226
+ ## References
227
+
228
+ - FFI: https://docs.moonbitlang.com/en/stable/language/ffi
229
+ - JS FFI Guide: https://www.moonbitlang.com/pearls/moonbit-jsffi
@@ -0,0 +1,189 @@
1
+ ---
2
+ title: 'moon ide'
3
+ ---
4
+
5
+ ## Code Navigation with `moon ide`
6
+
7
+ **ALWAYS use `moon ide` for code navigation in MoonBit projects instead of manual file searching, grep, or semantic search.**
8
+
9
+ This tool provides two essential commands for precise code exploration:
10
+
11
+ ### Core Commands
12
+
13
+ - `moon ide goto-definition` - Find where a symbol is defined
14
+ - `moon ide find-references` - Find all usages of a symbol
15
+
16
+ ### Query System
17
+
18
+ Symbol lookup uses a two-part query system for precise results:
19
+
20
+ #### 1. Symbol Name Query (`-query`)
21
+
22
+ Fuzzy search for symbol names with package filtering support:
23
+
24
+ ```bash
25
+ # Find any symbol named 'symbol'
26
+ moon ide goto-definition -query 'symbol'
27
+
28
+ # Find methods of a specific type
29
+ moon ide goto-definition -query 'Type::method'
30
+
31
+ # Find trait method implementations
32
+ moon ide goto-definition -query 'Trait for Type with method'
33
+
34
+ # Find symbol in specific package using @pkg prefix
35
+ moon ide goto-definition -query '@moonbitlang/x encode'
36
+
37
+ # Find symbol in multiple packages (searches in pkg1 OR pkg2)
38
+ moon ide goto-definition -query '@username/mymodule/pkg1 @username/mymodule/pkg2 helper'
39
+
40
+ # Find symbol in nested package
41
+ moon ide goto-definition -query '@username/mymodule/mypkg helper'
42
+ ```
43
+
44
+ **Supported symbols**: functions, constants, let bindings, types, structs, enums, traits
45
+
46
+ **Package filtering**: Prefix your query with `@package_name` to scope the search. Multiple `@pkg` prefixes create an OR condition.
47
+
48
+ #### 2. Tag-based Filtering (`-tags`)
49
+
50
+ Pre-filter symbols by characteristics before name matching:
51
+
52
+ **Visibility tags**:
53
+
54
+ - `pub` - Public symbols
55
+ - `pub all` - Public structs with all public fields
56
+ - `pub open` - Public traits with all methods public
57
+ - `priv` - Private symbols
58
+
59
+ **Symbol type tags**:
60
+
61
+ - `type` - Type definitions (struct, enum, typealias, abstract)
62
+ - `error` - Error type definitions
63
+ - `enum` - Enum definitions and variants
64
+ - `struct` - Struct definitions
65
+ - `alias` - Type/function/trait aliases
66
+ - `let` - Top-level let bindings
67
+ - `const` - Constant definitions
68
+ - `fn` - Function definitions
69
+ - `trait` - Trait definitions
70
+ - `impl` - Trait implementations
71
+ - `test` - Named test functions
72
+
73
+ **Combine tags with logical operators**:
74
+
75
+ ```bash
76
+ # Public functions only
77
+ moon ide goto-definition -tags 'pub fn' -query 'my_func'
78
+
79
+ # Functions or constants
80
+ moon ide goto-definition -tags 'fn | const' -query 'helper'
81
+
82
+ # Public functions or constants
83
+ moon ide goto-definition -tags 'pub (fn | const)' -query 'api'
84
+
85
+ # Public types or traits
86
+ moon ide goto-definition -tags 'pub (type | trait)' -query 'MyType'
87
+ ```
88
+
89
+ ### Practical Examples
90
+
91
+ ```bash
92
+ # Find public function definition
93
+ moon ide goto-definition -tags 'pub fn' -query 'maximum'
94
+
95
+ # Find all references to a struct
96
+ moon ide find-references -tags 'struct' -query 'Rectangle'
97
+
98
+ # Find trait implementations
99
+ moon ide goto-definition -tags 'impl' -query 'Show for MyType'
100
+
101
+ # Find errors in specific package
102
+ moon ide goto-definition -tags 'error' -query '@mymodule/parser ParseError'
103
+
104
+ # Find symbol across multiple packages
105
+ moon ide goto-definition -query '@moonbitlang/x @moonbitlang/core encode'
106
+
107
+ # Combine package filtering with tags
108
+ moon ide goto-definition -tags 'pub fn' -query '@username/myapp helper'
109
+ ```
110
+
111
+ ### Query Processing
112
+
113
+ The tool processes queries in this order:
114
+
115
+ 1. Filter symbols by `-tags` conditions
116
+ 2. Extract package scope from `@pkg` prefixes in `-query`
117
+ 3. Fuzzy match remaining symbols by name
118
+ 4. Return top 3 best matches with location information
119
+
120
+ **Best Practice**: Start with `-tags` to reduce noise, then use `@pkg` prefixes in `-query` to scope by package for precise navigation.
121
+
122
+ ## Additional IDE Commands
123
+
124
+ ### `moon ide peek-def`
125
+
126
+ Display definitions inline. More accurate than grep (semantic search).
127
+
128
+ ```bash
129
+ # Top-level symbol definition
130
+ $ moon ide peek-def String::rev
131
+ Found 1 symbols matching 'String::rev':
132
+ `pub fn String::rev` in package moonbitlang/core/builtin at .../string_methods.mbt:1039-1044
133
+
134
+ # Local symbol definition with location
135
+ $ moon ide peek-def Parser -loc src/parse.mbt:46:4
136
+ Definition found at file src/parse.mbt
137
+ | ///|
138
+ 2 | priv struct Parser {
139
+ | ^^^^^^
140
+ | bytes : Bytes
141
+ | mut pos : Int
142
+ | }
143
+ ```
144
+
145
+ ### `moon ide outline`
146
+
147
+ List top-level symbols in a package or file.
148
+
149
+ ```bash
150
+ # Directory (package) outline
151
+ $ moon ide outline .
152
+ spec.mbt:
153
+ L003 | pub(all) enum CStandard {
154
+ ...
155
+ L013 | pub(all) struct Position {
156
+ ...
157
+
158
+ # Single file outline
159
+ $ moon ide outline parser.mbt
160
+ ```
161
+
162
+ ### `moon ide find-references`
163
+
164
+ Find all references to a symbol.
165
+
166
+ ```bash
167
+ $ moon ide find-references TranslationUnit
168
+ ```
169
+
170
+ ## `moon doc` for API Discovery
171
+
172
+ **CRITICAL**: `moon doc '<query>'` is the primary tool for API discovery. Faster and more accurate than grep.
173
+
174
+ ```bash
175
+ # Empty query: list available packages
176
+ moon doc ''
177
+
178
+ # List type methods
179
+ moon doc "String"
180
+
181
+ # List symbols in a package
182
+ moon doc "@buffer"
183
+
184
+ # Specific function details
185
+ moon doc "@buffer.new"
186
+
187
+ # Glob pattern
188
+ moon doc "String::*rev*"
189
+ ```