Skip to content

Commit 0fdf5b9

Browse files
committed
feat: add use case context
1 parent cc6df46 commit 0fdf5b9

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

arc-assistants/src/main/kotlin/usecases/UseCaseFormatter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ suspend fun List<UseCase>.formatToString(
6161
temp.append("#### Solution\n")
6262
useCase.fallbackSolution.output(allConditions, temp, codeBlockProcessor)
6363
}
64+
if (outputOptions.outputSolution != false && useCase.context.isNotEmpty()) {
65+
temp.append("#### Context\n")
66+
useCase.context.output(allConditions, temp, codeBlockProcessor)
67+
}
6468
if (useCase.examples.isNotEmpty() && outputOptions.outputExamples != false) {
6569
temp.append("#### Examples\n")
6670
useCase.examples.split("\n").take(exampleLimit).forEach { example ->

arc-assistants/src/main/kotlin/usecases/UseCaseParser.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fun String.toUseCases(): List<UseCase> {
4646
line.contains("# Fallback") -> FALLBACK_SOLUTION
4747
line.contains("# Step") -> STEPS
4848
line.contains("# Example") -> EXAMPLES
49+
line.contains("# Context") -> CONTEXT
4950
else -> error("Unknown UseCase section: ${line.trim()}")
5051
}
5152
return@forEachLine
@@ -62,6 +63,10 @@ fun String.toUseCases(): List<UseCase> {
6263
goal = (currentUseCase?.goal ?: emptyList()) + line.asConditional(),
6364
)
6465

66+
CONTEXT -> currentUseCase?.copy(
67+
context = (currentUseCase?.context ?: emptyList()) + line.asConditional(),
68+
)
69+
6570
STEPS -> currentUseCase?.copy(steps = (currentUseCase?.steps ?: emptyList()) + line.asConditional())
6671
EXAMPLES -> currentUseCase?.copy(examples = (currentUseCase?.examples ?: "") + line)
6772
DESCRIPTION -> currentUseCase?.copy(
@@ -202,6 +207,7 @@ enum class Section {
202207
FALLBACK_SOLUTION,
203208
STEPS,
204209
EXAMPLES,
210+
CONTEXT,
205211
}
206212

207213
@Serializable
@@ -219,6 +225,7 @@ data class UseCase(
219225
val goal: List<Conditional> = emptyList(),
220226
val subUseCase: Boolean = false,
221227
val category: String? = null,
228+
val context: List<Conditional> = emptyList(),
222229
) {
223230
fun matches(allConditions: Set<String>, input: String? = null): Boolean = conditions.matches(allConditions, input)
224231

@@ -294,20 +301,20 @@ fun Set<String>.matches(conditions: Set<String>, input: String? = null): Boolean
294301
conditions
295302
}
296303
return isEmpty() || (
297-
positiveConditionals().all { allConditions.contains(it) } &&
298-
negativeConditionals().none { allConditions.contains(it) } &&
299-
orConditionals().all { ors ->
300-
ors.any {
301-
if (it.startsWith("!")) {
302-
!allConditions.contains(
303-
it.removePrefix("!").trim(),
304-
)
305-
} else {
306-
allConditions.contains(it.trim())
304+
positiveConditionals().all { allConditions.contains(it) } &&
305+
negativeConditionals().none { allConditions.contains(it) } &&
306+
orConditionals().all { ors ->
307+
ors.any {
308+
if (it.startsWith("!")) {
309+
!allConditions.contains(
310+
it.removePrefix("!").trim(),
311+
)
312+
} else {
313+
allConditions.contains(it.trim())
314+
}
315+
}
307316
}
308-
}
309-
}
310-
)
317+
)
311318
}
312319

313320
/**

0 commit comments

Comments
 (0)