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
178
179
180
181
182
183
184
185
186
//! The chat screen — the attached code project (`/project attach`): the feed
//! note for a command's outcome. Part of the [`super`] module.
//! See docs/history/code-workspace.md, spec §9.12.
use super::*;
use crate::features::project_command::ProjectProgress;
impl ChatScreen {
/// Reports the outcome of a `/project` command as a note in the feed.
pub fn set_project_progress(&mut self, progress: ProjectProgress) {
match progress {
ProjectProgress::Attached { root, name } => {
// The note names what the assistant can now do, not just what
// happened: an attach whose consequence is invisible reads as a
// no-op, and the tools are the consequence (docs/lessons.md §4).
let msg = self
.loc
.tf("ui.project.attached", &[("name", &name), ("root", &root)]);
self.push_note(&msg);
}
ProjectProgress::Detached { root } => {
let msg = self.loc.tf("ui.project.detached", &[("root", &root)]);
self.push_note(&msg);
}
ProjectProgress::Status { root, commands } => {
let msg = match root {
Some(root) => {
let mut msg = self.loc.tf("ui.project.status", &[("root", &root)]);
// Every slot, including the empty ones: the question
// being asked is "what can the assistant run here", and
// an answer that lists only what is set cannot say "none
// of them" (docs/lessons.md §4).
for (slot, line) in commands {
let value = match line {
Some(line) => line,
None => self.loc.t("ui.project.slot_unset").to_string(),
};
msg.push('\n');
msg.push_str(&self.loc.tf(
"ui.project.status_slot",
&[("slot", slot.key()), ("line", &value)],
));
}
msg
}
// "Nothing attached" has to say how to attach one, or the
// answer is a dead end.
None => self.loc.tf(
"ui.project.status_none",
&[("usage", self.loc.t("ui.project.usage"))],
),
};
self.push_note(&msg);
}
ProjectProgress::CommandSet { slot, line } => {
let msg = self.loc.tf(
"ui.project.command_set",
&[("slot", slot.key()), ("line", &line)],
);
self.push_note(&msg);
}
ProjectProgress::CommandShown { slot, line } => {
let msg = match line {
Some(line) => self.loc.tf(
"ui.project.command_shown",
&[("slot", slot.key()), ("line", &line)],
),
// "Nothing here" has to name the command that puts something
// here, or the answer is a dead end (docs/lessons.md §4).
None => self.loc.tf(
"ui.project.command_none",
&[("slot", slot.key()), ("cmd", &slot.setter_command())],
),
};
self.push_note(&msg);
}
ProjectProgress::CommandCleared { slot, had } => {
let key = if had {
"ui.project.command_cleared"
} else {
// Clearing an empty slot is not an error, and it must not be
// silent either: saying so is what tells the user their
// earlier `build-cmd` never landed.
"ui.project.command_was_empty"
};
let msg = self.loc.tf(key, &[("slot", slot.key())]);
self.push_note(&msg);
}
ProjectProgress::CommandRefused { line, ch } => {
self.push_error(&self.loc.tf(
"ui.project.command_shell",
&[("line", &line), ("char", &ch.to_string())],
));
}
ProjectProgress::Failed(err) => {
self.push_error(&self.loc.tf("ui.project.failed", &[("err", &err)]));
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::entities::workspace::CommandSlot;
/// Every outcome must produce a visible note: a command that answers with
/// nothing is the silence the command-only-control track exists to remove
/// (docs/lessons.md §4).
#[test]
fn every_outcome_is_reported() {
let cases = [
ProjectProgress::Attached {
root: "D:/proj".into(),
name: "proj".into(),
},
ProjectProgress::Detached {
root: "D:/proj".into(),
},
ProjectProgress::Status {
root: Some("D:/proj".into()),
commands: vec![
(CommandSlot::Build, Some("cargo build".into())),
(CommandSlot::Run, None),
(CommandSlot::Test, None),
],
},
ProjectProgress::Status {
root: None,
commands: Vec::new(),
},
ProjectProgress::CommandSet {
slot: CommandSlot::Build,
line: "cargo build".into(),
},
ProjectProgress::CommandShown {
slot: CommandSlot::Run,
line: Some("cargo run".into()),
},
ProjectProgress::CommandShown {
slot: CommandSlot::Test,
line: None,
},
ProjectProgress::CommandCleared {
slot: CommandSlot::Test,
had: true,
},
ProjectProgress::CommandCleared {
slot: CommandSlot::Test,
had: false,
},
ProjectProgress::CommandRefused {
line: "cargo build | tee log".into(),
ch: '|',
},
ProjectProgress::Failed("boom".into()),
];
for case in cases {
let mut s = ChatScreen::new();
let before = s.feed.len();
s.set_project_progress(case.clone());
assert!(s.feed.len() > before, "{case:?} produced no note");
}
}
/// "Nothing attached" must name the route that attaches something, and the
/// attached note must name the root — a note that only says "done" leaves
/// the user unable to tell *which* directory landed.
#[test]
fn the_notes_carry_what_the_user_needs_next() {
let mut s = ChatScreen::new();
s.set_project_progress(ProjectProgress::Status {
root: None,
commands: Vec::new(),
});
let empty = s.feed.last().expect("a note").text.clone();
assert!(empty.contains("/project"), "got: {empty}");
s.set_project_progress(ProjectProgress::Attached {
root: "D:/proj".into(),
name: "proj".into(),
});
let attached = s.feed.last().expect("a note").text.clone();
assert!(attached.contains("D:/proj"), "got: {attached}");
}
}