takt 0.2.3 → 0.3.2

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 (185) hide show
  1. package/README.md +186 -162
  2. package/dist/agents/runner.d.ts +2 -4
  3. package/dist/agents/runner.d.ts.map +1 -1
  4. package/dist/agents/runner.js +6 -35
  5. package/dist/agents/runner.js.map +1 -1
  6. package/dist/claude/client.d.ts +31 -6
  7. package/dist/claude/client.d.ts.map +1 -1
  8. package/dist/claude/client.js +78 -30
  9. package/dist/claude/client.js.map +1 -1
  10. package/dist/claude/executor.d.ts.map +1 -1
  11. package/dist/claude/executor.js +17 -8
  12. package/dist/claude/executor.js.map +1 -1
  13. package/dist/claude/index.d.ts +1 -1
  14. package/dist/claude/index.d.ts.map +1 -1
  15. package/dist/claude/index.js +1 -1
  16. package/dist/claude/index.js.map +1 -1
  17. package/dist/cli.d.ts +5 -5
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +160 -119
  20. package/dist/cli.js.map +1 -1
  21. package/dist/codex/client.d.ts +0 -1
  22. package/dist/codex/client.d.ts.map +1 -1
  23. package/dist/codex/client.js +3 -6
  24. package/dist/codex/client.js.map +1 -1
  25. package/dist/commands/addTask.d.ts +15 -8
  26. package/dist/commands/addTask.d.ts.map +1 -1
  27. package/dist/commands/addTask.js +63 -26
  28. package/dist/commands/addTask.js.map +1 -1
  29. package/dist/commands/eject.d.ts +13 -0
  30. package/dist/commands/eject.d.ts.map +1 -0
  31. package/dist/commands/eject.js +105 -0
  32. package/dist/commands/eject.js.map +1 -0
  33. package/dist/commands/index.d.ts +2 -2
  34. package/dist/commands/index.d.ts.map +1 -1
  35. package/dist/commands/index.js +2 -2
  36. package/dist/commands/index.js.map +1 -1
  37. package/dist/commands/interactive.d.ts +28 -0
  38. package/dist/commands/interactive.d.ts.map +1 -0
  39. package/dist/commands/interactive.js +186 -0
  40. package/dist/commands/interactive.js.map +1 -0
  41. package/dist/commands/taskExecution.js +2 -2
  42. package/dist/commands/taskExecution.js.map +1 -1
  43. package/dist/commands/workflowExecution.d.ts.map +1 -1
  44. package/dist/commands/workflowExecution.js +85 -18
  45. package/dist/commands/workflowExecution.js.map +1 -1
  46. package/dist/config/agentLoader.d.ts +3 -1
  47. package/dist/config/agentLoader.d.ts.map +1 -1
  48. package/dist/config/agentLoader.js +17 -24
  49. package/dist/config/agentLoader.js.map +1 -1
  50. package/dist/config/globalConfig.d.ts +2 -0
  51. package/dist/config/globalConfig.d.ts.map +1 -1
  52. package/dist/config/globalConfig.js +14 -0
  53. package/dist/config/globalConfig.js.map +1 -1
  54. package/dist/config/initialization.d.ts +7 -5
  55. package/dist/config/initialization.d.ts.map +1 -1
  56. package/dist/config/initialization.js +23 -21
  57. package/dist/config/initialization.js.map +1 -1
  58. package/dist/config/paths.d.ts +5 -0
  59. package/dist/config/paths.d.ts.map +1 -1
  60. package/dist/config/paths.js +9 -0
  61. package/dist/config/paths.js.map +1 -1
  62. package/dist/config/workflowLoader.d.ts +6 -4
  63. package/dist/config/workflowLoader.d.ts.map +1 -1
  64. package/dist/config/workflowLoader.js +190 -35
  65. package/dist/config/workflowLoader.js.map +1 -1
  66. package/dist/github/issue.d.ts +72 -0
  67. package/dist/github/issue.d.ts.map +1 -0
  68. package/dist/github/issue.js +143 -0
  69. package/dist/github/issue.js.map +1 -0
  70. package/dist/models/index.d.ts +1 -1
  71. package/dist/models/index.d.ts.map +1 -1
  72. package/dist/models/index.js.map +1 -1
  73. package/dist/models/schemas.d.ts +164 -90
  74. package/dist/models/schemas.d.ts.map +1 -1
  75. package/dist/models/schemas.js +77 -51
  76. package/dist/models/schemas.js.map +1 -1
  77. package/dist/models/types.d.ts +51 -20
  78. package/dist/models/types.d.ts.map +1 -1
  79. package/dist/prompt/index.d.ts +0 -7
  80. package/dist/prompt/index.d.ts.map +1 -1
  81. package/dist/prompt/index.js +0 -11
  82. package/dist/prompt/index.js.map +1 -1
  83. package/dist/providers/claude.js +2 -2
  84. package/dist/providers/claude.js.map +1 -1
  85. package/dist/providers/codex.d.ts.map +1 -1
  86. package/dist/providers/codex.js +0 -2
  87. package/dist/providers/codex.js.map +1 -1
  88. package/dist/providers/index.d.ts +2 -1
  89. package/dist/providers/index.d.ts.map +1 -1
  90. package/dist/providers/index.js.map +1 -1
  91. package/dist/resources/index.d.ts +3 -22
  92. package/dist/resources/index.d.ts.map +1 -1
  93. package/dist/resources/index.js +3 -73
  94. package/dist/resources/index.js.map +1 -1
  95. package/dist/task/display.js +1 -1
  96. package/dist/task/display.js.map +1 -1
  97. package/dist/utils/session.d.ts +74 -10
  98. package/dist/utils/session.d.ts.map +1 -1
  99. package/dist/utils/session.js +101 -51
  100. package/dist/utils/session.js.map +1 -1
  101. package/dist/workflow/engine.d.ts +34 -1
  102. package/dist/workflow/engine.d.ts.map +1 -1
  103. package/dist/workflow/engine.js +228 -36
  104. package/dist/workflow/engine.js.map +1 -1
  105. package/dist/workflow/index.d.ts +1 -1
  106. package/dist/workflow/index.d.ts.map +1 -1
  107. package/dist/workflow/index.js +1 -1
  108. package/dist/workflow/index.js.map +1 -1
  109. package/dist/workflow/instruction-builder.d.ts +87 -18
  110. package/dist/workflow/instruction-builder.d.ts.map +1 -1
  111. package/dist/workflow/instruction-builder.js +404 -57
  112. package/dist/workflow/instruction-builder.js.map +1 -1
  113. package/dist/workflow/parallel-logger.d.ts +76 -0
  114. package/dist/workflow/parallel-logger.d.ts.map +1 -0
  115. package/dist/workflow/parallel-logger.js +173 -0
  116. package/dist/workflow/parallel-logger.js.map +1 -0
  117. package/dist/workflow/phase-runner.d.ts +40 -0
  118. package/dist/workflow/phase-runner.d.ts.map +1 -0
  119. package/dist/workflow/phase-runner.js +69 -0
  120. package/dist/workflow/phase-runner.js.map +1 -0
  121. package/dist/workflow/rule-evaluator.d.ts +64 -0
  122. package/dist/workflow/rule-evaluator.d.ts.map +1 -0
  123. package/dist/workflow/rule-evaluator.js +178 -0
  124. package/dist/workflow/rule-evaluator.js.map +1 -0
  125. package/dist/workflow/rule-utils.d.ts +13 -0
  126. package/dist/workflow/rule-utils.d.ts.map +1 -0
  127. package/dist/workflow/rule-utils.js +17 -0
  128. package/dist/workflow/rule-utils.js.map +1 -0
  129. package/dist/workflow/transitions.d.ts +5 -13
  130. package/dist/workflow/transitions.d.ts.map +1 -1
  131. package/dist/workflow/transitions.js +8 -78
  132. package/dist/workflow/transitions.js.map +1 -1
  133. package/dist/workflow/types.d.ts +2 -1
  134. package/dist/workflow/types.d.ts.map +1 -1
  135. package/package.json +1 -1
  136. package/resources/global/en/agents/default/ai-antipattern-reviewer.md +84 -15
  137. package/resources/global/en/agents/default/{architect.md → architecture-reviewer.md} +144 -44
  138. package/resources/global/en/agents/default/coder.md +4 -4
  139. package/resources/global/en/agents/default/planner.md +16 -9
  140. package/resources/global/en/agents/default/{security.md → security-reviewer.md} +23 -5
  141. package/resources/global/en/agents/default/supervisor.md +22 -2
  142. package/resources/global/en/agents/expert/frontend-reviewer.md +0 -17
  143. package/resources/global/en/agents/expert/qa-reviewer.md +0 -16
  144. package/resources/global/en/agents/expert/security-reviewer.md +0 -16
  145. package/resources/global/en/agents/expert/supervisor.md +2 -0
  146. package/resources/global/en/agents/expert-cqrs/cqrs-es-reviewer.md +0 -17
  147. package/resources/global/en/agents/templates/coder.md +128 -0
  148. package/resources/global/en/agents/templates/planner.md +44 -0
  149. package/resources/global/en/agents/templates/reviewer.md +57 -0
  150. package/resources/global/en/agents/templates/supervisor.md +64 -0
  151. package/resources/global/en/workflows/default.yaml +232 -772
  152. package/resources/global/en/workflows/expert-cqrs.yaml +319 -698
  153. package/resources/global/en/workflows/expert.yaml +348 -723
  154. package/resources/global/en/workflows/magi.yaml +45 -52
  155. package/resources/global/en/workflows/research.yaml +18 -99
  156. package/resources/global/en/workflows/simple.yaml +152 -421
  157. package/resources/global/ja/agents/default/ai-antipattern-reviewer.md +84 -15
  158. package/resources/global/ja/agents/default/{architect.md → architecture-reviewer.md} +148 -48
  159. package/resources/global/ja/agents/default/coder.md +4 -4
  160. package/resources/global/ja/agents/default/planner.md +16 -9
  161. package/resources/global/ja/agents/default/{security.md → security-reviewer.md} +23 -5
  162. package/resources/global/ja/agents/default/supervisor.md +22 -2
  163. package/resources/global/ja/agents/expert/frontend-reviewer.md +0 -18
  164. package/resources/global/ja/agents/expert/qa-reviewer.md +0 -16
  165. package/resources/global/ja/agents/expert/security-reviewer.md +0 -16
  166. package/resources/global/ja/agents/expert/supervisor.md +2 -0
  167. package/resources/global/ja/agents/expert-cqrs/cqrs-es-reviewer.md +0 -18
  168. package/resources/global/ja/agents/templates/coder.md +128 -0
  169. package/resources/global/ja/agents/templates/planner.md +44 -0
  170. package/resources/global/ja/agents/templates/reviewer.md +57 -0
  171. package/resources/global/ja/agents/templates/supervisor.md +64 -0
  172. package/resources/global/ja/workflows/default.yaml +227 -773
  173. package/resources/global/ja/workflows/expert-cqrs.yaml +309 -833
  174. package/resources/global/ja/workflows/expert.yaml +325 -712
  175. package/resources/global/ja/workflows/magi.yaml +45 -52
  176. package/resources/global/ja/workflows/research.yaml +18 -99
  177. package/resources/global/ja/workflows/simple.yaml +145 -415
  178. package/dist/commands/help.d.ts +0 -8
  179. package/dist/commands/help.d.ts.map +0 -1
  180. package/dist/commands/help.js +0 -48
  181. package/dist/commands/help.js.map +0 -1
  182. package/dist/commands/refreshBuiltin.d.ts +0 -11
  183. package/dist/commands/refreshBuiltin.d.ts.map +0 -1
  184. package/dist/commands/refreshBuiltin.js +0 -37
  185. package/dist/commands/refreshBuiltin.js.map +0 -1
@@ -1,9 +1,97 @@
1
1
  /**
2
2
  * Session management utilities
3
3
  */
4
- import { existsSync, readFileSync, copyFileSync } from 'node:fs';
4
+ import { existsSync, readFileSync, copyFileSync, appendFileSync } from 'node:fs';
5
5
  import { join } from 'node:path';
6
6
  import { getProjectLogsDir, getGlobalLogsDir, ensureDir, writeFileAtomic } from '../config/paths.js';
7
+ /**
8
+ * Append a single NDJSON line to a log file.
9
+ * Uses appendFileSync for atomic open→write→close (no file lock held).
10
+ */
11
+ export function appendNdjsonLine(filepath, record) {
12
+ appendFileSync(filepath, JSON.stringify(record) + '\n', 'utf-8');
13
+ }
14
+ /**
15
+ * Initialize an NDJSON log file with the workflow_start record.
16
+ * Creates the logs directory if needed and returns the file path.
17
+ */
18
+ export function initNdjsonLog(sessionId, task, workflowName, projectDir) {
19
+ const logsDir = projectDir
20
+ ? getProjectLogsDir(projectDir)
21
+ : getGlobalLogsDir();
22
+ ensureDir(logsDir);
23
+ const filepath = join(logsDir, `${sessionId}.jsonl`);
24
+ const record = {
25
+ type: 'workflow_start',
26
+ task,
27
+ workflowName,
28
+ startTime: new Date().toISOString(),
29
+ };
30
+ appendNdjsonLine(filepath, record);
31
+ return filepath;
32
+ }
33
+ /**
34
+ * Load an NDJSON log file and convert it to a SessionLog for backward compatibility.
35
+ * Parses each line as a JSON record and reconstructs the SessionLog structure.
36
+ */
37
+ export function loadNdjsonLog(filepath) {
38
+ if (!existsSync(filepath)) {
39
+ return null;
40
+ }
41
+ const content = readFileSync(filepath, 'utf-8');
42
+ const lines = content.trim().split('\n').filter((line) => line.length > 0);
43
+ if (lines.length === 0)
44
+ return null;
45
+ let sessionLog = null;
46
+ for (const line of lines) {
47
+ const record = JSON.parse(line);
48
+ switch (record.type) {
49
+ case 'workflow_start':
50
+ sessionLog = {
51
+ task: record.task,
52
+ projectDir: '',
53
+ workflowName: record.workflowName,
54
+ iterations: 0,
55
+ startTime: record.startTime,
56
+ status: 'running',
57
+ history: [],
58
+ };
59
+ break;
60
+ case 'step_complete':
61
+ if (sessionLog) {
62
+ sessionLog.history.push({
63
+ step: record.step,
64
+ agent: record.agent,
65
+ instruction: record.instruction,
66
+ status: record.status,
67
+ timestamp: record.timestamp,
68
+ content: record.content,
69
+ ...(record.error ? { error: record.error } : {}),
70
+ ...(record.matchedRuleIndex != null ? { matchedRuleIndex: record.matchedRuleIndex } : {}),
71
+ ...(record.matchedRuleMethod ? { matchedRuleMethod: record.matchedRuleMethod } : {}),
72
+ });
73
+ sessionLog.iterations++;
74
+ }
75
+ break;
76
+ case 'workflow_complete':
77
+ if (sessionLog) {
78
+ sessionLog.status = 'completed';
79
+ sessionLog.endTime = record.endTime;
80
+ }
81
+ break;
82
+ case 'workflow_abort':
83
+ if (sessionLog) {
84
+ sessionLog.status = 'aborted';
85
+ sessionLog.endTime = record.endTime;
86
+ }
87
+ break;
88
+ // stream and step_start records are not stored in SessionLog
89
+ default:
90
+ break;
91
+ }
92
+ }
93
+ return sessionLog;
94
+ }
7
95
  /** Generate a session ID */
8
96
  export function generateSessionId() {
9
97
  const timestamp = Date.now().toString(36);
@@ -41,36 +129,20 @@ export function createSessionLog(task, projectDir, workflowName) {
41
129
  history: [],
42
130
  };
43
131
  }
44
- /** Add agent response to session log */
45
- export function addToSessionLog(log, stepName, response) {
46
- log.history.push({
47
- step: stepName,
48
- agent: response.agent,
49
- status: response.status,
50
- timestamp: response.timestamp.toISOString(),
51
- content: response.content,
52
- ...(response.error ? { error: response.error } : {}),
53
- });
54
- log.iterations++;
55
- }
56
- /** Finalize session log */
132
+ /** Create a finalized copy of a session log (immutable — does not modify the original) */
57
133
  export function finalizeSessionLog(log, status) {
58
- log.status = status;
59
- log.endTime = new Date().toISOString();
60
- }
61
- /** Save session log to file */
62
- export function saveSessionLog(log, sessionId, projectDir) {
63
- const logsDir = projectDir
64
- ? getProjectLogsDir(projectDir)
65
- : getGlobalLogsDir();
66
- ensureDir(logsDir);
67
- const filename = `${sessionId}.json`;
68
- const filepath = join(logsDir, filename);
69
- writeFileAtomic(filepath, JSON.stringify(log, null, 2));
70
- return filepath;
134
+ return {
135
+ ...log,
136
+ status,
137
+ endTime: new Date().toISOString(),
138
+ };
71
139
  }
72
- /** Load session log from file */
140
+ /** Load session log from file (supports both .json and .jsonl formats) */
73
141
  export function loadSessionLog(filepath) {
142
+ // Try NDJSON format for .jsonl files
143
+ if (filepath.endsWith('.jsonl')) {
144
+ return loadNdjsonLog(filepath);
145
+ }
74
146
  if (!existsSync(filepath)) {
75
147
  return null;
76
148
  }
@@ -110,7 +182,7 @@ export function updateLatestPointer(log, sessionId, projectDir, options) {
110
182
  }
111
183
  const pointer = {
112
184
  sessionId,
113
- logFile: `${sessionId}.json`,
185
+ logFile: `${sessionId}.jsonl`,
114
186
  task: log.task,
115
187
  workflowName: log.workflowName,
116
188
  status: log.status,
@@ -120,26 +192,4 @@ export function updateLatestPointer(log, sessionId, projectDir, options) {
120
192
  };
121
193
  writeFileAtomic(latestPath, JSON.stringify(pointer, null, 2));
122
194
  }
123
- /** Convert workflow state to session log */
124
- export function workflowStateToSessionLog(state, task, projectDir) {
125
- const log = {
126
- task,
127
- projectDir,
128
- workflowName: state.workflowName,
129
- iterations: state.iteration,
130
- startTime: new Date().toISOString(),
131
- status: state.status === 'running' ? 'running' : state.status === 'completed' ? 'completed' : 'aborted',
132
- history: [],
133
- };
134
- for (const [stepName, response] of state.stepOutputs) {
135
- log.history.push({
136
- step: stepName,
137
- agent: response.agent,
138
- status: response.status,
139
- timestamp: response.timestamp.toISOString(),
140
- content: response.content,
141
- });
142
- }
143
- return log;
144
- }
145
195
  //# sourceMappingURL=session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAqBrG,4BAA4B;AAC5B,MAAM,UAAU,iBAAiB;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,E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AAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;IAEF,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC"}
@@ -36,8 +36,41 @@ export declare class WorkflowEngine extends EventEmitter {
36
36
  private buildInstruction;
37
37
  /** Get step by name */
38
38
  private getStep;
39
- /** Run a single step */
39
+ /**
40
+ * Emit step:report events for each report file that exists after step completion.
41
+ * The UI layer (workflowExecution.ts) listens and displays the content.
42
+ */
43
+ private emitStepReports;
44
+ /** Emit step:report if the report file exists */
45
+ private emitIfReportExists;
46
+ /** Run a single step (delegates to runParallelStep if step has parallel sub-steps) */
40
47
  private runStep;
48
+ /** Build common RunAgentOptions shared by all phases */
49
+ private buildBaseOptions;
50
+ /** Build RunAgentOptions from a step's configuration (Phase 1) */
51
+ private buildAgentOptions;
52
+ /**
53
+ * Build RunAgentOptions for session-resume phases (Phase 2, Phase 3).
54
+ */
55
+ private buildResumeOptions;
56
+ /** Update agent session and notify via callback if session changed */
57
+ private updateAgentSession;
58
+ /** Build phase runner context for Phase 2/3 execution */
59
+ private buildPhaseRunnerContext;
60
+ /** Run a normal (non-parallel) step */
61
+ private runNormalStep;
62
+ /**
63
+ * Run a parallel step: execute all sub-steps concurrently, then aggregate results.
64
+ * The aggregated output becomes the parent step's response for rules evaluation.
65
+ *
66
+ * When onStream is provided, uses ParallelLogger to prefix each sub-step's
67
+ * output with `[name]` for readable interleaved display.
68
+ */
69
+ private runParallelStep;
70
+ /**
71
+ * Determine next step for a completed step using rules-based routing.
72
+ */
73
+ private resolveNextStep;
41
74
  /** Run the workflow to completion */
42
75
  run(): Promise<WorkflowState>;
43
76
  /** Run a single iteration (for interactive mode) */
@@ -1 +1 @@
1
- {"version":3,"file":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AAyE;IACzE,OAAO,CAAC,qBAAqB;IAmB7B,2DAA2D;IAC3D,OAAO,CAAC,cAAc;IAuBtB,iCAAiC;IACjC,QAAQ,IAAI,aAAa;IAIzB,qBAAqB;IACrB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC,+BAA+B;IAC/B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,oCAAoC;IACpC,MAAM,IAAI,MAAM;IAIhB,sDAAsD;IACtD,aAAa,IAAI,MAAM;IAIvB,sCAAsC;IACtC,OAAO,CAAC,gBAAgB;IAexB,uBAAuB;IACvB,OAAO,CAAC,OAAO;IAQf;;;OAGG;IACH,OAAO,CAAC,eAAe;IAgBvB,iDAAiD;IACjD,OAAO,CAAC,kBAAkB;IAO1B,sFAAsF;YACxE,OAAO;IAOrB,wDAAwD;IACxD,OAAO,CAAC,gBAAgB;IAcxB,kEAAkE;IAClE,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAS1B,sEAAsE;IACtE,OAAO,CAAC,kBAAkB;IAW1B,yDAAyD;IACzD,OAAO,CAAC,uBAAuB;IAW/B,uCAAuC;YACzB,aAAa;IA2C3B;;;;;;OAMG;YACW,eAAe;IAkG7B;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB,qCAAqC;IAC/B,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;IA6FnC,oDAAoD;IAC9C,kBAAkB,IAAI,OAAO,CAAC;QAClC,QAAQ,EAAE,aAAa,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CAgCH"}
@@ -6,10 +6,13 @@ import { mkdirSync, existsSync, symlinkSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
  import { runAgent } from '../agents/runner.js';
8
8
  import { COMPLETE_STEP, ABORT_STEP, ERROR_MESSAGES } from './constants.js';
9
- import { determineNextStep } from './transitions.js';
10
- import { buildInstruction as buildInstructionFromTemplate } from './instruction-builder.js';
9
+ import { determineNextStepByRules } from './transitions.js';
10
+ import { buildInstruction as buildInstructionFromTemplate, isReportObjectConfig } from './instruction-builder.js';
11
11
  import { LoopDetector } from './loop-detector.js';
12
12
  import { handleBlocked } from './blocked-handler.js';
13
+ import { ParallelLogger } from './parallel-logger.js';
14
+ import { detectMatchedRule } from './rule-evaluator.js';
15
+ import { needsStatusJudgmentPhase, runReportPhase, runStatusJudgmentPhase } from './phase-runner.js';
13
16
  import { createInitialState, addUserInput, getPreviousOutput, incrementStepIteration, } from './state-manager.js';
14
17
  import { generateReportDir } from '../utils/session.js';
15
18
  import { createLogger } from '../utils/debug.js';
@@ -35,7 +38,7 @@ export class WorkflowEngine extends EventEmitter {
35
38
  this.options = options;
36
39
  this.language = options.language;
37
40
  this.loopDetector = new LoopDetector(config.loopDetection);
38
- this.reportDir = generateReportDir(task);
41
+ this.reportDir = `.takt/reports/${generateReportDir(task)}`;
39
42
  this.ensureReportDirExists();
40
43
  this.validateConfig();
41
44
  this.state = createInitialState(config, options);
@@ -48,7 +51,7 @@ export class WorkflowEngine extends EventEmitter {
48
51
  }
49
52
  /** Ensure report directory exists (always in project root, not clone) */
50
53
  ensureReportDirExists() {
51
- const reportDirPath = join(this.projectCwd, '.takt', 'reports', this.reportDir);
54
+ const reportDirPath = join(this.projectCwd, this.reportDir);
52
55
  if (!existsSync(reportDirPath)) {
53
56
  mkdirSync(reportDirPath, { recursive: true });
54
57
  }
@@ -71,9 +74,11 @@ export class WorkflowEngine extends EventEmitter {
71
74
  stepNames.add(COMPLETE_STEP);
72
75
  stepNames.add(ABORT_STEP);
73
76
  for (const step of this.config.steps) {
74
- for (const transition of step.transitions) {
75
- if (!stepNames.has(transition.nextStep)) {
76
- throw new Error(`Invalid transition in step "${step.name}": target step "${transition.nextStep}" does not exist`);
77
+ if (step.rules) {
78
+ for (const rule of step.rules) {
79
+ if (rule.next && !stepNames.has(rule.next)) {
80
+ throw new Error(`Invalid rule in step "${step.name}": target step "${rule.next}" does not exist`);
81
+ }
77
82
  }
78
83
  }
79
84
  }
@@ -121,25 +126,46 @@ export class WorkflowEngine extends EventEmitter {
121
126
  }
122
127
  return step;
123
128
  }
124
- /** Run a single step */
129
+ /**
130
+ * Emit step:report events for each report file that exists after step completion.
131
+ * The UI layer (workflowExecution.ts) listens and displays the content.
132
+ */
133
+ emitStepReports(step) {
134
+ if (!step.report || !this.reportDir)
135
+ return;
136
+ const baseDir = join(this.projectCwd, this.reportDir);
137
+ if (typeof step.report === 'string') {
138
+ this.emitIfReportExists(step, baseDir, step.report);
139
+ }
140
+ else if (isReportObjectConfig(step.report)) {
141
+ this.emitIfReportExists(step, baseDir, step.report.name);
142
+ }
143
+ else {
144
+ // ReportConfig[] (array)
145
+ for (const rc of step.report) {
146
+ this.emitIfReportExists(step, baseDir, rc.path);
147
+ }
148
+ }
149
+ }
150
+ /** Emit step:report if the report file exists */
151
+ emitIfReportExists(step, baseDir, fileName) {
152
+ const filePath = join(baseDir, fileName);
153
+ if (existsSync(filePath)) {
154
+ this.emit('step:report', step, filePath, fileName);
155
+ }
156
+ }
157
+ /** Run a single step (delegates to runParallelStep if step has parallel sub-steps) */
125
158
  async runStep(step) {
126
- // Increment step iteration counter before building instruction
127
- const stepIteration = incrementStepIteration(this.state, step.name);
128
- const instruction = this.buildInstruction(step, stepIteration);
129
- const sessionId = this.state.agentSessions.get(step.agent);
130
- log.debug('Running step', {
131
- step: step.name,
132
- agent: step.agent,
133
- stepIteration,
134
- iteration: this.state.iteration,
135
- sessionId: sessionId ?? 'new',
136
- });
137
- const agentOptions = {
159
+ if (step.parallel && step.parallel.length > 0) {
160
+ return this.runParallelStep(step);
161
+ }
162
+ return this.runNormalStep(step);
163
+ }
164
+ /** Build common RunAgentOptions shared by all phases */
165
+ buildBaseOptions(step) {
166
+ return {
138
167
  cwd: this.cwd,
139
- sessionId,
140
168
  agentPath: step.agentPath,
141
- allowedTools: step.allowedTools,
142
- statusRulesPrompt: step.statusRulesPrompt,
143
169
  provider: step.provider,
144
170
  model: step.model,
145
171
  permissionMode: step.permissionMode,
@@ -148,16 +174,181 @@ export class WorkflowEngine extends EventEmitter {
148
174
  onAskUserQuestion: this.options.onAskUserQuestion,
149
175
  bypassPermissions: this.options.bypassPermissions,
150
176
  };
151
- const response = await runAgent(step.agent, instruction, agentOptions);
152
- if (response.sessionId) {
153
- const previousSessionId = this.state.agentSessions.get(step.agent);
154
- this.state.agentSessions.set(step.agent, response.sessionId);
155
- if (this.options.onSessionUpdate && response.sessionId !== previousSessionId) {
156
- this.options.onSessionUpdate(step.agent, response.sessionId);
157
- }
177
+ }
178
+ /** Build RunAgentOptions from a step's configuration (Phase 1) */
179
+ buildAgentOptions(step) {
180
+ // Phase 1: exclude Write from allowedTools when step has report config
181
+ const allowedTools = step.report
182
+ ? step.allowedTools?.filter((t) => t !== 'Write')
183
+ : step.allowedTools;
184
+ return {
185
+ ...this.buildBaseOptions(step),
186
+ sessionId: this.state.agentSessions.get(step.agent),
187
+ allowedTools,
188
+ };
189
+ }
190
+ /**
191
+ * Build RunAgentOptions for session-resume phases (Phase 2, Phase 3).
192
+ */
193
+ buildResumeOptions(step, sessionId, overrides) {
194
+ return {
195
+ ...this.buildBaseOptions(step),
196
+ sessionId,
197
+ allowedTools: overrides.allowedTools,
198
+ maxTurns: overrides.maxTurns,
199
+ };
200
+ }
201
+ /** Update agent session and notify via callback if session changed */
202
+ updateAgentSession(agent, sessionId) {
203
+ if (!sessionId)
204
+ return;
205
+ const previousSessionId = this.state.agentSessions.get(agent);
206
+ this.state.agentSessions.set(agent, sessionId);
207
+ if (this.options.onSessionUpdate && sessionId !== previousSessionId) {
208
+ this.options.onSessionUpdate(agent, sessionId);
209
+ }
210
+ }
211
+ /** Build phase runner context for Phase 2/3 execution */
212
+ buildPhaseRunnerContext() {
213
+ return {
214
+ cwd: this.cwd,
215
+ reportDir: this.reportDir,
216
+ language: this.language,
217
+ getSessionId: (agent) => this.state.agentSessions.get(agent),
218
+ buildResumeOptions: this.buildResumeOptions.bind(this),
219
+ updateAgentSession: this.updateAgentSession.bind(this),
220
+ };
221
+ }
222
+ /** Run a normal (non-parallel) step */
223
+ async runNormalStep(step) {
224
+ const stepIteration = incrementStepIteration(this.state, step.name);
225
+ const instruction = this.buildInstruction(step, stepIteration);
226
+ log.debug('Running step', {
227
+ step: step.name,
228
+ agent: step.agent,
229
+ stepIteration,
230
+ iteration: this.state.iteration,
231
+ sessionId: this.state.agentSessions.get(step.agent) ?? 'new',
232
+ });
233
+ // Phase 1: main execution (Write excluded if step has report)
234
+ const agentOptions = this.buildAgentOptions(step);
235
+ let response = await runAgent(step.agent, instruction, agentOptions);
236
+ this.updateAgentSession(step.agent, response.sessionId);
237
+ const phaseCtx = this.buildPhaseRunnerContext();
238
+ // Phase 2: report output (resume same session, Write only)
239
+ if (step.report) {
240
+ await runReportPhase(step, stepIteration, phaseCtx);
241
+ }
242
+ // Phase 3: status judgment (resume session, no tools, output status tag)
243
+ let tagContent = '';
244
+ if (needsStatusJudgmentPhase(step)) {
245
+ tagContent = await runStatusJudgmentPhase(step, phaseCtx);
246
+ }
247
+ const match = await detectMatchedRule(step, response.content, tagContent, {
248
+ state: this.state,
249
+ cwd: this.cwd,
250
+ });
251
+ if (match) {
252
+ log.debug('Rule matched', { step: step.name, ruleIndex: match.index, method: match.method });
253
+ response = { ...response, matchedRuleIndex: match.index, matchedRuleMethod: match.method };
158
254
  }
159
255
  this.state.stepOutputs.set(step.name, response);
160
- return response;
256
+ this.emitStepReports(step);
257
+ return { response, instruction };
258
+ }
259
+ /**
260
+ * Run a parallel step: execute all sub-steps concurrently, then aggregate results.
261
+ * The aggregated output becomes the parent step's response for rules evaluation.
262
+ *
263
+ * When onStream is provided, uses ParallelLogger to prefix each sub-step's
264
+ * output with `[name]` for readable interleaved display.
265
+ */
266
+ async runParallelStep(step) {
267
+ const subSteps = step.parallel;
268
+ const stepIteration = incrementStepIteration(this.state, step.name);
269
+ log.debug('Running parallel step', {
270
+ step: step.name,
271
+ subSteps: subSteps.map(s => s.name),
272
+ stepIteration,
273
+ });
274
+ // Create parallel logger for prefixed output (only when streaming is enabled)
275
+ const parallelLogger = this.options.onStream
276
+ ? new ParallelLogger({
277
+ subStepNames: subSteps.map((s) => s.name),
278
+ parentOnStream: this.options.onStream,
279
+ })
280
+ : undefined;
281
+ const phaseCtx = this.buildPhaseRunnerContext();
282
+ const ruleCtx = { state: this.state, cwd: this.cwd };
283
+ // Run all sub-steps concurrently
284
+ const subResults = await Promise.all(subSteps.map(async (subStep, index) => {
285
+ const subIteration = incrementStepIteration(this.state, subStep.name);
286
+ const subInstruction = this.buildInstruction(subStep, subIteration);
287
+ // Phase 1: main execution (Write excluded if sub-step has report)
288
+ const baseOptions = this.buildAgentOptions(subStep);
289
+ // Override onStream with parallel logger's prefixed handler (immutable)
290
+ const agentOptions = parallelLogger
291
+ ? { ...baseOptions, onStream: parallelLogger.createStreamHandler(subStep.name, index) }
292
+ : baseOptions;
293
+ const subResponse = await runAgent(subStep.agent, subInstruction, agentOptions);
294
+ this.updateAgentSession(subStep.agent, subResponse.sessionId);
295
+ // Phase 2: report output for sub-step
296
+ if (subStep.report) {
297
+ await runReportPhase(subStep, subIteration, phaseCtx);
298
+ }
299
+ // Phase 3: status judgment for sub-step
300
+ let subTagContent = '';
301
+ if (needsStatusJudgmentPhase(subStep)) {
302
+ subTagContent = await runStatusJudgmentPhase(subStep, phaseCtx);
303
+ }
304
+ const match = await detectMatchedRule(subStep, subResponse.content, subTagContent, ruleCtx);
305
+ const finalResponse = match
306
+ ? { ...subResponse, matchedRuleIndex: match.index, matchedRuleMethod: match.method }
307
+ : subResponse;
308
+ this.state.stepOutputs.set(subStep.name, finalResponse);
309
+ this.emitStepReports(subStep);
310
+ return { subStep, response: finalResponse, instruction: subInstruction };
311
+ }));
312
+ // Print completion summary
313
+ if (parallelLogger) {
314
+ parallelLogger.printSummary(step.name, subResults.map((r) => ({
315
+ name: r.subStep.name,
316
+ condition: r.response.matchedRuleIndex != null && r.subStep.rules
317
+ ? r.subStep.rules[r.response.matchedRuleIndex]?.condition
318
+ : undefined,
319
+ })));
320
+ }
321
+ // Aggregate sub-step outputs into parent step's response
322
+ const aggregatedContent = subResults
323
+ .map((r) => `## ${r.subStep.name}\n${r.response.content}`)
324
+ .join('\n\n---\n\n');
325
+ const aggregatedInstruction = subResults
326
+ .map((r) => r.instruction)
327
+ .join('\n\n');
328
+ // Parent step uses aggregate conditions, so tagContent is empty
329
+ const match = await detectMatchedRule(step, aggregatedContent, '', ruleCtx);
330
+ const aggregatedResponse = {
331
+ agent: step.name,
332
+ status: 'done',
333
+ content: aggregatedContent,
334
+ timestamp: new Date(),
335
+ ...(match && { matchedRuleIndex: match.index, matchedRuleMethod: match.method }),
336
+ };
337
+ this.state.stepOutputs.set(step.name, aggregatedResponse);
338
+ this.emitStepReports(step);
339
+ return { response: aggregatedResponse, instruction: aggregatedInstruction };
340
+ }
341
+ /**
342
+ * Determine next step for a completed step using rules-based routing.
343
+ */
344
+ resolveNextStep(step, response) {
345
+ if (response.matchedRuleIndex != null && step.rules) {
346
+ const nextByRules = determineNextStepByRules(step, response.matchedRuleIndex);
347
+ if (nextByRules) {
348
+ return nextByRules;
349
+ }
350
+ }
351
+ throw new Error(`No matching rule found for step "${step.name}" (status: ${response.status})`);
161
352
  }
162
353
  /** Run the workflow to completion */
163
354
  async run() {
@@ -195,8 +386,8 @@ export class WorkflowEngine extends EventEmitter {
195
386
  this.state.iteration++;
196
387
  this.emit('step:start', step, this.state.iteration);
197
388
  try {
198
- const response = await this.runStep(step);
199
- this.emit('step:complete', step, response);
389
+ const { response, instruction } = await this.runStep(step);
390
+ this.emit('step:complete', step, response, instruction);
200
391
  if (response.status === 'blocked') {
201
392
  this.emit('step:blocked', step, response);
202
393
  const result = await handleBlocked(step, response, this.options);
@@ -209,10 +400,11 @@ export class WorkflowEngine extends EventEmitter {
209
400
  this.emit('workflow:abort', this.state, 'Workflow blocked and no user input provided');
210
401
  break;
211
402
  }
212
- const nextStep = determineNextStep(step, response.status, this.config);
403
+ const nextStep = this.resolveNextStep(step, response);
213
404
  log.debug('Step transition', {
214
405
  from: step.name,
215
406
  status: response.status,
407
+ matchedRuleIndex: response.matchedRuleIndex,
216
408
  nextStep,
217
409
  });
218
410
  if (nextStep === COMPLETE_STEP) {
@@ -255,8 +447,8 @@ export class WorkflowEngine extends EventEmitter {
255
447
  };
256
448
  }
257
449
  this.state.iteration++;
258
- const response = await this.runStep(step);
259
- const nextStep = determineNextStep(step, response.status, this.config);
450
+ const { response } = await this.runStep(step);
451
+ const nextStep = this.resolveNextStep(step, response);
260
452
  const isComplete = nextStep === COMPLETE_STEP || nextStep === ABORT_STEP;
261
453
  if (!isComplete) {
262
454
  this.state.currentStep = nextStep;