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
package/src/types.ts ADDED
@@ -0,0 +1,341 @@
1
+ export type LayerType = "L1_UTILITY" | "L2_PERCEPTION" | "L3_ORCHESTRATION" | "L4_REVIEW_GUARD";
2
+
3
+ export interface McpToolBinding {
4
+ server: string;
5
+ tool: string;
6
+ reason: string;
7
+ template: string; // 标准调用示例,如 mcp({ server: "playwright", tool: "screenshot", args: { path: "preview.png" } })
8
+ }
9
+
10
+ export interface DistilledSkillContract {
11
+ skillName: string;
12
+ filePath?: string;
13
+ directives: string[];
14
+ sopSteps: string[];
15
+ rules: string[];
16
+ checkpoints: string[];
17
+ }
18
+
19
+ export interface CapabilityItem {
20
+ id: string;
21
+ name: string;
22
+ kind: "extension" | "skill" | "prompt" | "mcp" | "tool";
23
+ layer: LayerType;
24
+ description: string;
25
+ tokenImpact: "minimal" | "low" | "medium" | "high";
26
+ triggerWhen: string;
27
+ summary?: string;
28
+ tags?: string[];
29
+ costLevel?: "$0" | "$1" | "$2" | "$3";
30
+ bindingReason?: string;
31
+ filePath?: string; // 物理路径 (针对 SKILL.md 或 prompt 模板)
32
+ methods?: string[]; // 暴露的具体方法/命令列表 (针对 MCP Server 或插件)
33
+ }
34
+
35
+ export type ProjectType =
36
+ | "node"
37
+ | "rust"
38
+ | "python"
39
+ | "go"
40
+ | "cpp"
41
+ | "java"
42
+ | "bun"
43
+ | "deno"
44
+ | "csharp"
45
+ | "ruby"
46
+ | "php"
47
+ | "swift"
48
+ | "kotlin"
49
+ | "monorepo"
50
+ | "generic_doc"
51
+ | "unknown";
52
+
53
+ export interface ProjectFingerprint {
54
+ projectType: ProjectType;
55
+ mainFramework?: string;
56
+ packageManager:
57
+ | "npm"
58
+ | "pnpm"
59
+ | "yarn"
60
+ | "bun"
61
+ | "deno"
62
+ | "cargo"
63
+ | "pip"
64
+ | "uv"
65
+ | "poetry"
66
+ | "go"
67
+ | "cmake"
68
+ | "gradle"
69
+ | "maven"
70
+ | "dotnet"
71
+ | "unknown";
72
+ hasGit: boolean;
73
+ isClean: boolean;
74
+ topLevelDirs: string[];
75
+ coreDependencies: string[];
76
+ gitBranch?: string;
77
+ activeModifiedPaths?: string[]; // Git 变更集中度与受影响模块
78
+ language?: string;
79
+ }
80
+
81
+ export interface EcosystemTaxonomy {
82
+ installedFingerprint: string;
83
+ projectFingerprint?: ProjectFingerprint;
84
+ updatedAt: number | string;
85
+ extensions: CapabilityItem[];
86
+ skills: CapabilityItem[];
87
+ prompts: CapabilityItem[];
88
+ mcps?: CapabilityItem[];
89
+ tools?: CapabilityItem[];
90
+ availableToolNames?: string[]; // 真实存在且注册的工具名称清单 (来自 pi.getAllTools)
91
+ summaryByLayer: Record<LayerType, number>;
92
+ }
93
+
94
+ export interface TradeOffDimension {
95
+ name: string;
96
+ scoreA: number; // 1-5
97
+ scoreB: number; // 1-5
98
+ commentary: string;
99
+ }
100
+
101
+ export interface ABMatrix {
102
+ planA: {
103
+ name: string;
104
+ description: string;
105
+ pros: string[];
106
+ cons: string[];
107
+ tokenOverhead: "minimal" | "low" | "medium" | "high";
108
+ pipelineStagesCount?: number;
109
+ };
110
+ planB: {
111
+ name: string;
112
+ description: string;
113
+ pros: string[];
114
+ cons: string[];
115
+ tokenOverhead: "minimal" | "low" | "medium" | "high";
116
+ pipelineStagesCount?: number;
117
+ };
118
+ dimensions: TradeOffDimension[];
119
+ recommendation: "A" | "B";
120
+ rationale: string;
121
+ }
122
+
123
+ export interface TradeOffPlan {
124
+ id: string;
125
+ title: string;
126
+ summary: string;
127
+ matrix: ABMatrix;
128
+ }
129
+
130
+ export interface TaskRequirementChoice {
131
+ id: string;
132
+ label: string;
133
+ description: string;
134
+ isRecommended?: boolean;
135
+ tradeOffAnalysis?: {
136
+ pros: string[];
137
+ cons: string[];
138
+ };
139
+ recommendedEcosystem: {
140
+ extensions: string[];
141
+ skills?: string[];
142
+ prompts?: string[];
143
+ reason: string;
144
+ tokenSavingAdvice?: string;
145
+ };
146
+ }
147
+
148
+ export interface TaskRequirementSlot {
149
+ slotId: string;
150
+ title: string;
151
+ question: string;
152
+ category?: "scope" | "design" | "storage" | "interaction" | "architecture" | "gate" | "general" | "ecosystem";
153
+ options: TaskRequirementChoice[];
154
+ }
155
+
156
+ export interface TaskDiagnosis {
157
+ taskDescription?: string;
158
+ domain?: string;
159
+ technicalStack?: string[];
160
+ difficulty?: string;
161
+ recommendedExtensions?: string[];
162
+ recommendedSkills?: string[];
163
+ researchSummary?: string;
164
+ requirementSlots: TaskRequirementSlot[];
165
+ decisionSlots?: TaskRequirementSlot[]; // alias for compatibility
166
+ tradeOff?: TradeOffPlan;
167
+ dynamicGoals?: string[];
168
+ architectSparks?: Array<{
169
+ id: string;
170
+ title: string;
171
+ description: string;
172
+ impact: string;
173
+ isAcceptedByDefault?: boolean;
174
+ }>;
175
+ }
176
+
177
+ export type StageExecutionMode = "sequential" | "subagent_parallel" | "subagent_council" | "interactive_gate";
178
+
179
+ export interface BlueprintStage {
180
+ stageId: string;
181
+ title: string;
182
+ roleProfile: string;
183
+ coreObjective: string;
184
+ mode?: StageExecutionMode;
185
+ dependsOn?: string[]; // DAG 依赖前置阶段 ID 列表
186
+ subagentDispatch?: {
187
+ enabled?: boolean;
188
+ agentName?: string;
189
+ agentType?: string;
190
+ task?: string;
191
+ concurrency?: number;
192
+ promptFlow?: string;
193
+ };
194
+ boundCapabilities?: {
195
+ extensions?: string[];
196
+ skills?: string[];
197
+ prompts?: string[];
198
+ };
199
+ expectedArtifact: string;
200
+ expectedArtifacts?: string[];
201
+ targetPatterns?: string[];
202
+ artifactContract: string;
203
+ verificationCommands?: string[];
204
+ allowedTools: string[];
205
+ tokenCostNotice?: string;
206
+ isInteractiveCoCreation?: boolean;
207
+ proactiveInquiryPrompt?: string;
208
+ previewUrl?: string;
209
+ previewCommand?: string;
210
+ isReviewStage?: boolean; // 是否属于独立审查/验收阶段 (触发冷启动审阅与 Diff 物理隔离)
211
+ reviewIsolation?: {
212
+ enabled: boolean;
213
+ requireColdStart?: boolean;
214
+ diffOnlyContext?: boolean;
215
+ };
216
+ mcpToolBindings?: McpToolBinding[]; // 深度方法级 MCP 绑定与调用模版
217
+ skillContract?: DistilledSkillContract; // 深度蒸馏的 Skill SOP 契约
218
+ }
219
+
220
+ export interface DAGWave {
221
+ waveIndex: number;
222
+ stages: BlueprintStage[];
223
+ isParallel: boolean;
224
+ }
225
+
226
+ export interface DAGPlanResult {
227
+ sortedStages: BlueprintStage[];
228
+ waves: DAGWave[];
229
+ hasCycles: boolean;
230
+ cycleNodes?: string[];
231
+ }
232
+
233
+ export interface Blueprint {
234
+ blueprintId: string;
235
+ task: string;
236
+ createdAt: number;
237
+ projectFingerprint?: ProjectFingerprint;
238
+ userChoices: Record<string, string>;
239
+ activatedCapabilities: {
240
+ extensions: string[];
241
+ skills: string[];
242
+ prompts: string[];
243
+ };
244
+ tokenEfficiencySummary: string;
245
+ stages: BlueprintStage[];
246
+ dagWaves?: DAGWave[];
247
+ dynamicGoals?: string[];
248
+ customRequirements?: string[];
249
+ }
250
+
251
+ export interface ArtifactRecord {
252
+ path: string;
253
+ sha256: string;
254
+ sizeBytes: number;
255
+ verifiedAt: number;
256
+ gitStatus?: "unmodified" | "modified" | "created" | "untracked";
257
+ }
258
+
259
+ export interface StageSnapshot {
260
+ stageIndex: number;
261
+ stageId: string;
262
+ timestamp: number;
263
+ fileHashes: Record<string, string>;
264
+ fileContents?: Record<string, string>;
265
+ changedFiles?: string[];
266
+ gitTracked?: boolean;
267
+ shadowCommitHash?: string;
268
+ shadowRef?: string;
269
+ }
270
+
271
+ export interface StageVerificationResult {
272
+ valid: boolean;
273
+ artifactPath: string;
274
+ record?: ArtifactRecord;
275
+ changedFiles?: string[];
276
+ remediationGuidance?: string;
277
+ verificationCommands?: string[];
278
+ exitCode?: number;
279
+ isPrimaryMissing?: boolean;
280
+ healingAttempt?: number;
281
+ retryCount?: number;
282
+ isCircuitBroken?: boolean;
283
+ isExploring?: boolean;
284
+ reason?: string;
285
+ stderrOutput?: string;
286
+ missingExpected?: string;
287
+ heuristicReason?: string;
288
+ }
289
+
290
+ export interface SessionPlanState {
291
+ currentBlueprint: Blueprint | null;
292
+ currentStageIndex: number;
293
+ stepByStepGate: boolean;
294
+ status: "idle" | "awaiting_user_decisions" | "in_progress" | "stage_completed" | "completed" | "paused" | "healing_failed_circuit_break";
295
+ artifactLedger: Record<string, ArtifactRecord>;
296
+ snapshots?: Record<number, StageSnapshot>;
297
+ dynamicTargetFiles?: string[];
298
+ changedFiles?: string[];
299
+ retryCount?: number; // 当前阶段自愈重试计数 (0..3)
300
+ shadowHeadCommit?: string; // 初始/阶段影子快照
301
+ shadowCommitHash?: string;
302
+ customDirectives?: string[]; // 用户动态追加的最高优先级需求
303
+ }
304
+
305
+ export interface RecommendedPackageItem {
306
+ name: string;
307
+ source: string; // e.g. "npm:@community/pi-git-guard" or "git:github.com/user/repo"
308
+ description: string;
309
+ leverageReason: string; // 为什么推荐它,能帮用户省下什么
310
+ stars?: number;
311
+ official?: boolean;
312
+ }
313
+
314
+ export interface EcosystemBundlePlan {
315
+ id: string;
316
+ title: string;
317
+ description: string;
318
+ packages: RecommendedPackageItem[];
319
+ isRecommended?: boolean;
320
+ }
321
+
322
+ export type DecisionSlot = TaskRequirementSlot;
323
+
324
+ export type ArchitectNavigatorResult =
325
+ | { kind: "task_input"; task: string }
326
+ | { kind: "prompt_invoke"; command: string; filePath?: string }
327
+ | { kind: "resume_blueprint" }
328
+ | {
329
+ kind: "decisions";
330
+ decisions: Record<string, string>;
331
+ task: string;
332
+ customEcosystem?: {
333
+ enabledExtensions?: string[];
334
+ enabledSkills?: string[];
335
+ enabledPrompts?: string[];
336
+ };
337
+ selectedPlan?: "A" | "B";
338
+ customRequirements?: string[];
339
+ autoProceed?: boolean; // 是否一键极速开工
340
+ }
341
+ | null;