@downcity/agent 1.1.43 → 1.1.51
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 +6 -8
- package/bin/agent/Agent.d.ts +31 -16
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +47 -63
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/RemoteAgent.d.ts +6 -6
- package/bin/agent/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/RemoteAgent.js +377 -267
- package/bin/agent/RemoteAgent.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +4 -4
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +14 -12
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/Config.d.ts +9 -30
- package/bin/config/Config.d.ts.map +1 -1
- package/bin/config/Config.js +23 -70
- package/bin/config/Config.js.map +1 -1
- package/bin/config/Defaults.d.ts.map +1 -1
- package/bin/config/Defaults.js +1 -9
- package/bin/config/Defaults.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +3 -111
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/ExecutionBinding.d.ts +0 -15
- package/bin/config/ExecutionBinding.d.ts.map +1 -1
- package/bin/config/ExecutionBinding.js +1 -21
- package/bin/config/ExecutionBinding.js.map +1 -1
- package/bin/config/Paths.d.ts +4 -43
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +10 -30
- package/bin/config/Paths.js.map +1 -1
- package/bin/config/PlatformPaths.d.ts +0 -4
- package/bin/config/PlatformPaths.d.ts.map +1 -1
- package/bin/config/PlatformPaths.js +5 -1
- package/bin/config/PlatformPaths.js.map +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +2 -2
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/executor/types/SessionRun.d.ts +1 -1
- package/bin/index.d.ts +4 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +5 -5
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +4 -8
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/rpc/Client.d.ts +104 -0
- package/bin/rpc/Client.d.ts.map +1 -0
- package/bin/rpc/Client.js +300 -0
- package/bin/rpc/Client.js.map +1 -0
- package/bin/rpc/Server.d.ts +41 -0
- package/bin/rpc/Server.d.ts.map +1 -0
- package/bin/rpc/Server.js +164 -0
- package/bin/rpc/Server.js.map +1 -0
- package/bin/runtime/host/daemon/Api.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
- package/bin/runtime/host/daemon/Client.js +30 -20
- package/bin/runtime/host/daemon/Client.js.map +1 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
- package/bin/session/index.d.ts +1 -1
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +1 -1
- package/bin/session/index.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +0 -4
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +0 -6
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +23 -52
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/config/AgentProject.d.ts +6 -5
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +8 -66
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/config/LlmConfig.d.ts +1 -1
- package/bin/types/config/Start.d.ts +3 -0
- package/bin/types/config/Start.d.ts.map +1 -1
- package/bin/types/config/Start.js +2 -0
- package/bin/types/config/Start.js.map +1 -1
- package/bin/types/runtime/host/Store.d.ts +7 -50
- package/bin/types/runtime/host/Store.d.ts.map +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +6 -6
- package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
- package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
- package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
- package/bin/utils/Time.d.ts +0 -1
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +0 -7
- package/bin/utils/Time.js.map +1 -1
- package/bin/utils/storage/index.d.ts +0 -1
- package/bin/utils/storage/index.d.ts.map +1 -1
- package/bin/utils/storage/index.js +0 -6
- package/bin/utils/storage/index.js.map +1 -1
- package/package.json +4 -6
- package/src/agent/Agent.ts +54 -71
- package/src/agent/RemoteAgent.ts +515 -345
- package/src/config/AgentInitializer.ts +14 -12
- package/src/config/Config.ts +28 -85
- package/src/config/Defaults.ts +1 -9
- package/src/config/DowncitySchema.ts +3 -113
- package/src/config/ExecutionBinding.ts +1 -23
- package/src/config/Paths.ts +10 -43
- package/src/config/PlatformPaths.ts +5 -1
- package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +1 -1
- package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
- package/src/executor/tools/shell/ShellToolFormatting.ts +2 -2
- package/src/executor/types/SessionRun.ts +1 -1
- package/src/index.ts +7 -14
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +4 -8
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/rpc/Client.ts +467 -0
- package/src/rpc/Server.ts +302 -0
- package/src/runtime/host/daemon/Api.ts +1 -1
- package/src/runtime/host/daemon/Client.ts +44 -22
- package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
- package/src/session/index.ts +0 -1
- package/src/session/storage/Paths.ts +0 -10
- package/src/types/agent/AgentTypes.ts +23 -57
- package/src/types/config/AgentProject.ts +6 -5
- package/src/types/config/DowncityConfig.ts +8 -67
- package/src/types/config/LlmConfig.ts +1 -1
- package/src/types/config/Start.ts +3 -0
- package/src/types/runtime/host/Store.ts +7 -53
- package/src/types/runtime/platform/Platform.ts +6 -6
- package/src/types/runtime/platform/PlatformGateway.ts +2 -2
- package/src/utils/Time.ts +0 -6
- package/src/utils/storage/index.ts +0 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/ConfigEnvResolver.d.ts +0 -22
- package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
- package/bin/config/ConfigEnvResolver.js +0 -41
- package/bin/config/ConfigEnvResolver.js.map +0 -1
- package/bin/runtime/server/rpc/Server.d.ts +0 -18
- package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
- package/bin/runtime/server/rpc/Server.js +0 -315
- package/bin/runtime/server/rpc/Server.js.map +0 -1
- package/bin/runtime/transport/rpc/Client.d.ts +0 -13
- package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Client.js +0 -98
- package/bin/runtime/transport/rpc/Client.js.map +0 -1
- package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
- package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Paths.js +0 -42
- package/bin/runtime/transport/rpc/Paths.js.map +0 -1
- package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
- package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Transport.js +0 -30
- package/bin/runtime/transport/rpc/Transport.js.map +0 -1
- package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
- package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
- package/bin/types/common/ResolvedConfigValue.js +0 -2
- package/bin/types/common/ResolvedConfigValue.js.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
- package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.js +0 -9
- package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
- package/src/config/ConfigEnvResolver.ts +0 -52
- package/src/runtime/server/rpc/Server.ts +0 -408
- package/src/runtime/transport/rpc/Client.ts +0 -113
- package/src/runtime/transport/rpc/Paths.ts +0 -50
- package/src/runtime/transport/rpc/Transport.ts +0 -43
- package/src/types/common/ResolvedConfigValue.ts +0 -16
- package/src/types/runtime/rpc/LocalRpc.ts +0 -72
|
@@ -53,17 +53,19 @@ import { assertProjectExecutionTarget } from "@/config/ExecutionBinding.js";
|
|
|
53
53
|
import type { ExecutionBindingConfig } from "@/types/config/ExecutionBinding.js";
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* 规范化默认 Agent
|
|
56
|
+
* 规范化默认 Agent ID。
|
|
57
57
|
*
|
|
58
58
|
* 关键点(中文)
|
|
59
|
-
* -
|
|
60
|
-
* -
|
|
59
|
+
* - 把目录名清洗为稳定、可重复的 snake_case 标识,避免展示名语义混入 SDK。
|
|
60
|
+
* - 这里只做最小格式规整,不负责跨项目唯一性分配。
|
|
61
61
|
*/
|
|
62
|
-
export function
|
|
62
|
+
export function normalizeDefaultAgentId(input: string): string {
|
|
63
63
|
return String(input || "")
|
|
64
64
|
.trim()
|
|
65
|
-
.
|
|
66
|
-
.replace(
|
|
65
|
+
.toLowerCase()
|
|
66
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
67
|
+
.replace(/^_+|_+$/g, "")
|
|
68
|
+
.replace(/_{2,}/g, "_")
|
|
67
69
|
.trim();
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -112,8 +114,8 @@ export async function initializeAgentProject(
|
|
|
112
114
|
): Promise<AgentProjectInitializationResult> {
|
|
113
115
|
const projectRoot = path.resolve(String(input.projectRoot || "").trim() || ".");
|
|
114
116
|
const projectBaseName = path.basename(projectRoot);
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
+
const fallback_agent_id = normalizeDefaultAgentId(projectBaseName) || projectBaseName;
|
|
118
|
+
const agent_id = String(input.id || "").trim() || fallback_agent_id;
|
|
117
119
|
const execution = input.execution as ExecutionBindingConfig;
|
|
118
120
|
|
|
119
121
|
const channels = normalizeChannels(input.channels);
|
|
@@ -123,7 +125,7 @@ export async function initializeAgentProject(
|
|
|
123
125
|
const skippedFiles: string[] = [];
|
|
124
126
|
|
|
125
127
|
assertProjectExecutionTarget({
|
|
126
|
-
|
|
128
|
+
id: agent_id,
|
|
127
129
|
version: "1.0.0",
|
|
128
130
|
execution,
|
|
129
131
|
});
|
|
@@ -139,7 +141,7 @@ export async function initializeAgentProject(
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
const initTemplateVariables = {
|
|
142
|
-
|
|
144
|
+
agent_id,
|
|
143
145
|
};
|
|
144
146
|
const staticPromptFiles = [
|
|
145
147
|
{
|
|
@@ -176,7 +178,7 @@ export async function initializeAgentProject(
|
|
|
176
178
|
|
|
177
179
|
const shipConfig: DowncityConfig = {
|
|
178
180
|
$schema: DEFAULT_DOWNCITY_JSON.$schema,
|
|
179
|
-
|
|
181
|
+
id: agent_id,
|
|
180
182
|
version: "1.0.0",
|
|
181
183
|
execution,
|
|
182
184
|
plugins: {
|
|
@@ -251,7 +253,7 @@ export async function initializeAgentProject(
|
|
|
251
253
|
|
|
252
254
|
return {
|
|
253
255
|
projectRoot,
|
|
254
|
-
|
|
256
|
+
id: agent_id,
|
|
255
257
|
...(execution?.type === "api" && String(execution.modelId || "").trim()
|
|
256
258
|
? { modelId: String(execution.modelId || "").trim() }
|
|
257
259
|
: {}),
|
package/src/config/Config.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Agent 项目配置读取与装配模块。
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
|
-
* - 统一负责读取 `downcity.json`、项目 `.env`
|
|
5
|
+
* - 统一负责读取 `downcity.json`、项目 `.env` 与宿主显式注入的基础 env。
|
|
6
6
|
* - 负责把祖先目录中的多个 `downcity.json` 逐层合并成当前项目的最终配置。
|
|
7
|
-
* -
|
|
7
|
+
* - 负责在配置读取阶段完成最小结构校验。
|
|
8
8
|
*
|
|
9
9
|
* 边界说明(中文)
|
|
10
10
|
* - 这里只做“配置文件 -> 运行时配置对象”的装配,不负责项目初始化写文件。
|
|
@@ -14,61 +14,18 @@ import dotenv from "dotenv";
|
|
|
14
14
|
import fs from "fs-extra";
|
|
15
15
|
import path from "path";
|
|
16
16
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
17
|
-
import type { ResolvedConfigValue } from "@/types/common/ResolvedConfigValue.js";
|
|
18
17
|
import { assertProjectExecutionTarget } from "@/config/ExecutionBinding.js";
|
|
19
|
-
import { resolveEnvPlaceholdersDeep } from "@/config/ConfigEnvResolver.js";
|
|
20
18
|
import { deepMerge } from "@/utils/object/DeepMerge.js";
|
|
21
19
|
import { isPlainObject } from "@/utils/object/ObjectGuards.js";
|
|
22
20
|
import { collectAncestorNamedFilePaths } from "@/utils/path/AncestorFiles.js";
|
|
23
21
|
|
|
24
22
|
export type { DowncityConfig };
|
|
25
23
|
|
|
26
|
-
/**
|
|
27
|
-
* 读取平台共享环境变量(`env_entries.scope=global`)。
|
|
28
|
-
*
|
|
29
|
-
* 关键点(中文)
|
|
30
|
-
* - 当前 agent 包内仍保留空实现占位,等待后续接入平台级持久化存储。
|
|
31
|
-
* - 保持独立函数是为了让配置读取逻辑不依赖具体存储后端。
|
|
32
|
-
*/
|
|
33
|
-
export function loadGlobalEnvFromStore(): Record<string, string> {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 读取 agent 私有环境变量(`env_entries.scope=agent`)。
|
|
39
|
-
*
|
|
40
|
-
* 关键点(中文)
|
|
41
|
-
* - 当前 agent 包内仍保留空实现占位,避免把平台存储细节耦合进运行时。
|
|
42
|
-
* - 当 `agentId` 为空时直接返回空对象,表示没有可用私有环境变量。
|
|
43
|
-
*/
|
|
44
|
-
export function loadAgentEnvFromStore(agentId: string): Record<string, string> {
|
|
45
|
-
const normalizedAgentId = String(agentId || "").trim();
|
|
46
|
-
if (!normalizedAgentId) return {};
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 读取 agent 最终环境变量快照。
|
|
52
|
-
*
|
|
53
|
-
* 关键点(中文)
|
|
54
|
-
* - 来源:agent scope env(DB) + `<agent>/.env`(用户文件)。
|
|
55
|
-
* - 冲突时 `.env` 优先,满足用户可在本地即时覆盖。
|
|
56
|
-
*/
|
|
57
|
-
export function loadAgentEnvSnapshot(projectRoot: string): Record<string, string> {
|
|
58
|
-
const agentFromDb = loadAgentEnvFromStore(projectRoot);
|
|
59
|
-
const projectDotenv = loadProjectDotenv(projectRoot);
|
|
60
|
-
return {
|
|
61
|
-
...agentFromDb,
|
|
62
|
-
...projectDotenv,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
24
|
/**
|
|
67
25
|
* 读取项目 `.env` 快照(不污染全局 process.env)。
|
|
68
26
|
*
|
|
69
27
|
* 关键点(中文)
|
|
70
28
|
* - 只返回当前 agent 项目自己的 env 映射,供 runtime 局部使用。
|
|
71
|
-
* - 不再把 agent env 注入全局,避免多个 agent 在同一 control plane 进程里互相污染。
|
|
72
29
|
*/
|
|
73
30
|
export function loadProjectDotenv(projectRoot: string): Record<string, string> {
|
|
74
31
|
// 关键点(中文)
|
|
@@ -94,18 +51,31 @@ export function loadProjectDotenv(projectRoot: string): Record<string, string> {
|
|
|
94
51
|
}
|
|
95
52
|
|
|
96
53
|
/**
|
|
97
|
-
*
|
|
54
|
+
* 解析当前 agent 最终用户环境变量。
|
|
55
|
+
*
|
|
56
|
+
* 关键点(中文)
|
|
57
|
+
* - 合并顺序固定为:宿主显式 `env` < 项目 `.env`。
|
|
58
|
+
* - `@downcity/agent` 不再自动读取当前进程 `process.env`。
|
|
59
|
+
* - 这里返回的是“用户可感知”的最终 env,不包含 session/server 运行时元信息。
|
|
60
|
+
*/
|
|
61
|
+
export function resolveAgentEnv(
|
|
62
|
+
projectRoot: string,
|
|
63
|
+
hostEnv?: Record<string, string>,
|
|
64
|
+
): Record<string, string> {
|
|
65
|
+
return {
|
|
66
|
+
...(hostEnv ? { ...hostEnv } : {}),
|
|
67
|
+
...loadProjectDotenv(projectRoot),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 读取单层 `downcity.json`。
|
|
98
73
|
*
|
|
99
74
|
* 关键点(中文)
|
|
100
75
|
* - 单层读取不做字段语义校验,便于后续统一合并后再做最终断言。
|
|
101
|
-
* - 环境变量解析策略由调用方注入,保持该函数只负责“遍历 + 替换”。
|
|
102
76
|
*/
|
|
103
|
-
function readShipJsonLayer(
|
|
104
|
-
filePath
|
|
105
|
-
resolveEnvVar: (name: string) => string | undefined,
|
|
106
|
-
): ResolvedConfigValue {
|
|
107
|
-
const raw = fs.readJsonSync(filePath) as ResolvedConfigValue;
|
|
108
|
-
return resolveEnvPlaceholdersDeep(raw, resolveEnvVar);
|
|
77
|
+
function readShipJsonLayer(filePath: string): unknown {
|
|
78
|
+
return fs.readJsonSync(filePath) as unknown;
|
|
109
79
|
}
|
|
110
80
|
|
|
111
81
|
/**
|
|
@@ -117,7 +87,7 @@ function readShipJsonLayer(
|
|
|
117
87
|
*/
|
|
118
88
|
function assertNoProjectExtensionsLayer(
|
|
119
89
|
filePath: string,
|
|
120
|
-
layer:
|
|
90
|
+
layer: unknown,
|
|
121
91
|
): void {
|
|
122
92
|
if (!isPlainObject(layer)) return;
|
|
123
93
|
if (!Object.prototype.hasOwnProperty.call(layer, "extensions")) return;
|
|
@@ -131,36 +101,9 @@ function assertNoProjectExtensionsLayer(
|
|
|
131
101
|
*
|
|
132
102
|
* 关键点(中文)
|
|
133
103
|
* - 读取顺序为“祖先目录 -> 当前项目目录”,后层配置覆盖前层配置。
|
|
134
|
-
* - `.env` 只影响占位符解析,不会把值写回配置文件。
|
|
135
104
|
* - 返回前会断言最小执行目标,保证 agent 至少知道该如何执行。
|
|
136
105
|
*/
|
|
137
|
-
export function loadDowncityConfig(
|
|
138
|
-
projectRoot: string,
|
|
139
|
-
options?: {
|
|
140
|
-
projectEnv?: Record<string, string>;
|
|
141
|
-
agentEnv?: Record<string, string>;
|
|
142
|
-
globalEnv?: Record<string, string>;
|
|
143
|
-
},
|
|
144
|
-
): DowncityConfig {
|
|
145
|
-
const projectDotenv = options?.projectEnv ?? loadProjectDotenv(projectRoot);
|
|
146
|
-
const agentEnv = options?.agentEnv ?? loadAgentEnvFromStore(projectRoot);
|
|
147
|
-
const globalEnv = options?.globalEnv ?? loadGlobalEnvFromStore();
|
|
148
|
-
const runtimeAgentEnv = {
|
|
149
|
-
...agentEnv,
|
|
150
|
-
...projectDotenv,
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* 读取 agent 项目私有环境变量(services)。
|
|
154
|
-
*
|
|
155
|
-
* 关键点(中文)
|
|
156
|
-
* - project 层只读当前项目 .env,不再回退到共享 env。
|
|
157
|
-
* - 从根上杜绝跨 agent 的服务凭据串用。
|
|
158
|
-
*/
|
|
159
|
-
const resolveProjectEnvVar = (name: string): string | undefined => {
|
|
160
|
-
const projectValue = String(runtimeAgentEnv[name] || "").trim();
|
|
161
|
-
return projectValue || undefined;
|
|
162
|
-
};
|
|
163
|
-
|
|
106
|
+
export function loadDowncityConfig(projectRoot: string): DowncityConfig {
|
|
164
107
|
const ancestorShipJsonPaths = collectAncestorNamedFilePaths(
|
|
165
108
|
projectRoot,
|
|
166
109
|
"downcity.json",
|
|
@@ -171,7 +114,7 @@ export function loadDowncityConfig(
|
|
|
171
114
|
|
|
172
115
|
let merged: unknown = undefined;
|
|
173
116
|
for (const p of ancestorShipJsonPaths) {
|
|
174
|
-
const layer = readShipJsonLayer(p
|
|
117
|
+
const layer = readShipJsonLayer(p);
|
|
175
118
|
assertNoProjectExtensionsLayer(p, layer);
|
|
176
119
|
merged = deepMerge(merged, layer);
|
|
177
120
|
}
|
|
@@ -181,8 +124,8 @@ export function loadDowncityConfig(
|
|
|
181
124
|
}
|
|
182
125
|
|
|
183
126
|
const candidate = merged as Partial<DowncityConfig>;
|
|
184
|
-
if (typeof candidate.
|
|
185
|
-
throw new Error("Invalid downcity.json: missing required fields
|
|
127
|
+
if (typeof candidate.id !== "string" || typeof candidate.version !== "string") {
|
|
128
|
+
throw new Error("Invalid downcity.json: missing required fields id/version");
|
|
186
129
|
}
|
|
187
130
|
const config = candidate as DowncityConfig;
|
|
188
131
|
assertProjectExecutionTarget(config);
|
package/src/config/Defaults.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
|
21
21
|
*/
|
|
22
22
|
export const DEFAULT_DOWNCITY_JSON: DowncityConfig = {
|
|
23
23
|
$schema: "./.downcity/schema/downcity.schema.json",
|
|
24
|
-
|
|
24
|
+
id: "downcity",
|
|
25
25
|
version: "1.0.0",
|
|
26
26
|
start: {
|
|
27
27
|
port: 5314,
|
|
@@ -31,14 +31,6 @@ export const DEFAULT_DOWNCITY_JSON: DowncityConfig = {
|
|
|
31
31
|
type: "api",
|
|
32
32
|
modelId: "default",
|
|
33
33
|
},
|
|
34
|
-
context: {
|
|
35
|
-
messages: {
|
|
36
|
-
keepLastMessages: 30,
|
|
37
|
-
maxInputTokensApprox: 128000,
|
|
38
|
-
archiveOnCompact: true,
|
|
39
|
-
compactRatio: 0.5,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
34
|
plugins: {
|
|
43
35
|
chat: {
|
|
44
36
|
queue: {
|
|
@@ -30,9 +30,8 @@ export const DOWNCITY_JSON_SCHEMA: JsonObject = {
|
|
|
30
30
|
description:
|
|
31
31
|
"JSON Schema reference for editor/IDE validation (e.g. ./.downcity/schema/downcity.schema.json).",
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
id: { type: "string" },
|
|
34
34
|
version: { type: "string" },
|
|
35
|
-
description: { type: "string" },
|
|
36
35
|
start: {
|
|
37
36
|
type: "object",
|
|
38
37
|
additionalProperties: true,
|
|
@@ -47,70 +46,15 @@ export const DOWNCITY_JSON_SCHEMA: JsonObject = {
|
|
|
47
46
|
properties: {
|
|
48
47
|
type: {
|
|
49
48
|
type: "string",
|
|
50
|
-
enum: ["api"
|
|
49
|
+
enum: ["api"],
|
|
51
50
|
},
|
|
52
51
|
modelId: {
|
|
53
52
|
type: "string",
|
|
54
53
|
description:
|
|
55
54
|
"API 执行模式下绑定的平台全局模型 ID。",
|
|
56
55
|
},
|
|
57
|
-
agent: {
|
|
58
|
-
type: "object",
|
|
59
|
-
additionalProperties: true,
|
|
60
|
-
properties: {
|
|
61
|
-
type: {
|
|
62
|
-
type: "string",
|
|
63
|
-
enum: ["codex", "claude", "kimi"],
|
|
64
|
-
},
|
|
65
|
-
command: { type: "string" },
|
|
66
|
-
args: {
|
|
67
|
-
type: "array",
|
|
68
|
-
items: { type: "string" },
|
|
69
|
-
},
|
|
70
|
-
env: {
|
|
71
|
-
type: "object",
|
|
72
|
-
additionalProperties: { type: "string" },
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
required: ["type"],
|
|
76
|
-
},
|
|
77
|
-
local: {
|
|
78
|
-
type: "null",
|
|
79
|
-
description:
|
|
80
|
-
"本地执行模式不再从 execution.local 读取配置;请改为使用 plugins.lmp。",
|
|
81
|
-
},
|
|
82
56
|
},
|
|
83
|
-
required: ["type"],
|
|
84
|
-
allOf: [
|
|
85
|
-
{
|
|
86
|
-
if: {
|
|
87
|
-
properties: {
|
|
88
|
-
type: { const: "api" },
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
then: {
|
|
92
|
-
required: ["modelId"],
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
if: {
|
|
97
|
-
properties: {
|
|
98
|
-
type: { const: "acp" },
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
then: {
|
|
102
|
-
required: ["agent"],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
if: {
|
|
107
|
-
properties: {
|
|
108
|
-
type: { const: "local" },
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
then: true,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
57
|
+
required: ["type", "modelId"],
|
|
114
58
|
},
|
|
115
59
|
sandbox: {
|
|
116
60
|
type: "object",
|
|
@@ -274,44 +218,6 @@ export const DOWNCITY_JSON_SCHEMA: JsonObject = {
|
|
|
274
218
|
},
|
|
275
219
|
},
|
|
276
220
|
},
|
|
277
|
-
lmp: {
|
|
278
|
-
type: "object",
|
|
279
|
-
additionalProperties: true,
|
|
280
|
-
properties: {
|
|
281
|
-
provider: {
|
|
282
|
-
type: "string",
|
|
283
|
-
enum: ["llama"],
|
|
284
|
-
},
|
|
285
|
-
model: {
|
|
286
|
-
type: "string",
|
|
287
|
-
description:
|
|
288
|
-
"当前激活的本地模型文件名或绝对路径;相对路径默认相对 plugins.lmp.modelsDir。",
|
|
289
|
-
},
|
|
290
|
-
modelsDir: {
|
|
291
|
-
type: "string",
|
|
292
|
-
description: "本地模型目录,默认 ~/.models。",
|
|
293
|
-
},
|
|
294
|
-
command: {
|
|
295
|
-
type: "string",
|
|
296
|
-
description: "llama-server 可执行命令,默认 llama-server。",
|
|
297
|
-
},
|
|
298
|
-
args: {
|
|
299
|
-
type: "array",
|
|
300
|
-
items: { type: "string" },
|
|
301
|
-
},
|
|
302
|
-
host: { type: "string" },
|
|
303
|
-
port: { type: "integer", minimum: 1, maximum: 65535 },
|
|
304
|
-
contextSize: { type: "integer", minimum: 512, maximum: 1048576 },
|
|
305
|
-
gpuLayers: { type: "integer", minimum: -1, maximum: 65535 },
|
|
306
|
-
autoStart: { type: "boolean" },
|
|
307
|
-
installedModels: {
|
|
308
|
-
type: "array",
|
|
309
|
-
items: {
|
|
310
|
-
type: "string",
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
221
|
},
|
|
316
222
|
},
|
|
317
223
|
llm: {
|
|
@@ -369,21 +275,5 @@ export const DOWNCITY_JSON_SCHEMA: JsonObject = {
|
|
|
369
275
|
},
|
|
370
276
|
required: ["providers", "models"],
|
|
371
277
|
},
|
|
372
|
-
context: {
|
|
373
|
-
type: "object",
|
|
374
|
-
additionalProperties: true,
|
|
375
|
-
properties: {
|
|
376
|
-
messages: {
|
|
377
|
-
type: "object",
|
|
378
|
-
additionalProperties: true,
|
|
379
|
-
properties: {
|
|
380
|
-
keepLastMessages: { type: "integer", minimum: 6, maximum: 5000 },
|
|
381
|
-
maxInputTokensApprox: { type: "integer", minimum: 2000, maximum: 200000 },
|
|
382
|
-
archiveOnCompact: { type: "boolean" },
|
|
383
|
-
compactRatio: { type: "number", minimum: 0.1, maximum: 0.9 },
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
},
|
|
388
278
|
},
|
|
389
279
|
};
|
|
@@ -35,28 +35,6 @@ export function readProjectExecutionBinding(
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* 读取项目绑定的主模型 ID。
|
|
40
|
-
*
|
|
41
|
-
* 关键点(中文)
|
|
42
|
-
* - 当项目尚未声明可用执行目标时,返回空字符串而不是抛错。
|
|
43
|
-
* - 适合用于展示层或非强制校验场景读取默认值。
|
|
44
|
-
*/
|
|
45
|
-
export function readProjectPrimaryModelId(config: DowncityConfig): string {
|
|
46
|
-
const execution = readProjectExecutionBinding(config);
|
|
47
|
-
return execution ? execution.modelId : "";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 判断项目是否存在执行目标。
|
|
52
|
-
*
|
|
53
|
-
* 关键点(中文)
|
|
54
|
-
* - 该函数只判断结构是否合法,不判断目标模型是否可运行。
|
|
55
|
-
*/
|
|
56
|
-
export function hasProjectExecutionTarget(config: DowncityConfig): boolean {
|
|
57
|
-
return readProjectExecutionBinding(config) !== null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
38
|
/**
|
|
61
39
|
* 断言项目已经声明执行目标。
|
|
62
40
|
*
|
|
@@ -65,7 +43,7 @@ export function hasProjectExecutionTarget(config: DowncityConfig): boolean {
|
|
|
65
43
|
* - 失败时抛出稳定错误文案,便于 CLI 和上层界面直接展示。
|
|
66
44
|
*/
|
|
67
45
|
export function assertProjectExecutionTarget(config: DowncityConfig): void {
|
|
68
|
-
if (
|
|
46
|
+
if (readProjectExecutionBinding(config) !== null) return;
|
|
69
47
|
throw new Error(
|
|
70
48
|
'Invalid downcity.json: "execution" is required and must be { "type": "api", "modelId": "..." }',
|
|
71
49
|
);
|
package/src/config/Paths.ts
CHANGED
|
@@ -127,6 +127,10 @@ export function getCacheDirPath(cwd: string): string {
|
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* 返回 profile 运行态目录路径。
|
|
130
|
+
*
|
|
131
|
+
* 关键点(中文)
|
|
132
|
+
* - 初始化流程会统一创建该目录,并在其中写入 profile 相关文件。
|
|
133
|
+
* - 单独保留目录级 API,避免调用方散落 `path.join(..., "profile")`。
|
|
130
134
|
*/
|
|
131
135
|
export function getDowncityProfileDirPath(cwd: string): string {
|
|
132
136
|
return path.join(getDowncityDirPath(cwd), "profile");
|
|
@@ -157,8 +161,9 @@ export function getDowncityProfileOtherPath(cwd: string): string {
|
|
|
157
161
|
*
|
|
158
162
|
* 关键点(中文)
|
|
159
163
|
* - `.downcity/memory` 为跨会话记忆目录。
|
|
164
|
+
* - 当前仅供本模块内部继续拼接长期记忆与每日记忆路径。
|
|
160
165
|
*/
|
|
161
|
-
|
|
166
|
+
function getDowncityMemoryDirPath(cwd: string): string {
|
|
162
167
|
return path.join(getDowncityDirPath(cwd), "memory");
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -216,8 +221,9 @@ export function getDowncityAgentsRootDirPath(cwd: string): string {
|
|
|
216
221
|
*
|
|
217
222
|
* 关键点(中文)
|
|
218
223
|
* - `agentId` 会做 URL 编码,避免特殊字符污染文件系统结构。
|
|
224
|
+
* - 当前仅供本模块内部拼接 session 根目录使用。
|
|
219
225
|
*/
|
|
220
|
-
|
|
226
|
+
function getDowncityAgentDirPath(cwd: string, agentId: string): string {
|
|
221
227
|
return path.join(
|
|
222
228
|
getDowncityAgentsRootDirPath(cwd),
|
|
223
229
|
encodeURIComponent(String(agentId || "").trim()),
|
|
@@ -283,23 +289,6 @@ export function getDowncitySessionMessagesPath(
|
|
|
283
289
|
);
|
|
284
290
|
}
|
|
285
291
|
|
|
286
|
-
/**
|
|
287
|
-
* 返回 session 历史元信息文件路径。
|
|
288
|
-
*
|
|
289
|
-
* 关键点(中文)
|
|
290
|
-
* - 该文件保存 compaction、更新时间、SDK 配置等附加元信息。
|
|
291
|
-
*/
|
|
292
|
-
export function getDowncitySessionHistoryMetaPath(
|
|
293
|
-
cwd: string,
|
|
294
|
-
agentId: string,
|
|
295
|
-
sessionId: string,
|
|
296
|
-
): string {
|
|
297
|
-
return path.join(
|
|
298
|
-
getDowncitySessionMessagesDirPath(cwd, agentId, sessionId),
|
|
299
|
-
"meta.json",
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
292
|
/**
|
|
304
293
|
* 返回 session 消息归档目录路径。
|
|
305
294
|
*
|
|
@@ -368,8 +357,9 @@ export function getDowncityDebugDirPath(cwd: string): string {
|
|
|
368
357
|
* 关键点(中文)
|
|
369
358
|
* - 该目录存放 `sessionId -> chat` 的最近映射快照
|
|
370
359
|
* - 与 core session messages 分离,避免把平台路由细节耦合进 core
|
|
360
|
+
* - 当前仅供本模块内部继续拼接 chat 会话与 meta 子目录。
|
|
371
361
|
*/
|
|
372
|
-
|
|
362
|
+
function getDowncityChatDirPath(cwd: string): string {
|
|
373
363
|
return path.join(getDowncityDirPath(cwd), "chat");
|
|
374
364
|
}
|
|
375
365
|
|
|
@@ -394,29 +384,6 @@ export function getDowncityChannelMetaPath(cwd: string): string {
|
|
|
394
384
|
return path.join(getDowncityChannelDirPath(cwd), "meta.json");
|
|
395
385
|
}
|
|
396
386
|
|
|
397
|
-
/**
|
|
398
|
-
* 返回 chat 元信息目录路径。
|
|
399
|
-
*
|
|
400
|
-
* 关键点(中文)
|
|
401
|
-
* - 用于按 sessionId 存放最近聊天路由快照与附加索引信息。
|
|
402
|
-
*/
|
|
403
|
-
export function getDowncityChatMetaDirPath(cwd: string): string {
|
|
404
|
-
return path.join(getDowncityChatDirPath(cwd), "meta");
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* 返回指定 session 的 chat 元信息文件路径。
|
|
409
|
-
*
|
|
410
|
-
* 关键点(中文)
|
|
411
|
-
* - 文件名按 `sessionId` 编码,避免不同会话之间互相覆盖。
|
|
412
|
-
*/
|
|
413
|
-
export function getDowncityChatMetaPath(cwd: string, sessionId: string): string {
|
|
414
|
-
return path.join(
|
|
415
|
-
getDowncityChatMetaDirPath(cwd),
|
|
416
|
-
`${encodeURIComponent(String(sessionId || "").trim())}.json`,
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
387
|
/**
|
|
421
388
|
* Chat 会话目录(按 sessionId 组织)。
|
|
422
389
|
*
|
|
@@ -30,8 +30,12 @@ export function getPlatformRootDirPath(): string {
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* 返回平台级运行目录。
|
|
33
|
+
*
|
|
34
|
+
* 关键点(中文)
|
|
35
|
+
* - 当前仅供本模块内部拼接平台级派生路径使用。
|
|
36
|
+
* - 不再对外导出,避免暴露未被实际消费的路径 API。
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
function getPlatformRuntimeDirPath(): string {
|
|
35
39
|
return path.join(getPlatformRootDirPath(), "main");
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Source: src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "# 档案\n\n## 基本信息\n\n-
|
|
7
|
+
const TEXT_MODULE_CONTENT = "# 档案\n\n## 基本信息\n\n- ID:`{{agent_id}}`\n- 身份:长期协作型助手\n- 关系:用户的合作者,不是用户的替身\n\n## 角色定位\n\n- 你负责理解目标、拆解问题、推动落地。\n\n## 身份边界\n\n- 可访问的信息不等于可传播的信息,隐私默认保密。\n- 坚持真实与可验证,不伪造结论、不编造事实。\n\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -75,8 +75,8 @@ export function buildShellContextEnv(
|
|
|
75
75
|
|
|
76
76
|
applyEnvMap(env, injected);
|
|
77
77
|
setEnvString(env, "DC_SESSION_ID", contextCtx?.sessionId);
|
|
78
|
-
setEnvString(env, "
|
|
79
|
-
setEnvString(env, "
|
|
78
|
+
setEnvString(env, "DC_CITY_HOST", process.env.DC_CITY_HOST);
|
|
79
|
+
setEnvString(env, "DC_CITY_PORT", process.env.DC_CITY_PORT);
|
|
80
80
|
stripInvocationAuthEnv(env);
|
|
81
81
|
|
|
82
82
|
return env;
|
|
@@ -65,7 +65,7 @@ export type SessionAssistantStepCallback = (
|
|
|
65
65
|
*
|
|
66
66
|
* 关键点(中文)
|
|
67
67
|
* - 这里直接复用 AI SDK 的 `UIMessageChunk` 结构,避免在 session 内核层再复制一套协议。
|
|
68
|
-
* - SDK / HTTP
|
|
68
|
+
* - SDK / HTTP 若需要自己的事件模型,应在更上层做映射。
|
|
69
69
|
*/
|
|
70
70
|
export type SessionUiMessageChunk = UIMessageChunk;
|
|
71
71
|
|