-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.neva
More file actions
200 lines (174 loc) · 4.14 KB
/
main.neva
File metadata and controls
200 lines (174 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import {
fmt
lists
os
runtime
}
type Command struct {
mode string
tool string
prompt string
}
type ToolSpec struct {
name string
description string
}
type Request struct {
command Command
tools list<ToolSpec>
message string
}
type ToolCall struct {
name string
args string
}
type ToolResult struct {
output string
}
def Main(start any) (stop any) {
app App{
parser ParseCommandFromArgs,
planner CommandPlanner,
executor MockToolExecutor
}
println fmt.Println<string>
panic runtime.Panic
---
:start -> app
app:res -> println
println:res -> :stop
[app:err, println:err] -> panic
}
// High-level API surface:
// - parser: CLI model binding
// - planner: request -> tool call planning
// - executor: tool call execution backend
// This mirrors "construct dependencies, then run app" from cmd/neva in Go.
def App(sig any) (res string, err error) {
parser ICommandParser?
planner IRequestPlanner
executor IToolExecutor?
tools DefaultTools
req BuildRequest
out FormatOutput
---
:sig -> [parser, tools]
parser -> req:command
tools -> req:tools
req -> planner -> executor -> out -> :res
}
interface ICommandParser(any) (res Command, err error)
// Minimal strict parser for MVP:
// args[1] => mode, args[2] => tool, args[3] => prompt
// If user passes fewer args, parsing naturally returns compiler.Error.
def ParseCommandFromArgs(sig any) (res Command, err error) {
args os.Args
mode lists.At<string>?
tool lists.At<string>?
prompt lists.At<string>?
builder Struct<Command>
---
:sig -> args
args -> [
mode:data,
1 -> mode:idx,
tool:data,
2 -> tool:idx,
prompt:data,
3 -> prompt:idx
]
mode -> builder:mode
tool -> builder:tool
prompt -> builder:prompt
builder -> :res
}
def DefaultTools(sig any) (res list<ToolSpec>) {
run_tool Struct<ToolSpec>
build_tool Struct<ToolSpec>
to_list lists.FromArray<ToolSpec>
---
:sig -> [
'neva.run' -> run_tool:name,
'Compile and run a package' -> run_tool:description,
'neva.build' -> build_tool:name,
'Compile package without running' -> build_tool:description
]
run_tool -> to_list:port[0]
build_tool -> to_list:port[1]
to_list -> :res
}
def BuildRequest(command Command, tools list<ToolSpec>) (res Request) {
msg RenderPrompt
builder Struct<Request>
---
:command -> [msg, builder:command]
:tools -> builder:tools
msg -> builder:message
builder -> :res
}
// Current prompt renderer is intentionally typed and deterministic.
def RenderPrompt(cmd Command) (res string) {
a Add
b Add
c Add
d Add
e Add
---
:cmd -> [
'mode=' -> a:left,
.mode -> a:right,
' tool=' -> b:right,
.tool -> c:right,
' prompt=' -> d:right,
.prompt -> e:right
]
a -> b:left
b -> c:left
c -> d:left
d -> e:left
e -> :res
}
interface IRequestPlanner(Request) (res ToolCall)
// CommandPlanner keeps planning policy in one replaceable component.
def CommandPlanner(req Request) (res ToolCall) {
builder Struct<ToolCall>
---
:req -> [
.command -> .tool -> builder:name,
.message -> builder:args
]
builder -> :res
}
interface IToolExecutor(ToolCall) (res ToolResult, err error)
// Placeholder adapter. Replace with real bridge to pkg/cli functionality.
def MockToolExecutor(call ToolCall) (res ToolResult, err error) {
render RenderMockExecution
builder Struct<ToolResult>
---
:call -> render -> builder:output
builder -> :res
}
def RenderMockExecution(call ToolCall) (res string) {
a Add
b Add
c Add
---
:call -> [
'exec tool=' -> a:left,
.name -> a:right,
' args=' -> b:right,
.args -> c:right
]
a -> b:left
b -> c:left
c -> :res
}
def FormatOutput(result ToolResult) (res string) {
add_prefix Add
---
:result -> [
.output -> add_prefix:right,
'neva-ai> ' -> add_prefix:left
]
add_prefix -> :res
}