@tbox.cn/tboxcode-dsh-bundle 0.1.0-rc.15 → 0.1.0-rc.17
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/cordis.patch.yml +20 -24
- package/lib/convergence-core.d.ts +1 -1
- package/lib/convergence.d.ts +1 -1
- package/lib/identity.d.ts +9 -0
- package/lib/identity.js +113 -0
- package/lib/image-fetch-D_8nywZV.js +156 -0
- package/lib/image-fetch.d.ts +54 -0
- package/lib/image-fetch.js +3 -0
- package/lib/image-source.d.ts +62 -0
- package/lib/image-source.js +215 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.js +3 -3
- package/lib/logger.js +1 -1
- package/lib/prompts.d.ts +4 -21
- package/lib/prompts.js +13 -268
- package/lib/{remote-lvZ2n78k.js → remote-BocZwlS-.js} +138 -5
- package/lib/{remote-BZjKKp64.d.ts → remote-Cw_L6bz7.d.ts} +101 -4
- package/lib/remote.d.ts +5 -4
- package/lib/remote.js +4 -4
- package/lib/retention.d.ts +1 -1
- package/lib/retention.js +1 -1
- package/package.json +21 -11
- /package/lib/{convergence-CvqBcQv2.d.ts → convergence-Bb__S8RE.d.ts} +0 -0
- /package/lib/{convergence-core-C1ZtU17g.d.ts → convergence-core-B81Z55Bq.d.ts} +0 -0
- /package/lib/{logger-BGwLHZXY.js → logger-Dnz11jWP.js} +0 -0
- /package/lib/{retention-DNEdnIxC.js → retention-CVHXhi92.js} +0 -0
- /package/lib/{retention-B2V8Plpx.d.ts → retention-f1rAWNdl.d.ts} +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { n as fetchImage, t as DEFAULT_IMAGE_FETCH_POLICY } from "./image-fetch-D_8nywZV.js";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { resolveConfigDir, resolveConfigPath, stripJsonc, watchConfigFiles } from "@tbox.cn/tboxcode-dsh-runtime";
|
|
4
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
5
|
+
import { appendPluginRecord } from "@deepseek-ai/dsh-session";
|
|
6
|
+
import { IMAGE_SOURCE_RECORD } from "@tbox.cn/dsh-acp-bridge-core";
|
|
7
|
+
|
|
8
|
+
//#region src/image-source.ts
|
|
9
|
+
const name = "@tbox.cn/tboxcode-dsh-bundle/image-source";
|
|
10
|
+
const inject = ["attachments", "sessions"];
|
|
11
|
+
/** 抓取并发(进程级;与渲染预读同量级)。 */
|
|
12
|
+
const FETCH_CONCURRENCY = 4;
|
|
13
|
+
function positive(value, fallback) {
|
|
14
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
15
|
+
}
|
|
16
|
+
/** 自读域 → 策略(未知键忽略;非法值保持默认)。 */
|
|
17
|
+
function policyOf(config) {
|
|
18
|
+
if (config === void 0) return DEFAULT_IMAGE_FETCH_POLICY;
|
|
19
|
+
return {
|
|
20
|
+
maxBytes: positive(config.max_bytes, DEFAULT_IMAGE_FETCH_POLICY.maxBytes),
|
|
21
|
+
timeoutMs: Math.min(positive(config.timeout_ms, DEFAULT_IMAGE_FETCH_POLICY.timeoutMs), 12e4),
|
|
22
|
+
deadlineMs: Math.min(positive(config.deadline_ms, DEFAULT_IMAGE_FETCH_POLICY.deadlineMs), 12e4),
|
|
23
|
+
maxRedirects: Math.min(positive(config.max_redirects, DEFAULT_IMAGE_FETCH_POLICY.maxRedirects), 5),
|
|
24
|
+
maxUrlLength: positive(config.max_url_length, DEFAULT_IMAGE_FETCH_POLICY.maxUrlLength)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** 展示名兜底:URL pathname 末段(客户端未提供 name 时使用)。 */
|
|
28
|
+
function urlBasename(url) {
|
|
29
|
+
try {
|
|
30
|
+
const segment = new URL(url).pathname.split("/").filter((part) => part !== "").pop();
|
|
31
|
+
return segment === void 0 ? void 0 : decodeURIComponent(segment);
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 展示名裁决:客户端原始文件名优先(前端传 `fileName`),缺失/空白/超长时
|
|
38
|
+
* 回退 URL 末段。名称只作展示,永不参与路径解释。
|
|
39
|
+
*/
|
|
40
|
+
function displayNameFor(url, provided) {
|
|
41
|
+
const trimmed = provided?.trim();
|
|
42
|
+
if (trimmed !== void 0 && trimmed !== "" && trimmed.length <= 256) return trimmed;
|
|
43
|
+
return urlBasename(url);
|
|
44
|
+
}
|
|
45
|
+
/** 失败 reason → 面向调用方的稳定错误文案。 */
|
|
46
|
+
const REASON_TEXT = {
|
|
47
|
+
"url-invalid": "图片 URL 不是合法的 http(s) 绝对地址",
|
|
48
|
+
unreachable: "图片 URL 不可达(网络或状态码)",
|
|
49
|
+
timeout: "图片 URL 抓取超时",
|
|
50
|
+
"too-large": "图片超过准入字节上限",
|
|
51
|
+
"not-an-image": "响应不是受支持的图片(png / jpeg / webp / gif)"
|
|
52
|
+
};
|
|
53
|
+
/** 有界并发映射(保序)。 */
|
|
54
|
+
async function mapLimit(items, limit, fn) {
|
|
55
|
+
const results = new Array(items.length);
|
|
56
|
+
let next = 0;
|
|
57
|
+
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
58
|
+
while (true) {
|
|
59
|
+
const index = next++;
|
|
60
|
+
if (index >= items.length) return;
|
|
61
|
+
results[index] = await fn(items[index]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
await Promise.all(workers);
|
|
65
|
+
return results;
|
|
66
|
+
}
|
|
67
|
+
function stateOf(self) {
|
|
68
|
+
const carrier = self;
|
|
69
|
+
carrier._imageSourceState ??= {
|
|
70
|
+
policy: DEFAULT_IMAGE_FETCH_POLICY,
|
|
71
|
+
sessions: /* @__PURE__ */ new Map()
|
|
72
|
+
};
|
|
73
|
+
return carrier._imageSourceState;
|
|
74
|
+
}
|
|
75
|
+
var TboxcodeImageSource = class extends Service {
|
|
76
|
+
constructor(ctx) {
|
|
77
|
+
super(ctx, "imageSources");
|
|
78
|
+
this.syncConfig();
|
|
79
|
+
if (resolveConfigPath(resolveConfigDir()) !== null) {
|
|
80
|
+
const watcher = watchConfigFiles(resolveConfigDir(), ["config.jsonc", "config.json"], () => this.syncConfig());
|
|
81
|
+
ctx.effect(() => () => watcher.dispose());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** 自读域重新装载(构造 + watcher 回调;非法值告警后回落默认)。 */
|
|
85
|
+
syncConfig() {
|
|
86
|
+
const path = resolveConfigPath(resolveConfigDir());
|
|
87
|
+
if (path === null) {
|
|
88
|
+
stateOf(this).policy = DEFAULT_IMAGE_FETCH_POLICY;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(stripJsonc(readFileSync(path, "utf8")));
|
|
93
|
+
stateOf(this).policy = policyOf(parsed.image_url);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.warn("[tboxcode-image-source] image_url 配置无效,回落默认: " + String(error));
|
|
96
|
+
stateOf(this).policy = DEFAULT_IMAGE_FETCH_POLICY;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** 记录真实 Session 实例(注册到 session/created 与 agent/created 两路)。 */
|
|
100
|
+
remember(session) {
|
|
101
|
+
if (typeof session?.id === "string") stateOf(this).sessions.set(session.id, session);
|
|
102
|
+
}
|
|
103
|
+
/** 附件服务读面(可选服务——缺席即降级)。 */
|
|
104
|
+
attachmentsFace() {
|
|
105
|
+
return this.ctx.get("attachments");
|
|
106
|
+
}
|
|
107
|
+
/** 字节上限恒等于附件准入上限(只可调低——"上传能过则 URL 也能过")。 */
|
|
108
|
+
maxImageBytes() {
|
|
109
|
+
const policy = stateOf(this).policy;
|
|
110
|
+
const limit = this.attachmentsFace()?.imageLimits?.maxImageBytes;
|
|
111
|
+
return typeof limit === "number" && limit > 0 ? Math.min(policy.maxBytes, limit) : policy.maxBytes;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 准入一组图片 URL(等长同序返回;内部按 URL 去重抓取与落盘)。
|
|
115
|
+
* @param request - 会话 id、URL 列表与取消信号。
|
|
116
|
+
*/
|
|
117
|
+
async admitUrls(request) {
|
|
118
|
+
if (process.env.TBOXCODE_IMAGE_FETCH_DISABLED === "1") throw new Error("图片 URL 抓取已被部署开关禁用");
|
|
119
|
+
const attachments = this.attachmentsFace();
|
|
120
|
+
if (attachments === void 0) throw new Error("附件服务未挂载");
|
|
121
|
+
const session = this.ctx.sessions.get(request.sessionId);
|
|
122
|
+
if (session === void 0) throw new Error("会话 " + request.sessionId + " 不在内存(图片 URL 准入要求会话已激活)");
|
|
123
|
+
const unique = [...new Set(request.urls)];
|
|
124
|
+
const policy = {
|
|
125
|
+
...stateOf(this).policy,
|
|
126
|
+
maxBytes: this.maxImageBytes()
|
|
127
|
+
};
|
|
128
|
+
const fetched = await mapLimit(unique, FETCH_CONCURRENCY, async (url) => {
|
|
129
|
+
const result = await fetchImage(url, policy, {
|
|
130
|
+
fetch: (input, init) => fetch(input, init),
|
|
131
|
+
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
132
|
+
});
|
|
133
|
+
if (!result.ok) throw new Error(REASON_TEXT[result.reason] + "(" + new URL(url).origin + ")");
|
|
134
|
+
return {
|
|
135
|
+
url,
|
|
136
|
+
image: result.image
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
const providedNames = /* @__PURE__ */ new Map();
|
|
140
|
+
if (request.names !== void 0) request.urls.forEach((url, index) => {
|
|
141
|
+
const provided = request.names?.[index];
|
|
142
|
+
if (!providedNames.has(url) || providedNames.get(url) === void 0) providedNames.set(url, provided);
|
|
143
|
+
});
|
|
144
|
+
const parts = fetched.map((entry) => {
|
|
145
|
+
const name$1 = displayNameFor(entry.url, providedNames.get(entry.url));
|
|
146
|
+
return {
|
|
147
|
+
type: "image",
|
|
148
|
+
mediaType: entry.image.mediaType,
|
|
149
|
+
data: entry.image.data,
|
|
150
|
+
...name$1 === void 0 ? {} : { name: name$1 }
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
let admittedRaw;
|
|
154
|
+
try {
|
|
155
|
+
admittedRaw = await attachments.admitPromptContent(parts);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw new Error("附件准入失败:" + (error instanceof Error ? error.message : String(error)));
|
|
158
|
+
}
|
|
159
|
+
const admitted = admittedRaw;
|
|
160
|
+
if (admitted.length !== fetched.length) throw new Error("附件准入返回数量与请求不一致");
|
|
161
|
+
const images = admitted.map((part, index) => {
|
|
162
|
+
const attachmentId = part.attachment?.attachmentId;
|
|
163
|
+
if (typeof attachmentId !== "string" || attachmentId === "") throw new Error("附件准入返回缺少 attachmentId");
|
|
164
|
+
return {
|
|
165
|
+
attachmentId,
|
|
166
|
+
url: fetched[index].url
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
try {
|
|
170
|
+
appendPluginRecord(session, IMAGE_SOURCE_RECORD, { images });
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.warn("[tboxcode-image-source] 出处记录写入失败(live 仍可用):" + (error instanceof Error ? error.message : String(error)));
|
|
173
|
+
}
|
|
174
|
+
const byUrl = /* @__PURE__ */ new Map();
|
|
175
|
+
fetched.forEach((entry, index) => {
|
|
176
|
+
const name$1 = displayNameFor(entry.url, providedNames.get(entry.url));
|
|
177
|
+
byUrl.set(entry.url, {
|
|
178
|
+
attachment: admitted[index].attachment,
|
|
179
|
+
attachmentId: images[index].attachmentId,
|
|
180
|
+
...name$1 === void 0 ? {} : { name: name$1 }
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return request.urls.map((url) => {
|
|
184
|
+
const found = byUrl.get(url);
|
|
185
|
+
if (found === void 0) throw new Error("图片 URL 归并失败");
|
|
186
|
+
return found;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** 读一张已落盘图片(历史回显);失败返回 undefined(调用方降级占位)。 */
|
|
190
|
+
async readImage(attachment, signal) {
|
|
191
|
+
const attachments = this.attachmentsFace();
|
|
192
|
+
if (attachments?.readImage === void 0) return void 0;
|
|
193
|
+
try {
|
|
194
|
+
const stored = await attachments.readImage(attachment, signal);
|
|
195
|
+
return {
|
|
196
|
+
mediaType: stored.ref.mediaType,
|
|
197
|
+
data: Buffer.from(stored.data).toString("base64")
|
|
198
|
+
};
|
|
199
|
+
} catch {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
/** 插件入口:服务缺席才注册(重复挂载零副作用)。 */
|
|
205
|
+
function apply(ctx) {
|
|
206
|
+
if (ctx.get("imageSources") !== void 0) return;
|
|
207
|
+
const service = new TboxcodeImageSource(ctx);
|
|
208
|
+
ctx.on("session/created", ((session) => service.remember(session)));
|
|
209
|
+
ctx.on("agent/created", ((agent) => {
|
|
210
|
+
if (agent.session !== void 0) service.remember(agent.session);
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
//#endregion
|
|
215
|
+
export { TboxcodeImageSource, apply, displayNameFor, inject, name };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as createConvergenceCore, i as ConvergenceState, n as ConvergenceIO, o as rowsEqual, r as ConvergenceRow, t as ConvergenceCore } from "./convergence-core-
|
|
2
|
-
import { r as name, t as apply } from "./convergence-
|
|
3
|
-
import { a as SweepResult, l as sweepSessions, n as RetentionKnobs, o as isOwnedHome, r as RetentionScheduler, s as startRetentionScheduler, t as DEFAULT_KNOBS } from "./retention-
|
|
4
|
-
import { C as name$1, _ as handleRetentionRun, a as TboxcodeRemoteGateway, b as handleSkillsUserInvocable, d as handleCommit, f as handleDefaultSelection, g as handleReload, h as handleMode, l as handleCommandsExecute, m as handleHealth, o as TboxcodeRemoteServices, p as handleGitPushWatch, r as GitPushEvent, u as handleCommandsList, v as handleSessionsFlush } from "./remote-BZjKKp64.js";
|
|
1
|
+
import { a as createConvergenceCore, i as ConvergenceState, n as ConvergenceIO, o as rowsEqual, r as ConvergenceRow, t as ConvergenceCore } from "./convergence-core-B81Z55Bq.js";
|
|
2
|
+
import { r as name, t as apply } from "./convergence-Bb__S8RE.js";
|
|
3
|
+
import { a as SweepResult, l as sweepSessions, n as RetentionKnobs, o as isOwnedHome, r as RetentionScheduler, s as startRetentionScheduler, t as DEFAULT_KNOBS } from "./retention-f1rAWNdl.js";
|
|
5
4
|
import { a as redactTokens, i as createLogger, n as Logger, t as LogLevel } from "./logger-DcHqQwUI.js";
|
|
5
|
+
import { O as name$1, S as handleSessionsFlush, T as handleSkillsUserInvocable, b as handleRetentionRun, d as handleCommandsList, f as handleCommit, h as handleHealth, m as handleGitPushWatch, o as TboxcodeRemoteGateway, p as handleDefaultSelection, r as GitPushEvent, s as TboxcodeRemoteServices, u as handleCommandsExecute, v as handleMode, y as handleReload } from "./remote-Cw_L6bz7.js";
|
|
6
6
|
|
|
7
7
|
//#region src/index.d.ts
|
|
8
8
|
/**
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as rowsEqual, t as createConvergenceCore } from "./convergence-core-CbS-hTjK.js";
|
|
2
2
|
import { r as name, t as apply } from "./convergence-BnrNjcuS.js";
|
|
3
|
-
import { a as sweepSessions, n as isOwnedHome, r as startRetentionScheduler, t as DEFAULT_KNOBS } from "./retention-
|
|
4
|
-
import { n as redactTokens, t as createLogger } from "./logger-
|
|
5
|
-
import {
|
|
3
|
+
import { a as sweepSessions, n as isOwnedHome, r as startRetentionScheduler, t as DEFAULT_KNOBS } from "./retention-CVHXhi92.js";
|
|
4
|
+
import { n as redactTokens, t as createLogger } from "./logger-Dnz11jWP.js";
|
|
5
|
+
import { S as name$1, a as handleCommandsList, c as handleGitPushWatch, f as handleMode, g as handleSessionsFlush, i as handleCommandsExecute, l as handleHealth, m as handleRetentionRun, o as handleCommit, p as handleReload, s as handleDefaultSelection, t as TboxcodeRemoteGateway, y as handleSkillsUserInvocable } from "./remote-BocZwlS-.js";
|
|
6
6
|
|
|
7
7
|
//#region src/index.ts
|
|
8
8
|
/**
|
package/lib/logger.js
CHANGED
package/lib/prompts.d.ts
CHANGED
|
@@ -3,27 +3,10 @@ import { Context } from "@deepseek-ai/cordis";
|
|
|
3
3
|
//#region src/prompts.d.ts
|
|
4
4
|
declare const name = "tboxcode-prompts";
|
|
5
5
|
declare const inject: never[];
|
|
6
|
-
|
|
7
|
-
/** `system_prompt` 翻译域:字面文本或 `file://` 路径——在场即 complete 整接管。 */
|
|
8
|
-
systemPrompt?: string;
|
|
9
|
-
/** `rules` 翻译域:用户规则条目(追加用户规则 section)。 */
|
|
10
|
-
rules?: string[];
|
|
11
|
-
}
|
|
12
|
-
/** 白名单二值(reminders-plugin-dissolution 定案):真实用户输入语义。 */
|
|
13
|
-
declare const USER_VOICE_KINDS: ReadonlySet<string>;
|
|
14
|
-
/** plan 档权限说明文案(composition note 引导层;build 档空串不渲染)。 */
|
|
6
|
+
/** plan 档权限说明文案(build 档空串不渲染)。 */
|
|
15
7
|
declare function renderPermissionContext(mode: string, scratchDir: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* scratch 根声明 context(model-context design 清单新增行;紧贴
|
|
18
|
-
* WORKING_DIRECTORY(100) 与 SANDBOX_POLICY(110) 之间形成 cwd 对照)。
|
|
19
|
-
* scratch_* 相对路径与 workdir 都解析到该目录——`working_directory` / cd
|
|
20
|
-
* 只影响常规工具(模型 cwd 认知第二层信号)。
|
|
21
|
-
*/
|
|
8
|
+
/** scratch 根声明 context:只补会话动态根路径;创建/路径规则归工具描述。 */
|
|
22
9
|
declare function renderScratchContext(scratchDir: string): string;
|
|
23
|
-
|
|
24
|
-
* Working directory 行退役——dsh 0.2.1 原生 working-directory 服务注入
|
|
25
|
-
* `Current working directory: "<path>".`(同信息超集 + 工具联动,subagent-native-adoption)。 */
|
|
26
|
-
declare function renderEnvironmentContext(cwd: string): string;
|
|
27
|
-
declare function apply(ctx: Context, config?: Config): () => void;
|
|
10
|
+
declare function apply(ctx: Context): void;
|
|
28
11
|
//#endregion
|
|
29
|
-
export {
|
|
12
|
+
export { apply, inject, name, renderPermissionContext, renderScratchContext };
|
package/lib/prompts.js
CHANGED
|
@@ -1,227 +1,36 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { resolveConfigDir
|
|
4
|
-
import {
|
|
5
|
-
import { z } from "zod";
|
|
3
|
+
import { resolveConfigDir } from "@tbox.cn/tboxcode-dsh-runtime";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
6
5
|
|
|
7
6
|
//#region src/prompts.ts
|
|
8
7
|
const name = "tboxcode-prompts";
|
|
9
8
|
const inject = [];
|
|
10
|
-
const ConfigSchema = z.object({
|
|
11
|
-
systemPrompt: z.string().optional(),
|
|
12
|
-
rules: z.array(z.string()).optional()
|
|
13
|
-
});
|
|
14
9
|
const SCRATCH_ROOT = join(tmpdir(), "tboxcode-scratch");
|
|
15
10
|
function scratchDirFor(sessionId) {
|
|
16
11
|
return join(SCRATCH_ROOT, sessionId);
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- 除非你确信 URL 是用于帮助用户编程的,否则绝不要为用户生成或猜测 URL。可以使用用户消息或本地文件中提供的 URL
|
|
21
|
-
- 保持简洁、直接、切中要点。执行复杂或会对系统产生影响的 bash 命令时,应解释命令的作用和运行原因
|
|
22
|
-
- 输出将显示在命令行界面,可使用 GitHub 风格的 Markdown 进行格式化,以等宽字体显示
|
|
23
|
-
- 仅使用文本来与用户沟通;工具之外的所有输出都会显示给用户。仅使用工具完成任务,不要在会话期间使用 bash 或代码注释来与用户沟通
|
|
24
|
-
- 如果无法或不愿帮助用户完成某件事,请不要解释原因,因为这会显得说教和烦人。请提供有用的替代方案,否则保持回复在 1-2 句话
|
|
25
|
-
- 仅在用户明确要求时使用 emoji,除非被要求,否则避免在所有沟通中使用 emoji
|
|
26
|
-
- 不要添加不必要的开场白或结尾(如解释代码或总结操作),除非用户要求
|
|
27
|
-
|
|
28
|
-
# 客观专业
|
|
29
|
-
|
|
30
|
-
优先考虑技术准确性和真实性,而不是迎合用户的观点。专注于事实和问题解决,提供直接、客观的技术信息,不带不必要的赞美或情感认同。百宝箱应该对所有观点都应用同样严格的标准,必要时敢于提出异议。客观的指导和礼貌的纠正比虚假的认同更有价值。当存在不确定性时,最好先调查寻找真相,而不是下意识地迎合用户的想法。`;
|
|
31
|
-
const TASK_EXECUTION = `# 执行任务
|
|
32
|
-
|
|
33
|
-
用户主要会要求你执行软件工程任务,包括解决 bug、添加新功能、重构代码、解释代码等。对于这些任务,建议遵循以下步骤:
|
|
34
|
-
|
|
35
|
-
- 使用可用的搜索工具理解代码库和用户查询。建议灵活地并行或顺序使用搜索工具
|
|
36
|
-
- 使用 todowrite tool 规划任务(如需要)
|
|
37
|
-
- 使用所有可用工具实现解决方案
|
|
38
|
-
- 尽可能通过测试验证解决方案。不要假设特定的测试框架或脚本。检查 README 或搜索代码库确定测试方法
|
|
39
|
-
- 完成任务后,必须运行 lint 和类型检查命令(如 npm run lint、npm run typecheck、ruff 等)确保代码正确。如果找不到正确的命令,询问用户提供命令,如果他们提供了,建议将其写入 AGENTS.md 以便下次知道要运行什么
|
|
40
|
-
- 除非用户明确要求,否则绝不要提交更改。只有在明确要求时才提交,否则用户会认为你过于自作主张
|
|
41
|
-
|
|
42
|
-
工具结果和用户消息可能包含 <system-reminder> 标签。这些标签包含有用的信息和提醒,由系统自动添加,不代表特定的工具结果或用户消息的内容。
|
|
43
|
-
|
|
44
|
-
# 主动性
|
|
45
|
-
|
|
46
|
-
你可以主动采取行动,但仅在用户要求你做某事时。你应该努力在以下之间取得平衡:
|
|
47
|
-
|
|
48
|
-
1. 被要求时做正确的事,包括采取行动和后续行动
|
|
49
|
-
2. 不要在用户未询问的情况下做出令其惊讶的行动
|
|
50
|
-
例如,如果用户问你如何处理某事,你应该先尽力回答他们的问题,而不是立即跳入采取行动
|
|
51
|
-
3. 除非用户要求,否则不要添加额外的代码解释总结。处理完文件后直接停止即可,不要额外解释你做了什么
|
|
52
|
-
|
|
53
|
-
# 遵循约定
|
|
54
|
-
|
|
55
|
-
修改文件前,先了解该文件的代码规范。模仿代码风格,使用现有库和工具,遵循现有模式。
|
|
56
|
-
|
|
57
|
-
- 编写使用某个库或框架的代码时,首先检查代码库是否已使用该库。例如,查看相邻文件或检查 package.json(或 cargo.toml 等,取决于语言)
|
|
58
|
-
- 创建新组件时,首先查看现有组件的写法;然后考虑框架选择、命名约定、类型等
|
|
59
|
-
- 编辑代码时,首先查看代码的周围上下文(特别是导入)以了解代码使用的框架和库。然后考虑如何以最符合项目风格的方式进行更改
|
|
60
|
-
- 始终遵循安全最佳实践。绝不要编写会泄露或记录密钥和凭据的代码。绝不要将密钥或凭据提交到仓库`;
|
|
61
|
-
const TOOL_DISCIPLINE = `# 工具使用纪律
|
|
62
|
-
|
|
63
|
-
- 尽可能使用专用工具替代 bash 命令,因为这提供更好的用户体验。对于文件操作,使用专用工具:read 读取文件而不是 cat/head/tail,edit 编辑而不是 sed/awk,write 创建文件而不是 cat 加 heredoc 或 echo 重定向。仅在需要 shell 执行的系统命令和终端操作时才使用 bash 工具。绝不要使用 bash echo 或其他命令行工具向用户输出想法、解释或指令。直接在回复文本中输出所有沟通内容
|
|
64
|
-
- 你可以在单次响应中调用多个工具。如果你打算调用多个工具且它们之间没有依赖关系,应同时发起所有独立的工具调用。尽量并行调用工具以提高效率。但是,如果某些工具调用需要前一个调用的结果作为参数,不要并行调用,而是顺序调用。例如,如果一个操作必须在另一个操作之前完成,请顺序运行这些操作。绝不要在工具调用中使用占位符或猜测缺失参数
|
|
65
|
-
- 如果用户指定他们希望你"并行"运行工具,你必须在单条消息中发送包含多个工具调用的请求
|
|
66
|
-
- webfetch 会自动跟随 HTTP 重定向和 JS 页面跳转(最多 3 跳)
|
|
67
|
-
- 临时验证与一次性产物使用 scratch_bash / scratch_write / scratch_edit:它们以系统临时目录为根(相对路径与 scratch_bash 的工作目录都解析到那里);其他工具以当前工作目录为根;不要在工作区内创建临时目录
|
|
68
|
-
- 用户消息以斜杠命令开头时,先使用 skill 工具加载对应技能(若尚未加载);如需读取 skill 目录内其他文件,以 \`<skill_location>\` 中 SKILL.md 所在目录为基础目录`;
|
|
69
|
-
const DELEGATION = `# 委派纪律
|
|
70
|
-
|
|
71
|
-
- 对明确文件、函数、类或关键词的精确查询,直接使用 read、glob、grep 等专用工具;需要跨文件或跨模块的开放式查找与信息收集时,再使用 subagent 委派
|
|
72
|
-
- subagent 工具用于创建子代理执行委派任务。子代理上下文独立,看不到当前对话和你已掌握的信息,执行中也无法与你或用户交互,且不可再创建子代理(委派深度已到上限,收到深度提示后亲自完成)。委派前用一个统一标准判断:拿到返回结果后,你能否不重做这项任务就核实其正确性与完整性
|
|
73
|
-
- 能核实的可以委派:信息收集(查找文件、定位符号与调用点、收集指定事实)与方案已定的变更(你已写明改哪里、怎么改、怎么算完成)
|
|
74
|
-
- 核实即重做的必须亲自完成:判断、结论与设计类产出(哪里有问题、原因是什么、方案怎么定),逐条检查只能验证其报出的内容,确认没有遗漏唯有自己重做,委派它等于放弃质量控制
|
|
75
|
-
- 你对交付的每个结论和改动负全责。子代理的输出是供你使用的工作材料,不是可直接转交的成品:采信其发现前对照实际代码核实,接受其改动前按既定规格核查
|
|
76
|
-
- 任务规模与上下文压力不改变上述划分:大任务拆小后产出若仍是判断(如按模块拆分的评审、排查),依然不可委派;正确做法是你分轮亲自完成判断部分,把其中可核实的查找、收集与照规格执行环节剥离出来委派
|
|
77
|
-
- 每次委派只包含一个目标明确、范围有限的子任务,说明目标、范围和期望输出,要求达成后立即返回、不自行扩展范围;互不依赖的委派并行执行,汇总并核实结果后再推进下一轮
|
|
78
|
-
|
|
79
|
-
<example>
|
|
80
|
-
user: 客户端的错误在哪里处理?
|
|
81
|
-
assistant: [这是跨模块的开放式探索,委派 subagent 调查]
|
|
82
|
-
</example>
|
|
83
|
-
<example>
|
|
84
|
-
user: getUserById 函数定义在哪里?
|
|
85
|
-
assistant: [明确的函数名查询,直接使用 grep 搜索定义即可]
|
|
86
|
-
</example>
|
|
87
|
-
<example>
|
|
88
|
-
user: 深入评审 commit abc1234 以来的所有变更
|
|
89
|
-
assistant: [评审的产出是判断:不重做评审就无法确认子代理的结论没有遗漏,必须亲自完成——运行 git log/diff 查看变更、read 相关文件并逐一分析,变更量大时分轮进行;其中可核实的子任务剥离出来委派,如"列出 FooService.create 的所有调用点"]
|
|
90
|
-
</example>`;
|
|
91
|
-
const CODE_REFERENCES = `# 代码引用
|
|
92
|
-
|
|
93
|
-
引用特定函数或代码片段时,使用 \`file_path:line_number\` 格式,以便用户轻松导航到源代码位置。
|
|
94
|
-
|
|
95
|
-
<example>
|
|
96
|
-
user: 客户端的错误在哪里处理?
|
|
97
|
-
assistant: 客户端连接在 \`connectToServer\` 函数中被标记为失败,位于 src/services/process.ts:712。
|
|
98
|
-
</example>`;
|
|
99
|
-
const TODO_SECTION = `# 任务管理
|
|
100
|
-
|
|
101
|
-
你可以使用 todowrite tool 来管理和规划任务。经常使用这些工具来跟踪任务进度,并让用户了解你的进展。
|
|
102
|
-
|
|
103
|
-
这些工具对于规划任务和将复杂的大型任务分解为更小的步骤也非常有用。如果在规划时不使用这个工具,你可能会忘记做重要的任务——这是不可接受的。
|
|
104
|
-
|
|
105
|
-
关键的是,完成任务后应立即将 todo 标记为已完成。不要攒着多个任务一起标记完成。
|
|
106
|
-
|
|
107
|
-
示例:
|
|
108
|
-
|
|
109
|
-
<example>
|
|
110
|
-
user: 运行构建并修复所有类型错误
|
|
111
|
-
assistant: 我将使用 todowrite tool 写入以下 todo 列表:
|
|
112
|
-
- 运行构建
|
|
113
|
-
- 修复所有类型错误
|
|
114
|
-
|
|
115
|
-
现在我将使用 bash 运行构建。
|
|
116
|
-
|
|
117
|
-
看起来我发现了 10 个类型错误。我将使用 todowrite tool 写入 10 个 todo。
|
|
118
|
-
|
|
119
|
-
将第一个 todo 标记为 in_progress
|
|
120
|
-
|
|
121
|
-
让我从修复第一个开始...
|
|
122
|
-
|
|
123
|
-
第一个已修复,将其标记为 completed,然后继续第二个...
|
|
124
|
-
</example>
|
|
125
|
-
在上面的示例中,助手完成了所有任务,包括 10 个错误修复以及运行构建。
|
|
126
|
-
|
|
127
|
-
重要:在对话中始终使用 todowrite tool 来规划和跟踪任务。`;
|
|
128
|
-
const SECTION_ORDERS_TBOX = {
|
|
129
|
-
TONE_OBJECTIVITY: 100,
|
|
130
|
-
TASK_EXECUTION: 150,
|
|
131
|
-
TOOL_DISCIPLINE: 200,
|
|
132
|
-
DELEGATION: 250,
|
|
133
|
-
CODE_REFERENCES: 300,
|
|
134
|
-
TODO_MANAGEMENT: 350,
|
|
135
|
-
USER_RULES: 400
|
|
136
|
-
};
|
|
137
|
-
/** 白名单二值(reminders-plugin-dissolution 定案):真实用户输入语义。 */
|
|
138
|
-
const USER_VOICE_KINDS = new Set(["user", "user-question-reply"]);
|
|
139
|
-
/** plan 档权限说明文案(composition note 引导层;build 档空串不渲染)。 */
|
|
13
|
+
/** plan 档权限说明文案(build 档空串不渲染)。 */
|
|
140
14
|
function renderPermissionContext(mode, scratchDir) {
|
|
141
15
|
if (mode !== "read-only") return "";
|
|
142
16
|
return [
|
|
143
17
|
"# 权限模式:plan(只读)",
|
|
144
18
|
"",
|
|
145
|
-
|
|
146
|
-
`-
|
|
147
|
-
|
|
148
|
-
`- webfetch 与 curl 不得发起对目标系统有写入效果的调用。`,
|
|
149
|
-
`- 对项目的一切修改请写入计划,切回 build 模式后执行。`
|
|
19
|
+
"- 当前处于只读模式:文件写入与变更类 bash 命令会被内核拒绝(含系统临时目录)。",
|
|
20
|
+
`- 临时验证使用 scratch_bash / scratch_write / scratch_edit;它们在 \`${scratchDir}\` 放行,相对路径按该目录解析。`,
|
|
21
|
+
"- 对项目的一切修改请写入计划,切回 build 模式后执行。"
|
|
150
22
|
].join("\n");
|
|
151
23
|
}
|
|
152
|
-
/**
|
|
153
|
-
* scratch 根声明 context(model-context design 清单新增行;紧贴
|
|
154
|
-
* WORKING_DIRECTORY(100) 与 SANDBOX_POLICY(110) 之间形成 cwd 对照)。
|
|
155
|
-
* scratch_* 相对路径与 workdir 都解析到该目录——`working_directory` / cd
|
|
156
|
-
* 只影响常规工具(模型 cwd 认知第二层信号)。
|
|
157
|
-
*/
|
|
24
|
+
/** scratch 根声明 context:只补会话动态根路径;创建/路径规则归工具描述。 */
|
|
158
25
|
function renderScratchContext(scratchDir) {
|
|
159
|
-
return
|
|
160
|
-
`Scratch directory (system temp; the root for scratch_bash / scratch_write / scratch_edit): "${scratchDir}"`,
|
|
161
|
-
`- scratch_* tools create this directory on first use; never pass it as an output file target,`,
|
|
162
|
-
` even from regular bash — write to a file path inside it.`,
|
|
163
|
-
`- scratch_* tools resolve relative paths and run with this directory as their working directory.`,
|
|
164
|
-
`- Regular tools (bash, read, write, edit, glob, grep) use the current working directory; working_directory / cd changes it for regular tools only, never for the scratch root.`,
|
|
165
|
-
`- Use scratch_* for throwaway scripts and one-off artifacts; do not create temporary directories inside the workspace.`
|
|
166
|
-
].join("\n");
|
|
26
|
+
return `Scratch directory (session-private; scratch_* relative paths resolve here): "${scratchDir}".`;
|
|
167
27
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
function renderEnvironmentContext(cwd) {
|
|
172
|
-
const gitState = existsSync(join(cwd, ".git")) ? "yes" : "no";
|
|
173
|
-
return [
|
|
174
|
-
`Platform: ${platform()}`,
|
|
175
|
-
`Workspace root folder: ${cwd}`,
|
|
176
|
-
`Is directory a git repo: ${gitState}`
|
|
177
|
-
].join("\n");
|
|
178
|
-
}
|
|
179
|
-
function apply(ctx, config = {}) {
|
|
180
|
-
const parsed = ConfigSchema.parse(config);
|
|
181
|
-
const rulesCache = /* @__PURE__ */ new Map();
|
|
182
|
-
const userRulesText = (scopeKey) => {
|
|
183
|
-
const cacheKey = String(scopeKey ?? "global");
|
|
184
|
-
if (rulesCache.has(cacheKey)) return rulesCache.get(cacheKey);
|
|
185
|
-
const lines = [];
|
|
186
|
-
for (const rule of parsed.rules ?? []) lines.push(`- ${rule}`);
|
|
187
|
-
try {
|
|
188
|
-
const rulesDir = join(resolveConfigDir(), "rules");
|
|
189
|
-
if (existsSync(rulesDir)) for (const entry of readdirSync(rulesDir).sort()) {
|
|
190
|
-
const fp = join(rulesDir, entry);
|
|
191
|
-
if (statSync(fp).isFile()) lines.push(`- ${stripJsonc(readFileSync(fp, "utf-8")).trim()}`);
|
|
192
|
-
}
|
|
193
|
-
} catch {}
|
|
194
|
-
const text = lines.length > 0 ? `# 用户规则\n\n${lines.join("\n")}` : "";
|
|
195
|
-
rulesCache.set(cacheKey, text);
|
|
196
|
-
return text;
|
|
197
|
-
};
|
|
198
|
-
const completeText = () => {
|
|
199
|
-
const raw = parsed.systemPrompt;
|
|
200
|
-
if (raw === void 0) return void 0;
|
|
201
|
-
if (raw.startsWith("file://")) {
|
|
202
|
-
const fp = raw.slice(7).replace(/^~(?=\/|$)/, homedir());
|
|
203
|
-
return existsSync(fp) ? readFileSync(fp, "utf-8") : void 0;
|
|
204
|
-
}
|
|
205
|
-
return raw;
|
|
206
|
-
};
|
|
207
|
-
const preStepHandler = async (payload, next) => {
|
|
208
|
-
const decision = await next();
|
|
209
|
-
if (decision.kind !== "enter") return decision;
|
|
210
|
-
const messages = decision.messages ?? [];
|
|
211
|
-
if (messages.some((m) => typeof m?.source?.kind !== "string")) return decision;
|
|
212
|
-
if (!messages.some((m) => USER_VOICE_KINDS.has(m.source.kind))) return decision;
|
|
213
|
-
const users = messages.filter((m) => USER_VOICE_KINDS.has(m.source.kind));
|
|
214
|
-
return {
|
|
215
|
-
kind: "enter",
|
|
216
|
-
messages: [...messages.filter((m) => !USER_VOICE_KINDS.has(m.source.kind)), ...users],
|
|
217
|
-
...decision.startsRequestSeries !== void 0 ? { startsRequestSeries: decision.startsRequestSeries } : {}
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
ctx.on("agent/pre-step", preStepHandler, { prepend: true });
|
|
28
|
+
function apply(ctx) {
|
|
29
|
+
const rulesDir = join(resolveConfigDir(), "rules");
|
|
30
|
+
if (existsSync(rulesDir)) console.warn(`[tboxcode-prompts] ${rulesDir} 已不再读取(用户规则迁移到 $DSH_HOME/AGENTS.md 或项目 AGENTS.md)`);
|
|
221
31
|
ctx.inject(["systemPrompt"], (scope) => {
|
|
222
32
|
const sp = scope.systemPrompt;
|
|
223
33
|
const scopeGet = scope.get;
|
|
224
|
-
const tools = scopeGet?.call(scope, "tools") ?? void 0;
|
|
225
34
|
const sandboxModeOf = (c) => {
|
|
226
35
|
const session = c.agent?.session;
|
|
227
36
|
if (session === void 0) return void 0;
|
|
@@ -233,50 +42,6 @@ function apply(ctx, config = {}) {
|
|
|
233
42
|
return;
|
|
234
43
|
}
|
|
235
44
|
};
|
|
236
|
-
for (const s of [
|
|
237
|
-
{
|
|
238
|
-
name: "tboxcode:tone-objectivity",
|
|
239
|
-
order: SECTION_ORDERS_TBOX.TONE_OBJECTIVITY,
|
|
240
|
-
text: TONE_OBJECTIVITY
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: "tboxcode:task-execution",
|
|
244
|
-
order: SECTION_ORDERS_TBOX.TASK_EXECUTION,
|
|
245
|
-
text: TASK_EXECUTION
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
name: "tboxcode:tool-discipline",
|
|
249
|
-
order: SECTION_ORDERS_TBOX.TOOL_DISCIPLINE,
|
|
250
|
-
text: TOOL_DISCIPLINE
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
name: "tboxcode:delegation",
|
|
254
|
-
order: SECTION_ORDERS_TBOX.DELEGATION,
|
|
255
|
-
text: DELEGATION
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
name: "tboxcode:code-references",
|
|
259
|
-
order: SECTION_ORDERS_TBOX.CODE_REFERENCES,
|
|
260
|
-
text: CODE_REFERENCES
|
|
261
|
-
}
|
|
262
|
-
]) sp.section(s);
|
|
263
|
-
sp.section({
|
|
264
|
-
name: "tboxcode:todo-management",
|
|
265
|
-
order: SECTION_ORDERS_TBOX.TODO_MANAGEMENT,
|
|
266
|
-
text: (c) => tools !== void 0 && tools.schemas(c.scope).some((t) => t.name === "todo_write") ? TODO_SECTION : ""
|
|
267
|
-
});
|
|
268
|
-
sp.section({
|
|
269
|
-
name: "tboxcode:user-rules",
|
|
270
|
-
order: SECTION_ORDERS_TBOX.USER_RULES,
|
|
271
|
-
text: (c) => userRulesText(c.scope)
|
|
272
|
-
});
|
|
273
|
-
const complete = completeText();
|
|
274
|
-
if (complete !== void 0) sp.section({
|
|
275
|
-
name: "tboxcode:complete",
|
|
276
|
-
order: SECTION_ORDERS_TBOX.USER_RULES + 50,
|
|
277
|
-
text: complete,
|
|
278
|
-
complete: true
|
|
279
|
-
});
|
|
280
45
|
const sandboxOrder = sp.getContextOrder("SANDBOX_POLICY");
|
|
281
46
|
sp.context({
|
|
282
47
|
name: "tboxcode:permission",
|
|
@@ -296,28 +61,8 @@ function apply(ctx, config = {}) {
|
|
|
296
61
|
return renderScratchContext(scratchDirFor(sessionId));
|
|
297
62
|
}
|
|
298
63
|
});
|
|
299
|
-
sp.context({
|
|
300
|
-
name: "tboxcode:model",
|
|
301
|
-
order: sandboxOrder - 5,
|
|
302
|
-
text: (c) => {
|
|
303
|
-
if (c.agent === void 0) return "";
|
|
304
|
-
const sel = (scope.get?.("agentDefaultModel"))?.currentSelection?.();
|
|
305
|
-
if (sel?.provider === void 0 || sel?.model === void 0) return "";
|
|
306
|
-
return `Current model: ${sel.provider}/${sel.model}`;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
sp.context({
|
|
310
|
-
name: "tboxcode:environment",
|
|
311
|
-
order: sandboxOrder - 10,
|
|
312
|
-
text: (c) => {
|
|
313
|
-
const cwd = c.agent?.session?.header?.cwd;
|
|
314
|
-
if (c.agent === void 0 || cwd === void 0) return "";
|
|
315
|
-
return renderEnvironmentContext(cwd);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
64
|
});
|
|
319
|
-
return () => {};
|
|
320
65
|
}
|
|
321
66
|
|
|
322
67
|
//#endregion
|
|
323
|
-
export {
|
|
68
|
+
export { apply, inject, name, renderPermissionContext, renderScratchContext };
|