-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
177 lines (153 loc) · 5.02 KB
/
index.ts
File metadata and controls
177 lines (153 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { countConfig } from '../input.js'
import { userRequest } from '../input.js'
import { logger } from '../utils/logger.js'
import { findIsGoodToGo, findWhatIdo } from '../utils/match.js'
import { speak } from '../utils/speak.js'
import { doArchitectAntithese } from './antithese.js'
import { doArchitectSelection } from './selection.js'
import { doArchitectSynthese } from './synthese.js'
import { doArchitectThese } from './these.js'
import fs from 'node:fs'
export const doArchitect = async () => {
logger(
`요청사항에 따른 ${countConfig.architect.draftCount}가지 각기 다른 기획 시안을 생성 중입니다.\n`
)
speak(
`요청사항에 따른 ${countConfig.architect.draftCount}가지 각기 다른 기획 시안을 생성 중입니다.`
)
const drafts: string[] = []
for (let i = 1; i <= countConfig.architect.draftCount; i++) {
const draft = await doArchitectThese(userRequest)
drafts.push(draft)
const whatTheseDo = findWhatIdo(draft)
console.log(draft)
if (whatTheseDo) {
logger(`시안 ${i} 요약: ${whatTheseDo}`)
speak(`시안 ${i} 요약: ${whatTheseDo}`)
} else {
logger(`개발 기획을 세우는 중입니다...`)
}
fs.writeFileSync(`./result/architect-draft-${i}.txt`, draft)
}
let bestDraftNumber = 1
if (countConfig.architect.draftCount !== 1) {
const bestDraftSelection = await doArchitectSelection(drafts)
console.log(bestDraftSelection)
try {
const json = '{' + bestDraftSelection?.split('{')?.[1]?.split('```')[0]
const parsed = JSON.parse(json)
bestDraftNumber = parsed.bestDraftNumber
logger(`${parsed.bestDraftNumber}번 시안이 선택되었습니다.`)
speak(`${parsed.bestDraftNumber}번 시안이 선택되었습니다.`)
bestDraftNumber = parsed.bestDraftNumber - 1
} catch (e) {}
}
let reviewCount = 1
let isGoodToGo = false
let synthese = drafts[bestDraftNumber]
while (true) {
const dialect = await doDialectic({
isGoodToGo,
synthese,
reviewCount,
userRequest
})
isGoodToGo = dialect.isGoodToGo
synthese = `${dialect.synthese}`
reviewCount += 1
if (isGoodToGo) {
logger(`개발 기획이 완료되었습니다. (${reviewCount} 번째 검토 만에 완료)`)
speak(
`개발 기획이 완료되었습니다. ${reviewCount} 번째 검토 만에 완료되었습니다.`
)
fs.writeFileSync(`./result/architect-ver-${reviewCount}.txt`, synthese)
return synthese
}
}
}
export const doDialectic = async ({
isGoodToGo,
synthese: these,
reviewCount,
userRequest
}: {
isGoodToGo: boolean
synthese: string
reviewCount?: number
userRequest?: string
}) => {
if (isGoodToGo) {
return { isGoodToGo, synthese: these }
} else {
logger(`개발 기획을 추가로 보완하고 있습니다... (${reviewCount} 번째 검토)`)
speak(`개발 기획을 추가로 보완하고 있습니다... (${reviewCount} 번째 검토)`)
fs.writeFileSync(`./result/architect-ver-${reviewCount}.txt`, these)
const antithese = await doArchitectAntithese(these)
console.log(antithese)
const whatAntitheseDo = findWhatIdo(antithese)
if (whatAntitheseDo) {
logger(whatAntitheseDo)
speak(whatAntitheseDo)
} else {
logger('개발 기획을 보완하는 중입니다...')
}
// * Synthese 구하기
const synthese = await doArchitectSynthese(`${these}\n${antithese}`)
console.log(synthese)
const whatSyntheseDo = findWhatIdo(synthese)
if (whatSyntheseDo) {
logger(whatSyntheseDo)
speak(whatSyntheseDo)
} else {
logger('개발 기획을 검토하는 중입니다...')
}
const isGoodToGo = findIsGoodToGo(synthese)
return {
isGoodToGo,
synthese: `----USER REQUEST\n${userRequest}\n${synthese}`
}
}
}
export const doDialecticSynthese = async (
userRequest: string,
onThese: (these: string) => unknown
) => {
// * These 구하기
const these = await doArchitectThese(userRequest)
console.log(these)
onThese(these)
const whatTheseDo = findWhatIdo(these)
if (whatTheseDo) {
logger(whatTheseDo)
speak(whatTheseDo)
} else {
logger('개발 기획을 세우는 중입니다...')
}
// * Antithese 구하기
const antithese = await doArchitectAntithese(
`----USER REQUEST\n${userRequest}\n${these}`
)
console.log(antithese)
const whatAntitheseDo = findWhatIdo(antithese)
if (whatAntitheseDo) {
logger(whatAntitheseDo)
speak(whatAntitheseDo)
} else {
logger('개발 기획을 보완하는 중입니다...')
}
// * Synthese 구하기
const synthese = await doArchitectSynthese(`${these}\n${antithese}`)
console.log(synthese)
const whatSyntheseDo = findWhatIdo(synthese)
if (whatSyntheseDo) {
logger(whatSyntheseDo)
speak(whatSyntheseDo)
} else {
logger('개발 기획을 검토하는 중입니다...')
}
const isGoodToGo = findIsGoodToGo(synthese)
return {
isGoodToGo,
synthese: `----USER REQUEST\n${userRequest}\n${synthese}`
}
}