dev3000 0.0.189 → 0.0.192
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/README.md +101 -12
- package/dist/cdp-monitor.d.ts +10 -0
- package/dist/cdp-monitor.d.ts.map +1 -1
- package/dist/cdp-monitor.js +28 -4
- package/dist/cdp-monitor.js.map +1 -1
- package/dist/runtime/bridge.d.ts +2 -0
- package/dist/runtime/bridge.d.ts.map +1 -1
- package/dist/runtime/bridge.js +74 -0
- package/dist/runtime/bridge.js.map +1 -1
- package/dist/runtime/browser-capture.d.ts +117 -0
- package/dist/runtime/browser-capture.d.ts.map +1 -0
- package/dist/runtime/browser-capture.js +274 -0
- package/dist/runtime/browser-capture.js.map +1 -0
- package/dist/runtime/browser-compare.d.ts +91 -0
- package/dist/runtime/browser-compare.d.ts.map +1 -0
- package/dist/runtime/browser-compare.js +129 -0
- package/dist/runtime/browser-compare.js.map +1 -0
- package/dist/runtime/browser-events.d.ts +3 -2
- package/dist/runtime/browser-events.d.ts.map +1 -1
- package/dist/runtime/browser-events.js +11 -53
- package/dist/runtime/browser-events.js.map +1 -1
- package/dist/runtime/browser-metrics.d.ts +148 -0
- package/dist/runtime/browser-metrics.d.ts.map +1 -0
- package/dist/runtime/browser-metrics.js +243 -0
- package/dist/runtime/browser-metrics.js.map +1 -0
- package/dist/runtime/chrome-isolation.d.ts +4 -2
- package/dist/runtime/chrome-isolation.d.ts.map +1 -1
- package/dist/runtime/chrome-isolation.js +24 -35
- package/dist/runtime/chrome-isolation.js.map +1 -1
- package/dist/runtime/cli.js +67 -2
- package/dist/runtime/cli.js.map +1 -1
- package/dist/runtime/desktop-mcp.d.ts +216 -0
- package/dist/runtime/desktop-mcp.d.ts.map +1 -0
- package/dist/runtime/desktop-mcp.js +258 -0
- package/dist/runtime/desktop-mcp.js.map +1 -0
- package/dist/runtime/git-identity.d.ts +17 -0
- package/dist/runtime/git-identity.d.ts.map +1 -0
- package/dist/runtime/git-identity.js +41 -0
- package/dist/runtime/git-identity.js.map +1 -0
- package/dist/runtime/github-publish.d.ts +31 -0
- package/dist/runtime/github-publish.d.ts.map +1 -0
- package/dist/runtime/github-publish.js +237 -0
- package/dist/runtime/github-publish.js.map +1 -0
- package/dist/runtime/harness.d.ts +14 -3
- package/dist/runtime/harness.d.ts.map +1 -1
- package/dist/runtime/harness.js +55 -7
- package/dist/runtime/harness.js.map +1 -1
- package/dist/runtime/managed-cdp.d.ts +10 -0
- package/dist/runtime/managed-cdp.d.ts.map +1 -0
- package/dist/runtime/managed-cdp.js +80 -0
- package/dist/runtime/managed-cdp.js.map +1 -0
- package/dist/runtime/mcp-stdio.d.ts +17 -0
- package/dist/runtime/mcp-stdio.d.ts.map +1 -0
- package/dist/runtime/mcp-stdio.js +99 -0
- package/dist/runtime/mcp-stdio.js.map +1 -0
- package/dist/runtime/network-evidence.d.ts +28 -0
- package/dist/runtime/network-evidence.d.ts.map +1 -0
- package/dist/runtime/network-evidence.js +291 -0
- package/dist/runtime/network-evidence.js.map +1 -0
- package/dist/runtime/package-manager.d.ts +13 -0
- package/dist/runtime/package-manager.d.ts.map +1 -0
- package/dist/runtime/package-manager.js +69 -0
- package/dist/runtime/package-manager.js.map +1 -0
- package/dist/runtime/runtime.d.ts +7 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +54 -30
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/sandbox-agent.d.ts +5 -0
- package/dist/runtime/sandbox-agent.d.ts.map +1 -1
- package/dist/runtime/sandbox-agent.js +32 -0
- package/dist/runtime/sandbox-agent.js.map +1 -1
- package/dist/runtime/sandbox-cleanup.d.ts +14 -0
- package/dist/runtime/sandbox-cleanup.d.ts.map +1 -0
- package/dist/runtime/sandbox-cleanup.js +77 -0
- package/dist/runtime/sandbox-cleanup.js.map +1 -0
- package/dist/runtime/sandbox-command.d.ts +1 -0
- package/dist/runtime/sandbox-command.d.ts.map +1 -1
- package/dist/runtime/sandbox-command.js +39 -9
- package/dist/runtime/sandbox-command.js.map +1 -1
- package/dist/runtime/sandbox-context.d.ts +5 -0
- package/dist/runtime/sandbox-context.d.ts.map +1 -0
- package/dist/runtime/sandbox-context.js +42 -0
- package/dist/runtime/sandbox-context.js.map +1 -0
- package/dist/runtime/sandbox-fx-resume.d.ts +11 -0
- package/dist/runtime/sandbox-fx-resume.d.ts.map +1 -0
- package/dist/runtime/sandbox-fx-resume.js +45 -0
- package/dist/runtime/sandbox-fx-resume.js.map +1 -0
- package/dist/runtime/sandbox-gateway.d.ts +17 -0
- package/dist/runtime/sandbox-gateway.d.ts.map +1 -0
- package/dist/runtime/sandbox-gateway.js +34 -0
- package/dist/runtime/sandbox-gateway.js.map +1 -0
- package/dist/runtime/sandbox-git.d.ts +19 -0
- package/dist/runtime/sandbox-git.d.ts.map +1 -0
- package/dist/runtime/sandbox-git.js +42 -0
- package/dist/runtime/sandbox-git.js.map +1 -0
- package/dist/runtime/sandbox-github.d.ts +10 -0
- package/dist/runtime/sandbox-github.d.ts.map +1 -0
- package/dist/runtime/sandbox-github.js +35 -0
- package/dist/runtime/sandbox-github.js.map +1 -0
- package/dist/runtime/sandbox-local-harness.d.ts +34 -0
- package/dist/runtime/sandbox-local-harness.d.ts.map +1 -0
- package/dist/runtime/sandbox-local-harness.js +151 -0
- package/dist/runtime/sandbox-local-harness.js.map +1 -0
- package/dist/runtime/sandbox-ports.d.ts +6 -0
- package/dist/runtime/sandbox-ports.d.ts.map +1 -0
- package/dist/runtime/sandbox-ports.js +11 -0
- package/dist/runtime/sandbox-ports.js.map +1 -0
- package/dist/runtime/sandbox-preview.d.ts +14 -0
- package/dist/runtime/sandbox-preview.d.ts.map +1 -0
- package/dist/runtime/sandbox-preview.js +96 -0
- package/dist/runtime/sandbox-preview.js.map +1 -0
- package/dist/runtime/sandbox-process.d.ts +11 -0
- package/dist/runtime/sandbox-process.d.ts.map +1 -0
- package/dist/runtime/sandbox-process.js +77 -0
- package/dist/runtime/sandbox-process.js.map +1 -0
- package/dist/runtime/sandbox-proxy.d.ts +2 -0
- package/dist/runtime/sandbox-proxy.d.ts.map +1 -1
- package/dist/runtime/sandbox-proxy.js +75 -20
- package/dist/runtime/sandbox-proxy.js.map +1 -1
- package/dist/runtime/sandbox-recovery.d.ts +4 -0
- package/dist/runtime/sandbox-recovery.d.ts.map +1 -0
- package/dist/runtime/sandbox-recovery.js +36 -0
- package/dist/runtime/sandbox-recovery.js.map +1 -0
- package/dist/runtime/sandbox-sessions.d.ts +8 -1
- package/dist/runtime/sandbox-sessions.d.ts.map +1 -1
- package/dist/runtime/sandbox-sessions.js +20 -2
- package/dist/runtime/sandbox-sessions.js.map +1 -1
- package/dist/runtime/sandbox-setup.d.ts +5 -0
- package/dist/runtime/sandbox-setup.d.ts.map +1 -0
- package/dist/runtime/sandbox-setup.js +62 -0
- package/dist/runtime/sandbox-setup.js.map +1 -0
- package/dist/runtime/sandbox-shell.d.ts +27 -0
- package/dist/runtime/sandbox-shell.d.ts.map +1 -0
- package/dist/runtime/sandbox-shell.js +169 -0
- package/dist/runtime/sandbox-shell.js.map +1 -0
- package/dist/runtime/sandbox-watch.d.ts +11 -0
- package/dist/runtime/sandbox-watch.d.ts.map +1 -0
- package/dist/runtime/sandbox-watch.js +30 -0
- package/dist/runtime/sandbox-watch.js.map +1 -0
- package/dist/runtime/sandbox-workspace.d.ts +125 -0
- package/dist/runtime/sandbox-workspace.d.ts.map +1 -0
- package/dist/runtime/sandbox-workspace.js +205 -0
- package/dist/runtime/sandbox-workspace.js.map +1 -0
- package/dist/runtime/sandbox.d.ts +21 -2
- package/dist/runtime/sandbox.d.ts.map +1 -1
- package/dist/runtime/sandbox.js +473 -207
- package/dist/runtime/sandbox.js.map +1 -1
- package/dist/runtime/session.d.ts +1 -1
- package/dist/runtime/session.d.ts.map +1 -1
- package/dist/runtime/session.js +3 -3
- package/dist/runtime/session.js.map +1 -1
- package/dist/runtime/terminal.d.ts +19 -0
- package/dist/runtime/terminal.d.ts.map +1 -0
- package/dist/runtime/terminal.js +60 -0
- package/dist/runtime/terminal.js.map +1 -0
- package/dist/runtime/workspace-client.d.ts +2 -0
- package/dist/runtime/workspace-client.d.ts.map +1 -0
- package/dist/runtime/workspace-client.js +46 -0
- package/dist/runtime/workspace-client.js.map +1 -0
- package/package.json +2 -1
- package/scripts/eve/README.md +341 -0
- package/scripts/eve/agent/agent.ts +12 -0
- package/scripts/eve/agent/channels/eve.ts +23 -0
- package/scripts/eve/agent/instructions.md +53 -0
- package/scripts/eve/agent/sandbox.ts +34 -0
- package/scripts/eve/build-cache.mjs +18 -0
- package/scripts/eve/build-cache.test.mjs +32 -0
- package/scripts/eve/client.mjs +229 -0
- package/scripts/eve/connection.mjs +89 -0
- package/scripts/eve/conversation.mjs +91 -0
- package/scripts/eve/conversation.test.mjs +113 -0
- package/scripts/eve/fixture-agent.ts +101 -0
- package/scripts/eve/images.mjs +84 -0
- package/scripts/eve/launch.mjs +277 -0
- package/scripts/eve/model-command.mjs +21 -0
- package/scripts/eve/reconnect.mjs +22 -0
- package/scripts/eve/reconnect.test.mjs +41 -0
- package/scripts/eve/settings.mjs +33 -0
- package/scripts/eve/supervisor.mjs +41 -0
- package/scripts/eve/tui-client.mjs +234 -0
- package/scripts/eve/tui-input.mjs +114 -0
- package/scripts/eve/verify.mjs +575 -0
- package/skills/d3k/SKILL.md +60 -5
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { homedir } from "node:os"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
|
|
4
|
+
/** Parse image paths as data. Never evaluate pasted text in a shell. */
|
|
5
|
+
export function imagePaths(text) {
|
|
6
|
+
const paths = []
|
|
7
|
+
for (let start = 0; start < text.length; start++) {
|
|
8
|
+
if (start && !/\s/.test(text[start - 1])) continue
|
|
9
|
+
let cursor = start
|
|
10
|
+
const quote = ["'", '"'].includes(text[cursor]) ? text[cursor++] : undefined
|
|
11
|
+
if (!text.slice(cursor).match(/^(?:\/|~\/|file:\/\/)/)) continue
|
|
12
|
+
let path = ""
|
|
13
|
+
let closed = !quote
|
|
14
|
+
for (; cursor < text.length; cursor++) {
|
|
15
|
+
const character = text[cursor]
|
|
16
|
+
if (quote && character === quote) {
|
|
17
|
+
cursor++
|
|
18
|
+
closed = true
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
if (!quote && /\s/.test(character)) break
|
|
22
|
+
if (character === "\\" && quote !== "'" && cursor + 1 < text.length) path += text[++cursor]
|
|
23
|
+
else path += character
|
|
24
|
+
}
|
|
25
|
+
if (!closed || !/\.(png|jpe?g|webp)$/i.test(path)) continue
|
|
26
|
+
if (path.startsWith("~/")) path = homedir() + path.slice(1)
|
|
27
|
+
if (path.startsWith("file://")) {
|
|
28
|
+
try {
|
|
29
|
+
path = fileURLToPath(path)
|
|
30
|
+
} catch {
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
paths.push({ start, end: cursor, path })
|
|
35
|
+
start = cursor - 1
|
|
36
|
+
}
|
|
37
|
+
return paths
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class Images {
|
|
41
|
+
constructor(readImage) {
|
|
42
|
+
this.readImage = readImage
|
|
43
|
+
this.pending = new Map()
|
|
44
|
+
this.next = 1
|
|
45
|
+
}
|
|
46
|
+
add(image) {
|
|
47
|
+
if (this.pending.size >= 4) throw new Error("Send or clear the attached images before adding more (maximum four)")
|
|
48
|
+
const marker = `[Image #${this.next++}]`
|
|
49
|
+
this.pending.set(marker, {
|
|
50
|
+
...image,
|
|
51
|
+
filename: `${marker}.${image.mediaType === "image/jpeg" ? "jpg" : image.mediaType === "image/webp" ? "webp" : "png"}`
|
|
52
|
+
})
|
|
53
|
+
return marker
|
|
54
|
+
}
|
|
55
|
+
async replacePaths(text) {
|
|
56
|
+
const replacements = []
|
|
57
|
+
for (const candidate of imagePaths(text)) {
|
|
58
|
+
let image
|
|
59
|
+
try {
|
|
60
|
+
image = await this.readImage(candidate.path)
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// A remote path mentioned in a prompt is not a local attachment.
|
|
63
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR") continue
|
|
64
|
+
throw error
|
|
65
|
+
}
|
|
66
|
+
replacements.push({ ...candidate, image })
|
|
67
|
+
}
|
|
68
|
+
if (this.pending.size + replacements.length > 4) throw new Error("At most four images can be attached per message")
|
|
69
|
+
let result = ""
|
|
70
|
+
let after = 0
|
|
71
|
+
for (const replacement of replacements) {
|
|
72
|
+
result += text.slice(after, replacement.start) + this.add(replacement.image)
|
|
73
|
+
after = replacement.end
|
|
74
|
+
}
|
|
75
|
+
return result + text.slice(after)
|
|
76
|
+
}
|
|
77
|
+
message(text) {
|
|
78
|
+
const images = [...this.pending].filter(([marker]) => text.includes(marker)).map(([, image]) => image)
|
|
79
|
+
return images.length ? [{ type: "text", text }, ...images] : text
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
this.pending.clear()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto"
|
|
2
|
+
import { existsSync } from "node:fs"
|
|
3
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
|
|
4
|
+
import { homedir, tmpdir } from "node:os"
|
|
5
|
+
import { dirname, join } from "node:path"
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises"
|
|
7
|
+
import { fileURLToPath } from "node:url"
|
|
8
|
+
import { parseArgs } from "node:util"
|
|
9
|
+
import { Sandbox } from "@vercel/sandbox"
|
|
10
|
+
import { eveBuildCacheProbe, eveBuildFingerprint } from "./build-cache.mjs"
|
|
11
|
+
import { eveClient, runClient } from "./client.mjs"
|
|
12
|
+
import {
|
|
13
|
+
openEveConversation,
|
|
14
|
+
prepareEveWorkspaceScript,
|
|
15
|
+
saveEveConversationScript,
|
|
16
|
+
validateConversation
|
|
17
|
+
} from "./conversation.mjs"
|
|
18
|
+
import { ModelSelection } from "./model-command.mjs"
|
|
19
|
+
import { waitToReconnect } from "./reconnect.mjs"
|
|
20
|
+
import { EVE_INSTALL_CONFIG, EVE_MODEL, EVE_VERSION } from "./settings.mjs"
|
|
21
|
+
|
|
22
|
+
// Use source in the checkout and built modules in the locally installed package.
|
|
23
|
+
const runtimeModules = existsSync(new URL("../../src/runtime/sandbox-gateway.ts", import.meta.url)) ? "src" : "dist"
|
|
24
|
+
const extension = runtimeModules === "src" ? "ts" : "js"
|
|
25
|
+
const { createSandboxGateway } = await import(
|
|
26
|
+
new URL(`../../${runtimeModules}/runtime/sandbox-gateway.${extension}`, import.meta.url)
|
|
27
|
+
)
|
|
28
|
+
const { runSandboxCli } = await import(
|
|
29
|
+
new URL(`../../${runtimeModules}/runtime/sandbox-process.${extension}`, import.meta.url)
|
|
30
|
+
)
|
|
31
|
+
const { harnessStartupContext } = await import(
|
|
32
|
+
new URL(`../../${runtimeModules}/runtime/harness.${extension}`, import.meta.url)
|
|
33
|
+
)
|
|
34
|
+
const { configuredGitIdentity, configureSandboxGitIdentity } = await import(
|
|
35
|
+
new URL(`../../${runtimeModules}/runtime/git-identity.${extension}`, import.meta.url)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const { values } = parseArgs({ options: { resume: { type: "string" }, check: { type: "boolean" } } })
|
|
39
|
+
if (!values.resume || !/^[a-f\d-]{36}$/.test(values.resume))
|
|
40
|
+
throw new Error("Use: bun scripts/eve/launch.mjs --resume <d3k saved-session ID> [--check]")
|
|
41
|
+
if (!values.check && !process.stdin.isTTY) throw new Error("Run Eve in an interactive terminal")
|
|
42
|
+
const source = dirname(fileURLToPath(import.meta.url))
|
|
43
|
+
const record = JSON.parse(await readFile(join(homedir(), ".d3k/sandbox-sessions", `${values.resume}.json`), "utf8"))
|
|
44
|
+
const cli = (binary, args, options = {}) => runSandboxCli(binary, args, { timeoutMs: 120000, ...options })
|
|
45
|
+
const auth = JSON.parse(
|
|
46
|
+
await cli("vercel", ["project", "token", record.project, "--scope", record.team, "--format", "json"])
|
|
47
|
+
)
|
|
48
|
+
const credentials = { token: auth.token, projectId: record.project, teamId: record.team, name: record.sandbox }
|
|
49
|
+
const sandbox = await Sandbox.get({ ...credentials, resume: false })
|
|
50
|
+
const runtime = "/tmp/d3k-tools/node_modules/.bin/d3k-runtime"
|
|
51
|
+
const statusCommand = await sandbox.runCommand({ cmd: runtime, args: ["status"], cwd: record.workdir })
|
|
52
|
+
const status = JSON.parse(await statusCommand.stdout())
|
|
53
|
+
if (!status.running || !status.ready) throw new Error("Start/resume d3k first; Eve uses its existing sandbox")
|
|
54
|
+
const startedAt = sandbox.session.startedAt?.getTime()
|
|
55
|
+
if (!Number.isFinite(startedAt)) throw new Error("Could not determine the current sandbox session's lifetime")
|
|
56
|
+
const remainingMinutes = Math.floor((startedAt + sandbox.session.timeout - Date.now()) / 60000) - 1
|
|
57
|
+
const minutes = Math.min(values.check ? 10 : 30, remainingMinutes)
|
|
58
|
+
if (minutes < 1) throw new Error("The sandbox is about to expire; extend it or resume d3k before testing")
|
|
59
|
+
const port = 3001
|
|
60
|
+
if (sandbox.routes.some((route) => route.port === port)) throw new Error("Sandbox port 3001 is already in use")
|
|
61
|
+
let directory
|
|
62
|
+
let localDirectory
|
|
63
|
+
let gateway
|
|
64
|
+
let server
|
|
65
|
+
let serviceUrl
|
|
66
|
+
let stopping = false
|
|
67
|
+
const shutdown = new AbortController()
|
|
68
|
+
const interrupt = () => {
|
|
69
|
+
stopping = true
|
|
70
|
+
shutdown.abort()
|
|
71
|
+
}
|
|
72
|
+
process.on("SIGINT", interrupt)
|
|
73
|
+
process.on("SIGTERM", interrupt)
|
|
74
|
+
|
|
75
|
+
async function remote(command, args, options = {}) {
|
|
76
|
+
if (stopping) throw new Error("Eve session stopped")
|
|
77
|
+
const result = await sandbox.runCommand({ cmd: command, args, cwd: directory, ...options })
|
|
78
|
+
if (!options.detached && result.exitCode !== 0)
|
|
79
|
+
throw new Error((await result.stderr()).slice(-3000) || `${command} failed (${result.exitCode})`)
|
|
80
|
+
return result
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
console.log(`Preparing Eve ${EVE_VERSION} in ${record.sandbox}; the local browser stays paired through d3k…`)
|
|
85
|
+
const names = [
|
|
86
|
+
"connection.mjs",
|
|
87
|
+
"settings.mjs",
|
|
88
|
+
"supervisor.mjs",
|
|
89
|
+
"agent/agent.ts",
|
|
90
|
+
"agent/sandbox.ts",
|
|
91
|
+
"agent/instructions.md",
|
|
92
|
+
"agent/channels/eve.ts"
|
|
93
|
+
]
|
|
94
|
+
const manifest = JSON.stringify({
|
|
95
|
+
private: true,
|
|
96
|
+
type: "module",
|
|
97
|
+
dependencies: { eve: EVE_VERSION, ai: "7.0.159", zod: "4.6.7" }
|
|
98
|
+
})
|
|
99
|
+
const files = [
|
|
100
|
+
...(await Promise.all(
|
|
101
|
+
names.map(async (name) => ({
|
|
102
|
+
path: name,
|
|
103
|
+
content:
|
|
104
|
+
name === "agent/instructions.md"
|
|
105
|
+
? Buffer.from(
|
|
106
|
+
`${await readFile(join(source, name), "utf8")}\n\n${harnessStartupContext({ workdir: record.workdir, appUrl: status.appUrl })}`
|
|
107
|
+
)
|
|
108
|
+
: await readFile(join(source, name))
|
|
109
|
+
}))
|
|
110
|
+
)),
|
|
111
|
+
{ path: "package.json", content: Buffer.from(manifest) },
|
|
112
|
+
{ path: "bunfig.toml", content: Buffer.from(EVE_INSTALL_CONFIG) }
|
|
113
|
+
]
|
|
114
|
+
const buildFingerprint = eveBuildFingerprint(files)
|
|
115
|
+
directory = values.check
|
|
116
|
+
? `/tmp/d3k-eve-check-${randomBytes(6).toString("hex")}`
|
|
117
|
+
: `/tmp/d3k-eve-sessions/${record.id}`
|
|
118
|
+
const prepared = await sandbox.runCommand({
|
|
119
|
+
cmd: "node",
|
|
120
|
+
args: ["-e", prepareEveWorkspaceScript, directory, record.id, record.workdir, status.appUrl]
|
|
121
|
+
})
|
|
122
|
+
if (prepared.exitCode !== 0)
|
|
123
|
+
throw new Error(`Could not recover the Eve workspace: ${(await prepared.stderr()).slice(-2000)}`)
|
|
124
|
+
const { state: conversationState, migrated } = JSON.parse(await prepared.stdout())
|
|
125
|
+
if (conversationState) validateConversation(conversationState, { owner: record.id, workdir: record.workdir })
|
|
126
|
+
const created = await sandbox.runCommand({ cmd: "mkdir", args: ["-p", `${directory}/agent/channels`] })
|
|
127
|
+
if (created.exitCode !== 0) throw new Error("Could not prepare the remote Eve directory")
|
|
128
|
+
const cached = await sandbox.runCommand({
|
|
129
|
+
cmd: "node",
|
|
130
|
+
args: ["-e", eveBuildCacheProbe, buildFingerprint],
|
|
131
|
+
cwd: directory
|
|
132
|
+
})
|
|
133
|
+
const reuseBuild = cached.exitCode === 0
|
|
134
|
+
if (!reuseBuild) {
|
|
135
|
+
await remote("rm", ["-f", ".d3k-build.sha256"])
|
|
136
|
+
await sandbox.writeFiles(files.map((file) => ({ ...file, path: `${directory}/${file.path}` })))
|
|
137
|
+
}
|
|
138
|
+
const gitIdentity = await configureSandboxGitIdentity(sandbox, record.workdir, await configuredGitIdentity(cli))
|
|
139
|
+
const env = {
|
|
140
|
+
...gitIdentity,
|
|
141
|
+
D3K_EVE_WORKDIR: record.workdir,
|
|
142
|
+
D3K_EVE_ISOLATED_HOST: "1",
|
|
143
|
+
EVE_SCHEDULES_DISABLED: "1"
|
|
144
|
+
}
|
|
145
|
+
console.log(
|
|
146
|
+
reuseBuild
|
|
147
|
+
? "Reusing the built remote Eve service; preparing the local client…"
|
|
148
|
+
: "Building the remote service and preparing the local client…"
|
|
149
|
+
)
|
|
150
|
+
const timed = async (label, operation) => {
|
|
151
|
+
const started = performance.now()
|
|
152
|
+
await operation()
|
|
153
|
+
console.log(`${label} (${((performance.now() - started) / 1000).toFixed(1)}s)`)
|
|
154
|
+
}
|
|
155
|
+
// Both preparations are independent. Wait for both even if one fails so
|
|
156
|
+
// finally cannot remove the client's directory while its install is writing.
|
|
157
|
+
const preparations = await Promise.allSettled([
|
|
158
|
+
(async () => {
|
|
159
|
+
if (reuseBuild) return
|
|
160
|
+
await timed("Remote Eve dependencies installed", () => remote("bun", ["install"]))
|
|
161
|
+
await timed("Remote Eve service built", () => remote("node", ["node_modules/eve/bin/eve.js", "build"], { env }))
|
|
162
|
+
await sandbox.writeFiles([{ path: `${directory}/.d3k-build.sha256`, content: Buffer.from(buildFingerprint) }])
|
|
163
|
+
})(),
|
|
164
|
+
timed("Local Eve client ready", async () => {
|
|
165
|
+
localDirectory = await mkdtemp(join(tmpdir(), "d3k-eve-client-"))
|
|
166
|
+
await writeFile(join(localDirectory, "package.json"), manifest)
|
|
167
|
+
await writeFile(join(localDirectory, "bunfig.toml"), EVE_INSTALL_CONFIG)
|
|
168
|
+
await cli("bun", ["install"], { cwd: localDirectory })
|
|
169
|
+
})
|
|
170
|
+
])
|
|
171
|
+
for (const result of preparations) if (result.status === "rejected") throw result.reason
|
|
172
|
+
process.env.D3K_EVE_MODEL_ID = EVE_MODEL
|
|
173
|
+
process.env.D3K_EVE_PACKAGE_ROOT = join(localDirectory, "node_modules/eve")
|
|
174
|
+
gateway = await createSandboxGateway(cli, {
|
|
175
|
+
projectId: record.project,
|
|
176
|
+
teamId: record.team,
|
|
177
|
+
sessionId: `${record.id} Eve session`,
|
|
178
|
+
minutes,
|
|
179
|
+
budget:
|
|
180
|
+
record.gatewayBudgetConfigured && record.gatewayBudget && record.gatewayBudget !== "none"
|
|
181
|
+
? Number(record.gatewayBudget)
|
|
182
|
+
: undefined
|
|
183
|
+
})
|
|
184
|
+
const token = randomBytes(32).toString("hex")
|
|
185
|
+
await sandbox.update({ ports: [...sandbox.routes.map((route) => route.port), port] })
|
|
186
|
+
serviceUrl = sandbox.domain(port)
|
|
187
|
+
server = await remote("node", ["supervisor.mjs"], {
|
|
188
|
+
detached: true,
|
|
189
|
+
env: {
|
|
190
|
+
...env,
|
|
191
|
+
AI_GATEWAY_API_KEY: gateway.key,
|
|
192
|
+
D3K_EVE_TOKEN: token,
|
|
193
|
+
D3K_EVE_EXPIRES_AT: String(gateway.expiresAt),
|
|
194
|
+
D3K_EVE_PORT: String(port)
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
for (let attempt = 0; ; attempt++) {
|
|
198
|
+
if (stopping) throw new Error("Eve session stopped")
|
|
199
|
+
const healthy = await fetch(`${serviceUrl}/eve/v1/health`, { signal: AbortSignal.timeout(3000) })
|
|
200
|
+
.then((response) => response.ok)
|
|
201
|
+
.catch(() => false)
|
|
202
|
+
if (healthy) break
|
|
203
|
+
if (attempt >= 30) throw new Error("Eve did not become healthy")
|
|
204
|
+
await delay(500)
|
|
205
|
+
}
|
|
206
|
+
const { Client } = await eveClient()
|
|
207
|
+
const models = new ModelSelection(EVE_MODEL)
|
|
208
|
+
const client = new Client({ baseUrl: serviceUrl, auth: { bearer: token }, headers: () => models.headers() })
|
|
209
|
+
const session = values.check
|
|
210
|
+
? (await client.sessions.create()).session
|
|
211
|
+
: await openEveConversation({
|
|
212
|
+
client,
|
|
213
|
+
state: conversationState,
|
|
214
|
+
owner: record.id,
|
|
215
|
+
workdir: record.workdir,
|
|
216
|
+
save: async (state) => {
|
|
217
|
+
await remote("node", ["-e", saveEveConversationScript, directory, JSON.stringify(state)])
|
|
218
|
+
},
|
|
219
|
+
signal: AbortSignal.any([shutdown.signal, AbortSignal.timeout(20000)])
|
|
220
|
+
})
|
|
221
|
+
if (!values.check)
|
|
222
|
+
console.log(
|
|
223
|
+
`${conversationState ? (migrated ? "Recovered the most recent existing" : "Resuming") : "Created"} Eve conversation ${session.id}.`
|
|
224
|
+
)
|
|
225
|
+
console.log(`Ready. Local input → remote Eve → ${record.workdir}`)
|
|
226
|
+
const spendingLimit =
|
|
227
|
+
record.gatewayBudgetConfigured && record.gatewayBudget && record.gatewayBudget !== "none"
|
|
228
|
+
? `$${record.gatewayBudget} maximum`
|
|
229
|
+
: "no session spending cap"
|
|
230
|
+
console.log(`Team AI Gateway: ${spendingLimit}; access expires ${new Date(gateway.expiresAt).toLocaleTimeString()}.`)
|
|
231
|
+
if (values.check) {
|
|
232
|
+
const denied = await fetch(`${serviceUrl}/eve/v1/session`, { method: "POST" })
|
|
233
|
+
if (denied.status !== 401) throw new Error(`Expected 401, got ${denied.status}`)
|
|
234
|
+
const probe = await client.sessions.create({ message: "Reply with exactly EVE_READY. Do not call tools." })
|
|
235
|
+
const result = await probe.delivery.result({ signal: AbortSignal.timeout(60000) })
|
|
236
|
+
if (result.status !== "completed" || result.reply.trim() !== "EVE_READY") throw new Error(JSON.stringify(result))
|
|
237
|
+
console.log("PASS: Eve setup, HTTPS authorization, and real model response")
|
|
238
|
+
} else {
|
|
239
|
+
console.log(
|
|
240
|
+
"Try: inspect the current browser; paste an image path or Ctrl+V for a clipboard image; or a slow shell command."
|
|
241
|
+
)
|
|
242
|
+
console.log("/detach opens the reconnect menu. Ctrl-C at that prompt exits.")
|
|
243
|
+
const expiry = AbortSignal.timeout(Math.max(0, gateway.expiresAt - Date.now()))
|
|
244
|
+
const signal = AbortSignal.any([shutdown.signal, expiry])
|
|
245
|
+
while (!signal.aborted) {
|
|
246
|
+
await runClient({ baseUrl: serviceUrl, token, sessionId: session.id, models, signal })
|
|
247
|
+
if (signal.aborted) break
|
|
248
|
+
if (!(await waitToReconnect({ signal, onInterrupt: interrupt }))) break
|
|
249
|
+
}
|
|
250
|
+
if (expiry.aborted)
|
|
251
|
+
console.log(
|
|
252
|
+
"Eve's session time limit was reached. Remote Eve has stopped; no message was retried. Resume d3k to return to this conversation with renewed access."
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
process.off("SIGINT", interrupt)
|
|
257
|
+
process.off("SIGTERM", interrupt)
|
|
258
|
+
const failures = []
|
|
259
|
+
if (server) await server.kill("SIGTERM").catch((error) => failures.push(`service: ${error.message}`))
|
|
260
|
+
if (gateway)
|
|
261
|
+
await cli("vercel", ["ai-gateway", "api-keys", "remove", gateway.id, "--scope", record.team, "--yes"]).catch(
|
|
262
|
+
(error) => failures.push(`Gateway key removal: ${error.message}`)
|
|
263
|
+
)
|
|
264
|
+
if (serviceUrl) {
|
|
265
|
+
await (async () => {
|
|
266
|
+
const current = await Sandbox.get({ ...credentials, resume: false })
|
|
267
|
+
if (current.routes.some((route) => route.port === port && route.url === serviceUrl))
|
|
268
|
+
await current.update({
|
|
269
|
+
ports: current.routes.filter((route) => route.port !== port).map((route) => route.port)
|
|
270
|
+
})
|
|
271
|
+
})().catch((error) => failures.push(`route: ${error.message}`))
|
|
272
|
+
}
|
|
273
|
+
if (localDirectory) await rm(localDirectory, { recursive: true, force: true })
|
|
274
|
+
if (failures.length)
|
|
275
|
+
console.error(`Cleanup needs attention (access still expires automatically): ${failures.join("; ")}`)
|
|
276
|
+
else console.log("Eve stopped; temporary model access removed.")
|
|
277
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EVE_MODEL, EVE_MODELS, MODEL_HEADER, resolveModel } from "./settings.mjs"
|
|
2
|
+
|
|
3
|
+
/** Kept by the launcher across local UI detaches; transmitted with the next request. */
|
|
4
|
+
export class ModelSelection {
|
|
5
|
+
constructor(initial = process.env.D3K_EVE_MODEL_ID || EVE_MODEL) {
|
|
6
|
+
this.current = resolveModel(initial)
|
|
7
|
+
}
|
|
8
|
+
headers() {
|
|
9
|
+
return { [MODEL_HEADER]: this.current.id }
|
|
10
|
+
}
|
|
11
|
+
select(value) {
|
|
12
|
+
this.current = resolveModel(value)
|
|
13
|
+
return `${this.describe()}\nSelected for subsequent model calls; conversation history is retained.`
|
|
14
|
+
}
|
|
15
|
+
describe() {
|
|
16
|
+
return `Configured model: ${this.current.id}\nReasoning: ${this.current.reasoning}`
|
|
17
|
+
}
|
|
18
|
+
list() {
|
|
19
|
+
return `${this.describe()}\n${EVE_MODELS.map((model) => `/model ${model.aliases[0]} — ${model.label}`).join("\n")}`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises"
|
|
2
|
+
|
|
3
|
+
export async function waitToReconnect({ signal, onInterrupt, input = process.stdin, output = process.stdout }) {
|
|
4
|
+
const closed = new AbortController()
|
|
5
|
+
const menu = createInterface({ input, output })
|
|
6
|
+
menu.on("SIGINT", () => {
|
|
7
|
+
closed.abort()
|
|
8
|
+
onInterrupt?.()
|
|
9
|
+
})
|
|
10
|
+
menu.on("close", () => closed.abort())
|
|
11
|
+
try {
|
|
12
|
+
await menu.question("Agent remains remote. Enter to reconnect; Ctrl-C to exit: ", {
|
|
13
|
+
signal: signal ? AbortSignal.any([signal, closed.signal]) : closed.signal
|
|
14
|
+
})
|
|
15
|
+
return true
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.name !== "AbortError") throw error
|
|
18
|
+
return false
|
|
19
|
+
} finally {
|
|
20
|
+
menu.close()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import assert from "node:assert/strict"
|
|
2
|
+
import { PassThrough } from "node:stream"
|
|
3
|
+
import { test } from "vitest"
|
|
4
|
+
import { waitToReconnect } from "./reconnect.mjs"
|
|
5
|
+
|
|
6
|
+
for (const action of ["enter", "ctrl-c", "signal", "expired", "eof"]) {
|
|
7
|
+
test(`reconnect prompt handles ${action}`, async () => {
|
|
8
|
+
const input = new PassThrough()
|
|
9
|
+
const output = new PassThrough()
|
|
10
|
+
input.isTTY = true
|
|
11
|
+
input.setRawMode = () => input
|
|
12
|
+
output.isTTY = true
|
|
13
|
+
output.columns = 100
|
|
14
|
+
let displayed = ""
|
|
15
|
+
output.on("data", (chunk) => {
|
|
16
|
+
displayed += chunk
|
|
17
|
+
})
|
|
18
|
+
const shutdown = new AbortController()
|
|
19
|
+
if (action === "expired") shutdown.abort()
|
|
20
|
+
let interrupted = false
|
|
21
|
+
const result = waitToReconnect({
|
|
22
|
+
input,
|
|
23
|
+
output,
|
|
24
|
+
signal: shutdown.signal,
|
|
25
|
+
onInterrupt: () => {
|
|
26
|
+
interrupted = true
|
|
27
|
+
shutdown.abort()
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
if (action === "enter") input.write("\r")
|
|
31
|
+
if (action === "ctrl-c") input.write("\x03")
|
|
32
|
+
if (action === "signal") shutdown.abort()
|
|
33
|
+
if (action === "eof") input.end()
|
|
34
|
+
assert.equal(await result, action === "enter")
|
|
35
|
+
assert.equal(interrupted, action === "ctrl-c")
|
|
36
|
+
if (action === "expired") assert.equal(displayed, "")
|
|
37
|
+
else assert.match(displayed, /Ctrl-C to exit/)
|
|
38
|
+
input.destroy()
|
|
39
|
+
output.destroy()
|
|
40
|
+
})
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const EVE_VERSION = "1.0.0-rc.6"
|
|
2
|
+
// The launcher intentionally pins the requested current RC. Keep the host's
|
|
3
|
+
// package-age policy for all other dependencies; do not modify global config.
|
|
4
|
+
export const EVE_INSTALL_CONFIG = '[install]\nminimumReleaseAgeExcludes = ["eve"]\n'
|
|
5
|
+
|
|
6
|
+
// Validated against AI Gateway's public model catalogue: image input and tool use.
|
|
7
|
+
export const EVE_MODELS = [
|
|
8
|
+
{
|
|
9
|
+
id: "anthropic/claude-haiku-5.5",
|
|
10
|
+
label: "Claude Haiku 5.5",
|
|
11
|
+
aliases: ["haiku"],
|
|
12
|
+
reasoning: "none",
|
|
13
|
+
context: 1000000
|
|
14
|
+
},
|
|
15
|
+
{ id: "google/gemini-3.8-flash", label: "Gemini 3.8 Flash", aliases: ["flash"], reasoning: "low", context: 1000000 },
|
|
16
|
+
{ id: "openai/gpt-5.4-mini", label: "GPT 5.4 Mini", aliases: ["mini"], reasoning: "none", context: 400000 },
|
|
17
|
+
{
|
|
18
|
+
id: "anthropic/claude-sonnet-4.6",
|
|
19
|
+
label: "Claude Sonnet 4.6",
|
|
20
|
+
aliases: ["sonnet"],
|
|
21
|
+
reasoning: "none",
|
|
22
|
+
context: 1000000
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
export const EVE_MODEL = "anthropic/claude-haiku-5.5"
|
|
26
|
+
export const MODEL_HEADER = "x-d3k-eve-model"
|
|
27
|
+
|
|
28
|
+
export function resolveModel(value = EVE_MODEL) {
|
|
29
|
+
const selected = value === "fast" ? EVE_MODEL : value.toLowerCase()
|
|
30
|
+
const model = EVE_MODELS.find((model) => model.id === selected || model.aliases.includes(selected))
|
|
31
|
+
if (!model) throw new Error(`Unknown model: ${value}. Use /model to see available models.`)
|
|
32
|
+
return model
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { spawn } from "node:child_process"
|
|
2
|
+
|
|
3
|
+
// Run inside the existing isolated VM. Bound the Eve session independently of the laptop.
|
|
4
|
+
const expiresAt = Number(process.env.D3K_EVE_EXPIRES_AT)
|
|
5
|
+
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) throw new Error("Eve session access has expired")
|
|
6
|
+
const child = spawn(
|
|
7
|
+
process.execPath,
|
|
8
|
+
["node_modules/eve/bin/eve.js", "start", "--host", "0.0.0.0", "--port", process.env.D3K_EVE_PORT, "--no-schedules"],
|
|
9
|
+
{ detached: true, stdio: "inherit" }
|
|
10
|
+
)
|
|
11
|
+
let stopping = false
|
|
12
|
+
let force
|
|
13
|
+
function signalGroup(signal) {
|
|
14
|
+
if (!child.pid) return
|
|
15
|
+
try {
|
|
16
|
+
process.kill(-child.pid, signal)
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error.code !== "ESRCH") throw error
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function stop() {
|
|
22
|
+
if (stopping) return
|
|
23
|
+
stopping = true
|
|
24
|
+
signalGroup("SIGTERM")
|
|
25
|
+
force = setTimeout(() => signalGroup("SIGKILL"), 2000)
|
|
26
|
+
}
|
|
27
|
+
const deadline = setTimeout(stop, expiresAt - Date.now())
|
|
28
|
+
process.on("SIGTERM", stop)
|
|
29
|
+
process.on("SIGINT", stop)
|
|
30
|
+
child.on("error", (error) => {
|
|
31
|
+
console.error(error.message)
|
|
32
|
+
clearTimeout(deadline)
|
|
33
|
+
process.exitCode = 1
|
|
34
|
+
})
|
|
35
|
+
child.on("exit", (code) => {
|
|
36
|
+
// Ensure descendants cannot outlive the bounded service supervisor.
|
|
37
|
+
signalGroup("SIGKILL")
|
|
38
|
+
clearTimeout(deadline)
|
|
39
|
+
clearTimeout(force)
|
|
40
|
+
process.exitCode = stopping ? 0 : (code ?? 1)
|
|
41
|
+
})
|