Skip to content

Commit 6bfaa48

Browse files
committed
feat(server): headless 复用入口与 server-mode 加固 (server-v1 §13/§20.4)
- package.json 显式导出 ./server 子路径 (listen/openapi 稳定入口) - /global/capabilities 增加 commit 字段 (DEEPAGENT_CODE_COMMIT, CI 注入) - DEEPAGENT_SERVER_MODE=true 时 Auth.set/remove fail-close, 禁 key 落盘
1 parent c2eadad commit 6bfaa48

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

packages/core/src/flag/flag.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export const Flag = {
3030
DEEPAGENT_CODE_FAKE_VCS: process.env["DEEPAGENT_CODE_FAKE_VCS"],
3131
DEEPAGENT_CODE_SERVER_PASSWORD: process.env["DEEPAGENT_CODE_SERVER_PASSWORD"],
3232
DEEPAGENT_CODE_SERVER_USERNAME: process.env["DEEPAGENT_CODE_SERVER_USERNAME"],
33+
// Server Edition: CI injects the deepagent-code commit into workspace images so
34+
// the gateway can report/version-check the data plane (server-v1 §13.3).
35+
DEEPAGENT_CODE_COMMIT: process.env["DEEPAGENT_CODE_COMMIT"],
36+
// Server Edition: when running inside a gateway-managed workspace container,
37+
// provider keys are injected via env and must not persist to the volume (§20.4).
38+
DEEPAGENT_SERVER_MODE: truthy("DEEPAGENT_SERVER_MODE"),
3339

3440
// Experimental
3541
DEEPAGENT_CODE_EXPERIMENTAL_FILEWATCHER: Config.boolean("DEEPAGENT_CODE_EXPERIMENTAL_FILEWATCHER").pipe(

packages/deepagent-code/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"deepagent": "./bin/deepagent"
2222
},
2323
"exports": {
24+
"./server": "./src/server/server.ts",
2425
"./*": "./src/*.ts"
2526
},
2627
"imports": {

packages/deepagent-code/src/auth/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import { Effect, Layer, Record, Result, Schema, Context } from "effect"
33
import { NonNegativeInt } from "@deepagent-code/core/schema"
44
import { Global } from "@deepagent-code/core/global"
5+
import { Flag } from "@deepagent-code/core/flag/flag"
56
import { FSUtil } from "@deepagent-code/core/fs-util"
67

78
export const OAUTH_DUMMY_KEY = "deepagent-code-oauth-dummy-key"
@@ -70,6 +71,13 @@ export const layer = Layer.effect(
7071
})
7172

7273
const set = Effect.fn("Auth.set")(function* (key: string, info: Info) {
74+
// Server Edition (§20.4): gateway-managed containers receive provider keys
75+
// via env injection; persisting them to the workspace volume is forbidden.
76+
if (Flag.DEEPAGENT_SERVER_MODE)
77+
return yield* new AuthError({
78+
message:
79+
"Provider credentials are managed by the gateway in server mode; persisting auth.json is disabled (DEEPAGENT_SERVER_MODE)",
80+
})
7381
const norm = key.replace(/\/+$/, "")
7482
const data = yield* all()
7583
if (norm !== key) delete data[key]
@@ -80,6 +88,11 @@ export const layer = Layer.effect(
8088
})
8189

8290
const remove = Effect.fn("Auth.remove")(function* (key: string) {
91+
if (Flag.DEEPAGENT_SERVER_MODE)
92+
return yield* new AuthError({
93+
message:
94+
"Provider credentials are managed by the gateway in server mode; modifying auth.json is disabled (DEEPAGENT_SERVER_MODE)",
95+
})
8396
const norm = key.replace(/\/+$/, "")
8497
const data = yield* all()
8598
delete data[key]

packages/deepagent-code/src/server/routes/instance/httpapi/groups/global.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const GlobalHealth = Schema.Struct({
2424
const GlobalCapabilities = Schema.Struct({
2525
protocolVersion: Schema.String,
2626
version: Schema.String,
27+
// deepagent-code commit the data plane was built from; only present when CI
28+
// injected DEEPAGENT_CODE_COMMIT (workspace images), absent on local builds.
29+
commit: Schema.optional(Schema.String),
2730
features: Schema.Struct({
2831
im: Schema.Boolean,
2932
sessions: Schema.Boolean,

packages/deepagent-code/src/server/routes/instance/httpapi/handlers/global.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EventV2 } from "@deepagent-code/core/event"
66
import { Installation } from "@/installation"
77
import { disposeAllInstancesAndEmitGlobalDisposed, disposeInstancesForDirectories } from "@/server/global-lifecycle"
88
import { InstallationVersion } from "@deepagent-code/core/installation/version"
9+
import { Flag } from "@deepagent-code/core/flag/flag"
910
import { IM_PROTOCOL_VERSION } from "@deepagent-code/core/im/protocol"
1011
import * as Log from "@deepagent-code/core/util/log"
1112
import { Effect, Queue, Schema } from "effect"
@@ -91,6 +92,7 @@ export const globalHandlers = HttpApiBuilder.group(RootHttpApi, "global", (handl
9192
return {
9293
protocolVersion: IM_PROTOCOL_VERSION,
9394
version: InstallationVersion,
95+
commit: Flag.DEEPAGENT_CODE_COMMIT,
9496
features: {
9597
im: true,
9698
sessions: true,

0 commit comments

Comments
 (0)