-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mill
More file actions
346 lines (297 loc) · 13.8 KB
/
Copy pathbuild.mill
File metadata and controls
346 lines (297 loc) · 13.8 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//| mill-version: 1.1.5
//| mill-jvm-version: system
//| mvnDeps:
//| - com.tjclp::mill-bun_mill1:0.2.0
package build
import mill.*, scalalib.*, publish.*
import mill.bun.bun
import mill.scalalib.scalafmt.*
import mill.scalajslib.api.*
import mill.scalajslib.bun.*
// ── Shared values ────────────────────────────────────────────────────────────
//
// `agent.js` and `agent.jvm` produce independent Maven artifacts (Scala.js
// + JVM respectively). The shared values below keep their config in sync
// without forcing a single common trait through the BunScalaJSModule /
// ScalaModule trait hierarchies (which diverge at the class level).
private val sharedScalaVersion: String = "3.8.3"
private val sharedZioVersion: String = "2.1.24"
private val sharedZioJsonVersion = "0.9.0"
private val sharedZioSchemaVersion = "1.8.3"
private val sharedZioBlocksVersion = "0.0.33"
private val sharedScalaPBVersion = "1.0.0-alpha.3"
private val sharedProtobufJavaVersion = "4.34.1"
private val sharedGoogleProtosVersion = "2.64.1"
private val sharedGrpcJavaVersion = "1.76.0"
private val sharedWellKnownProtoFiles = Seq(
"google/protobuf/descriptor.proto",
"google/protobuf/duration.proto",
"google/protobuf/empty.proto",
"google/protobuf/struct.proto",
"google/protobuf/timestamp.proto",
)
private val sharedGoogleApiProtoFiles = Seq(
"google/api/annotations.proto",
"google/api/client.proto",
"google/api/field_behavior.proto",
"google/api/http.proto",
"google/api/launch_stage.proto",
)
private val sharedZioDeps = Seq(
mvn"dev.zio::zio::$sharedZioVersion",
mvn"dev.zio::zio-streams::$sharedZioVersion",
mvn"dev.zio::zio-json::$sharedZioJsonVersion",
// zio-schema for JSON Schema derivation from case classes
mvn"dev.zio::zio-schema::$sharedZioSchemaVersion",
mvn"dev.zio::zio-schema-json::$sharedZioSchemaVersion",
mvn"dev.zio::zio-schema-derivation::$sharedZioSchemaVersion",
// zio-blocks/scope for compile-time resource safety (non-experimental alternative to capture checking)
mvn"dev.zio::zio-blocks-scope::$sharedZioBlocksVersion",
)
private def sharedPomSettings = PomSettings(
description = "Scalagent - Type-safe Scala wrapper for the Claude Agent SDK (cross-built JS + JVM)",
organization = "com.tjclp",
url = "https://github.com/TJC-LP/scalagent",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("TJC-LP", "scalagent"),
developers = Seq(
Developer("TJC-LP", "TJC-LP", "https://github.com/TJC-LP")
),
)
private def sharedPublishVersion = Task.Input {
Task.env.get("PUBLISH_VERSION").getOrElse("0.13.1")
}
// Empty Javadoc jar (Scala.js facades trip Scaladoc; we keep parity on JVM).
private def emptyDocJar(taskDest: os.Path): os.Path =
val jar = taskDest / "empty-javadoc.jar"
val jos = new java.util.jar.JarOutputStream(new java.io.FileOutputStream(jar.toIO))
jos.close()
jar
// ── agent (cross-built JS + JVM) ────────────────────────────────────────────
object agent extends Module:
/** Backwards-compatible aggregate target used by CI/docs. */
def compile: T[Unit] = Task {
js.compile()
jvm.compile()
()
}
/** Run both platform test suites from the historical `agent.test` target. */
def test(): Command[Unit] = Task.Command {
js.test.bunTest(mill.api.Args())()
jvm.test.testForked()()
()
}
/** Preserve `show agent.publishVersion` for release workflows. */
def publishVersion = sharedPublishVersion
/** Scala.js / Bun build. Current scalagent surface — Claude Agent SDK,
* @a2a-js/sdk facades, Codex SDK, MCP server bindings. Sources from
* `src/shared/` (cross-built) plus `src/js/` (JS-only files that use
* `@JSImport` / `node:*` / Bun.serve / etc.). */
object js extends BunScalaJSModule with BunPublishModule with PublishModule with ScalafmtModule:
def scalaVersion = sharedScalaVersion
override def moduleKind = Task { ModuleKind.ESModule }
// JS dependencies (replaces package.json)
def bunDeps = Task {
Seq(
bun"@anthropic-ai/claude-agent-sdk@^0.3.201",
bun"@a2a-js/sdk@^0.3.13",
bun"@openai/codex-sdk@^0.142.5",
bun"zod@^4.0.0",
)
}
def bunDevDeps = Task { Seq(bun"@types/bun@^1.3.5") }
def mvnDeps = sharedZioDeps
override def moduleDir = build.moduleDir
override def sources = Task.Sources(
moduleDir / "src" / "shared",
moduleDir / "src" / "js",
)
override def publishVersion = sharedPublishVersion
override def docJar: T[PathRef] = Task { PathRef(emptyDocJar(Task.dest)) }
def pomSettings = sharedPomSettings
def artifactName = "scalagent"
object test extends BunScalaJSTests, TestModule.Munit:
def munitVersion = "1.2.4"
override def sources = Task.Sources(
build.moduleDir / "test" / "shared",
build.moduleDir / "test" / "js",
)
end js
/** JVM build. Subset of the Scala.js surface usable on the JVM: A2A
* protocol types, ADTs, codecs, plus a JVM-native A2A server runtime
* (zio-http) for Phase 2b CMA-backed agents. Excludes Claude/Codex
* SDK bindings and `@a2a-js/sdk` facades — those live in
* [[js]] sources. */
object jvm extends ScalaModule with PublishModule with ScalafmtModule:
def scalaVersion = sharedScalaVersion
def mvnDeps = sharedZioDeps ++ Seq(
// JVM-only deps for the A2A server runtime + JSON / HTTP.
mvn"dev.zio::zio-http::3.0.1",
// JVM-only generated protobuf bindings for the A2A gRPC wire contract.
mvn"com.google.protobuf:protobuf-java:$sharedProtobufJavaVersion",
mvn"com.google.protobuf:protobuf-java-util:$sharedProtobufJavaVersion",
mvn"com.google.api.grpc:proto-google-common-protos:$sharedGoogleProtosVersion",
mvn"io.grpc:grpc-api:$sharedGrpcJavaVersion",
mvn"io.grpc:grpc-netty-shaded:$sharedGrpcJavaVersion",
mvn"io.grpc:grpc-protobuf:$sharedGrpcJavaVersion",
mvn"io.grpc:grpc-stub:$sharedGrpcJavaVersion",
)
override def moduleDir = build.moduleDir
override def sources = Task.Sources(
moduleDir / "src" / "shared",
moduleDir / "src" / "jvm",
)
def scalaPBCompilerClasspath: T[Seq[PathRef]] = Task {
defaultResolver().classpath(
Seq(mvn"com.thesamet.scalapb:scalapbc_2.13:$sharedScalaPBVersion"),
)
}
def protobufJavaClasspath: T[Seq[PathRef]] = Task {
defaultResolver().classpath(
Seq(mvn"com.google.protobuf:protobuf-java:$sharedProtobufJavaVersion"),
)
}
def googleProtoClasspath: T[Seq[PathRef]] = Task {
defaultResolver().classpath(
Seq(mvn"com.google.api.grpc:proto-google-common-protos:$sharedGoogleProtosVersion"),
)
}
/** The A2A proto VENDORED in-repo (proto/a2a.proto), tracked as a Mill
* source so the build is hermetic and codegen re-runs when it changes. This
* is the single source of truth — to track a new upstream proto, replace
* the file (provenance: proto/A2A_PROTO_SOURCE.txt). No env indirection. */
def a2aProtoSpec: T[PathRef] = Task.Source(moduleDir / "proto" / "a2a.proto")
def compileA2AJavaProto: T[PathRef] = Task(persistent = true) {
val spec = a2aProtoSpec().path
val protoInclude = Task.dest / "_protobuf_include"
os.remove.all(Task.dest)
os.makeDir.all(Task.dest)
os.makeDir.all(protoInclude)
val protobufJar = protobufJavaClasspath()
.map(_.path)
.find(path => path.last.startsWith("protobuf-java-"))
.getOrElse(throw new RuntimeException("protobuf-java jar not found on classpath"))
os.proc("jar", Seq("xf", protobufJar.toString) ++ sharedWellKnownProtoFiles)
.call(cwd = protoInclude, stdout = os.Inherit, stderr = os.Inherit)
val googleProtosJar = googleProtoClasspath()
.map(_.path)
.find(path => path.last.startsWith("proto-google-common-protos-"))
.getOrElse(throw new RuntimeException("proto-google-common-protos jar not found on classpath"))
os.proc("jar", Seq("xf", googleProtosJar.toString) ++ sharedGoogleApiProtoFiles)
.call(cwd = protoInclude, stdout = os.Inherit, stderr = os.Inherit)
val classpath = scalaPBCompilerClasspath().map(_.path.toString).mkString(java.io.File.pathSeparator)
os.proc(
"java",
"-cp",
classpath,
"scalapb.scripts.scalapbc",
s"--proto_path=${spec / os.up}",
s"--proto_path=$protoInclude",
s"--java_out=${Task.dest}",
spec.toString,
).call(cwd = moduleDir, stdout = os.Inherit, stderr = os.Inherit)
PathRef(Task.dest)
}
override def generatedSources: T[Seq[PathRef]] = Task {
super.generatedSources() :+ compileA2AJavaProto()
}
override def publishVersion = sharedPublishVersion
override def docJar: T[PathRef] = Task { PathRef(emptyDocJar(Task.dest)) }
def pomSettings = sharedPomSettings
def artifactName = "scalagent"
object test extends ScalaTests, TestModule.Munit:
def mvnDeps = Seq(
mvn"org.scalameta::munit::1.2.4",
mvn"org.yaml:snakeyaml:2.3",
mvn"io.grpc:grpc-inprocess:$sharedGrpcJavaVersion",
)
override def sources = Task.Sources(
build.moduleDir / "test" / "shared",
build.moduleDir / "test" / "jvm",
)
// Vendored A2A conformance inputs on the test classpath so the proto/ACTS
// parity tests run hermetically — no ~/git/a2a checkout required:
// test/resources/acts/*.yaml + specification.md → /acts/*, /specification.md
// proto/a2a.proto (single source, shared with codegen) → /a2a.proto
// See A2AProtoParitySpec / A2AActsStreamingSpec.
override def resources = Task.Sources(
build.moduleDir / "test" / "resources",
build.moduleDir / "proto",
)
end jvm
end agent
// ── fastMcp (JS-only; depends on JS-only ClaudeAgent surface) ───────────────
object fastMcp extends BunScalaJSModule with BunPublishModule with PublishModule with ScalafmtModule:
def scalaVersion = sharedScalaVersion
override def moduleKind = Task { ModuleKind.ESModule }
override def moduleDeps = Seq(agent.js)
override def moduleDir = build.moduleDir / "interop" / "fastmcp"
override def sources = Task.Sources(moduleDir / "src")
def mvnDeps = Seq(
mvn"com.tjclp::fast-mcp-scala::0.4.0",
mvn"dev.zio::zio::$sharedZioVersion",
mvn"dev.zio::zio-json::$sharedZioJsonVersion",
)
override def scalacOptions = Seq("-experimental")
override def publishVersion = sharedPublishVersion
override def docJar: T[PathRef] = Task { PathRef(emptyDocJar(Task.dest)) }
def pomSettings = sharedPomSettings.copy(
description = "Optional fast-mcp-scala interop for Scalagent",
)
def artifactName = "scalagent-fast-mcp"
object test extends BunScalaJSTests, TestModule.Munit:
def munitVersion = "1.2.4"
end fastMcp
// ── examples (JS-only; uses agent.js for Claude integration) ────────────────
object examples extends BunScalaJSModule with ScalafmtModule:
def scalaVersion = sharedScalaVersion
override def moduleKind = Task { ModuleKind.ESModule }
override def moduleDeps = Seq(agent.js)
override def bunBundleTarget = Task { "bun" }
def mvnDeps = Seq(
mvn"dev.zio::zio::$sharedZioVersion",
mvn"dev.zio::zio-streams::$sharedZioVersion",
)
override def moduleDir = build.moduleDir
override def sources = Task.Sources(moduleDir / "examples")
val exampleClasses = Map(
"simple" -> "com.tjclp.scalagent.examples.SimpleQuery",
"macro" -> "com.tjclp.scalagent.examples.MacroToolExample",
"custom" -> "com.tjclp.scalagent.examples.CustomToolExample",
"hook" -> "com.tjclp.scalagent.examples.HookExample",
"permission" -> "com.tjclp.scalagent.examples.PermissionExample",
"session" -> "com.tjclp.scalagent.examples.SessionExample",
"structured" -> "com.tjclp.scalagent.examples.StructuredOutputExample",
"subagent" -> "com.tjclp.scalagent.examples.SubagentExample",
"plugin" -> "com.tjclp.scalagent.examples.PluginExample",
"prompt" -> "com.tjclp.scalagent.examples.SystemPromptExample",
"command" -> "com.tjclp.scalagent.examples.SlashCommandExample",
"a2a" -> "com.tjclp.scalagent.examples.A2AExample",
"agent-hooks" -> "com.tjclp.scalagent.examples.AgentHooksExample",
"dsl-basic" -> "com.tjclp.scalagent.examples.DslBasicExample",
"dsl-builder" -> "com.tjclp.scalagent.examples.DslBuilderExample",
"dsl-delegation" -> "com.tjclp.scalagent.examples.DslDelegationExample",
"dsl-review" -> "com.tjclp.scalagent.examples.DslReviewExample",
"dsl-cells" -> "com.tjclp.scalagent.examples.DslClandestineCellExample",
"dsl-structured" -> "com.tjclp.scalagent.examples.DslStructuredOutputExample",
"dsl-dirscope" -> "com.tjclp.scalagent.examples.DslDirectoryScopeExample",
"dsl-codex" -> "com.tjclp.scalagent.examples.DslCodexExample",
"dsl-cross" -> "com.tjclp.scalagent.examples.DslCrossProviderExample",
)
override def mainClass = Task { Some("com.tjclp.scalagent.examples.ExampleRunner") }
override def run(args: mill.api.Task[mill.api.Args] = mill.api.Task.Anon(mill.api.Args())) = Task.Command {
val cliArgs = args().value
val example = cliArgs.headOption.getOrElse("")
val linked = fastLinkJS()
val entry = primaryEntrypoint(linked)
val env =
if example.nonEmpty then bunJsEnv() ++ Map("EXAMPLE" -> example)
else bunJsEnv()
runBun(
bunExecutable(),
Seq("run", entry.toString),
cwd = linked.dest.path,
env = env,
)
}
end examples