@downcity/agent 1.1.210 → 1.1.215

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.
Files changed (112) hide show
  1. package/README.md +3 -3
  2. package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -1
  3. package/bin/agent/local/AgentRuntimeAssembly.js +2 -2
  4. package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -1
  5. package/bin/agent/local/ProjectSetup.d.ts +0 -1
  6. package/bin/agent/local/ProjectSetup.d.ts.map +1 -1
  7. package/bin/agent/local/ProjectSetup.js +4 -17
  8. package/bin/agent/local/ProjectSetup.js.map +1 -1
  9. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  10. package/bin/agent/local/services/AgentAssemblyService.js +6 -11
  11. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  12. package/bin/config/AgentEnv.d.ts +9 -0
  13. package/bin/config/AgentEnv.d.ts.map +1 -0
  14. package/bin/config/AgentEnv.js +48 -0
  15. package/bin/config/AgentEnv.js.map +1 -0
  16. package/bin/config/AgentInitializer.d.ts +2 -10
  17. package/bin/config/AgentInitializer.d.ts.map +1 -1
  18. package/bin/config/AgentInitializer.js +17 -49
  19. package/bin/config/AgentInitializer.js.map +1 -1
  20. package/bin/config/EnvFile.d.ts +1 -1
  21. package/bin/config/EnvFile.js +1 -1
  22. package/bin/config/ExecutionBinding.d.ts +1 -1
  23. package/bin/config/ExecutionBinding.js +2 -2
  24. package/bin/config/ExecutionBinding.js.map +1 -1
  25. package/bin/config/Paths.d.ts +0 -66
  26. package/bin/config/Paths.d.ts.map +1 -1
  27. package/bin/config/Paths.js +0 -80
  28. package/bin/config/Paths.js.map +1 -1
  29. package/bin/index.d.ts +4 -5
  30. package/bin/index.d.ts.map +1 -1
  31. package/bin/index.js +2 -3
  32. package/bin/index.js.map +1 -1
  33. package/bin/plugin/core/PluginLocalExecution.js +2 -2
  34. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  35. package/bin/session/runtime/SessionPromptRuntime.d.ts +14 -0
  36. package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
  37. package/bin/session/runtime/SessionPromptRuntime.js +11 -0
  38. package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
  39. package/bin/session/services/SessionTurnService.d.ts.map +1 -1
  40. package/bin/session/services/SessionTurnService.js +9 -0
  41. package/bin/session/services/SessionTurnService.js.map +1 -1
  42. package/bin/types/agent/AgentOptions.d.ts +12 -3
  43. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  44. package/bin/types/common/EnvFile.d.ts +1 -1
  45. package/bin/types/common/EnvFile.js +1 -1
  46. package/bin/types/config/DowncityConfig.d.ts +3 -21
  47. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  48. package/bin/types/config/ExecutionBinding.d.ts +1 -1
  49. package/bin/types/config/ExecutionBinding.js +1 -1
  50. package/bin/types/runtime/platform/Platform.d.ts +4 -12
  51. package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
  52. package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -122
  53. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
  54. package/bin/types/runtime/platform/PlatformGateway.js +0 -7
  55. package/bin/types/runtime/platform/PlatformGateway.js.map +1 -1
  56. package/bin/utils/logger/FormatRequest.js +1 -1
  57. package/bin/utils/logger/FormatRequest.js.map +1 -1
  58. package/package.json +3 -3
  59. package/scripts/agent-env.test.mjs +101 -0
  60. package/scripts/session-prompt-runtime.test.mjs +22 -0
  61. package/src/agent/local/AgentRuntimeAssembly.ts +4 -2
  62. package/src/agent/local/ProjectSetup.ts +3 -22
  63. package/src/agent/local/services/AgentAssemblyService.ts +6 -10
  64. package/src/config/AgentEnv.ts +49 -0
  65. package/src/config/AgentInitializer.ts +18 -61
  66. package/src/config/EnvFile.ts +1 -1
  67. package/src/config/ExecutionBinding.ts +2 -2
  68. package/src/config/Paths.ts +0 -89
  69. package/src/index.ts +12 -16
  70. package/src/plugin/core/PluginLocalExecution.ts +2 -2
  71. package/src/session/runtime/SessionPromptRuntime.ts +29 -4
  72. package/src/session/services/SessionTurnService.ts +9 -0
  73. package/src/types/agent/AgentOptions.ts +13 -3
  74. package/src/types/common/EnvFile.ts +1 -1
  75. package/src/types/config/DowncityConfig.ts +3 -22
  76. package/src/types/config/ExecutionBinding.ts +1 -1
  77. package/src/types/runtime/platform/Platform.ts +4 -14
  78. package/src/types/runtime/platform/PlatformGateway.ts +2 -138
  79. package/src/utils/logger/FormatRequest.ts +1 -1
  80. package/tsconfig.tsbuildinfo +1 -1
  81. package/bin/config/Config.d.ts +0 -27
  82. package/bin/config/Config.d.ts.map +0 -1
  83. package/bin/config/Config.js +0 -128
  84. package/bin/config/Config.js.map +0 -1
  85. package/bin/executor/composer/system/default/InitPromptAssets.d.ts +0 -16
  86. package/bin/executor/composer/system/default/InitPromptAssets.d.ts.map +0 -1
  87. package/bin/executor/composer/system/default/InitPromptAssets.js +0 -18
  88. package/bin/executor/composer/system/default/InitPromptAssets.js.map +0 -1
  89. package/bin/executor/composer/system/default/InitPrompts.d.ts +0 -9
  90. package/bin/executor/composer/system/default/InitPrompts.d.ts.map +0 -1
  91. package/bin/executor/composer/system/default/InitPrompts.js +0 -9
  92. package/bin/executor/composer/system/default/InitPrompts.js.map +0 -1
  93. package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts +0 -50
  94. package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts.map +0 -1
  95. package/bin/executor/composer/system/default/StaticPromptCatalog.js +0 -227
  96. package/bin/executor/composer/system/default/StaticPromptCatalog.js.map +0 -1
  97. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +0 -7
  98. package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +0 -1
  99. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +0 -8
  100. package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +0 -1
  101. package/bin/executor/composer/system/default/assets/init/SOUL.md.d.ts +0 -7
  102. package/bin/executor/composer/system/default/assets/init/SOUL.md.d.ts.map +0 -1
  103. package/bin/executor/composer/system/default/assets/init/SOUL.md.js +0 -8
  104. package/bin/executor/composer/system/default/assets/init/SOUL.md.js.map +0 -1
  105. package/src/config/Config.ts +0 -146
  106. package/src/executor/composer/system/default/InitPromptAssets.ts +0 -20
  107. package/src/executor/composer/system/default/InitPrompts.ts +0 -11
  108. package/src/executor/composer/system/default/StaticPromptCatalog.ts +0 -291
  109. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +0 -9
  110. package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +0 -16
  111. package/src/executor/composer/system/default/assets/init/SOUL.md.ts +0 -9
  112. package/src/executor/composer/system/default/assets/init/SOUL.md.ts.txt +0 -87
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 职责说明(中文)
5
5
  * - CLI `downcity agent create` 与 Console 共用同一套初始化逻辑,避免模板与目录结构分叉。
6
- * - 负责创建项目骨架、静态 prompt、基础目录与 schema 文件。
6
+ * - 负责创建项目运行目录、项目 `.env` Skills 目录。
7
7
  * - CLI 侧运行配置应写入宿主配置存储,不再由 SDK 初始化器写项目配置文件。
8
8
  *
9
9
  * 边界说明(中文)
@@ -17,8 +17,6 @@ import {
17
17
  getCacheDirPath,
18
18
  getDowncityAgentsRootDirPath,
19
19
  getLogsDirPath,
20
- getProfileMdPath,
21
- getDowncityConfigDirPath,
22
20
  getDowncityDataDirPath,
23
21
  getDowncityDebugDirPath,
24
22
  getDowncityDirPath,
@@ -28,16 +26,10 @@ import {
28
26
  getDowncityPublicDirPath,
29
27
  getDowncityResourcesDirPath,
30
28
  getDowncityTasksDirPath,
31
- getSoulMdPath,
32
29
  } from "@/config/Paths.js";
33
- import {
34
- DEFAULT_PROFILE_MD_TEMPLATE,
35
- DEFAULT_SOUL_MD_TEMPLATE,
36
- } from "@executor/composer/system/default/InitPrompts.js";
37
30
  import type { EnvFileEntry } from "@/types/common/EnvFile.js";
38
31
  import { appendMissingEnvEntries } from "@/config/EnvFile.js";
39
32
  import { ensureGitignoreEntry } from "@/config/Gitignore.js";
40
- import { renderTemplateVariables } from "@/utils/Template.js";
41
33
  import { ensureDir } from "@/utils/storage/index.js";
42
34
  import type {
43
35
  AgentProjectChannel,
@@ -82,24 +74,11 @@ function normalizeChannels(input: AgentProjectChannel[] | undefined): AgentProje
82
74
  return [...seen];
83
75
  }
84
76
 
85
- /**
86
- * 判断项目是否已经具备最小初始化文件。
87
- *
88
- * 关键点(中文)
89
- * - 当前只检查 `PROFILE.md`,用于快速判断项目行为资产是否已初始化过。
90
- * - 不把 `.downcity/` 目录作为硬性条件,避免用户手动清理缓存后被误判为未初始化。
91
- */
92
- export async function isAgentProjectInitialized(projectRoot: string): Promise<boolean> {
93
- const normalizedRoot = path.resolve(String(projectRoot || "").trim() || ".");
94
- const profileReady = await fs.pathExists(getProfileMdPath(normalizedRoot));
95
- return profileReady;
96
- }
97
-
98
77
  /**
99
78
  * 初始化 agent 项目骨架。
100
79
  *
101
80
  * 关键点(中文)
102
- * - 会创建 prompt 文件、`.downcity` 目录结构以及 schema 快照。
81
+ * - 会创建 `.downcity` 运行目录、项目 `.env` 与 `.agents/skills`。
103
82
  * - 对已存在文件采取“能跳过就跳过、明确冲突则报错”的策略,降低误覆盖风险。
104
83
  * - 返回结果只描述本次初始化写入摘要,方便 CLI 与控制台直接展示。
105
84
  */
@@ -114,7 +93,8 @@ export async function initializeAgentProject(
114
93
 
115
94
  const channels = normalizeChannels(input.channels);
116
95
  const dotEnvPath = path.join(projectRoot, ".env");
117
- const dotEnvExamplePath = path.join(projectRoot, ".env.example");
96
+ const downcity_dir_path = getDowncityDirPath(projectRoot);
97
+ const skills_dir_path = path.join(projectRoot, ".agents", "skills");
118
98
  const createdFiles: string[] = [];
119
99
  const skippedFiles: string[] = [];
120
100
 
@@ -126,53 +106,29 @@ export async function initializeAgentProject(
126
106
 
127
107
  await ensureDir(projectRoot);
128
108
 
129
- const profileMdPath = getProfileMdPath(projectRoot);
130
- const soulMdPath = getSoulMdPath(projectRoot);
131
- const initTemplateVariables = {
132
- agent_id,
133
- };
134
- const staticPromptFiles = [
135
- {
136
- filename: "PROFILE.md",
137
- filePath: profileMdPath,
138
- content: renderTemplateVariables(DEFAULT_PROFILE_MD_TEMPLATE, initTemplateVariables),
139
- },
140
- {
141
- filename: "SOUL.md",
142
- filePath: soulMdPath,
143
- content: renderTemplateVariables(DEFAULT_SOUL_MD_TEMPLATE, initTemplateVariables),
144
- },
145
- ] as const;
146
-
147
- for (const file of staticPromptFiles) {
148
- if (await fs.pathExists(file.filePath)) {
149
- skippedFiles.push(file.filename);
150
- continue;
151
- }
152
- await fs.writeFile(file.filePath, file.content, "utf-8");
153
- createdFiles.push(file.filename);
154
- }
155
-
109
+ const dot_env_exists = await fs.pathExists(dotEnvPath);
156
110
  await appendMissingEnvEntries(
157
111
  dotEnvPath,
158
112
  "Downcity Create",
159
113
  [] satisfies EnvFileEntry[],
160
114
  );
161
- await appendMissingEnvEntries(
162
- dotEnvExamplePath,
163
- "Downcity Create Example",
164
- [] satisfies EnvFileEntry[],
165
- );
115
+ (dot_env_exists ? skippedFiles : createdFiles).push(".env");
166
116
 
167
- const gitignoreStatus = await ensureGitignoreEntry(projectRoot, ".downcity");
168
- if (gitignoreStatus === "created" || gitignoreStatus === "updated") {
117
+ const downcity_gitignore_status = await ensureGitignoreEntry(projectRoot, ".downcity");
118
+ const dotenv_gitignore_status = await ensureGitignoreEntry(projectRoot, ".env");
119
+ if (
120
+ downcity_gitignore_status !== "unchanged" ||
121
+ dotenv_gitignore_status !== "unchanged"
122
+ ) {
169
123
  createdFiles.push(".gitignore");
170
124
  } else {
171
125
  skippedFiles.push(".gitignore");
172
126
  }
173
127
 
128
+ const downcity_dir_exists = await fs.pathExists(downcity_dir_path);
129
+ const skills_dir_exists = await fs.pathExists(skills_dir_path);
174
130
  const dirs = [
175
- getDowncityDirPath(projectRoot),
131
+ downcity_dir_path,
176
132
  getDowncityTasksDirPath(projectRoot),
177
133
  getLogsDirPath(projectRoot),
178
134
  getCacheDirPath(projectRoot),
@@ -181,13 +137,14 @@ export async function initializeAgentProject(
181
137
  getDowncityAgentsRootDirPath(projectRoot),
182
138
  getDowncityPublicDirPath(projectRoot),
183
139
  getDowncityResourcesDirPath(projectRoot),
184
- getDowncityConfigDirPath(projectRoot),
185
- path.join(projectRoot, ".agents", "skills"),
140
+ skills_dir_path,
186
141
  getDowncityDebugDirPath(projectRoot),
187
142
  ];
188
143
  for (const dir of dirs) {
189
144
  await ensureDir(dir);
190
145
  }
146
+ (downcity_dir_exists ? skippedFiles : createdFiles).push(".downcity/");
147
+ (skills_dir_exists ? skippedFiles : createdFiles).push(".agents/skills/");
191
148
 
192
149
  try {
193
150
  await ensureDir(getDowncityProfileDirPath(projectRoot));
@@ -2,7 +2,7 @@
2
2
  * Agent 配置域 Env 文件工具模块。
3
3
  *
4
4
  * 职责说明(中文)
5
- * - 负责 `.env` / `.env.example` 这类项目配置文件的轻量解析与补齐。
5
+ * - 负责项目 `.env` 文件的轻量解析与补齐。
6
6
  * - 服务于 agent 项目初始化与配置维护流程,避免把文本拼接逻辑散落到业务模块。
7
7
  *
8
8
  * 边界说明(中文)
@@ -2,7 +2,7 @@
2
2
  * 项目执行绑定解析与校验模块。
3
3
  *
4
4
  * 职责说明(中文)
5
- * - 统一负责从 `downcity.json` 中读取 agent 的执行目标定义。
5
+ * - 统一负责从宿主传入的 Agent 配置中读取执行目标定义。
6
6
  * - 负责提供最小的存在性判断、主模型读取与错误断言,避免调用方重复解析结构。
7
7
  * - 让初始化、配置装配、运行时启动都复用同一套执行目标解释规则。
8
8
  *
@@ -45,6 +45,6 @@ export function readProjectExecutionBinding(
45
45
  export function assertProjectExecutionTarget(config: DowncityConfig): void {
46
46
  if (readProjectExecutionBinding(config) !== null) return;
47
47
  throw new Error(
48
- 'Invalid downcity.json: "execution" is required and must be { "type": "api", "modelId": "..." }',
48
+ 'Invalid Agent config: "execution" is required and must be { "type": "api", "modelId": "..." }',
49
49
  );
50
50
  }
@@ -12,75 +12,6 @@
12
12
  */
13
13
  import path from "path";
14
14
 
15
- /**
16
- * PROFILE.md 候选文件名(按优先级从高到低)。
17
- *
18
- * 关键点(中文)
19
- * - 统一使用大写文件名:`PROFILE.md`。
20
- * - 与 SOUL 一起作为静态 prompt 入口。
21
- */
22
- export const PROFILE_MD_FILE_CANDIDATES = ["PROFILE.md"] as const;
23
-
24
- /**
25
- * 返回项目主 `PROFILE.md` 的标准路径。
26
- *
27
- * 关键点(中文)
28
- * - 当前始终返回候选列表中的第一优先级文件。
29
- * - 调用方可把该路径视为初始化时默认写入位置。
30
- */
31
- export function getProfileMdPath(cwd: string): string {
32
- return path.join(cwd, PROFILE_MD_FILE_CANDIDATES[0]);
33
- }
34
-
35
- /**
36
- * 返回 `PROFILE.md` 的全部候选路径。
37
- *
38
- * 关键点(中文)
39
- * - 便于后续扩展多候选命名时保持调用方逻辑不变。
40
- * - 当前虽然只有一个候选值,仍统一暴露数组接口。
41
- */
42
- export function getProfileMdCandidatePaths(cwd: string): string[] {
43
- return PROFILE_MD_FILE_CANDIDATES.map((filename) => path.join(cwd, filename));
44
- }
45
-
46
- /**
47
- * SOUL.md 候选文件名(按优先级从高到低)。
48
- *
49
- * 关键点(中文)
50
- * - 统一使用大写文件名:`SOUL.md`。
51
- * - 统一由 Paths 模块暴露,避免调用方散落硬编码。
52
- */
53
- export const SOUL_MD_FILE_CANDIDATES = ["SOUL.md"] as const;
54
-
55
- /**
56
- * 返回项目主 `SOUL.md` 的标准路径。
57
- *
58
- * 关键点(中文)
59
- * - 当前始终返回候选列表中的第一优先级文件。
60
- * - 与 `PROFILE.md` 一样,属于静态 system prompt 入口文件。
61
- */
62
- export function getSoulMdPath(cwd: string): string {
63
- return path.join(cwd, SOUL_MD_FILE_CANDIDATES[0]);
64
- }
65
-
66
- /**
67
- * 返回 `SOUL.md` 的全部候选路径。
68
- *
69
- * 关键点(中文)
70
- * - 供探测逻辑统一遍历候选文件名。
71
- * - 保留数组形式便于后续新增兼容命名。
72
- */
73
- export function getSoulMdCandidatePaths(cwd: string): string[] {
74
- return SOUL_MD_FILE_CANDIDATES.map((filename) => path.join(cwd, filename));
75
- }
76
-
77
- /**
78
- * 返回项目主配置文件 `downcity.json` 的路径。
79
- */
80
- export function getDowncityJsonPath(cwd: string): string {
81
- return path.join(cwd, "downcity.json");
82
- }
83
-
84
15
  /**
85
16
  * 返回项目运行时状态根目录 `.downcity` 的路径。
86
17
  */
@@ -88,26 +19,6 @@ export function getDowncityDirPath(cwd: string): string {
88
19
  return path.join(cwd, ".downcity");
89
20
  }
90
21
 
91
- /**
92
- * 返回项目内 schema 快照文件路径。
93
- *
94
- * 关键点(中文)
95
- * - 初始化流程会把本地 schema 副本写到这里,供编辑器联想与校验。
96
- */
97
- export function getDowncitySchemaPath(cwd: string): string {
98
- return path.join(getDowncityDirPath(cwd), "schema", "downcity.schema.json");
99
- }
100
-
101
- /**
102
- * 返回 `.downcity/config` 目录路径。
103
- *
104
- * 关键点(中文)
105
- * - 用于存放项目级额外配置快照或未来扩展的辅助配置文件。
106
- */
107
- export function getDowncityConfigDirPath(cwd: string): string {
108
- return path.join(getDowncityDirPath(cwd), "config");
109
- }
110
-
111
22
  /**
112
23
  * 返回项目日志目录路径。
113
24
  */
package/src/index.ts CHANGED
@@ -146,11 +146,6 @@ export type {
146
146
  SessionComposerOptions,
147
147
  } from "./types/session/SessionComposerOptions.js";
148
148
  export { transformPromptsIntoSystemMessages } from "./executor/composer/system/default/PromptRenderer.js";
149
- export {
150
- loadStaticSystemPrompts,
151
- StaticPromptCatalog,
152
- } from "./executor/composer/system/default/StaticPromptCatalog.js";
153
-
154
149
  // 通用 plugin 宿主工具
155
150
  export {
156
151
  buildStaticPluginAvailability,
@@ -198,10 +193,12 @@ export type {
198
193
  // 项目与配置集成
199
194
  export {
200
195
  initializeAgentProject,
201
- isAgentProjectInitialized,
202
196
  normalizeDefaultAgentId,
203
197
  } from "./config/AgentInitializer.js";
204
- export { loadDowncityConfig } from "./config/Config.js";
198
+ export {
199
+ load_project_dotenv,
200
+ resolve_agent_env,
201
+ } from "./config/AgentEnv.js";
205
202
  export {
206
203
  getDowncityChatHistoryPath,
207
204
  getDowncitySessionMessagesPath,
@@ -238,7 +235,14 @@ export type {
238
235
  export type { ExecutionBindingConfig } from "./types/config/ExecutionBinding.js";
239
236
 
240
237
  // 配置与模型类型
241
- export type { DowncityConfig } from "./types/config/DowncityConfig.js";
238
+ export type {
239
+ DowncityChatChannelConfig,
240
+ DowncityChatPluginChannelsConfig,
241
+ DowncityChatPluginConfig,
242
+ DowncityChatPluginQueueConfig,
243
+ DowncityConfig,
244
+ DowncityPluginConfigMap,
245
+ } from "./types/config/DowncityConfig.js";
242
246
  export type {
243
247
  LlmConfig,
244
248
  LlmModelConfig,
@@ -266,14 +270,6 @@ export type {
266
270
 
267
271
  export type {
268
272
  PlatformAgentChatChannelStatus,
269
- PlatformAgentShipChatChannelsConfig,
270
- PlatformAgentShipChatPluginConfig,
271
- PlatformAgentShipExecutionAgentConfig,
272
- PlatformAgentShipExecutionConfig,
273
- PlatformAgentShipJson,
274
- PlatformAgentShipPluginsConfig,
275
- PlatformAgentShipSingleChannelConfig,
276
- PlatformAgentShipStartConfig,
277
273
  } from "./types/runtime/platform/PlatformGateway.js";
278
274
 
279
275
  // Inline instant 协议类型
@@ -9,7 +9,7 @@
9
9
 
10
10
  import path from "node:path";
11
11
  import { logger as defaultLogger } from "@/utils/logger/Logger.js";
12
- import { resolveAgentEnv } from "@/config/Config.js";
12
+ import { resolve_agent_env } from "@/config/AgentEnv.js";
13
13
  import { findPluginByName } from "@/plugin/core/PluginCatalog.js";
14
14
  import {
15
15
  createAgentPathRuntime,
@@ -39,7 +39,7 @@ export function createLocalPluginCommandContext(
39
39
  ): PluginCommandContext {
40
40
  const projectRoot = typeof input === "string" ? input : input.projectRoot;
41
41
  const rootPath = path.resolve(String(projectRoot || "").trim() || ".");
42
- const env = resolveAgentEnv(rootPath);
42
+ const env = resolve_agent_env(rootPath);
43
43
  const config = typeof input === "string" || !input.config
44
44
  ? createFallbackSdkConfig(path.basename(rootPath) || "agent")
45
45
  : input.config;
@@ -98,6 +98,21 @@ export interface SessionPromptRuntimeOptions {
98
98
  input: AgentSessionPromptInput,
99
99
  ) => Promise<SessionUserMessageV1>;
100
100
 
101
+ /**
102
+ * 在 steer message 成功持久化后发送对应 action。
103
+ */
104
+ emit_steer_action: (input: {
105
+ /**
106
+ * steer message 所属的当前 turn 标识。
107
+ */
108
+ turn_id: string;
109
+
110
+ /**
111
+ * 已成功持久化的 steer message。
112
+ */
113
+ message: SessionUserMessageV1;
114
+ }) => Promise<void>;
115
+
101
116
  /**
102
117
  * 执行单轮 turn。
103
118
  */
@@ -126,6 +141,7 @@ export class SessionPromptRuntime {
126
141
  private readonly sessionId: string;
127
142
  private readonly publish: SessionPromptRuntimeOptions["publish"];
128
143
  private readonly createAndPersistUserMessage: SessionPromptRuntimeOptions["createAndPersistUserMessage"];
144
+ private readonly emit_steer_action: SessionPromptRuntimeOptions["emit_steer_action"];
129
145
  private readonly executeTurn: SessionPromptRuntimeOptions["executeTurn"];
130
146
  private readonly stopTurn: SessionPromptRuntimeOptions["stopTurn"];
131
147
  private readonly queue: QueuedPrompt[] = [];
@@ -136,6 +152,7 @@ export class SessionPromptRuntime {
136
152
  this.sessionId = String(options.sessionId || "").trim();
137
153
  this.publish = options.publish;
138
154
  this.createAndPersistUserMessage = options.createAndPersistUserMessage;
155
+ this.emit_steer_action = options.emit_steer_action;
139
156
  this.executeTurn = options.executeTurn;
140
157
  this.stopTurn = options.stopTurn;
141
158
  if (!this.sessionId) {
@@ -329,12 +346,20 @@ export class SessionPromptRuntime {
329
346
  const merged: SessionUserMessageV1[] = [];
330
347
 
331
348
  for (let index = 0; index < drained.length; index += 1) {
332
- const item = drained[index];
349
+ const item = drained[index];
350
+ try {
351
+ const message = await this.createAndPersistUserMessage(item.input);
352
+ item.deferredHandle.resolve(createTurnHandle(activeTurn));
353
+ merged.push(message);
333
354
  try {
334
- const message = await this.createAndPersistUserMessage(item.input);
335
- item.deferredHandle.resolve(createTurnHandle(activeTurn));
336
- merged.push(message);
355
+ await this.emit_steer_action({
356
+ turn_id: activeTurn.turnId,
357
+ message,
358
+ });
337
359
  } catch {
360
+ // action 发送失败不应阻断已经持久化的 steer message。
361
+ }
362
+ } catch {
338
363
  // 关键点(中文):若某条消息持久化失败,把未处理部分重新放回队列头部,避免静默丢失。
339
364
  const remaining = drained.slice(index);
340
365
  this.queue.unshift(...remaining);
@@ -83,6 +83,15 @@ export class SessionTurnService {
83
83
  input,
84
84
  );
85
85
  },
86
+ emit_steer_action: async ({ turn_id, message }) => {
87
+ await this.state_service.emit_action_event({
88
+ id: `steer-message:${message.id}`,
89
+ title: "Session steer message sent",
90
+ description: "Merged a new user message into the active turn.",
91
+ state: "completed",
92
+ turnId: turn_id,
93
+ });
94
+ },
86
95
  executeTurn: async ({ turnId, promptInput, onStepMerge, abortSignal }) => {
87
96
  return await this.execute_prompt_turn({
88
97
  turnId,
@@ -11,6 +11,7 @@ import type { Shell } from "@downcity/shell";
11
11
  import type { Plugin } from "@/types/plugin/PluginDefinition.js";
12
12
  import type { AgentModel } from "@/model/CityModelAdapter.js";
13
13
  import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
14
+ import type { AgentPluginConfigRuntime } from "@/types/agent/AgentRuntimeAssembly.js";
14
15
  import type {
15
16
  AgentManagedSession,
16
17
  SessionOptions,
@@ -66,7 +67,7 @@ export interface AgentOptions {
66
67
  *
67
68
  * 关键点(中文)
68
69
  * - `instruction` 是稳定、缓存友好的 system 前缀,不做动态变量替换。
69
- * - SDK 不主动读取 `PROFILE.md` / `SOUL.md`;这类项目文件应由 city 或调用方读取后传入。
70
+ * - 项目目录不再提供隐式 prompt 文件;调用方需要的指令必须显式传入。
70
71
  * - 未传入时,SDK 会使用包内最小 core instruction 作为 fallback。
71
72
  */
72
73
  instruction?: string | string[];
@@ -116,8 +117,17 @@ export interface AgentOptions {
116
117
  * 宿主显式传入的运行时配置。
117
118
  *
118
119
  * 关键点(中文)
119
- * - SDK 不要求项目目录存在 `downcity.json`。
120
- * - CLI / Console 可从自己的配置存储读取后传入这里。
120
+ * - SDK 不读取项目配置文件。
121
+ * - CLI / Console 从自己的全局配置存储读取后传入这里。
121
122
  */
122
123
  config?: DowncityConfig;
124
+
125
+ /**
126
+ * 宿主提供的 plugin 配置持久化能力。
127
+ *
128
+ * 关键点(中文)
129
+ * - SDK 默认会拒绝持久化操作;CLI 等宿主可在这里接入自己的全局数据库。
130
+ * - plugin 只依赖该稳定接口,不感知 SQLite、文件或远端服务等具体实现。
131
+ */
132
+ plugin_config?: AgentPluginConfigRuntime;
123
133
  }
@@ -2,7 +2,7 @@
2
2
  * Env 文件工具相关类型定义。
3
3
  *
4
4
  * 职责说明(中文)
5
- * - 统一描述 `.env` / `.env.example` 写入工具使用的最小数据结构。
5
+ * - 统一描述项目 `.env` 写入工具使用的最小数据结构。
6
6
  * - 避免工具模块直接内联匿名对象,便于后续在其他初始化流程中复用。
7
7
  * - 这里只描述“文件写入条目”,不承载运行时环境变量快照语义。
8
8
  */
@@ -74,20 +74,6 @@ export interface DowncityChatPluginQueueConfig {
74
74
  mergeMaxWaitMs?: number;
75
75
  }
76
76
 
77
- /**
78
- * 聊天插件出站控制配置。
79
- */
80
- export interface DowncityChatPluginEgressConfig {
81
- /**
82
- * 单次 agent run 内,`chat_send` 允许调用的最大次数。
83
- */
84
- chatSendMaxCallsPerRun?: number;
85
- /**
86
- * 是否启用 `chat_send` 幂等去重(基于 inbound messageId + 回复内容 hash)。
87
- */
88
- chatSendIdempotency?: boolean;
89
- }
90
-
91
77
  /**
92
78
  * 聊天插件配置。
93
79
  */
@@ -96,10 +82,6 @@ export interface DowncityChatPluginConfig {
96
82
  * Chat 调度队列(按 chatKey 分 lane)。
97
83
  */
98
84
  queue?: DowncityChatPluginQueueConfig;
99
- /**
100
- * 出站(egress)控制:用于限制工具发送、避免重复与无限循环刷屏。
101
- */
102
- egress?: DowncityChatPluginEgressConfig;
103
85
  /**
104
86
  * 消息平台 channel 配置。
105
87
  */
@@ -107,7 +89,7 @@ export interface DowncityChatPluginConfig {
107
89
  }
108
90
 
109
91
  /**
110
- * downcity.json 中的插件配置映射。
92
+ * Agent 全局配置中的插件配置映射。
111
93
  */
112
94
  export interface DowncityPluginConfigMap {
113
95
  /**
@@ -124,7 +106,6 @@ export interface DowncityPluginConfigMap {
124
106
  }
125
107
 
126
108
  export interface DowncityConfig {
127
- $schema?: string;
128
109
  /**
129
110
  * agent 唯一标识。
130
111
  *
@@ -147,7 +128,7 @@ export interface DowncityConfig {
147
128
  *
148
129
  * 关键点(中文)
149
130
  * - 所有可配置能力统一收敛到 `plugins`,不再保留独立 `services` 域。
150
- * - 需要持久化到项目文件的 plugin 配置(例如 `plugins.chat.channels`)放在这里。
131
+ * - 需要持久化的 plugin 配置(例如 `plugins.chat.channels`)由宿主写入全局配置存储。
151
132
  * - key 为 plugin 名称,value 为对应插件的结构化配置对象。
152
133
  * - 当前阶段允许各 plugin 自定义字段,但必须保持 JSON 可序列化。
153
134
  */
@@ -166,7 +147,7 @@ export interface DowncityConfig {
166
147
  * 关键点(中文)
167
148
  * - `@downcity/agent` 本地 SDK 不直接消费该字段。
168
149
  * - 宿主侧(例如 `downcity`)可读取该字段控制模型工厂行为,例如 `llm.logMessages`。
169
- * - 对于项目内 `downcity.json`,通常不需要显式写 provider/model 明细。
150
+ * - 该字段通常由宿主平台装配,不由 Agent SDK 解析。
170
151
  */
171
152
  llm?: LlmConfig;
172
153
  }
@@ -4,7 +4,7 @@
4
4
  * 关键点(中文)
5
5
  * - 项目运行入口只有一种执行模式:`api`。
6
6
  * - 绑定 City AIService 暴露的模型 ID。
7
- * - 该类型是项目 `downcity.json` 中唯一的执行配置。
7
+ * - 该类型是 Agent 全局配置中的执行绑定结构。
8
8
  */
9
9
 
10
10
  /**
@@ -17,7 +17,7 @@ export interface PlatformAgentOption {
17
17
  id: string;
18
18
 
19
19
  /**
20
- * agent 项目自身的稳定标识(优先 downcity.json.id,回退目录名推导)。
20
+ * Agent 全局配置中的稳定标识。
21
21
  */
22
22
  agentId: string;
23
23
 
@@ -90,7 +90,7 @@ export interface PlatformAgentOption {
90
90
  }>;
91
91
 
92
92
  /**
93
- * 当前 agent 绑定的 console 模型 ID(downcity.json.execution.modelId)。
93
+ * 当前 Agent 全局配置绑定的模型 ID
94
94
  */
95
95
  modelId?: string;
96
96
  }
@@ -154,16 +154,6 @@ export interface PlatformAgentDirectoryInspection {
154
154
  */
155
155
  initialized: boolean;
156
156
 
157
- /**
158
- * `downcity.json` 是否存在。
159
- */
160
- hasShipJson: boolean;
161
-
162
- /**
163
- * `PROFILE.md` 是否存在。
164
- */
165
- hasProfileMd: boolean;
166
-
167
157
  /** 该目录是否已出现在 managed agent registry 中。 */
168
158
  knownAgent: boolean;
169
159
 
@@ -266,7 +256,7 @@ export interface ControlPlaneRuntimeStatus {
266
256
  */
267
257
  export interface PlatformConfigFileStatusItem {
268
258
  /**
269
- * 配置文件逻辑名称(例如 `ship_json`、`control_plane_pid`)。
259
+ * 配置状态逻辑名称(例如 `agent_config`、`control_plane_pid`)。
270
260
  */
271
261
  key: string;
272
262
 
@@ -336,7 +326,7 @@ export interface PlatformConfigStatusResponse {
336
326
  selectedAgentId: string;
337
327
 
338
328
  /**
339
- * 当前选中的 agent 项目 id(即 `downcity.json.id`,可能为空)。
329
+ * 当前选中的 Agent 配置 id(可能为空)。
340
330
  */
341
331
  selectedAgentProjectId: string;
342
332