@xgjktech/xg-openclaw-harness-tools 0.3.0 → 0.3.1
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plan-execute-tool.d.ts +2 -1
- package/dist/plan-execute-tool.d.ts.map +1 -1
- package/dist/plan-execute-tool.js +27 -3
- package/dist/plan-scope.d.ts +8 -0
- package/dist/plan-scope.d.ts.map +1 -0
- package/dist/plan-scope.js +16 -0
- package/dist/plan-write-tool.d.ts.map +1 -1
- package/dist/plan-write-tool.js +5 -3
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,wBAoCG"}
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ export default defineToolPlugin({
|
|
|
34
34
|
description: PLAN_EXECUTE_DESCRIPTION,
|
|
35
35
|
parameters: PlanExecuteParams,
|
|
36
36
|
optional: true,
|
|
37
|
-
factory: ({ api }) => buildPlanExecuteTool({ store: getStore(api) }),
|
|
37
|
+
factory: ({ api, toolContext }) => buildPlanExecuteTool({ store: getStore(api), origin: toPlanOrigin(toolContext) }),
|
|
38
38
|
}),
|
|
39
39
|
];
|
|
40
40
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
2
|
import type { AnyAgentTool } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
|
-
import type { PlanStore } from "@xgjktech/xg-openclaw-shared";
|
|
3
|
+
import type { PlanOrigin, PlanStore } from "@xgjktech/xg-openclaw-shared";
|
|
4
4
|
export declare const PlanExecuteParams: Type.TObject<{
|
|
5
5
|
planId: Type.TOptional<Type.TString>;
|
|
6
6
|
}>;
|
|
@@ -8,5 +8,6 @@ export type PlanExecuteParamsT = Static<typeof PlanExecuteParams>;
|
|
|
8
8
|
export declare const PLAN_EXECUTE_DESCRIPTION: string;
|
|
9
9
|
export declare function buildPlanExecuteTool(deps: {
|
|
10
10
|
store: PlanStore;
|
|
11
|
+
origin?: PlanOrigin;
|
|
11
12
|
}): AnyAgentTool;
|
|
12
13
|
//# sourceMappingURL=plan-execute-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-execute-tool.d.ts","sourceRoot":"","sources":["../src/plan-execute-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"plan-execute-tool.d.ts","sourceRoot":"","sources":["../src/plan-execute-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAQ,UAAU,EAAE,SAAS,EAAe,MAAM,8BAA8B,CAAC;AAK7F,eAAO,MAAM,iBAAiB;;EAK7B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE,eAAO,MAAM,wBAAwB,QAQzB,CAAC;AAuBb,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,YAAY,CA2ClG"}
|
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { renderPlanView } from "./plan-view.js";
|
|
3
|
+
import { planInScope, scopeKey } from "./plan-scope.js";
|
|
3
4
|
import { toolJsonResult } from "./tool-json-result.js";
|
|
4
5
|
export const PlanExecuteParams = Type.Object({
|
|
5
6
|
planId: Type.Optional(Type.String({ description: "要查看的计划 id;留空则列出最近计划" })),
|
|
6
7
|
}, { additionalProperties: false });
|
|
7
8
|
export const PLAN_EXECUTE_DESCRIPTION = [
|
|
8
9
|
"用途:只读查看已保存的计划;不执行任务,也不修改计划。",
|
|
10
|
+
"只能看到当前会话来源的计划。",
|
|
9
11
|
"",
|
|
10
12
|
"- 带 planId:返回该计划当前的完整清单。",
|
|
11
13
|
"- 不带 planId:返回最近计划的摘要列表,用于忘记或跨会话找回 planId。",
|
|
12
14
|
"",
|
|
13
15
|
"需要更新进度时,用 xg_plan_write 重新提交整张计划。",
|
|
14
16
|
].join("\n");
|
|
17
|
+
function summarizePlan(plan) {
|
|
18
|
+
const taskCounts = { total: 0, completed: 0, blocked: 0, inProgress: 0 };
|
|
19
|
+
for (const task of plan.tasks) {
|
|
20
|
+
taskCounts.total += 1;
|
|
21
|
+
if (task.status === "completed")
|
|
22
|
+
taskCounts.completed += 1;
|
|
23
|
+
if (task.status === "blocked")
|
|
24
|
+
taskCounts.blocked += 1;
|
|
25
|
+
if (task.status === "in_progress")
|
|
26
|
+
taskCounts.inProgress += 1;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
planId: plan.planId,
|
|
30
|
+
goal: plan.goal,
|
|
31
|
+
updatedAt: plan.updatedAt,
|
|
32
|
+
taskCounts,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
15
35
|
export function buildPlanExecuteTool(deps) {
|
|
16
|
-
const { store } = deps;
|
|
36
|
+
const { store, origin } = deps;
|
|
37
|
+
const scope = scopeKey(origin);
|
|
17
38
|
return {
|
|
18
39
|
name: "xg_plan_execute",
|
|
19
40
|
label: "【xg-harness】查看计划",
|
|
@@ -23,11 +44,14 @@ export function buildPlanExecuteTool(deps) {
|
|
|
23
44
|
const params = rawParams;
|
|
24
45
|
try {
|
|
25
46
|
if (params.planId === undefined) {
|
|
26
|
-
const
|
|
47
|
+
const plans = scope === undefined
|
|
48
|
+
? []
|
|
49
|
+
: store.listPlansByOrigin(scope).slice(0, 10).map(summarizePlan);
|
|
50
|
+
const result = { ok: true, plans };
|
|
27
51
|
return toolJsonResult(result);
|
|
28
52
|
}
|
|
29
53
|
const plan = store.get(params.planId);
|
|
30
|
-
if (plan === undefined) {
|
|
54
|
+
if (plan === undefined || !planInScope(plan, scope)) {
|
|
31
55
|
const result = { ok: false, error: { code: "PLAN_NOT_FOUND" } };
|
|
32
56
|
return toolJsonResult(result);
|
|
33
57
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plan, PlanOrigin } from "@xgjktech/xg-openclaw-shared";
|
|
2
|
+
export interface PlanScope {
|
|
3
|
+
channel: string;
|
|
4
|
+
to: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function scopeKey(origin?: PlanOrigin): PlanScope | undefined;
|
|
7
|
+
export declare function planInScope(plan: Plan, scope: PlanScope | undefined): boolean;
|
|
8
|
+
//# sourceMappingURL=plan-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-scope.d.ts","sourceRoot":"","sources":["../src/plan-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAMD,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAKnE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAQ7E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function isNonEmptyString(value) {
|
|
2
|
+
return typeof value === "string" && value.trim() !== "";
|
|
3
|
+
}
|
|
4
|
+
export function scopeKey(origin) {
|
|
5
|
+
if (!isNonEmptyString(origin?.channel) || !isNonEmptyString(origin?.to)) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return { channel: origin.channel, to: origin.to };
|
|
9
|
+
}
|
|
10
|
+
export function planInScope(plan, scope) {
|
|
11
|
+
const planScope = scopeKey(plan.origin);
|
|
12
|
+
return (scope !== undefined &&
|
|
13
|
+
planScope !== undefined &&
|
|
14
|
+
planScope.channel === scope.channel &&
|
|
15
|
+
planScope.to === scope.to);
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-write-tool.d.ts","sourceRoot":"","sources":["../src/plan-write-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,SAAS,EAGf,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"plan-write-tool.d.ts","sourceRoot":"","sources":["../src/plan-write-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,SAAS,EAGf,MAAM,8BAA8B,CAAC;AA4BtC,eAAO,MAAM,eAAe;;;;;;;;EAiB3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,eAAO,MAAM,sBAAsB,QAkBvB,CAAC;AAwCb,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CA6CtF"}
|
package/dist/plan-write-tool.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { assertPlanInvariants, } from "@xgjktech/xg-openclaw-shared";
|
|
4
4
|
import { toolJsonResult } from "./tool-json-result.js";
|
|
5
5
|
import { renderPlanView } from "./plan-view.js";
|
|
6
|
+
import { planInScope, scopeKey } from "./plan-scope.js";
|
|
6
7
|
const TaskInput = Type.Object({
|
|
7
8
|
title: Type.String({
|
|
8
9
|
minLength: 1,
|
|
@@ -68,8 +69,8 @@ function buildPlan(params, existing, planId, origin) {
|
|
|
68
69
|
updatedAt: now,
|
|
69
70
|
tasks: params.tasks.map(toTask),
|
|
70
71
|
};
|
|
71
|
-
// 改写已有计划时保留原 origin
|
|
72
|
-
//
|
|
72
|
+
// 改写已有计划时保留原 origin(改写是内容编辑,不是重新发起)。
|
|
73
|
+
// 无 origin 的旧计划已在作用域校验阶段被拒绝,不会在这里被认领。
|
|
73
74
|
const resolvedOrigin = existing !== undefined ? (existing.origin ?? origin) : origin;
|
|
74
75
|
if (resolvedOrigin !== undefined) {
|
|
75
76
|
plan.origin = resolvedOrigin;
|
|
@@ -77,6 +78,7 @@ function buildPlan(params, existing, planId, origin) {
|
|
|
77
78
|
return plan;
|
|
78
79
|
}
|
|
79
80
|
export function buildPlanWriteTool(store, origin) {
|
|
81
|
+
const scope = scopeKey(origin);
|
|
80
82
|
return {
|
|
81
83
|
name: "xg_plan_write",
|
|
82
84
|
label: "【xg-harness】编写计划",
|
|
@@ -88,7 +90,7 @@ export function buildPlanWriteTool(store, origin) {
|
|
|
88
90
|
let existing;
|
|
89
91
|
if (params.planId !== undefined) {
|
|
90
92
|
existing = store.get(params.planId);
|
|
91
|
-
if (existing === undefined) {
|
|
93
|
+
if (existing === undefined || !planInScope(existing, scope)) {
|
|
92
94
|
const result = {
|
|
93
95
|
ok: false,
|
|
94
96
|
error: { code: "PLAN_NOT_FOUND" },
|