@xgjktech/xg-openclaw-harness-tools 0.4.7 → 0.4.8
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 +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -3
- package/dist/plan-prompt.d.ts +5 -4
- package/dist/plan-prompt.d.ts.map +1 -1
- package/dist/plan-prompt.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,10 +107,13 @@ task;写入 schema 不接受 steps,但读取旧计划仍兼容旧 steps 数
|
|
|
107
107
|
|
|
108
108
|
## 主动计划提示词注入(before_prompt_build)
|
|
109
109
|
|
|
110
|
-
插件在 `register` 时挂载 `before_prompt_build` hook,用 `appendSystemContext`
|
|
110
|
+
插件在 `register` 时挂载 `before_prompt_build` hook,用 `appendSystemContext` 向**主 agent** 的
|
|
111
111
|
system prompt 追加一段"主动工作计划"纪律(`src/plan-prompt.ts`):多步工作先建计划、逐项整张回写、
|
|
112
112
|
blocked 带 note、台账≠执行。内容与工具 description 一致,仅抬升"主动触发"的优先级。
|
|
113
113
|
|
|
114
|
+
- **subagent 不参与计划**:hook 通过 `isSubagentSessionKey(sessionKey)` 识别 subagent 会话,
|
|
115
|
+
对 subagent 不注入纪律;同时 `xg_plan_write` / `xg_plan_view` 两个工具在 subagent 会话的
|
|
116
|
+
factory 阶段返回 `null` 不注册,只有主 agent 能建计划,避免 subagent 建计划污染主面板。
|
|
114
117
|
- **与其他注入不冲突**:IM 通道的 `GroupSystemPrompt` 落在 base system prompt,本段追加在其后,
|
|
115
118
|
纯叠加不覆盖;对内置 runtime 与 Codex runtime 均生效。
|
|
116
119
|
- **如需关闭**:在部署配置里对该插件入口设 `hooks.allowPromptInjection: false`(默认放行):
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+BA,QAAA,MAAM,WAAW,kEA6Df,CAAC;AAaH,eAAe,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineToolPlugin } from "openclaw/plugin-sdk/tool-plugin";
|
|
2
|
+
import { isSubagentSessionKey } from "openclaw/plugin-sdk/routing";
|
|
2
3
|
import { resolvePlanDbPath, SqlitePlanStore, SqliteActionStore } from "@xgjktech/xg-openclaw-shared";
|
|
3
4
|
import { PLAN_WRITE_DESCRIPTION, PlanWriteParams, buildPlanWriteTool } from "./plan-write-tool.js";
|
|
4
5
|
import { PLAN_VIEW_DESCRIPTION, PlanViewParams, buildPlanViewTool, } from "./plan-view-tool.js";
|
|
@@ -6,6 +7,15 @@ import { ACTION_DISPATCH_DESCRIPTION, ActionDispatchParams, buildActionDispatchT
|
|
|
6
7
|
import { toPlanOrigin } from "./plan-origin.js";
|
|
7
8
|
import { buildPlanPromptInjection } from "./plan-prompt.js";
|
|
8
9
|
const PLUGIN_ID = "xg-harness-tools";
|
|
10
|
+
// 临时诊断日志:确认 subagent 会话的 sessionKey 是否到达 hook/tool factory 且判定正确。确认后删除。
|
|
11
|
+
function logPlanGate(api, tag, sessionKey) {
|
|
12
|
+
api.runtime?.logging
|
|
13
|
+
?.getChildLogger({ plugin: PLUGIN_ID })
|
|
14
|
+
?.info?.(`plan-gate:${tag}`, {
|
|
15
|
+
sessionKey: sessionKey ?? null,
|
|
16
|
+
subagent: isSubagentSessionKey(sessionKey),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
9
19
|
const pluginEntry = defineToolPlugin({
|
|
10
20
|
id: PLUGIN_ID,
|
|
11
21
|
name: "XG Harness Tools",
|
|
@@ -34,7 +44,13 @@ const pluginEntry = defineToolPlugin({
|
|
|
34
44
|
description: PLAN_WRITE_DESCRIPTION,
|
|
35
45
|
parameters: PlanWriteParams,
|
|
36
46
|
optional: true,
|
|
37
|
-
factory: ({ api, toolContext }) =>
|
|
47
|
+
factory: ({ api, toolContext }) => {
|
|
48
|
+
// 计划只允许主 agent 维护;subagent 会话不注册计划工具,杜绝其建计划。
|
|
49
|
+
logPlanGate(api, "plan_write_factory", toolContext.sessionKey);
|
|
50
|
+
if (isSubagentSessionKey(toolContext.sessionKey))
|
|
51
|
+
return null;
|
|
52
|
+
return buildPlanWriteTool(getPlanStore(api), toPlanOrigin(toolContext));
|
|
53
|
+
},
|
|
38
54
|
}),
|
|
39
55
|
tool({
|
|
40
56
|
name: "xg_plan_view",
|
|
@@ -42,7 +58,12 @@ const pluginEntry = defineToolPlugin({
|
|
|
42
58
|
description: PLAN_VIEW_DESCRIPTION,
|
|
43
59
|
parameters: PlanViewParams,
|
|
44
60
|
optional: true,
|
|
45
|
-
factory: ({ api, toolContext }) =>
|
|
61
|
+
factory: ({ api, toolContext }) => {
|
|
62
|
+
logPlanGate(api, "plan_view_factory", toolContext.sessionKey);
|
|
63
|
+
if (isSubagentSessionKey(toolContext.sessionKey))
|
|
64
|
+
return null;
|
|
65
|
+
return buildPlanViewTool({ store: getPlanStore(api), origin: toPlanOrigin(toolContext) });
|
|
66
|
+
},
|
|
46
67
|
}),
|
|
47
68
|
tool({
|
|
48
69
|
name: "xg_action_dispatch",
|
|
@@ -60,6 +81,9 @@ const pluginEntry = defineToolPlugin({
|
|
|
60
81
|
const baseRegister = pluginEntry.register;
|
|
61
82
|
pluginEntry.register = (api) => {
|
|
62
83
|
baseRegister(api);
|
|
63
|
-
api.on("before_prompt_build",
|
|
84
|
+
api.on("before_prompt_build", (event, ctx) => {
|
|
85
|
+
logPlanGate(api, "hook", ctx.sessionKey);
|
|
86
|
+
return buildPlanPromptInjection(event, ctx);
|
|
87
|
+
});
|
|
64
88
|
};
|
|
65
89
|
export default pluginEntry;
|
package/dist/plan-prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PluginHookBeforePromptBuildResult } from "openclaw/plugin-sdk/types";
|
|
1
|
+
import type { PluginHookAgentContext, PluginHookBeforePromptBuildEvent, PluginHookBeforePromptBuildResult } from "openclaw/plugin-sdk/types";
|
|
2
2
|
/**
|
|
3
3
|
* 追加到 agent system prompt 的"主动建计划"纪律(appendSystemContext)。
|
|
4
4
|
* 与 IM 通道的 GroupSystemPrompt 纯叠加不冲突:本段拼在 base systemPrompt 之后。
|
|
@@ -6,8 +6,9 @@ import type { PluginHookBeforePromptBuildResult } from "openclaw/plugin-sdk/type
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const PLAN_FIRST_SYSTEM_CONTEXT: string;
|
|
8
8
|
/**
|
|
9
|
-
* before_prompt_build
|
|
10
|
-
*
|
|
9
|
+
* before_prompt_build 钩子处理器:仅向主 agent 的 system prompt 追加主动建计划纪律。
|
|
10
|
+
* subagent 会话(sessionKey 命中 isSubagentSessionKey)不注入,避免其主动建计划污染主面板;
|
|
11
|
+
* 返回 void 语义由宿主管控。
|
|
11
12
|
*/
|
|
12
|
-
export declare function buildPlanPromptInjection(): PluginHookBeforePromptBuildResult;
|
|
13
|
+
export declare function buildPlanPromptInjection(_event: PluginHookBeforePromptBuildEvent, ctx: PluginHookAgentContext): PluginHookBeforePromptBuildResult | void;
|
|
13
14
|
//# sourceMappingURL=plan-prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-prompt.d.ts","sourceRoot":"","sources":["../src/plan-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"plan-prompt.d.ts","sourceRoot":"","sources":["../src/plan-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,gCAAgC,EAChC,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AAGnC;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAQ1B,CAAC;AAEb;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,gCAAgC,EACxC,GAAG,EAAE,sBAAsB,GAC1B,iCAAiC,GAAG,IAAI,CAG1C"}
|
package/dist/plan-prompt.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSubagentSessionKey } from "openclaw/plugin-sdk/routing";
|
|
1
2
|
/**
|
|
2
3
|
* 追加到 agent system prompt 的"主动建计划"纪律(appendSystemContext)。
|
|
3
4
|
* 与 IM 通道的 GroupSystemPrompt 纯叠加不冲突:本段拼在 base systemPrompt 之后。
|
|
@@ -13,9 +14,12 @@ export const PLAN_FIRST_SYSTEM_CONTEXT = [
|
|
|
13
14
|
"- xg_plan_write / xg_plan_view 只是台账,不执行、不调度、无后台运行;保存/查看之后必须继续逐项实际执行任务。",
|
|
14
15
|
].join("\n");
|
|
15
16
|
/**
|
|
16
|
-
* before_prompt_build
|
|
17
|
-
*
|
|
17
|
+
* before_prompt_build 钩子处理器:仅向主 agent 的 system prompt 追加主动建计划纪律。
|
|
18
|
+
* subagent 会话(sessionKey 命中 isSubagentSessionKey)不注入,避免其主动建计划污染主面板;
|
|
19
|
+
* 返回 void 语义由宿主管控。
|
|
18
20
|
*/
|
|
19
|
-
export function buildPlanPromptInjection() {
|
|
21
|
+
export function buildPlanPromptInjection(_event, ctx) {
|
|
22
|
+
if (isSubagentSessionKey(ctx.sessionKey))
|
|
23
|
+
return undefined;
|
|
20
24
|
return { appendSystemContext: PLAN_FIRST_SYSTEM_CONTEXT };
|
|
21
25
|
}
|