@downcity/agent 1.1.174 → 1.1.178
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/bin/agent/local/AgentPluginFactory.d.ts +4 -2
- package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -1
- package/bin/agent/local/AgentPluginFactory.js +4 -6
- package/bin/agent/local/AgentPluginFactory.js.map +1 -1
- package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -1
- package/bin/agent/local/AgentRuntimeAssembly.js +3 -8
- package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -1
- package/bin/agent/local/ProjectSetup.d.ts +1 -1
- package/bin/agent/local/ProjectSetup.d.ts.map +1 -1
- package/bin/agent/local/ProjectSetup.js +2 -6
- package/bin/agent/local/ProjectSetup.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +2 -3
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +9 -14
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.js +5 -6
- package/bin/agent/local/services/AgentBackgroundService.js.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.d.ts +2 -2
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.js +1 -28
- package/bin/agent/local/services/AgentSessionManager.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 +7 -49
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts +3 -4
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +1 -2
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +1 -1
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +1 -2
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/index.d.ts +0 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -4
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/Activation.d.ts +6 -5
- package/bin/plugin/core/Activation.d.ts.map +1 -1
- package/bin/plugin/core/Activation.js +9 -9
- package/bin/plugin/core/Activation.js.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +5 -4
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js +7 -4
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +4 -0
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.js +40 -0
- package/bin/plugin/core/HookRegistry.js.map +1 -1
- package/bin/plugin/core/Manager.d.ts +1 -1
- package/bin/plugin/core/Manager.d.ts.map +1 -1
- package/bin/plugin/core/Manager.js +1 -1
- package/bin/plugin/core/Manager.js.map +1 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +13 -7
- package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionRunner.js +46 -111
- package/bin/plugin/core/PluginActionRunner.js.map +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts.map +1 -1
- package/bin/plugin/core/PluginCatalog.js +1 -21
- package/bin/plugin/core/PluginCatalog.js.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts +12 -2
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +18 -24
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +60 -7
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +269 -42
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +11 -36
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +45 -190
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/Plugin.d.ts +1 -1
- package/bin/plugin/types/Plugin.d.ts.map +1 -1
- package/bin/plugin/types/PluginState.d.ts +1 -1
- package/bin/plugin/types/PluginState.d.ts.map +1 -1
- package/bin/plugin/types/Plugins.d.ts +12 -12
- package/bin/plugin/types/Plugins.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +1 -1
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +12 -3
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentRuntimeAssembly.d.ts +1 -1
- package/bin/types/config/AgentProject.d.ts +6 -14
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +23 -2
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.d.ts +47 -36
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.js +4 -3
- package/bin/types/plugin/PluginState.js.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +3 -3
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/local/AgentPluginFactory.ts +8 -8
- package/src/agent/local/AgentRuntimeAssembly.ts +3 -9
- package/src/agent/local/ProjectSetup.ts +1 -8
- package/src/agent/local/services/AgentAssemblyService.ts +13 -23
- package/src/agent/local/services/AgentBackgroundService.ts +5 -6
- package/src/agent/local/services/AgentSessionManager.ts +4 -26
- package/src/config/AgentInitializer.ts +7 -57
- package/src/config/DowncitySchema.ts +3 -4
- package/src/executor/Executor.ts +1 -3
- package/src/executor/composer/system/default/SystemDomain.ts +1 -2
- 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/index.ts +1 -8
- package/src/plugin/core/Activation.ts +10 -10
- package/src/plugin/core/BasePlugin.ts +9 -6
- package/src/plugin/core/HookRegistry.ts +41 -0
- package/src/plugin/core/Manager.ts +0 -2
- package/src/plugin/core/PluginActionRunner.ts +52 -133
- package/src/plugin/core/PluginCatalog.ts +1 -23
- package/src/plugin/core/PluginLocalExecution.ts +30 -25
- package/src/plugin/core/PluginRegistry.ts +298 -44
- package/src/plugin/core/PluginStateController.ts +45 -235
- package/src/plugin/types/Plugin.ts +2 -1
- package/src/plugin/types/PluginState.ts +2 -1
- package/src/plugin/types/Plugins.ts +12 -12
- package/src/session/services/SessionStateService.ts +1 -3
- package/src/types/agent/AgentOptions.ts +13 -3
- package/src/types/agent/AgentRuntimeAssembly.ts +1 -1
- package/src/types/config/AgentProject.ts +7 -15
- package/src/types/plugin/PluginRuntime.ts +23 -2
- package/src/types/plugin/PluginState.ts +50 -43
- package/src/types/runtime/agent/AgentContext.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/Defaults.d.ts +0 -21
- package/bin/config/Defaults.d.ts.map +0 -1
- package/bin/config/Defaults.js +0 -47
- package/bin/config/Defaults.js.map +0 -1
- package/bin/plugin/core/ProjectConfigStore.d.ts +0 -84
- package/bin/plugin/core/ProjectConfigStore.d.ts.map +0 -1
- package/bin/plugin/core/ProjectConfigStore.js +0 -89
- package/bin/plugin/core/ProjectConfigStore.js.map +0 -1
- package/src/config/Defaults.ts +0 -49
- package/src/plugin/core/ProjectConfigStore.ts +0 -155
|
@@ -37,8 +37,7 @@ import {
|
|
|
37
37
|
} from "@/session/index.js";
|
|
38
38
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
39
39
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
40
|
-
import type {
|
|
41
|
-
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
40
|
+
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
42
41
|
import { createInstructionSystemBlocks } from "@/agent/local/AgentInstructions.js";
|
|
43
42
|
|
|
44
43
|
function decodeMaybe(input: string): string {
|
|
@@ -86,7 +85,7 @@ type AgentSessionManagerOptions = {
|
|
|
86
85
|
/**
|
|
87
86
|
* 当前 plugin 实例集合。
|
|
88
87
|
*/
|
|
89
|
-
plugin_instances: Map<string,
|
|
88
|
+
plugin_instances: Map<string, Plugin>;
|
|
90
89
|
|
|
91
90
|
/**
|
|
92
91
|
* 当前默认模型实例。
|
|
@@ -109,7 +108,7 @@ export class AgentSessionManager {
|
|
|
109
108
|
private readonly logger: Logger;
|
|
110
109
|
private readonly get_agent_context: AgentSessionManagerOptions["get_agent_context"];
|
|
111
110
|
private readonly get_instruction: AgentSessionManagerOptions["get_instruction"];
|
|
112
|
-
private readonly plugin_instances: Map<string,
|
|
111
|
+
private readonly plugin_instances: Map<string, Plugin>;
|
|
113
112
|
private readonly default_model?: AgentModel;
|
|
114
113
|
private readonly SessionClass: AgentSessionConstructor;
|
|
115
114
|
private readonly sessions_by_id = new Map<string, AgentManagedSession>();
|
|
@@ -378,27 +377,6 @@ export class AgentSessionManager {
|
|
|
378
377
|
}
|
|
379
378
|
|
|
380
379
|
private async load_plugin_system_blocks(): Promise<AgentSessionSystemBlock[]> {
|
|
381
|
-
|
|
382
|
-
const out: AgentSessionSystemBlock[] = [];
|
|
383
|
-
for (const plugin of this.plugin_instances.values()) {
|
|
384
|
-
if (typeof plugin.system !== "function") continue;
|
|
385
|
-
try {
|
|
386
|
-
if (!isPluginEnabled({ plugin, context })) continue;
|
|
387
|
-
if (typeof plugin.availability === "function") {
|
|
388
|
-
const availability = await plugin.availability(context);
|
|
389
|
-
if (!availability.available) continue;
|
|
390
|
-
}
|
|
391
|
-
const text = String(await plugin.system(context)).trim();
|
|
392
|
-
if (!text) continue;
|
|
393
|
-
out.push({
|
|
394
|
-
source: "plugin",
|
|
395
|
-
name: plugin.name,
|
|
396
|
-
content: text,
|
|
397
|
-
});
|
|
398
|
-
} catch {
|
|
399
|
-
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return out;
|
|
380
|
+
return await this.get_agent_context().plugins.systemBlocks();
|
|
403
381
|
}
|
|
404
382
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - CLI `downcity agent create` 与 Console 共用同一套初始化逻辑,避免模板与目录结构分叉。
|
|
6
|
-
* - 负责创建项目骨架、静态 prompt
|
|
7
|
-
* -
|
|
6
|
+
* - 负责创建项目骨架、静态 prompt、基础目录与 schema 文件。
|
|
7
|
+
* - CLI 侧运行配置应写入宿主配置存储,不再由 SDK 初始化器写项目配置文件。
|
|
8
8
|
*
|
|
9
9
|
* 边界说明(中文)
|
|
10
10
|
* - 这里只处理“初始化一个新项目”所需的静态文件与目录,不处理 downcity 托管进程启停。
|
|
@@ -22,20 +22,14 @@ import {
|
|
|
22
22
|
getDowncityDataDirPath,
|
|
23
23
|
getDowncityDebugDirPath,
|
|
24
24
|
getDowncityDirPath,
|
|
25
|
-
getDowncityJsonPath,
|
|
26
25
|
getDowncityProfileDirPath,
|
|
27
26
|
getDowncityProfileOtherPath,
|
|
28
27
|
getDowncityProfilePrimaryPath,
|
|
29
28
|
getDowncityPublicDirPath,
|
|
30
29
|
getDowncityResourcesDirPath,
|
|
31
|
-
getDowncitySchemaPath,
|
|
32
30
|
getDowncityTasksDirPath,
|
|
33
31
|
getSoulMdPath,
|
|
34
32
|
} from "@/config/Paths.js";
|
|
35
|
-
import { DEFAULT_DOWNCITY_JSON } from "@/config/Defaults.js";
|
|
36
|
-
import { DOWNCITY_JSON_SCHEMA } from "@/config/DowncitySchema.js";
|
|
37
|
-
import type { DowncityConfig } from "@/config/Config.js";
|
|
38
|
-
import type { DowncityChatPluginChannelsConfig } from "@/types/config/DowncityConfig.js";
|
|
39
33
|
import {
|
|
40
34
|
DEFAULT_PROFILE_MD_TEMPLATE,
|
|
41
35
|
DEFAULT_SOUL_MD_TEMPLATE,
|
|
@@ -44,14 +38,14 @@ import type { EnvFileEntry } from "@/types/common/EnvFile.js";
|
|
|
44
38
|
import { appendMissingEnvEntries } from "@/config/EnvFile.js";
|
|
45
39
|
import { ensureGitignoreEntry } from "@/config/Gitignore.js";
|
|
46
40
|
import { renderTemplateVariables } from "@/utils/Template.js";
|
|
47
|
-
import { ensureDir
|
|
41
|
+
import { ensureDir } from "@/utils/storage/index.js";
|
|
48
42
|
import type {
|
|
49
43
|
AgentProjectChannel,
|
|
50
44
|
AgentProjectInitializationInput,
|
|
51
45
|
AgentProjectInitializationResult,
|
|
52
46
|
} from "@/types/config/AgentProject.js";
|
|
53
|
-
import { assertProjectExecutionTarget } from "@/config/ExecutionBinding.js";
|
|
54
47
|
import type { ExecutionBindingConfig } from "@/types/config/ExecutionBinding.js";
|
|
48
|
+
import { assertProjectExecutionTarget } from "@/config/ExecutionBinding.js";
|
|
55
49
|
|
|
56
50
|
/**
|
|
57
51
|
* 规范化默认 Agent ID。
|
|
@@ -92,21 +86,20 @@ function normalizeChannels(input: AgentProjectChannel[] | undefined): AgentProje
|
|
|
92
86
|
* 判断项目是否已经具备最小初始化文件。
|
|
93
87
|
*
|
|
94
88
|
* 关键点(中文)
|
|
95
|
-
* - 当前只检查 `PROFILE.md
|
|
89
|
+
* - 当前只检查 `PROFILE.md`,用于快速判断项目行为资产是否已初始化过。
|
|
96
90
|
* - 不把 `.downcity/` 目录作为硬性条件,避免用户手动清理缓存后被误判为未初始化。
|
|
97
91
|
*/
|
|
98
92
|
export async function isAgentProjectInitialized(projectRoot: string): Promise<boolean> {
|
|
99
93
|
const normalizedRoot = path.resolve(String(projectRoot || "").trim() || ".");
|
|
100
94
|
const profileReady = await fs.pathExists(getProfileMdPath(normalizedRoot));
|
|
101
|
-
|
|
102
|
-
return profileReady && shipReady;
|
|
95
|
+
return profileReady;
|
|
103
96
|
}
|
|
104
97
|
|
|
105
98
|
/**
|
|
106
99
|
* 初始化 agent 项目骨架。
|
|
107
100
|
*
|
|
108
101
|
* 关键点(中文)
|
|
109
|
-
* - 会创建 prompt
|
|
102
|
+
* - 会创建 prompt 文件、`.downcity` 目录结构以及 schema 快照。
|
|
110
103
|
* - 对已存在文件采取“能跳过就跳过、明确冲突则报错”的策略,降低误覆盖风险。
|
|
111
104
|
* - 返回结果只描述本次初始化写入摘要,方便 CLI 与控制台直接展示。
|
|
112
105
|
*/
|
|
@@ -135,12 +128,6 @@ export async function initializeAgentProject(
|
|
|
135
128
|
|
|
136
129
|
const profileMdPath = getProfileMdPath(projectRoot);
|
|
137
130
|
const soulMdPath = getSoulMdPath(projectRoot);
|
|
138
|
-
const shipJsonPath = getDowncityJsonPath(projectRoot);
|
|
139
|
-
const existingShipJson = await fs.pathExists(shipJsonPath);
|
|
140
|
-
if (existingShipJson && input.forceOverwriteShipJson !== true) {
|
|
141
|
-
throw new Error(`downcity.json already exists: ${shipJsonPath}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
131
|
const initTemplateVariables = {
|
|
145
132
|
agent_id,
|
|
146
133
|
};
|
|
@@ -166,37 +153,6 @@ export async function initializeAgentProject(
|
|
|
166
153
|
createdFiles.push(file.filename);
|
|
167
154
|
}
|
|
168
155
|
|
|
169
|
-
const channelsConfig: DowncityChatPluginChannelsConfig = {};
|
|
170
|
-
if (channels.includes("telegram")) {
|
|
171
|
-
channelsConfig.telegram = { enabled: true };
|
|
172
|
-
}
|
|
173
|
-
if (channels.includes("feishu")) {
|
|
174
|
-
channelsConfig.feishu = { enabled: true };
|
|
175
|
-
}
|
|
176
|
-
if (channels.includes("qq")) {
|
|
177
|
-
channelsConfig.qq = { enabled: true };
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const shipConfig: DowncityConfig = {
|
|
181
|
-
$schema: DEFAULT_DOWNCITY_JSON.$schema,
|
|
182
|
-
id: agent_id,
|
|
183
|
-
version: "1.0.0",
|
|
184
|
-
execution,
|
|
185
|
-
plugins: {
|
|
186
|
-
...(input.plugins || {}),
|
|
187
|
-
...(Object.keys(channelsConfig).length > 0
|
|
188
|
-
? {
|
|
189
|
-
chat: {
|
|
190
|
-
...input.plugins?.chat,
|
|
191
|
-
channels: channelsConfig,
|
|
192
|
-
},
|
|
193
|
-
}
|
|
194
|
-
: {}),
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
await saveJson(shipJsonPath, shipConfig);
|
|
198
|
-
createdFiles.push("downcity.json");
|
|
199
|
-
|
|
200
156
|
await appendMissingEnvEntries(
|
|
201
157
|
dotEnvPath,
|
|
202
158
|
"Downcity Create",
|
|
@@ -227,18 +183,12 @@ export async function initializeAgentProject(
|
|
|
227
183
|
getDowncityResourcesDirPath(projectRoot),
|
|
228
184
|
getDowncityConfigDirPath(projectRoot),
|
|
229
185
|
path.join(projectRoot, ".agents", "skills"),
|
|
230
|
-
path.join(getDowncityDirPath(projectRoot), "schema"),
|
|
231
186
|
getDowncityDebugDirPath(projectRoot),
|
|
232
187
|
];
|
|
233
188
|
for (const dir of dirs) {
|
|
234
189
|
await ensureDir(dir);
|
|
235
190
|
}
|
|
236
191
|
|
|
237
|
-
const shipSchemaPath = getDowncitySchemaPath(projectRoot);
|
|
238
|
-
await ensureDir(path.dirname(shipSchemaPath));
|
|
239
|
-
await saveJson(shipSchemaPath, DOWNCITY_JSON_SCHEMA);
|
|
240
|
-
createdFiles.push(".downcity/schema/downcity.schema.json");
|
|
241
|
-
|
|
242
192
|
try {
|
|
243
193
|
await ensureDir(getDowncityProfileDirPath(projectRoot));
|
|
244
194
|
await fs.ensureFile(getDowncityProfilePrimaryPath(projectRoot));
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* `downcity.json` Schema 定义模块。
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - 提供旧版 `downcity.json` 的 JSON Schema 常量。
|
|
6
|
+
* - 保留给迁移场景与编辑器辅助,不再作为新 Agent 项目的默认配置入口。
|
|
7
7
|
*
|
|
8
8
|
* 边界说明(中文)
|
|
9
9
|
* - 这里是静态 schema 常量,不负责运行时配置装配或业务校验逻辑。
|
|
@@ -15,8 +15,7 @@ import type { JsonObject } from "@/types/common/Json.js";
|
|
|
15
15
|
* `downcity.json` 的本地 Schema 常量。
|
|
16
16
|
*
|
|
17
17
|
* 关键点(中文)
|
|
18
|
-
* -
|
|
19
|
-
* - 该结构主要面向 IDE 校验与用户编辑体验,不替代运行时断言。
|
|
18
|
+
* - 该结构主要面向 legacy 文件的 IDE 校验与用户编辑体验,不替代运行时断言。
|
|
20
19
|
*/
|
|
21
20
|
export const DOWNCITY_JSON_SCHEMA: JsonObject = {
|
|
22
21
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
package/src/executor/Executor.ts
CHANGED
|
@@ -490,9 +490,7 @@ export class Executor implements SessionExecutor {
|
|
|
490
490
|
private resolveModelOrThrow(): LanguageModel {
|
|
491
491
|
const model = this.getModel();
|
|
492
492
|
if (!model) {
|
|
493
|
-
throw new Error(
|
|
494
|
-
`Executor for session "${this.sessionId}" requires a configured model. Pass model to new Agent({ model }) or call session.set({ model }) before execution.`,
|
|
495
|
-
);
|
|
493
|
+
throw new Error("requires a configured model.");
|
|
496
494
|
}
|
|
497
495
|
return model;
|
|
498
496
|
}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
import type { SystemModelMessage } from "ai";
|
|
10
10
|
import { transformPromptsIntoSystemMessages } from "@executor/composer/system/default/PromptRenderer.js";
|
|
11
|
-
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
12
11
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
13
12
|
import { buildRuntimeClockSystemPrompt } from "@executor/composer/system/default/variables/VariableReplacer.js";
|
|
14
13
|
import {
|
|
@@ -177,7 +176,7 @@ export async function loadManagedPluginSystemPrompts(input: {
|
|
|
177
176
|
if (disabledPluginNames.has(plugin.name)) continue;
|
|
178
177
|
if (typeof plugin.system !== "function") continue;
|
|
179
178
|
try {
|
|
180
|
-
if (
|
|
179
|
+
if (input.context.plugins.status(plugin.name)?.status !== "ready") continue;
|
|
181
180
|
if (typeof plugin.availability === "function") {
|
|
182
181
|
const availability = await plugin.availability(input.context);
|
|
183
182
|
if (!availability.available) continue;
|
|
@@ -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 HTTP gateway 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(托管进程 pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n - `.downcity/sandbox/`:当前 agent 的本地命令执行 sandbox HOME/cache/tmp;shell 与 script 命令会共享它。\n2. PROFILE.md + SOUL.md
|
|
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 HTTP gateway 会把 `.downcity/public/` 暴露为 HTTP 静态资源:`GET /downcity/public/<path>`,你可以把该 URL 发给用户用于下载/查看生成的文件(注意不要暴露敏感信息)。\n - `.downcity/logs/<YYYY-MM-DD>.jsonl`:运行日志(JSONL);用于排查问题,避免把原始日志整段贴给用户。\n - `.downcity/.cache/`:幂等/去重缓存(ingress/egress);不要手动改。\n - `.downcity/.debug/`:调试产物(托管进程 pid/log/meta、适配器事件抓取等);仅在排查问题时查看。\n - `.downcity/data/`:小型持久化数据(预留)。\n - `.downcity/task/`:Task 目录。\n - `.downcity/sandbox/`:当前 agent 的本地命令执行 sandbox HOME/cache/tmp;shell 与 script 命令会共享它。\n2. PROFILE.md + SOUL.md 是你的一些配置文件,你不需要读取。\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- 向 unrestricted shell session 使用 `shell_write` 时,每一次写入都必须提供清楚的 `reason`,并等待用户确认;`shell_start` 的审批只授权启动进程,不授权后续 stdin 写入。\n- 命令会话完成后若不再需要,使用 `shell_close` 主动释放资源。\n- 不要把原始超长 shell 输出直接转发给用户,应先总结。\n- shell 命令默认在 Safe Sandbox 中执行:项目目录可读写,网络可用,HOME 指向 `.downcity/sandbox/`,真实用户 HOME 与系统目录不可写。\n- 安装 Python 依赖时优先使用项目内 `.venv`,不要使用 `pip install --user`。\n- 需要全局安装、写宿主目录、访问宿主级能力时,可以请求 `sandbox: \"unrestricted\"`;必须提供清楚的 `reason`,等待用户确认后才能执行。\n- 不要尝试 `sudo`、Xcode Command Line Tools 安装、修改 SSH/keychain/shell profile,或执行明显破坏性命令;这些请求即使使用 unrestricted sandbox 也会被拒绝。\n- 用户拒绝 unrestricted sandbox 请求后,不要反复请求同一命令,应解释影响并给出项目内替代方案。\n- 下载模型、工具缓存、临时状态应自然落在 `.downcity/sandbox/` 或项目目录中,不要假设可复用真实用户缓存。\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- 密钥列表能力只能返回已配置的 key 名与描述,不会返回密钥值。不要让用户把密钥“发给你自己”或继续尝试获取明文。\n";
|
|
8
8
|
|
|
9
9
|
export default TEXT_MODULE_CONTENT;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
- `.downcity/data/`:小型持久化数据(预留)。
|
|
11
11
|
- `.downcity/task/`:Task 目录。
|
|
12
12
|
- `.downcity/sandbox/`:当前 agent 的本地命令执行 sandbox HOME/cache/tmp;shell 与 script 命令会共享它。
|
|
13
|
-
2. PROFILE.md + SOUL.md
|
|
13
|
+
2. PROFILE.md + SOUL.md 是你的一些配置文件,你不需要读取。
|
|
14
14
|
|
|
15
15
|
# 最重要
|
|
16
16
|
【关于命令执行工具】(重要)
|
package/src/index.ts
CHANGED
|
@@ -139,11 +139,7 @@ export {
|
|
|
139
139
|
registerPluginActionCommandsForCli,
|
|
140
140
|
} from "./plugin/core/PluginCommand.js";
|
|
141
141
|
|
|
142
|
-
// Runtime plugin
|
|
143
|
-
export {
|
|
144
|
-
startAllPlugins,
|
|
145
|
-
stopAllPlugins,
|
|
146
|
-
} from "./plugin/core/Manager.js";
|
|
142
|
+
// Runtime plugin 调度集成
|
|
147
143
|
export { ActionScheduleStore } from "./plugin/core/ActionScheduleStore.js";
|
|
148
144
|
export { parseActionScheduleRunAtMsOrThrow } from "./plugin/core/ActionScheduleTime.js";
|
|
149
145
|
export {
|
|
@@ -151,9 +147,6 @@ export {
|
|
|
151
147
|
resolveAssistantMessageForPersistence,
|
|
152
148
|
} from "./executor/messages/UserVisibleText.js";
|
|
153
149
|
|
|
154
|
-
// Plugin 与权限配置集成
|
|
155
|
-
export { persistProjectPluginConfig } from "./plugin/core/ProjectConfigStore.js";
|
|
156
|
-
|
|
157
150
|
// 项目与配置集成
|
|
158
151
|
export {
|
|
159
152
|
initializeAgentProject,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Plugin
|
|
2
|
+
* Plugin 激活兼容工具。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* - plugin
|
|
5
|
+
* - 新模型不再读取 `downcity.json.plugins.<name>.enabled`。
|
|
6
|
+
* - 传入 plugin 本身就表示调用方希望它可见;Agent runtime 以注册表作为真实边界。
|
|
7
|
+
* - 该函数仅为旧内部集成保留,后续应优先使用 `context.plugins.has/status`。
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
import { readProjectPluginEnabled } from "@/plugin/core/ProjectConfigStore.js";
|
|
10
10
|
import type { Plugin } from "@/plugin/types/Plugin.js";
|
|
11
11
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* 判断当前 plugin 是否可被视为启用。
|
|
15
15
|
*/
|
|
16
16
|
export function isPluginEnabled(params: {
|
|
17
17
|
plugin: Plugin;
|
|
18
|
-
context?: Pick<AgentContext, "
|
|
18
|
+
context?: Pick<AgentContext, "plugins">;
|
|
19
19
|
}): boolean {
|
|
20
20
|
const pluginName = String(params.plugin.name || "").trim();
|
|
21
21
|
if (!pluginName) return false;
|
|
22
|
-
|
|
23
|
-
pluginName
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (params.context?.plugins) {
|
|
23
|
+
return params.context.plugins.status(pluginName)?.status === "ready";
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
26
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 主动运行型能力与被动扩展型能力统一收敛到 plugin 概念。
|
|
6
6
|
* - plugin 的长期状态归属于实例本身,而不是模块级单例。
|
|
7
|
-
* -
|
|
7
|
+
* - Agent 注册 plugin 时自动启动 lifecycle;卸载时自动停止 lifecycle。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
@@ -19,9 +19,9 @@ import type {
|
|
|
19
19
|
PluginLifecycle,
|
|
20
20
|
PluginResolves,
|
|
21
21
|
PluginSetupDefinition,
|
|
22
|
-
PluginStateRecord,
|
|
23
22
|
PluginUsageDefinition,
|
|
24
23
|
} from "@/plugin/types/Plugin.js";
|
|
24
|
+
import type { PluginRuntimeRecord } from "@/types/plugin/PluginState.js";
|
|
25
25
|
import type { StructuredConfig } from "@/types/runtime/agent/AgentContext.js";
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -29,12 +29,15 @@ import type { StructuredConfig } from "@/types/runtime/agent/AgentContext.js";
|
|
|
29
29
|
*/
|
|
30
30
|
export abstract class BasePlugin implements Plugin {
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* 当前实例持有的 plugin 注册状态记录。
|
|
33
33
|
*/
|
|
34
|
-
public readonly pluginStateRecord:
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
public readonly pluginStateRecord: PluginRuntimeRecord = {
|
|
35
|
+
plugin: this,
|
|
36
|
+
state: "ready",
|
|
37
|
+
registered_at: Date.now(),
|
|
38
|
+
updated_at: Date.now(),
|
|
37
39
|
chain: Promise.resolve(),
|
|
40
|
+
lifecycle_started: false,
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -145,6 +145,47 @@ export class HookRegistry {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* 移除指定 plugin 注册的全部扩展点。
|
|
150
|
+
*/
|
|
151
|
+
unregisterPlugin(pluginName: string): void {
|
|
152
|
+
const key = String(pluginName || "").trim();
|
|
153
|
+
if (!key) return;
|
|
154
|
+
|
|
155
|
+
for (const [pointName, bucket] of this.pipelineHooks.entries()) {
|
|
156
|
+
const next = bucket.filter((item) => item.pluginName !== key);
|
|
157
|
+
if (next.length > 0) {
|
|
158
|
+
this.pipelineHooks.set(pointName, next);
|
|
159
|
+
} else {
|
|
160
|
+
this.pipelineHooks.delete(pointName);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const [pointName, bucket] of this.guardHooks.entries()) {
|
|
165
|
+
const next = bucket.filter((item) => item.pluginName !== key);
|
|
166
|
+
if (next.length > 0) {
|
|
167
|
+
this.guardHooks.set(pointName, next);
|
|
168
|
+
} else {
|
|
169
|
+
this.guardHooks.delete(pointName);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const [pointName, bucket] of this.effectHooks.entries()) {
|
|
174
|
+
const next = bucket.filter((item) => item.pluginName !== key);
|
|
175
|
+
if (next.length > 0) {
|
|
176
|
+
this.effectHooks.set(pointName, next);
|
|
177
|
+
} else {
|
|
178
|
+
this.effectHooks.delete(pointName);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (const [pointName, record] of this.resolveHooks.entries()) {
|
|
183
|
+
if (record.pluginName === key) {
|
|
184
|
+
this.resolveHooks.delete(pointName);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
148
189
|
/**
|
|
149
190
|
* 列出所有已注册扩展点。
|
|
150
191
|
*/
|