@zyro-sec/server 1.0.0 → 1.0.2
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.
- package/package.json +15 -18
- package/script/build.ts +28 -0
- package/script/pack.ts +5 -0
- package/script/workerd-probe.ts +59 -0
- package/src/api.ts +12 -0
- package/src/auth.ts +70 -0
- package/src/content-headers.ts +32 -0
- package/src/cors.ts +34 -0
- package/src/event-feed.ts +93 -0
- package/src/fetch.ts +67 -0
- package/src/handlers/agent.ts +23 -0
- package/src/handlers/artifact.ts +242 -0
- package/src/handlers/automation.ts +63 -0
- package/src/handlers/blob.ts +55 -0
- package/src/handlers/command.ts +8 -0
- package/src/handlers/config.ts +26 -0
- package/src/handlers/credential.ts +87 -0
- package/src/handlers/debug.ts +57 -0
- package/src/handlers/event.ts +38 -0
- package/src/handlers/form.ts +15 -0
- package/src/handlers/fs.ts +180 -0
- package/src/handlers/generate.ts +117 -0
- package/src/handlers/integration.ts +310 -0
- package/src/handlers/job.ts +29 -0
- package/src/handlers/location.ts +33 -0
- package/src/handlers/machine.ts +336 -0
- package/src/handlers/mcp.ts +160 -0
- package/src/handlers/media.ts +44 -0
- package/src/handlers/message.ts +82 -0
- package/src/handlers/migration.ts +13 -0
- package/src/handlers/model.ts +25 -0
- package/src/handlers/permission.ts +131 -0
- package/src/handlers/persistent-pty.ts +285 -0
- package/src/handlers/plugin.ts +97 -0
- package/src/handlers/project.ts +23 -0
- package/src/handlers/provider.ts +32 -0
- package/src/handlers/pty-socket.ts +47 -0
- package/src/handlers/pty.ts +181 -0
- package/src/handlers/push.ts +67 -0
- package/src/handlers/reference.ts +8 -0
- package/src/handlers/rpc.ts +31 -0
- package/src/handlers/server.ts +58 -0
- package/src/handlers/session-error.ts +47 -0
- package/src/handlers/session.ts +722 -0
- package/src/handlers/shell.ts +72 -0
- package/src/handlers/skill.ts +34 -0
- package/src/handlers/usage.ts +23 -0
- package/src/handlers/vcs.ts +104 -0
- package/src/handlers/voice.ts +50 -0
- package/src/handlers/websearch.ts +50 -0
- package/src/handlers/worktree.ts +60 -0
- package/src/handlers.ts +69 -0
- package/src/location.ts +86 -0
- package/src/media-uri.ts +13 -0
- package/src/middleware/authorization.ts +111 -0
- package/src/middleware/defect-response.ts +39 -0
- package/src/middleware/form-location.ts +44 -0
- package/src/middleware/schema-error.ts +49 -0
- package/src/middleware/session-location.ts +30 -0
- package/src/options.ts +61 -0
- package/src/pairing.ts +36 -0
- package/src/process.ts +274 -0
- package/src/range.ts +16 -0
- package/src/request-site.ts +36 -0
- package/src/request-tracing.ts +9 -0
- package/src/routes.ts +261 -0
- package/src/server-info.ts +41 -0
- package/src/service-status.ts +30 -0
- package/src/workerd.ts +184 -0
- package/test/artifact.test.ts +224 -0
- package/test/auth.test.ts +24 -0
- package/test/automation.test.ts +315 -0
- package/test/client-mcp.test.ts +369 -0
- package/test/codemode-api.test.ts +88 -0
- package/test/config.test.ts +104 -0
- package/test/cors.test.ts +24 -0
- package/test/defect-response.test.ts +83 -0
- package/test/event-feed.test.ts +201 -0
- package/test/fetch-option.test.ts +104 -0
- package/test/fetch.test.ts +698 -0
- package/test/fixture/mcp-starts.cjs +20 -0
- package/test/fixture/routes.ts +37 -0
- package/test/fixture/server.ts +20 -0
- package/test/fixture/worktree-delegate/index.ts +13 -0
- package/test/fixture/worktree-plugin/index.ts +47 -0
- package/test/flag-channel.test.ts +126 -0
- package/test/fs.test.ts +439 -0
- package/test/generate.test.ts +132 -0
- package/test/handler-policy.test.ts +43 -0
- package/test/heap-dump.test.ts +137 -0
- package/test/integration-policy.test.ts +93 -0
- package/test/job.test.ts +186 -0
- package/test/machine-iroh.test.ts +259 -0
- package/test/machine-link.test.ts +1234 -0
- package/test/machine-routes.test.ts +198 -0
- package/test/media.test.ts +343 -0
- package/test/message.test.ts +105 -0
- package/test/model.test.ts +62 -0
- package/test/options.test.ts +42 -0
- package/test/permission-saved.test.ts +73 -0
- package/test/persistent-pty.test.ts +1007 -0
- package/test/process.test.ts +261 -0
- package/test/provider.test.ts +88 -0
- package/test/pty-socket.property.test.ts +240 -0
- package/test/pty-socket.test.ts +89 -0
- package/test/pty-transport.test.ts +200 -0
- package/test/push-routes.test.ts +157 -0
- package/test/request-site.test.ts +71 -0
- package/test/request-tracing.test.ts +87 -0
- package/test/rpc-handler-errors.test.ts +76 -0
- package/test/schema-error.test.ts +68 -0
- package/test/service-status.test.ts +34 -0
- package/test/session-admit-location.test.ts +92 -0
- package/test/session-create.test.ts +65 -0
- package/test/session-diff.test.ts +100 -0
- package/test/session-form.test.ts +50 -0
- package/test/session-import.test.ts +152 -0
- package/test/session-instances.test.ts +335 -0
- package/test/session-unarchive.test.ts +73 -0
- package/test/session-update.test.ts +66 -0
- package/test/skill.test.ts +57 -0
- package/test/sse-failure.test.ts +71 -0
- package/test/usage.test.ts +88 -0
- package/test/vcs.test.ts +356 -0
- package/test/video-generate.test.ts +131 -0
- package/test/voice.test.ts +170 -0
- package/test/workerd.test.ts +227 -0
- package/test/worktree.test.ts +333 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require("node:fs")
|
|
2
|
+
const readline = require("node:readline")
|
|
3
|
+
|
|
4
|
+
fs.appendFileSync(process.argv[2], `${process.pid}\n`)
|
|
5
|
+
readline
|
|
6
|
+
.createInterface({ input: process.stdin })
|
|
7
|
+
.on("line", (line) => {
|
|
8
|
+
const request = JSON.parse(line)
|
|
9
|
+
if (request.id === undefined) return
|
|
10
|
+
const result =
|
|
11
|
+
request.method === "initialize"
|
|
12
|
+
? {
|
|
13
|
+
protocolVersion: request.params.protocolVersion,
|
|
14
|
+
capabilities: { tools: {} },
|
|
15
|
+
serverInfo: { name: "filesystem-test", version: "1" },
|
|
16
|
+
}
|
|
17
|
+
: { tools: [] }
|
|
18
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: request.id, result }) + "\n")
|
|
19
|
+
})
|
|
20
|
+
.on("close", () => process.exit(0))
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LocationServiceMap } from "@zyro-sec/core/location-service-map"
|
|
2
|
+
import { Plugin } from "@zyro-sec/core/plugin"
|
|
3
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
+
import { AbsolutePath } from "@zyro-sec/schema/schema"
|
|
5
|
+
import type { LayerNode } from "@zyro-sec/util/effect/layer-node"
|
|
6
|
+
import { Context, Effect, Layer } from "effect"
|
|
7
|
+
import { HttpEffect, HttpRouter, HttpServer } from "effect/http"
|
|
8
|
+
import type { ServerOptions } from "../../src/options"
|
|
9
|
+
import { createRoutes } from "../../src/routes"
|
|
10
|
+
|
|
11
|
+
// The server never waits for a Location's plugins to load. A test that sets up a Location does, so it can
|
|
12
|
+
// exercise plugin-provided entries without polling.
|
|
13
|
+
export const pluginsLoaded = (context: Context.Context<LocationServiceMap.Service>, directory: string) =>
|
|
14
|
+
Plugin.awaitActivation.pipe(
|
|
15
|
+
Effect.provide(
|
|
16
|
+
Context.get(context, LocationServiceMap.Service).get(
|
|
17
|
+
Location.Ref.make({ directory: AbsolutePath.make(directory) }),
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
// Serves the routes in this process so the test can reach the Location's plugins.
|
|
23
|
+
export const serveRoutes = Effect.fnUntraced(function* (
|
|
24
|
+
options: ServerOptions,
|
|
25
|
+
overrides: LayerNode.Replacements = [],
|
|
26
|
+
) {
|
|
27
|
+
const context = yield* Layer.build(
|
|
28
|
+
createRoutes(options, () => [], overrides).pipe(Layer.provide(HttpServer.layerServices)),
|
|
29
|
+
)
|
|
30
|
+
const handler = Context.get(context, HttpRouter.HttpRouter).asHttpEffect().pipe(HttpEffect.toWebHandlerWith(context))
|
|
31
|
+
return {
|
|
32
|
+
context,
|
|
33
|
+
handler,
|
|
34
|
+
fetch: (input: string | URL, init?: RequestInit) => handler(new Request(input, init)),
|
|
35
|
+
pluginsLoaded: (directory: string) => pluginsLoaded(context, directory),
|
|
36
|
+
}
|
|
37
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { HttpServer } from "effect/http"
|
|
3
|
+
import { ServerProcess } from "../../src/process"
|
|
4
|
+
|
|
5
|
+
export const startServer = Effect.fnUntraced(function* (directory: string) {
|
|
6
|
+
const server = yield* ServerProcess.start<never, never>({
|
|
7
|
+
hostname: "127.0.0.1",
|
|
8
|
+
port: 0,
|
|
9
|
+
password: "secret",
|
|
10
|
+
app: { version: "test-version" },
|
|
11
|
+
database: { path: ":memory:" },
|
|
12
|
+
config: { directory },
|
|
13
|
+
fs: { filewatcher: false },
|
|
14
|
+
models: { fetch: false },
|
|
15
|
+
})
|
|
16
|
+
return {
|
|
17
|
+
base: HttpServer.formatAddress(server.address),
|
|
18
|
+
headers: { authorization: `Basic ${btoa("opencode:secret")}` },
|
|
19
|
+
}
|
|
20
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "@zyro-sec/plugin"
|
|
2
|
+
|
|
3
|
+
export default Plugin.define({
|
|
4
|
+
id: "test.worktree-delegate",
|
|
5
|
+
async setup(ctx) {
|
|
6
|
+
const projectID = ctx.options.projectID ?? ctx.location.project.id
|
|
7
|
+
if (typeof projectID !== "string") throw new Error("Missing target project")
|
|
8
|
+
await ctx.worktree.create({
|
|
9
|
+
projectID,
|
|
10
|
+
name: "delegated",
|
|
11
|
+
})
|
|
12
|
+
},
|
|
13
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Plugin, Worktree } from "@zyro-sec/plugin"
|
|
2
|
+
|
|
3
|
+
export default Plugin.define({
|
|
4
|
+
id: "test.worktree",
|
|
5
|
+
async setup(ctx) {
|
|
6
|
+
const id = typeof ctx.options.strategy === "string" ? ctx.options.strategy : "test-copy"
|
|
7
|
+
await ctx.worktree.transform((editor) =>
|
|
8
|
+
editor.add({
|
|
9
|
+
id,
|
|
10
|
+
async create(input, { signal }) {
|
|
11
|
+
await git(
|
|
12
|
+
input.sourceDirectory,
|
|
13
|
+
["worktree", "add", "--detach", "--", input.directory, input.branch ?? "HEAD"],
|
|
14
|
+
signal,
|
|
15
|
+
)
|
|
16
|
+
await ctx.storage.set(`tree:${input.directory}`, input.sourceDirectory)
|
|
17
|
+
return { directory: input.directory }
|
|
18
|
+
},
|
|
19
|
+
async remove(input, { signal }) {
|
|
20
|
+
const source = await ctx.storage.get(`tree:${input.directory}`)
|
|
21
|
+
if (typeof source !== "string") throw new Worktree.OperationError({ message: "Worktree source not found" })
|
|
22
|
+
// Windows cannot remove the working directory of the Git process itself.
|
|
23
|
+
await git(
|
|
24
|
+
source,
|
|
25
|
+
["worktree", "remove", ...(input.force ? ["--force"] : []), input.directory],
|
|
26
|
+
signal,
|
|
27
|
+
!input.force,
|
|
28
|
+
)
|
|
29
|
+
await ctx.storage.remove(`tree:${input.directory}`)
|
|
30
|
+
},
|
|
31
|
+
async list(sourceDirectory, { signal }) {
|
|
32
|
+
signal.throwIfAborted()
|
|
33
|
+
const rows = await ctx.storage.scan({ prefix: "tree:" })
|
|
34
|
+
return rows.entries
|
|
35
|
+
.filter((row) => row.value === sourceDirectory)
|
|
36
|
+
.map((row) => ({ directory: row.key.slice(5), type: "worktree" as const }))
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
async function git(directory: string, args: string[], signal: AbortSignal, forceRequired = false) {
|
|
44
|
+
const child = Bun.spawn(["git", "-C", directory, ...args], { stdout: "pipe", stderr: "pipe", signal })
|
|
45
|
+
const [code, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()])
|
|
46
|
+
if (code !== 0) throw new Worktree.OperationError({ message: stderr, forceRequired })
|
|
47
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { expect } from "bun:test"
|
|
2
|
+
import { Agent } from "@zyro-sec/core/agent"
|
|
3
|
+
import { App } from "@zyro-sec/core/app"
|
|
4
|
+
import { Database } from "@zyro-sec/core/database/database"
|
|
5
|
+
import { llmClient } from "@zyro-sec/core/effect/app-node-platform"
|
|
6
|
+
import { Flag } from "@zyro-sec/core/flag"
|
|
7
|
+
import { Image } from "@zyro-sec/core/image"
|
|
8
|
+
import { LocationServiceMap } from "@zyro-sec/core/location-service-map"
|
|
9
|
+
import { Session } from "@zyro-sec/core/session"
|
|
10
|
+
import { SessionBlob } from "@zyro-sec/core/session/blob"
|
|
11
|
+
import { SessionRunnerModel } from "@zyro-sec/core/session/runner/model"
|
|
12
|
+
import { BlobTable, SessionMessageTable } from "@zyro-sec/core/session/sql"
|
|
13
|
+
import { SessionStored } from "@zyro-sec/core/session/stored"
|
|
14
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
15
|
+
import { AbsolutePath } from "@zyro-sec/schema/schema"
|
|
16
|
+
import { Global } from "@zyro-sec/util/global"
|
|
17
|
+
import { Context, Effect, Layer } from "effect"
|
|
18
|
+
import { HttpServer } from "effect/http"
|
|
19
|
+
import { LanguageModel, LLMClient } from "../../ai/src/effect"
|
|
20
|
+
import { OpenAIChat } from "../../ai/src/protocols/openai-chat"
|
|
21
|
+
import { TestLLM } from "../../ai/src/testing"
|
|
22
|
+
import { tempGlobalLayer } from "../../core/test/fixture/global"
|
|
23
|
+
import { tmpdirScoped } from "../../core/test/fixture/tmpdir"
|
|
24
|
+
import { it } from "../../core/test/lib/effect"
|
|
25
|
+
import { imagePassthrough } from "../../core/test/lib/image"
|
|
26
|
+
import { createEmbeddedRoutes } from "../src/routes"
|
|
27
|
+
|
|
28
|
+
const pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
|
|
29
|
+
const pngHash = SessionBlob.hashBytes(Buffer.from(pngBase64, "base64"))
|
|
30
|
+
|
|
31
|
+
const runChannel = (channel: "dev" | "latest") =>
|
|
32
|
+
Effect.gen(function* () {
|
|
33
|
+
const dir = yield* tmpdirScoped(`opencode-flag-channel-${channel}-`)
|
|
34
|
+
const location = Location.Ref.make({ directory: AbsolutePath.make(dir.path) })
|
|
35
|
+
const llm = yield* TestLLM.Test.pipe(Effect.provide(TestLLM.testLayer()))
|
|
36
|
+
const model = SessionRunnerModel.resolved(
|
|
37
|
+
LanguageModel.make({ id: "flag-channel-model", provider: "test", route: OpenAIChat.route }),
|
|
38
|
+
{
|
|
39
|
+
capabilities: { tools: true, input: ["text", "image"], output: ["text"] },
|
|
40
|
+
cost: [],
|
|
41
|
+
limit: { context: 200_000, output: 8_192 },
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const context = yield* Layer.build(
|
|
46
|
+
createEmbeddedRoutes(
|
|
47
|
+
{
|
|
48
|
+
app: { channel, version: "test" },
|
|
49
|
+
database: { path: ":memory:" },
|
|
50
|
+
config: { project: false, claude: false },
|
|
51
|
+
models: { fetch: false, snapshot: false },
|
|
52
|
+
fs: { filewatcher: false, fff: false },
|
|
53
|
+
},
|
|
54
|
+
[
|
|
55
|
+
Global.node.replace(tempGlobalLayer),
|
|
56
|
+
llmClient.replace(Layer.succeed(LLMClient.Service, llm)),
|
|
57
|
+
SessionRunnerModel.node.replace(
|
|
58
|
+
Layer.succeed(SessionRunnerModel.Service, { select: (session) => Effect.fail(new SessionRunnerModel.ModelNotSelectedError({ sessionID: session.id })), resolve: () => Effect.succeed(model) }),
|
|
59
|
+
),
|
|
60
|
+
Image.node.replace(imagePassthrough),
|
|
61
|
+
],
|
|
62
|
+
).pipe(Layer.provide(HttpServer.layerServices)),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const sessions = Context.get(context, Session.Service)
|
|
66
|
+
const locations = Context.get(context, LocationServiceMap.Service)
|
|
67
|
+
const { db } = Context.get(context, Database.Service)
|
|
68
|
+
expect(Context.get(context, App.Service)).toEqual({ name: "opencode", version: "test", channel })
|
|
69
|
+
|
|
70
|
+
const session = yield* sessions.create({
|
|
71
|
+
title: `channel-${channel}`,
|
|
72
|
+
agent: Agent.ID.make("build"),
|
|
73
|
+
model: model.ref,
|
|
74
|
+
location,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
expect(yield* App.Service.pipe(Effect.provide(locations.get(session.location)))).toEqual({
|
|
78
|
+
name: "opencode",
|
|
79
|
+
version: "test",
|
|
80
|
+
channel,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
yield* llm.push(TestLLM.text("done", "text_1"))
|
|
84
|
+
|
|
85
|
+
const admitted = yield* sessions.prompt({
|
|
86
|
+
sessionID: session.id,
|
|
87
|
+
text: "store image",
|
|
88
|
+
files: [{ uri: `data:image/png;base64,${pngBase64}`, name: "shot.png" }],
|
|
89
|
+
})
|
|
90
|
+
yield* sessions.wait(session.id)
|
|
91
|
+
|
|
92
|
+
const blobs = yield* db
|
|
93
|
+
.select({ hash: BlobTable.hash })
|
|
94
|
+
.from(BlobTable)
|
|
95
|
+
.all()
|
|
96
|
+
.pipe(Effect.orDie)
|
|
97
|
+
const rows = yield* db
|
|
98
|
+
.select()
|
|
99
|
+
.from(SessionMessageTable)
|
|
100
|
+
.all()
|
|
101
|
+
.pipe(Effect.orDie)
|
|
102
|
+
const userRow = rows.find((row) => row.id === admitted.id)
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
blobs,
|
|
106
|
+
userFiles: userRow && "files" in userRow.data ? userRow.data.files : undefined,
|
|
107
|
+
}
|
|
108
|
+
}).pipe(Effect.provideService(Flag.Overrides, undefined), Effect.scoped)
|
|
109
|
+
|
|
110
|
+
it.live("enables media_blob by default on dev builds", () =>
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
expect(yield* runChannel("dev")).toEqual({
|
|
113
|
+
blobs: [{ hash: pngHash }],
|
|
114
|
+
userFiles: [{ uri: SessionStored.ref(pngHash), mime: "image/png", name: "shot.png", source: { type: "inline" } }],
|
|
115
|
+
})
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
it.live("keeps media_blob off by default on latest builds", () =>
|
|
120
|
+
Effect.gen(function* () {
|
|
121
|
+
expect(yield* runChannel("latest")).toEqual({
|
|
122
|
+
blobs: [],
|
|
123
|
+
userFiles: [{ data: pngBase64, mime: "image/png", name: "shot.png", source: { type: "inline" } }],
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
)
|