dsh-arch-grower 0.1.0 → 0.2.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/README.md +5 -1
- package/lib/index.d.ts +35 -1
- package/lib/index.js +79 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,8 +30,12 @@ npm install -g dsh-arch-grower
|
|
|
30
30
|
| 工具 | 作用 | 写盘 |
|
|
31
31
|
| :--- | :--- | :--- |
|
|
32
32
|
| `arch_status` | 阶段、节点数、焦点、下一步建议 | 否 |
|
|
33
|
+
| `arch_focus` | 当前推演焦点:该做什么、能做多少、为什么卡住;可聚焦到节点或子系统 | 否 |
|
|
34
|
+
| `arch_facts` | 已核实的外部约束;可按节点过滤、含已取代的旧记录 | 否 |
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
`arch_focus` 接受 `node`(节点 id)与 `scope`(子系统超级节点 id);`arch_facts` 接受 `node`、`all`、`withSuperseded`。
|
|
37
|
+
|
|
38
|
+
写工具(`arch_collapse`、`arch_add_node`)见仓库 `.scratch/dsh-plugin/issues/` 下的工单。
|
|
35
39
|
|
|
36
40
|
## 配置示例
|
|
37
41
|
|
package/lib/index.d.ts
CHANGED
|
@@ -14,14 +14,48 @@ export interface RunResult {
|
|
|
14
14
|
}
|
|
15
15
|
/** 唯一对外接缝:给定命令行参数,返回退出码与输出。测试用它注入假实现。 */
|
|
16
16
|
export type Runner = (args: string[]) => Promise<RunResult>;
|
|
17
|
+
declare const textOutput: {
|
|
18
|
+
schema: {
|
|
19
|
+
readonly type: "object";
|
|
20
|
+
readonly additionalProperties: false;
|
|
21
|
+
readonly properties: {
|
|
22
|
+
readonly content: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly required: true;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
render: (_args: unknown, value: {
|
|
29
|
+
content: string;
|
|
30
|
+
}) => {
|
|
31
|
+
type: "text";
|
|
32
|
+
text: string;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
17
35
|
/** 项目目录解析顺序:显式配置 > ARCH_ROOT > 当前工作目录。 */
|
|
18
36
|
export declare function resolveProjectDir(explicit?: string, env?: Record<string, string | undefined>, cwd?: string): string;
|
|
19
37
|
/** 把引擎的失败变成可操作的一句话,原文照给,不改写。 */
|
|
20
38
|
export declare function toUserError(result: RunResult): string;
|
|
21
39
|
/** 子进程 runner:在项目目录下调用内嵌 CLI。 */
|
|
22
40
|
export declare function makeRunner(projectDir: string, python: string): Runner;
|
|
23
|
-
/**
|
|
41
|
+
/** 跑一条 CLI 命令;失败时抛引擎原文。 */
|
|
42
|
+
export declare function runCli(run: Runner, args: string[]): Promise<{
|
|
43
|
+
content: string;
|
|
44
|
+
}>;
|
|
45
|
+
export interface ToolSpec {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
parameters: Record<string, unknown>;
|
|
49
|
+
output: typeof textOutput;
|
|
50
|
+
execute: (args: Record<string, unknown>) => Promise<{
|
|
51
|
+
content: string;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
/** 只读工具集合。新增工具只加数据,不重复样板。 */
|
|
55
|
+
export declare function createReadTools(run: Runner): ToolSpec[];
|
|
56
|
+
/** 为兼容既有调用保留:只跑 status。 */
|
|
24
57
|
export declare function archStatus(run: Runner): Promise<{
|
|
25
58
|
content: string;
|
|
26
59
|
}>;
|
|
27
60
|
export declare function apply(ctx: Context, config?: Config): void;
|
|
61
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
5
5
|
export const name = 'arch-grower';
|
|
6
6
|
export const inject = ['tools'];
|
|
7
|
-
const
|
|
7
|
+
const textOutput = {
|
|
8
8
|
schema: {
|
|
9
9
|
type: 'object',
|
|
10
10
|
additionalProperties: false,
|
|
@@ -58,25 +58,91 @@ export function makeRunner(projectDir, python) {
|
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
export async function
|
|
63
|
-
const result = await run(
|
|
61
|
+
/** 跑一条 CLI 命令;失败时抛引擎原文。 */
|
|
62
|
+
export async function runCli(run, args) {
|
|
63
|
+
const result = await run(args);
|
|
64
64
|
if (result.code !== 0) {
|
|
65
65
|
throw new Error(toUserError(result));
|
|
66
66
|
}
|
|
67
67
|
return { content: result.stdout.trim() };
|
|
68
68
|
}
|
|
69
|
+
function str(value) {
|
|
70
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
71
|
+
}
|
|
72
|
+
/** 只读工具集合。新增工具只加数据,不重复样板。 */
|
|
73
|
+
export function createReadTools(run) {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
name: 'arch_status',
|
|
77
|
+
description: '读取 arch-grower 项目的架构状态:阶段、节点数、当前焦点与下一步建议。只读。',
|
|
78
|
+
parameters: { type: 'object', additionalProperties: false, properties: {} },
|
|
79
|
+
output: textOutput,
|
|
80
|
+
execute: () => runCli(run, ['status']),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'arch_focus',
|
|
84
|
+
description: '取当前推演焦点:该做什么、能做多少、为什么被卡住。可聚焦到某个节点或某个子系统。只读。',
|
|
85
|
+
parameters: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
properties: {
|
|
89
|
+
node: { type: 'string', description: '聚焦到某个节点 id,留空则用全局焦点' },
|
|
90
|
+
scope: { type: 'string', description: '子系统超级节点 id,留空表示顶层' },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
output: textOutput,
|
|
94
|
+
execute: (args) => {
|
|
95
|
+
const argv = ['focus'];
|
|
96
|
+
const node = str(args.node);
|
|
97
|
+
const scope = str(args.scope);
|
|
98
|
+
if (node) {
|
|
99
|
+
argv.push('--node', node);
|
|
100
|
+
}
|
|
101
|
+
if (scope) {
|
|
102
|
+
argv.push('--in', scope);
|
|
103
|
+
}
|
|
104
|
+
return runCli(run, argv);
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'arch_facts',
|
|
109
|
+
description: '读取已核实的 constrains/facts 记录,用来确认实现时不能违反的外部约束。只读。',
|
|
110
|
+
parameters: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
additionalProperties: false,
|
|
113
|
+
properties: {
|
|
114
|
+
node: { type: 'string', description: '只看某个节点的记录' },
|
|
115
|
+
all: { type: 'boolean', description: '包含全部节点,而不只是当前焦点' },
|
|
116
|
+
withSuperseded: { type: 'boolean', description: '同时列出已被取代的旧记录' },
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
output: textOutput,
|
|
120
|
+
execute: (args) => {
|
|
121
|
+
const argv = ['facts'];
|
|
122
|
+
const node = str(args.node);
|
|
123
|
+
if (node) {
|
|
124
|
+
argv.push('--node', node);
|
|
125
|
+
}
|
|
126
|
+
if (args.all === true) {
|
|
127
|
+
argv.push('--all');
|
|
128
|
+
}
|
|
129
|
+
if (args.withSuperseded === true) {
|
|
130
|
+
argv.push('--with-superseded');
|
|
131
|
+
}
|
|
132
|
+
return runCli(run, argv);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
/** 为兼容既有调用保留:只跑 status。 */
|
|
138
|
+
export async function archStatus(run) {
|
|
139
|
+
return runCli(run, ['status']);
|
|
140
|
+
}
|
|
69
141
|
export function apply(ctx, config = {}) {
|
|
70
142
|
const projectDir = resolveProjectDir(config.projectDir);
|
|
71
143
|
const python = config.python?.trim() || 'python';
|
|
72
144
|
const run = makeRunner(projectDir, python);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
parameters: {},
|
|
77
|
-
output,
|
|
78
|
-
async execute() {
|
|
79
|
-
return archStatus(run);
|
|
80
|
-
},
|
|
81
|
-
})));
|
|
145
|
+
for (const tool of createReadTools(run)) {
|
|
146
|
+
ctx.effect(() => ctx.tools.register(defineTool(tool)));
|
|
147
|
+
}
|
|
82
148
|
}
|