toolflow 3.1.4

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.
Files changed (49) hide show
  1. package/.github/workflows/ci.yml +31 -0
  2. package/README.md +106 -0
  3. package/README_zh.md +109 -0
  4. package/docs/reports/ADVANCED_EVOLUTION_REPORT.md +44 -0
  5. package/docs/reports/AUDIT_AND_OPTIMIZATION_REPORT.md +645 -0
  6. package/docs/reports/COLD_START_REVIEW_EVOLUTION.md +51 -0
  7. package/docs/reports/DEEP_ECOSYSTEM_EVOLUTION.md +43 -0
  8. package/docs/reports/MEMORY.md +18 -0
  9. package/docs/reports/MICHAEL_DISPATCH_RESULT.md +36 -0
  10. package/docs/reports/OPENSOURCE_INTEGRATION_REPORT.md +43 -0
  11. package/docs/reports/PHASE_1_OPTIMIZATION_REPORT.md +87 -0
  12. package/docs/reports/PHASE_2_OPTIMIZATION_REPORT.md +50 -0
  13. package/docs/reports/PHASE_3_OPTIMIZATION_REPORT.md +24 -0
  14. package/docs/reports/PHASE_4_OPTIMIZATION_REPORT.md +28 -0
  15. package/docs/reports/REPORT_TO_MICHAEL.md +101 -0
  16. package/docs/reports/SIGNOFF_AND_RELEASE_REPORT.md +85 -0
  17. package/docs/reports/STAFF_ASSIGNMENTS.md +26 -0
  18. package/docs/reports/TASK_ASSIGNMENTS.md +59 -0
  19. package/docs/reports/V1_6_0_EVOLUTION_REPORT.md +48 -0
  20. package/docs/reports/V1_9_0_HOTFIX_REPORT.md +30 -0
  21. package/docs/reports/V2_0_0_RELEASE_REPORT.md +18 -0
  22. package/docs/reports/V2_2_0_ZERO_SPECIALIZATION_REPORT.md +24 -0
  23. package/docs/reports/V2_3_0_EVOLUTION_REPORT.md +12 -0
  24. package/ecosystem_taxonomy.json +798 -0
  25. package/package.json +46 -0
  26. package/src/blast_radius.ts +302 -0
  27. package/src/deep_ecosystem.ts +523 -0
  28. package/src/degradation_matrix.ts +180 -0
  29. package/src/dehydrator.ts +532 -0
  30. package/src/ecosystem_taxonomy.json +803 -0
  31. package/src/engine.ts +1510 -0
  32. package/src/i18n.ts +89 -0
  33. package/src/index.ts +983 -0
  34. package/src/json_extractor.ts +57 -0
  35. package/src/memory.ts +151 -0
  36. package/src/prompts_manager.ts +262 -0
  37. package/src/review_isolation.ts +188 -0
  38. package/src/state.ts +810 -0
  39. package/src/taxonomy.ts +580 -0
  40. package/src/types.ts +341 -0
  41. package/src/ui.ts +1036 -0
  42. package/src/worker_orchestrator.ts +60 -0
  43. package/tests/challenger_stress_harness.ts +265 -0
  44. package/tests/monorepo_multilang_stress.ts +404 -0
  45. package/tests/sandbox_e2e.ts +167 -0
  46. package/tests/test_json_extractor.ts +44 -0
  47. package/tests/test_modules_1_to_4.ts +106 -0
  48. package/tests/test_suite.ts +1689 -0
  49. package/tsconfig.json +17 -0
@@ -0,0 +1,180 @@
1
+ import type { EcosystemTaxonomy } from "./types.js";
2
+
3
+ export type DegradationTier = "TIER_1_NATIVE" | "TIER_2_GENERIC" | "TIER_3_FALLBACK";
4
+
5
+ export interface ToolCapabilityResolution {
6
+ capability: string;
7
+ selectedTool: string;
8
+ fallbackTool: string;
9
+ tier: DegradationTier;
10
+ instruction: string;
11
+ }
12
+
13
+ export class GracefulDegradationMatrix {
14
+ private availableTools: Set<string>;
15
+
16
+ constructor(taxonomyOrTools?: EcosystemTaxonomy | string[]) {
17
+ this.availableTools = new Set();
18
+ if (Array.isArray(taxonomyOrTools)) {
19
+ taxonomyOrTools.forEach(t => this.availableTools.add(t));
20
+ } else if (taxonomyOrTools && taxonomyOrTools.extensions) {
21
+ taxonomyOrTools.extensions.forEach(e => this.availableTools.add(e.id));
22
+ taxonomyOrTools.extensions.forEach(e => this.availableTools.add(e.name));
23
+ }
24
+ }
25
+
26
+ public resolveCapability(
27
+ capability: "git_checkpoint" | "code_edit" | "test_runner" | "file_search" | "browser_preview",
28
+ projectType?: "node" | "rust" | "python" | "go" | "unknown"
29
+ ): ToolCapabilityResolution {
30
+ const defaultShell = process.platform === "win32" ? "powershell" : "bash";
31
+
32
+ switch (capability) {
33
+ case "git_checkpoint":
34
+ if (this.availableTools.has("pi-rewind") || this.availableTools.has("git_checkpoint")) {
35
+ return {
36
+ capability,
37
+ selectedTool: "pi-rewind",
38
+ fallbackTool: defaultShell,
39
+ tier: "TIER_1_NATIVE",
40
+ instruction: "调用专用快照插件秒级创建快照"
41
+ };
42
+ }
43
+ return {
44
+ capability,
45
+ selectedTool: defaultShell,
46
+ fallbackTool: defaultShell,
47
+ tier: "TIER_2_GENERIC",
48
+ instruction: "使用原生 Git plumbing 命令 refs/pi-checkpoints/* 创建影子引用"
49
+ };
50
+
51
+ case "code_edit":
52
+ if (this.availableTools.has("edit")) {
53
+ return {
54
+ capability,
55
+ selectedTool: "edit",
56
+ fallbackTool: "write",
57
+ tier: "TIER_1_NATIVE",
58
+ instruction: "使用精准差量替换工具 edit 进行无损补丁修改"
59
+ };
60
+ }
61
+ return {
62
+ capability,
63
+ selectedTool: "write",
64
+ fallbackTool: "write",
65
+ tier: "TIER_2_GENERIC",
66
+ instruction: "使用 write 工具直接进行文件重写落盘"
67
+ };
68
+
69
+ case "file_search":
70
+ if (this.availableTools.has("rg") || this.availableTools.has("grep")) {
71
+ return {
72
+ capability,
73
+ selectedTool: "grep",
74
+ fallbackTool: "find",
75
+ tier: "TIER_1_NATIVE",
76
+ instruction: "使用正则文本搜索定位关键符号"
77
+ };
78
+ }
79
+ return {
80
+ capability,
81
+ selectedTool: "find",
82
+ fallbackTool: "read",
83
+ tier: "TIER_2_GENERIC",
84
+ instruction: "使用文件树遍历过滤目标文件"
85
+ };
86
+
87
+ case "browser_preview":
88
+ if (this.availableTools.has("pi-browser") || this.availableTools.has("browser_action")) {
89
+ return {
90
+ capability,
91
+ selectedTool: "pi-browser",
92
+ fallbackTool: defaultShell,
93
+ tier: "TIER_1_NATIVE",
94
+ instruction: "拉起真机浏览器执行交互式验收与截图"
95
+ };
96
+ }
97
+ return {
98
+ capability,
99
+ selectedTool: defaultShell,
100
+ fallbackTool: "read",
101
+ tier: "TIER_3_FALLBACK",
102
+ instruction: "输出本地静态链接或启动临时开发服务器供人工预览"
103
+ };
104
+
105
+ case "test_runner":
106
+ default:
107
+ let runnerInstruction = "调用语言原生命令执行单元测试与门禁退出码校验";
108
+ if (projectType === "rust") {
109
+ runnerInstruction = "执行 cargo test 运行 Rust 原生测试套件与类型校验";
110
+ } else if (projectType === "python") {
111
+ runnerInstruction = "执行 pytest / python -m unittest 运行 Python 测试套件";
112
+ } else if (projectType === "go") {
113
+ runnerInstruction = "执行 go test ./... 运行 Go 单元测试与覆盖率检查";
114
+ } else if (projectType === "node") {
115
+ runnerInstruction = "执行 npm test / pnpm test / vitest 运行 Node.js 测试";
116
+ }
117
+
118
+ return {
119
+ capability,
120
+ selectedTool: defaultShell,
121
+ fallbackTool: defaultShell,
122
+ tier: "TIER_2_GENERIC",
123
+ instruction: runnerInstruction
124
+ };
125
+ }
126
+ }
127
+
128
+ /**
129
+ * P0: 动态工具剪枝 (Stage 粒度工具集合解析)
130
+ * 严防设计阶段死锁:允许 write 写入设计文档 docs/design.md
131
+ */
132
+ public resolvePrunedToolsForStage(
133
+ stageKindOrId?: string,
134
+ stageAllowedTools: string[] = []
135
+ ): { allowedTools: string[]; blockedTools: string[] } {
136
+ let baseAllowed: string[] = [];
137
+ let baseBlocked: string[] = [];
138
+
139
+ const raw = (stageKindOrId || "").toLowerCase();
140
+ let normalizedKind = "code";
141
+ if (raw.includes("design") || raw.includes("architect") || raw.includes("spec") || raw.includes("rfc")) {
142
+ normalizedKind = "design";
143
+ } else if (raw.includes("preview") || raw.includes("audit") || raw.includes("receipt") || raw.includes("review")) {
144
+ normalizedKind = "preview";
145
+ } else if (raw.includes("test") || raw.includes("verif") || raw.includes("qa") || raw.includes("gate")) {
146
+ normalizedKind = "test";
147
+ }
148
+
149
+ switch (normalizedKind) {
150
+ case "design":
151
+ baseAllowed = ["read", "grep", "find", "ls", "write", "web_search", "fetch_content"];
152
+ baseBlocked = ["edit", "bash", "powershell"];
153
+ break;
154
+ case "preview":
155
+ baseAllowed = ["read", "grep", "find", "ls", "plannotator", "fetch_content", "mcp"];
156
+ baseBlocked = ["edit", "write"];
157
+ break;
158
+ case "test":
159
+ baseAllowed = ["read", "grep", "find", "ls", "bash", "powershell", "write", "goal_complete", "goal_blocked", "goal_wait", "mcp"];
160
+ baseBlocked = ["edit"];
161
+ break;
162
+ case "code":
163
+ default:
164
+ baseAllowed = ["read", "grep", "find", "ls", "write", "edit", "bash", "powershell", "workflow", "subagent", "mcp"];
165
+ baseBlocked = [];
166
+ break;
167
+ }
168
+
169
+ // 若 stage 显式声明了允许的高阶工具或受限工具,以显式声明与基线交集/并集为准
170
+ let mergedAllowed = Array.from(new Set([...baseAllowed, ...stageAllowedTools]));
171
+ if (stageAllowedTools && stageAllowedTools.length > 0) {
172
+ // 保证显式声明的高级工具(如 workflow / goal_complete 等)必被激活
173
+ mergedAllowed = Array.from(new Set([...stageAllowedTools, ...baseAllowed.filter(b => ["read", "grep", "find", "ls"].includes(b))]));
174
+ }
175
+ return {
176
+ allowedTools: mergedAllowed,
177
+ blockedTools: baseBlocked.filter(b => !mergedAllowed.includes(b))
178
+ };
179
+ }
180
+ }