speccoder_runtime/
context.rs1use serde::Serialize;
8use speccoder_core::snapshot::ProjectSnapshot;
9
10pub const PART_LIMIT: usize = 32 * 1024;
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
15pub struct Bundle {
16 pub feature: String,
18 pub constitution: String,
20 pub plan: String,
22 pub story: String,
25 pub task: TaskContext,
27 pub dependencies: Vec<DependencyContext>,
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
33pub struct TaskContext {
34 pub id: String,
36 pub title: String,
38 pub phase: String,
40 pub subsection: String,
42 pub story: String,
44 pub parallel: bool,
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
50pub struct DependencyContext {
51 pub id: String,
53 pub title: String,
55 pub done: bool,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq)]
61pub enum BundleError {
62 NoFeature,
64 NoTasks,
66 NotFound(String),
68}
69
70pub fn bundle(snapshot: &ProjectSnapshot, task_id: &str) -> Result<Bundle, BundleError> {
73 crate::format::reference().bundle(snapshot, task_id)
74}
75
76pub(crate) fn cap(text: &str) -> String {
78 if text.len() <= PART_LIMIT {
79 return text.to_owned();
80 }
81 let mut end = PART_LIMIT;
82 while !text.is_char_boundary(end) {
83 end -= 1;
84 }
85 format!(
86 "{}\n[… cut at {PART_LIMIT} bytes of {} …]",
87 &text[..end],
88 text.len()
89 )
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95
96 #[test]
97 fn cap_marks_the_cut() {
98 let long = "é".repeat(PART_LIMIT);
99 let capped = cap(&long);
100 assert!(capped.len() < long.len());
101 assert!(
102 capped.contains("[… cut at 32768 bytes of 65536 …]"),
103 "{}",
104 &capped[capped.len() - 40..]
105 );
106 }
107}