takt/src/features/prompt/preview.ts
nrslib 1466a7176d takt: # タスク指示書: Output Contracts と Quality Gates の実装
## 概要
仕様ドキュメント `/Users/m_naruse/work/git/takt/task_planning/output-contracts-and-quality-gates.md` に基づき、YAML構造の変更を実装する。

---

## タスク一覧

### 【高】トップレベル構造の変更
- 現在の `output_contracts` を `report_formats` にリネーム
- レポートテンプレート定義として機能させる

### 【高】Movement内の output_contracts 構造変更
- 各 movement の `output_contracts` が直接レポート配列を持つ構造に変更
- `output_contracts.report` の `report` キーを廃止

**変更後の構造:**
```yaml
report_formats:           # トップレベル(テンプレート定義)
  plan: ...

movements:
  - name: plan
    output_contracts:     # 直接配列(reportキー不要)
      - name: 00-plan.md
        format: plan
```

### 【中】quality_gates の実装
- エージェントへの通達として機能させる(自動検証は将来実装)
- Movement完了時にエージェントが参照できる形式で定義

---

## 制約(ユーザー明示)
- 後方互換性は不要

---

## 確認方法
- 既存のピース定義YAMLが新構造でパースできること
- テストが通ること
2026-02-07 22:03:43 +09:00

88 lines
3.2 KiB
TypeScript

/**
* Prompt preview feature
*
* Loads a piece and displays the assembled prompt for each movement and phase.
* Useful for debugging and understanding what prompts agents will receive.
*/
import { loadPieceByIdentifier, getCurrentPiece, loadGlobalConfig } from '../../infra/config/index.js';
import { InstructionBuilder } from '../../core/piece/instruction/InstructionBuilder.js';
import { ReportInstructionBuilder } from '../../core/piece/instruction/ReportInstructionBuilder.js';
import { StatusJudgmentBuilder } from '../../core/piece/instruction/StatusJudgmentBuilder.js';
import { needsStatusJudgmentPhase } from '../../core/piece/index.js';
import type { InstructionContext } from '../../core/piece/instruction/instruction-context.js';
import type { Language } from '../../core/models/types.js';
import { header, info, error, blankLine } from '../../shared/ui/index.js';
/**
* Preview all prompts for a piece.
*
* Loads the piece definition, then for each movement builds and displays
* the Phase 1, Phase 2, and Phase 3 prompts with sample variable values.
*/
export async function previewPrompts(cwd: string, pieceIdentifier?: string): Promise<void> {
const identifier = pieceIdentifier ?? getCurrentPiece(cwd);
const config = loadPieceByIdentifier(identifier, cwd);
if (!config) {
error(`Piece "${identifier}" not found.`);
return;
}
const globalConfig = loadGlobalConfig();
const language: Language = globalConfig.language ?? 'en';
header(`Prompt Preview: ${config.name}`);
info(`Movements: ${config.movements.length}`);
info(`Language: ${language}`);
blankLine();
for (const [i, movement] of config.movements.entries()) {
const separator = '='.repeat(60);
console.log(separator);
console.log(`Movement ${i + 1}: ${movement.name} (persona: ${movement.personaDisplayName})`);
console.log(separator);
// Phase 1: Main execution
const context: InstructionContext = {
task: '<task content>',
iteration: 1,
maxIterations: config.maxIterations,
movementIteration: 1,
cwd,
projectCwd: cwd,
userInputs: [],
pieceMovements: config.movements,
currentMovementIndex: i,
reportDir: movement.outputContracts && movement.outputContracts.length > 0 ? '.takt/reports/preview' : undefined,
language,
};
const phase1Builder = new InstructionBuilder(movement, context);
console.log('\n--- Phase 1 (Main Execution) ---\n');
console.log(phase1Builder.build());
// Phase 2: Report output (only if movement has output contracts)
if (movement.outputContracts && movement.outputContracts.length > 0) {
const reportBuilder = new ReportInstructionBuilder(movement, {
cwd,
reportDir: '.takt/reports/preview',
movementIteration: 1,
language,
});
console.log('\n--- Phase 2 (Report Output) ---\n');
console.log(reportBuilder.build());
}
// Phase 3: Status judgment (only if movement has tag-based rules)
if (needsStatusJudgmentPhase(movement)) {
const judgmentBuilder = new StatusJudgmentBuilder(movement, { language });
console.log('\n--- Phase 3 (Status Judgment) ---\n');
console.log(judgmentBuilder.build());
}
blankLine();
}
}