@downcity/agent 1.1.43 → 1.1.62
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 +11 -12
- 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 +5 -5
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +15 -13
- 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 +4 -112
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/ExecutionBinding.d.ts +1 -16
- package/bin/config/ExecutionBinding.d.ts.map +1 -1
- package/bin/config/ExecutionBinding.js +2 -22
- 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/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +0 -4
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/composer/system/default/InitPrompts.d.ts +1 -1
- package/bin/executor/composer/system/default/InitPrompts.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +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/composer/system/default/assets/plugin.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +1 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +17 -56
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts +2 -2
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +9 -9
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts +7 -75
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +5 -24
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/executor/types/SessionRun.d.ts +1 -1
- package/bin/index.d.ts +5 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +6 -5
- package/bin/index.js.map +1 -1
- package/bin/model/CityModelAdapter.d.ts +23 -0
- package/bin/model/CityModelAdapter.d.ts.map +1 -0
- package/bin/model/CityModelAdapter.js +338 -0
- package/bin/model/CityModelAdapter.js.map +1 -0
- 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/host/daemon/Paths.d.ts +1 -1
- package/bin/runtime/host/daemon/Paths.js +1 -1
- package/bin/runtime/host/daemon/ProjectSetup.js +2 -2
- package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
- package/bin/session/Session.d.ts +1 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +32 -6
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +49 -0
- package/bin/session/SessionTitle.d.ts.map +1 -0
- package/bin/session/SessionTitle.js +130 -0
- package/bin/session/SessionTitle.js.map +1 -0
- package/bin/session/browse/Browse.d.ts +2 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +18 -15
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +3 -2
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +3 -2
- package/bin/session/index.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +4 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +12 -25
- package/bin/session/storage/Metadata.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/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +1 -4
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +32 -57
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/config/AgentProject.d.ts +7 -6
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +11 -69
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/config/ExecutionBinding.d.ts +4 -4
- package/bin/types/config/ExecutionBinding.js +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/auth/AuthPermission.js +2 -2
- package/bin/types/runtime/auth/AuthPermission.js.map +1 -1
- package/bin/types/runtime/host/Store.d.ts +10 -227
- package/bin/types/runtime/host/Store.d.ts.map +1 -1
- package/bin/types/runtime/host/Store.js +7 -0
- package/bin/types/runtime/host/Store.js.map +1 -1
- package/bin/types/runtime/http/InlineInstant.d.ts +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +7 -7
- 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 +22 -23
- package/src/agent/Agent.ts +57 -73
- package/src/agent/RemoteAgent.ts +515 -345
- package/src/config/AgentInitializer.ts +15 -13
- package/src/config/Config.ts +28 -85
- package/src/config/Defaults.ts +1 -9
- package/src/config/DowncitySchema.ts +4 -114
- package/src/config/ExecutionBinding.ts +2 -24
- package/src/config/Paths.ts +10 -43
- package/src/config/PlatformPaths.ts +5 -1
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +0 -4
- package/src/executor/composer/system/default/InitPrompts.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -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/composer/system/default/assets/plugin.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +18 -18
- package/src/executor/composer/system/default/assets/task.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +1 -1
- package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +17 -57
- package/src/executor/tools/shell/ShellToolBridge.ts +1 -1
- package/src/executor/tools/shell/ShellToolFormatting.ts +9 -9
- package/src/executor/types/SessionHistoryMeta.ts +5 -25
- package/src/executor/types/SessionRun.ts +1 -1
- package/src/index.ts +12 -19
- package/src/model/CityModelAdapter.ts +384 -0
- 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/host/daemon/Paths.ts +1 -1
- package/src/runtime/host/daemon/ProjectSetup.ts +2 -2
- package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
- package/src/session/Session.ts +40 -6
- package/src/session/SessionTitle.ts +192 -0
- package/src/session/browse/Browse.ts +22 -13
- package/src/session/index.ts +5 -1
- package/src/session/storage/Metadata.ts +14 -29
- package/src/session/storage/Paths.ts +0 -10
- package/src/session/storage/Persistence.ts +1 -4
- package/src/types/agent/AgentTypes.ts +33 -62
- package/src/types/config/AgentProject.ts +7 -6
- package/src/types/config/DowncityConfig.ts +11 -70
- package/src/types/config/ExecutionBinding.ts +4 -4
- package/src/types/config/LlmConfig.ts +1 -1
- package/src/types/config/Start.ts +3 -0
- package/src/types/runtime/auth/AuthPermission.ts +2 -2
- package/src/types/runtime/host/Store.ts +10 -235
- package/src/types/runtime/http/InlineInstant.ts +1 -1
- package/src/types/runtime/platform/Platform.ts +7 -7
- 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.json +1 -0
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Agent 项目初始化模块。
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
|
-
* - CLI `
|
|
5
|
+
* - CLI `town agent create` 与 Console 共用同一套初始化逻辑,避免模板与目录结构分叉。
|
|
6
6
|
* - 负责创建项目骨架、静态 prompt、默认 `downcity.json`、基础目录与 schema 文件。
|
|
7
7
|
* - 负责把用户在创建阶段提供的最小执行配置与渠道配置写入项目。
|
|
8
8
|
*
|
|
@@ -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
|
-
"API
|
|
56
|
-
},
|
|
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。",
|
|
54
|
+
"API 执行模式下绑定的 City AIService 模型 ID。",
|
|
81
55
|
},
|
|
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
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 让初始化、配置装配、运行时启动都复用同一套执行目标解释规则。
|
|
8
8
|
*
|
|
9
9
|
* 边界说明(中文)
|
|
10
|
-
* -
|
|
10
|
+
* - 这里只解析配置结构,不负责验证模型是否真实存在于 City AIService 中。
|
|
11
11
|
* - 当前只接受 agent 包已经落地支持的执行绑定格式。
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -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
|
|
|
@@ -191,10 +191,6 @@ export async function compactSessionMessagesIfNeeded(
|
|
|
191
191
|
await deps.writeMetaUnsafe({
|
|
192
192
|
...prevMeta,
|
|
193
193
|
updatedAt: Date.now(),
|
|
194
|
-
lastArchiveId: params.archiveOnCompact ? archiveId : undefined,
|
|
195
|
-
keepLastMessages: Math.max(1, currentKept.length),
|
|
196
|
-
maxInputTokensApprox: params.maxInputTokensApprox,
|
|
197
|
-
compactRatio,
|
|
198
194
|
});
|
|
199
195
|
});
|
|
200
196
|
|
|
@@ -74,7 +74,7 @@ export function buildContextSystemPrompt(input: {
|
|
|
74
74
|
const outputRules = [
|
|
75
75
|
"Task-run output rules:",
|
|
76
76
|
"- This is a task execution context, not an interactive chat turn.",
|
|
77
|
-
"- Do NOT send external channel messages via `
|
|
77
|
+
"- Do NOT send external channel messages via `town chat send` unless explicitly required by the task itself.",
|
|
78
78
|
"- Reply with result-oriented content; do NOT paste raw tool outputs or JSON logs.",
|
|
79
79
|
"- Keep output compact and avoid unnecessary conversational fillers.",
|
|
80
80
|
].join("\n");
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Source: src/executor/composer/system/default/assets/core.prompt.ts.txt
|
|
7
|
-
const TEXT_MODULE_CONTENT = "你拥有且仅拥有当前项目 {{project_path}} 的使用权和修改权。当前年份是 {{current_year}} 年。\n1. `.downcity/` 是 Downcity 的运行时数据目录(通常不需要你手动读取/修改;系统会自动写入与注入)。结构与逻辑如下:\n - `.downcity/agents/<agentId>/sessions/` 是会话消息。\n - `.downcity/memory/` 是中长期记忆。\n - `.downcity/profile/Primary.md`、`.downcity/profile/other.md`:全局 profile 记忆;存在时会自动作为 system prompt 注入。\n - `.downcity/public/`:对外静态资源目录,通过 `GET /downcity/public/<path>` 访问;用于给外部访问的路径。不要存放敏感信息,运行中的 agent server 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(daemon pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n2. PROFILE.md + SOUL.md + downcity.json 是你的一些配置文件,你不需要读取。\n\n# 最重要\n【关于命令执行工具】(重要)\n- 短命令、一次性命令优先使用 `shell_exec`。\n- 长任务、需要中途查状态、需要 stdin 交互时,使用 `shell_start` / `shell_status` / `shell_read` / `shell_write` / `shell_wait` / `shell_close`。\n- 先用 `shell_start` 启动命令并拿到 `shell_id`。\n- `shell_id` 是 shell 会话标识;它不是 chat `session_id`。\n- 长任务期间,优先使用 `shell_status` 查询进度,或使用 `shell_wait` 等待状态变化;不要自己写高频空轮询循环。\n- 只有在确实需要原始增量输出时,才使用 `shell_read` 按 `from_cursor` 继续读取。\n- 需要向进程 stdin 输入内容时,使用 `shell_write`。\n- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。\n- 不要把原始超长 shell 输出直接转发给用户,应先总结。\n\n# 默认决策与澄清\n- 默认先执行,再沟通:对低风险、可回滚、用户意图已经足够明显的请求,优先基于当前日期、时区、聊天上下文与常见默认值直接执行,不要在事件标题、默认平台、显然的时间表达上反复追问。\n- 只有当“缺失信息会实质改变结果”时才追问;例如:会影响日期/对象/金额/账户/发送目标,或会触发不可逆、高风险、涉隐私操作。\n- 处理时间表达时,优先使用当前环境提供的 `current_date`、`current_time` 与 `timezone`;如果入站 `<info>` 明确提供了 `user_timezone`,则优先按 `user_timezone` 解析,否则按 runtime clock 的 `timezone` 解析。像“今天/明天/下午两点/提前两小时”这类表达,应先解析为绝对时间,再执行,并在回复里明确写出绝对日期时间。\n- 当任务依赖外部权限、系统能力或第三方连接(如日历、提醒事项、聊天渠道、系统授权)时,先探测可用性,再决定是否承诺“我来创建/发送/写入”。\n- 如果探测结果显示被系统权限、宿主环境或连接状态阻塞,要直接说明真实阻塞点和下一步,而不是先给出“可以,我来做”的承诺后再多轮追问。\n- 若已经有足够信息可以一次完成多个低风险默认动作,应直接完成,并在结果里简短说明采用了哪些默认假设。\n\n# 很重要\n\n安全与边界\n- 不要执行破坏性命令(如 `rm -rf`、`git reset --hard`)除非用户明确要求。\n- 遇到 API Key、Token、Secret、环境变量、bot 凭据等密钥管理问题时,优先指导用户使用 Console(如 `Global / Env`、`Global / Channel Accounts`)维护,不要要求用户把密钥明文直接发送到当前聊天里。\n- `
|
|
7
|
+
const TEXT_MODULE_CONTENT = "你拥有且仅拥有当前项目 {{project_path}} 的使用权和修改权。当前年份是 {{current_year}} 年。\n1. `.downcity/` 是 Downcity 的运行时数据目录(通常不需要你手动读取/修改;系统会自动写入与注入)。结构与逻辑如下:\n - `.downcity/agents/<agentId>/sessions/` 是会话消息。\n - `.downcity/memory/` 是中长期记忆。\n - `.downcity/profile/Primary.md`、`.downcity/profile/other.md`:全局 profile 记忆;存在时会自动作为 system prompt 注入。\n - `.downcity/public/`:对外静态资源目录,通过 `GET /downcity/public/<path>` 访问;用于给外部访问的路径。不要存放敏感信息,运行中的 agent server 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(daemon pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n2. PROFILE.md + SOUL.md + downcity.json 是你的一些配置文件,你不需要读取。\n\n# 最重要\n【关于命令执行工具】(重要)\n- 短命令、一次性命令优先使用 `shell_exec`。\n- 长任务、需要中途查状态、需要 stdin 交互时,使用 `shell_start` / `shell_status` / `shell_read` / `shell_write` / `shell_wait` / `shell_close`。\n- 先用 `shell_start` 启动命令并拿到 `shell_id`。\n- `shell_id` 是 shell 会话标识;它不是 chat `session_id`。\n- 长任务期间,优先使用 `shell_status` 查询进度,或使用 `shell_wait` 等待状态变化;不要自己写高频空轮询循环。\n- 只有在确实需要原始增量输出时,才使用 `shell_read` 按 `from_cursor` 继续读取。\n- 需要向进程 stdin 输入内容时,使用 `shell_write`。\n- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。\n- 不要把原始超长 shell 输出直接转发给用户,应先总结。\n\n# 默认决策与澄清\n- 默认先执行,再沟通:对低风险、可回滚、用户意图已经足够明显的请求,优先基于当前日期、时区、聊天上下文与常见默认值直接执行,不要在事件标题、默认平台、显然的时间表达上反复追问。\n- 只有当“缺失信息会实质改变结果”时才追问;例如:会影响日期/对象/金额/账户/发送目标,或会触发不可逆、高风险、涉隐私操作。\n- 处理时间表达时,优先使用当前环境提供的 `current_date`、`current_time` 与 `timezone`;如果入站 `<info>` 明确提供了 `user_timezone`,则优先按 `user_timezone` 解析,否则按 runtime clock 的 `timezone` 解析。像“今天/明天/下午两点/提前两小时”这类表达,应先解析为绝对时间,再执行,并在回复里明确写出绝对日期时间。\n- 当任务依赖外部权限、系统能力或第三方连接(如日历、提醒事项、聊天渠道、系统授权)时,先探测可用性,再决定是否承诺“我来创建/发送/写入”。\n- 如果探测结果显示被系统权限、宿主环境或连接状态阻塞,要直接说明真实阻塞点和下一步,而不是先给出“可以,我来做”的承诺后再多轮追问。\n- 若已经有足够信息可以一次完成多个低风险默认动作,应直接完成,并在结果里简短说明采用了哪些默认假设。\n\n# 很重要\n\n安全与边界\n- 不要执行破坏性命令(如 `rm -rf`、`git reset --hard`)除非用户明确要求。\n- 遇到 API Key、Token、Secret、环境变量、bot 凭据等密钥管理问题时,优先指导用户使用 Console(如 `Global / Env`、`Global / Channel Accounts`)维护,不要要求用户把密钥明文直接发送到当前聊天里。\n- `town keys` 只能列出已配置的 key 名与描述,不会返回密钥值。不要让用户把密钥“发给你自己”或继续尝试通过 `town keys` 获取明文。\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
安全与边界
|
|
37
37
|
- 不要执行破坏性命令(如 `rm -rf`、`git reset --hard`)除非用户明确要求。
|
|
38
38
|
- 遇到 API Key、Token、Secret、环境变量、bot 凭据等密钥管理问题时,优先指导用户使用 Console(如 `Global / Env`、`Global / Channel Accounts`)维护,不要要求用户把密钥明文直接发送到当前聊天里。
|
|
39
|
-
- `
|
|
39
|
+
- `town keys` 只能列出已配置的 key 名与描述,不会返回密钥值。不要让用户把密钥“发给你自己”或继续尝试通过 `town keys` 获取明文。
|
|
@@ -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;
|