♻️ Quality: internal/acpcreate without smells (4 → 0)
- handle with answered (skill, written, not started, asked) - the slash commands as a turnCommands table; /cancel, /start, /restart and /write as methods of their own - scaffold.go (sbxinit, dockerinit), texts.go, forms.go by theme Checked old vs new binary: mm acp-create driven over ACP through 22 prompts (help, preview, back, start, answers, refused answers, cancel, write, skillcreate and its answers, restart, an unknown command): the same messages (but the random session id) and the same files written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ac0bb79 parent: 96ba0ec modified
internal/acpcreate/ask.go +0 -139 | @@ -8,8 +8,6 @@ import ( | ||
| 8 | 8 | |
| 9 | 9 | "mm/internal/agentinit" |
| 10 | 10 | "mm/internal/elicit" |
| 11 | - | |
| 12 | - sdk "github.com/coder/acp-go-sdk" | |
| 13 | 11 | ) |
| 14 | 12 | |
| 15 | 13 | // --- the conversation: one question per message --------------------------------- |
| @@ -152,140 +150,3 @@ func batch(pending []agentinit.Step, deps map[string][]string) []agentinit.Step | ||
| 152 | 150 | // wizard stops asking: a client that keeps sending invalid answers must |
| 153 | 151 | // not loop forever. |
| 154 | 152 | const maxIdleForms = 3 |
| 155 | - | |
| 156 | -// askByForms asks the pending questions form after form, then writes. A | |
| 157 | -// multi-line text (the skill's) is asked as a message even here: whether a | |
| 158 | -// client offers several lines in a form's text field is unknown, and the | |
| 159 | -// reply box of the chat always does. | |
| 160 | -func (t *turn) askByForms(r *run) { | |
| 161 | - idle := 0 | |
| 162 | - for { | |
| 163 | - pending := r.w.Pending() | |
| 164 | - if len(pending) == 0 { | |
| 165 | - r.finish(t) | |
| 166 | - return | |
| 167 | - } | |
| 168 | - if pending[0].Multiline { | |
| 169 | - t.ask(r, pending[0]) | |
| 170 | - return | |
| 171 | - } | |
| 172 | - steps := batch(pending, r.deps) | |
| 173 | - answers, status := t.form(steps) | |
| 174 | - switch status { | |
| 175 | - case elicit.Declined: | |
| 176 | - t.say("Stopped: nothing written. Send any message to go on, `/restart` to start again.") | |
| 177 | - return | |
| 178 | - case elicit.Cancelled, elicit.Unavailable: | |
| 179 | - t.say("The form was closed: nothing written. Send any message to go on.") | |
| 180 | - return | |
| 181 | - } | |
| 182 | - if t.apply(r, steps, answers) == 0 { | |
| 183 | - idle++ | |
| 184 | - if idle >= maxIdleForms { | |
| 185 | - t.say("No answer could be used: stopping here. Send any message to try again.") | |
| 186 | - return | |
| 187 | - } | |
| 188 | - } else { | |
| 189 | - idle = 0 | |
| 190 | - } | |
| 191 | - } | |
| 192 | -} | |
| 193 | - | |
| 194 | -// apply answers the questions of a form; it reports what was refused and | |
| 195 | -// returns how many answers were taken. | |
| 196 | -func (t *turn) apply(r *run, steps []agentinit.Step, answers []elicit.Answer) int { | |
| 197 | - taken := 0 | |
| 198 | - var refused []string | |
| 199 | - for i, st := range steps { | |
| 200 | - value := "" | |
| 201 | - if i < len(answers) && len(answers[i].Values) > 0 { | |
| 202 | - value = answers[i].Values[0] | |
| 203 | - } | |
| 204 | - if strings.TrimSpace(value) == "" { | |
| 205 | - value = st.Default | |
| 206 | - } | |
| 207 | - if err := r.w.Set(st.Key, value); err != nil { | |
| 208 | - refused = append(refused, "⚠️ "+err.Error()) | |
| 209 | - continue | |
| 210 | - } | |
| 211 | - r.answered = append(r.answered, st.Key) | |
| 212 | - taken++ | |
| 213 | - } | |
| 214 | - if len(refused) > 0 { | |
| 215 | - t.say(strings.Join(refused, "\n") + "\n\nAsking again.") | |
| 216 | - } | |
| 217 | - return taken | |
| 218 | -} | |
| 219 | - | |
| 220 | -// form sends steps as one elicitation/create form. | |
| 221 | -func (t *turn) form(steps []agentinit.Step) ([]elicit.Answer, elicit.Status) { | |
| 222 | - f := formOf(steps) | |
| 223 | - schema := elicit.Schema(f) | |
| 224 | - names := make([]string, len(f.Questions)) | |
| 225 | - for i, q := range f.Questions { | |
| 226 | - names[i] = q.Name | |
| 227 | - } | |
| 228 | - req := sdk.NewUnstableCreateElicitationRequestForm(sdk.UnstableElicitationSchema{ | |
| 229 | - Type: sdk.UnstableElicitationSchemaTypeObject, | |
| 230 | - Properties: schema["properties"].(map[string]any), | |
| 231 | - Required: names, | |
| 232 | - }) | |
| 233 | - req.Form.Message = formMessage(steps) | |
| 234 | - // The session scope rides in _meta; acpwire.Writer puts it where the | |
| 235 | - // specification wants it. | |
| 236 | - req.Form.Meta = map[string]any{elicit.ScopeMetaKey: map[string]any{"sessionId": string(t.sid)}} | |
| 237 | - resp, err := t.ag.conn.UnstableCreateElicitation(t.ctx, req) | |
| 238 | - switch { | |
| 239 | - case err != nil && t.ctx.Err() != nil: | |
| 240 | - return nil, elicit.Cancelled | |
| 241 | - case err != nil: | |
| 242 | - return nil, elicit.Unavailable | |
| 243 | - case resp.Accept != nil: | |
| 244 | - return elicit.FromContent(f, resp.Accept.Content).Answers, elicit.Answered | |
| 245 | - case resp.Decline != nil: | |
| 246 | - return nil, elicit.Declined | |
| 247 | - } | |
| 248 | - return nil, elicit.Cancelled | |
| 249 | -} | |
| 250 | - | |
| 251 | -// formOf is the steps as an elicit form: one question per step, named by | |
| 252 | -// its key, its options' values as the choices. | |
| 253 | -func formOf(steps []agentinit.Step) elicit.Form { | |
| 254 | - var f elicit.Form | |
| 255 | - for _, st := range steps { | |
| 256 | - q := elicit.Question{Name: st.Key, Prompt: st.Prompt, Kind: st.Kind, Default: st.Default} | |
| 257 | - for _, o := range st.Options { | |
| 258 | - q.Options = append(q.Options, o.Value) | |
| 259 | - } | |
| 260 | - f.Questions = append(f.Questions, q) | |
| 261 | - } | |
| 262 | - return f | |
| 263 | -} | |
| 264 | - | |
| 265 | -// formMessage is the text above a form: what is being made, and what the | |
| 266 | -// options of its choices mean — a schema's enum carries values only. | |
| 267 | -func formMessage(steps []agentinit.Step) string { | |
| 268 | - var b strings.Builder | |
| 269 | - b.WriteString("mm init — create an agent") | |
| 270 | - for _, st := range steps { | |
| 271 | - if st.Kind != elicit.Choice || !hasDetails(st) { | |
| 272 | - continue | |
| 273 | - } | |
| 274 | - fmt.Fprintf(&b, "\n\n%s", st.Title) | |
| 275 | - for _, o := range st.Options { | |
| 276 | - if o.Detail != "" { | |
| 277 | - fmt.Fprintf(&b, "\n %s — %s", o.Label, o.Detail) | |
| 278 | - } | |
| 279 | - } | |
| 280 | - } | |
| 281 | - return b.String() | |
| 282 | -} | |
| 283 | - | |
| 284 | -func hasDetails(st agentinit.Step) bool { | |
| 285 | - for _, o := range st.Options { | |
| 286 | - if o.Detail != "" { | |
| 287 | - return true | |
| 288 | - } | |
| 289 | - } | |
| 290 | - return false | |
| 291 | -} | |
| @@ -8,8 +8,6 @@ import ( | |||
| 8 | 8 | ||
| 9 | "mm/internal/agentinit" | 9 | "mm/internal/agentinit" |
| 10 | "mm/internal/elicit" | 10 | "mm/internal/elicit" |
| 11 | - | ||
| 12 | - sdk "github.com/coder/acp-go-sdk" | ||
| 13 | ) | 11 | ) |
| 14 | 12 | ||
| 15 | // --- the conversation: one question per message --------------------------------- | 13 | // --- the conversation: one question per message --------------------------------- |
| @@ -152,140 +150,3 @@ func batch(pending []agentinit.Step, deps map[string][]string) []agentinit.Step | |||
| 152 | // wizard stops asking: a client that keeps sending invalid answers must | 150 | // wizard stops asking: a client that keeps sending invalid answers must |
| 153 | // not loop forever. | 151 | // not loop forever. |
| 154 | const maxIdleForms = 3 | 152 | const maxIdleForms = 3 |
| 155 | - | ||
| 156 | -// askByForms asks the pending questions form after form, then writes. A | ||
| 157 | -// multi-line text (the skill's) is asked as a message even here: whether a | ||
| 158 | -// client offers several lines in a form's text field is unknown, and the | ||
| 159 | -// reply box of the chat always does. | ||
| 160 | -func (t *turn) askByForms(r *run) { | ||
| 161 | - idle := 0 | ||
| 162 | - for { | ||
| 163 | - pending := r.w.Pending() | ||
| 164 | - if len(pending) == 0 { | ||
| 165 | - r.finish(t) | ||
| 166 | - return | ||
| 167 | - } | ||
| 168 | - if pending[0].Multiline { | ||
| 169 | - t.ask(r, pending[0]) | ||
| 170 | - return | ||
| 171 | - } | ||
| 172 | - steps := batch(pending, r.deps) | ||
| 173 | - answers, status := t.form(steps) | ||
| 174 | - switch status { | ||
| 175 | - case elicit.Declined: | ||
| 176 | - t.say("Stopped: nothing written. Send any message to go on, `/restart` to start again.") | ||
| 177 | - return | ||
| 178 | - case elicit.Cancelled, elicit.Unavailable: | ||
| 179 | - t.say("The form was closed: nothing written. Send any message to go on.") | ||
| 180 | - return | ||
| 181 | - } | ||
| 182 | - if t.apply(r, steps, answers) == 0 { | ||
| 183 | - idle++ | ||
| 184 | - if idle >= maxIdleForms { | ||
| 185 | - t.say("No answer could be used: stopping here. Send any message to try again.") | ||
| 186 | - return | ||
| 187 | - } | ||
| 188 | - } else { | ||
| 189 | - idle = 0 | ||
| 190 | - } | ||
| 191 | - } | ||
| 192 | -} | ||
| 193 | - | ||
| 194 | -// apply answers the questions of a form; it reports what was refused and | ||
| 195 | -// returns how many answers were taken. | ||
| 196 | -func (t *turn) apply(r *run, steps []agentinit.Step, answers []elicit.Answer) int { | ||
| 197 | - taken := 0 | ||
| 198 | - var refused []string | ||
| 199 | - for i, st := range steps { | ||
| 200 | - value := "" | ||
| 201 | - if i < len(answers) && len(answers[i].Values) > 0 { | ||
| 202 | - value = answers[i].Values[0] | ||
| 203 | - } | ||
| 204 | - if strings.TrimSpace(value) == "" { | ||
| 205 | - value = st.Default | ||
| 206 | - } | ||
| 207 | - if err := r.w.Set(st.Key, value); err != nil { | ||
| 208 | - refused = append(refused, "⚠️ "+err.Error()) | ||
| 209 | - continue | ||
| 210 | - } | ||
| 211 | - r.answered = append(r.answered, st.Key) | ||
| 212 | - taken++ | ||
| 213 | - } | ||
| 214 | - if len(refused) > 0 { | ||
| 215 | - t.say(strings.Join(refused, "\n") + "\n\nAsking again.") | ||
| 216 | - } | ||
| 217 | - return taken | ||
| 218 | -} | ||
| 219 | - | ||
| 220 | -// form sends steps as one elicitation/create form. | ||
| 221 | -func (t *turn) form(steps []agentinit.Step) ([]elicit.Answer, elicit.Status) { | ||
| 222 | - f := formOf(steps) | ||
| 223 | - schema := elicit.Schema(f) | ||
| 224 | - names := make([]string, len(f.Questions)) | ||
| 225 | - for i, q := range f.Questions { | ||
| 226 | - names[i] = q.Name | ||
| 227 | - } | ||
| 228 | - req := sdk.NewUnstableCreateElicitationRequestForm(sdk.UnstableElicitationSchema{ | ||
| 229 | - Type: sdk.UnstableElicitationSchemaTypeObject, | ||
| 230 | - Properties: schema["properties"].(map[string]any), | ||
| 231 | - Required: names, | ||
| 232 | - }) | ||
| 233 | - req.Form.Message = formMessage(steps) | ||
| 234 | - // The session scope rides in _meta; acpwire.Writer puts it where the | ||
| 235 | - // specification wants it. | ||
| 236 | - req.Form.Meta = map[string]any{elicit.ScopeMetaKey: map[string]any{"sessionId": string(t.sid)}} | ||
| 237 | - resp, err := t.ag.conn.UnstableCreateElicitation(t.ctx, req) | ||
| 238 | - switch { | ||
| 239 | - case err != nil && t.ctx.Err() != nil: | ||
| 240 | - return nil, elicit.Cancelled | ||
| 241 | - case err != nil: | ||
| 242 | - return nil, elicit.Unavailable | ||
| 243 | - case resp.Accept != nil: | ||
| 244 | - return elicit.FromContent(f, resp.Accept.Content).Answers, elicit.Answered | ||
| 245 | - case resp.Decline != nil: | ||
| 246 | - return nil, elicit.Declined | ||
| 247 | - } | ||
| 248 | - return nil, elicit.Cancelled | ||
| 249 | -} | ||
| 250 | - | ||
| 251 | -// formOf is the steps as an elicit form: one question per step, named by | ||
| 252 | -// its key, its options' values as the choices. | ||
| 253 | -func formOf(steps []agentinit.Step) elicit.Form { | ||
| 254 | - var f elicit.Form | ||
| 255 | - for _, st := range steps { | ||
| 256 | - q := elicit.Question{Name: st.Key, Prompt: st.Prompt, Kind: st.Kind, Default: st.Default} | ||
| 257 | - for _, o := range st.Options { | ||
| 258 | - q.Options = append(q.Options, o.Value) | ||
| 259 | - } | ||
| 260 | - f.Questions = append(f.Questions, q) | ||
| 261 | - } | ||
| 262 | - return f | ||
| 263 | -} | ||
| 264 | - | ||
| 265 | -// formMessage is the text above a form: what is being made, and what the | ||
| 266 | -// options of its choices mean — a schema's enum carries values only. | ||
| 267 | -func formMessage(steps []agentinit.Step) string { | ||
| 268 | - var b strings.Builder | ||
| 269 | - b.WriteString("mm init — create an agent") | ||
| 270 | - for _, st := range steps { | ||
| 271 | - if st.Kind != elicit.Choice || !hasDetails(st) { | ||
| 272 | - continue | ||
| 273 | - } | ||
| 274 | - fmt.Fprintf(&b, "\n\n%s", st.Title) | ||
| 275 | - for _, o := range st.Options { | ||
| 276 | - if o.Detail != "" { | ||
| 277 | - fmt.Fprintf(&b, "\n %s — %s", o.Label, o.Detail) | ||
| 278 | - } | ||
| 279 | - } | ||
| 280 | - } | ||
| 281 | - return b.String() | ||
| 282 | -} | ||
| 283 | - | ||
| 284 | -func hasDetails(st agentinit.Step) bool { | ||
| 285 | - for _, o := range st.Options { | ||
| 286 | - if o.Detail != "" { | ||
| 287 | - return true | ||
| 288 | - } | ||
| 289 | - } | ||
| 290 | - return false | ||
| 291 | -} | ||
added
internal/acpcreate/forms.go +148 -0 | new file mode 100644 | ||
| @@ -0,0 +1,148 @@ | ||
| 1 | +package acpcreate | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "fmt" | |
| 5 | + "strings" | |
| 6 | + | |
| 7 | + "mm/internal/agentinit" | |
| 8 | + "mm/internal/elicit" | |
| 9 | + | |
| 10 | + sdk "github.com/coder/acp-go-sdk" | |
| 11 | +) | |
| 12 | + | |
| 13 | +// askByForms asks the pending questions form after form, then writes. A | |
| 14 | +// multi-line text (the skill's) is asked as a message even here: whether a | |
| 15 | +// client offers several lines in a form's text field is unknown, and the | |
| 16 | +// reply box of the chat always does. | |
| 17 | +func (t *turn) askByForms(r *run) { | |
| 18 | + idle := 0 | |
| 19 | + for { | |
| 20 | + pending := r.w.Pending() | |
| 21 | + if len(pending) == 0 { | |
| 22 | + r.finish(t) | |
| 23 | + return | |
| 24 | + } | |
| 25 | + if pending[0].Multiline { | |
| 26 | + t.ask(r, pending[0]) | |
| 27 | + return | |
| 28 | + } | |
| 29 | + steps := batch(pending, r.deps) | |
| 30 | + answers, status := t.form(steps) | |
| 31 | + switch status { | |
| 32 | + case elicit.Declined: | |
| 33 | + t.say("Stopped: nothing written. Send any message to go on, `/restart` to start again.") | |
| 34 | + return | |
| 35 | + case elicit.Cancelled, elicit.Unavailable: | |
| 36 | + t.say("The form was closed: nothing written. Send any message to go on.") | |
| 37 | + return | |
| 38 | + } | |
| 39 | + if t.apply(r, steps, answers) == 0 { | |
| 40 | + idle++ | |
| 41 | + if idle >= maxIdleForms { | |
| 42 | + t.say("No answer could be used: stopping here. Send any message to try again.") | |
| 43 | + return | |
| 44 | + } | |
| 45 | + } else { | |
| 46 | + idle = 0 | |
| 47 | + } | |
| 48 | + } | |
| 49 | +} | |
| 50 | + | |
| 51 | +// apply answers the questions of a form; it reports what was refused and | |
| 52 | +// returns how many answers were taken. | |
| 53 | +func (t *turn) apply(r *run, steps []agentinit.Step, answers []elicit.Answer) int { | |
| 54 | + taken := 0 | |
| 55 | + var refused []string | |
| 56 | + for i, st := range steps { | |
| 57 | + value := "" | |
| 58 | + if i < len(answers) && len(answers[i].Values) > 0 { | |
| 59 | + value = answers[i].Values[0] | |
| 60 | + } | |
| 61 | + if strings.TrimSpace(value) == "" { | |
| 62 | + value = st.Default | |
| 63 | + } | |
| 64 | + if err := r.w.Set(st.Key, value); err != nil { | |
| 65 | + refused = append(refused, "⚠️ "+err.Error()) | |
| 66 | + continue | |
| 67 | + } | |
| 68 | + r.answered = append(r.answered, st.Key) | |
| 69 | + taken++ | |
| 70 | + } | |
| 71 | + if len(refused) > 0 { | |
| 72 | + t.say(strings.Join(refused, "\n") + "\n\nAsking again.") | |
| 73 | + } | |
| 74 | + return taken | |
| 75 | +} | |
| 76 | + | |
| 77 | +// form sends steps as one elicitation/create form. | |
| 78 | +func (t *turn) form(steps []agentinit.Step) ([]elicit.Answer, elicit.Status) { | |
| 79 | + f := formOf(steps) | |
| 80 | + schema := elicit.Schema(f) | |
| 81 | + names := make([]string, len(f.Questions)) | |
| 82 | + for i, q := range f.Questions { | |
| 83 | + names[i] = q.Name | |
| 84 | + } | |
| 85 | + req := sdk.NewUnstableCreateElicitationRequestForm(sdk.UnstableElicitationSchema{ | |
| 86 | + Type: sdk.UnstableElicitationSchemaTypeObject, | |
| 87 | + Properties: schema["properties"].(map[string]any), | |
| 88 | + Required: names, | |
| 89 | + }) | |
| 90 | + req.Form.Message = formMessage(steps) | |
| 91 | + // The session scope rides in _meta; acpwire.Writer puts it where the | |
| 92 | + // specification wants it. | |
| 93 | + req.Form.Meta = map[string]any{elicit.ScopeMetaKey: map[string]any{"sessionId": string(t.sid)}} | |
| 94 | + resp, err := t.ag.conn.UnstableCreateElicitation(t.ctx, req) | |
| 95 | + switch { | |
| 96 | + case err != nil && t.ctx.Err() != nil: | |
| 97 | + return nil, elicit.Cancelled | |
| 98 | + case err != nil: | |
| 99 | + return nil, elicit.Unavailable | |
| 100 | + case resp.Accept != nil: | |
| 101 | + return elicit.FromContent(f, resp.Accept.Content).Answers, elicit.Answered | |
| 102 | + case resp.Decline != nil: | |
| 103 | + return nil, elicit.Declined | |
| 104 | + } | |
| 105 | + return nil, elicit.Cancelled | |
| 106 | +} | |
| 107 | + | |
| 108 | +// formOf is the steps as an elicit form: one question per step, named by | |
| 109 | +// its key, its options' values as the choices. | |
| 110 | +func formOf(steps []agentinit.Step) elicit.Form { | |
| 111 | + var f elicit.Form | |
| 112 | + for _, st := range steps { | |
| 113 | + q := elicit.Question{Name: st.Key, Prompt: st.Prompt, Kind: st.Kind, Default: st.Default} | |
| 114 | + for _, o := range st.Options { | |
| 115 | + q.Options = append(q.Options, o.Value) | |
| 116 | + } | |
| 117 | + f.Questions = append(f.Questions, q) | |
| 118 | + } | |
| 119 | + return f | |
| 120 | +} | |
| 121 | + | |
| 122 | +// formMessage is the text above a form: what is being made, and what the | |
| 123 | +// options of its choices mean — a schema's enum carries values only. | |
| 124 | +func formMessage(steps []agentinit.Step) string { | |
| 125 | + var b strings.Builder | |
| 126 | + b.WriteString("mm init — create an agent") | |
| 127 | + for _, st := range steps { | |
| 128 | + if st.Kind != elicit.Choice || !hasDetails(st) { | |
| 129 | + continue | |
| 130 | + } | |
| 131 | + fmt.Fprintf(&b, "\n\n%s", st.Title) | |
| 132 | + for _, o := range st.Options { | |
| 133 | + if o.Detail != "" { | |
| 134 | + fmt.Fprintf(&b, "\n %s — %s", o.Label, o.Detail) | |
| 135 | + } | |
| 136 | + } | |
| 137 | + } | |
| 138 | + return b.String() | |
| 139 | +} | |
| 140 | + | |
| 141 | +func hasDetails(st agentinit.Step) bool { | |
| 142 | + for _, o := range st.Options { | |
| 143 | + if o.Detail != "" { | |
| 144 | + return true | |
| 145 | + } | |
| 146 | + } | |
| 147 | + return false | |
| 148 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | +package acpcreate | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "strings" | ||
| 6 | + | ||
| 7 | + "mm/internal/agentinit" | ||
| 8 | + "mm/internal/elicit" | ||
| 9 | + | ||
| 10 | + sdk "github.com/coder/acp-go-sdk" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +// askByForms asks the pending questions form after form, then writes. A | ||
| 14 | +// multi-line text (the skill's) is asked as a message even here: whether a | ||
| 15 | +// client offers several lines in a form's text field is unknown, and the | ||
| 16 | +// reply box of the chat always does. | ||
| 17 | +func (t *turn) askByForms(r *run) { | ||
| 18 | + idle := 0 | ||
| 19 | + for { | ||
| 20 | + pending := r.w.Pending() | ||
| 21 | + if len(pending) == 0 { | ||
| 22 | + r.finish(t) | ||
| 23 | + return | ||
| 24 | + } | ||
| 25 | + if pending[0].Multiline { | ||
| 26 | + t.ask(r, pending[0]) | ||
| 27 | + return | ||
| 28 | + } | ||
| 29 | + steps := batch(pending, r.deps) | ||
| 30 | + answers, status := t.form(steps) | ||
| 31 | + switch status { | ||
| 32 | + case elicit.Declined: | ||
| 33 | + t.say("Stopped: nothing written. Send any message to go on, `/restart` to start again.") | ||
| 34 | + return | ||
| 35 | + case elicit.Cancelled, elicit.Unavailable: | ||
| 36 | + t.say("The form was closed: nothing written. Send any message to go on.") | ||
| 37 | + return | ||
| 38 | + } | ||
| 39 | + if t.apply(r, steps, answers) == 0 { | ||
| 40 | + idle++ | ||
| 41 | + if idle >= maxIdleForms { | ||
| 42 | + t.say("No answer could be used: stopping here. Send any message to try again.") | ||
| 43 | + return | ||
| 44 | + } | ||
| 45 | + } else { | ||
| 46 | + idle = 0 | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +// apply answers the questions of a form; it reports what was refused and | ||
| 52 | +// returns how many answers were taken. | ||
| 53 | +func (t *turn) apply(r *run, steps []agentinit.Step, answers []elicit.Answer) int { | ||
| 54 | + taken := 0 | ||
| 55 | + var refused []string | ||
| 56 | + for i, st := range steps { | ||
| 57 | + value := "" | ||
| 58 | + if i < len(answers) && len(answers[i].Values) > 0 { | ||
| 59 | + value = answers[i].Values[0] | ||
| 60 | + } | ||
| 61 | + if strings.TrimSpace(value) == "" { | ||
| 62 | + value = st.Default | ||
| 63 | + } | ||
| 64 | + if err := r.w.Set(st.Key, value); err != nil { | ||
| 65 | + refused = append(refused, "⚠️ "+err.Error()) | ||
| 66 | + continue | ||
| 67 | + } | ||
| 68 | + r.answered = append(r.answered, st.Key) | ||
| 69 | + taken++ | ||
| 70 | + } | ||
| 71 | + if len(refused) > 0 { | ||
| 72 | + t.say(strings.Join(refused, "\n") + "\n\nAsking again.") | ||
| 73 | + } | ||
| 74 | + return taken | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +// form sends steps as one elicitation/create form. | ||
| 78 | +func (t *turn) form(steps []agentinit.Step) ([]elicit.Answer, elicit.Status) { | ||
| 79 | + f := formOf(steps) | ||
| 80 | + schema := elicit.Schema(f) | ||
| 81 | + names := make([]string, len(f.Questions)) | ||
| 82 | + for i, q := range f.Questions { | ||
| 83 | + names[i] = q.Name | ||
| 84 | + } | ||
| 85 | + req := sdk.NewUnstableCreateElicitationRequestForm(sdk.UnstableElicitationSchema{ | ||
| 86 | + Type: sdk.UnstableElicitationSchemaTypeObject, | ||
| 87 | + Properties: schema["properties"].(map[string]any), | ||
| 88 | + Required: names, | ||
| 89 | + }) | ||
| 90 | + req.Form.Message = formMessage(steps) | ||
| 91 | + // The session scope rides in _meta; acpwire.Writer puts it where the | ||
| 92 | + // specification wants it. | ||
| 93 | + req.Form.Meta = map[string]any{elicit.ScopeMetaKey: map[string]any{"sessionId": string(t.sid)}} | ||
| 94 | + resp, err := t.ag.conn.UnstableCreateElicitation(t.ctx, req) | ||
| 95 | + switch { | ||
| 96 | + case err != nil && t.ctx.Err() != nil: | ||
| 97 | + return nil, elicit.Cancelled | ||
| 98 | + case err != nil: | ||
| 99 | + return nil, elicit.Unavailable | ||
| 100 | + case resp.Accept != nil: | ||
| 101 | + return elicit.FromContent(f, resp.Accept.Content).Answers, elicit.Answered | ||
| 102 | + case resp.Decline != nil: | ||
| 103 | + return nil, elicit.Declined | ||
| 104 | + } | ||
| 105 | + return nil, elicit.Cancelled | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +// formOf is the steps as an elicit form: one question per step, named by | ||
| 109 | +// its key, its options' values as the choices. | ||
| 110 | +func formOf(steps []agentinit.Step) elicit.Form { | ||
| 111 | + var f elicit.Form | ||
| 112 | + for _, st := range steps { | ||
| 113 | + q := elicit.Question{Name: st.Key, Prompt: st.Prompt, Kind: st.Kind, Default: st.Default} | ||
| 114 | + for _, o := range st.Options { | ||
| 115 | + q.Options = append(q.Options, o.Value) | ||
| 116 | + } | ||
| 117 | + f.Questions = append(f.Questions, q) | ||
| 118 | + } | ||
| 119 | + return f | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +// formMessage is the text above a form: what is being made, and what the | ||
| 123 | +// options of its choices mean — a schema's enum carries values only. | ||
| 124 | +func formMessage(steps []agentinit.Step) string { | ||
| 125 | + var b strings.Builder | ||
| 126 | + b.WriteString("mm init — create an agent") | ||
| 127 | + for _, st := range steps { | ||
| 128 | + if st.Kind != elicit.Choice || !hasDetails(st) { | ||
| 129 | + continue | ||
| 130 | + } | ||
| 131 | + fmt.Fprintf(&b, "\n\n%s", st.Title) | ||
| 132 | + for _, o := range st.Options { | ||
| 133 | + if o.Detail != "" { | ||
| 134 | + fmt.Fprintf(&b, "\n %s — %s", o.Label, o.Detail) | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + return b.String() | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +func hasDetails(st agentinit.Step) bool { | ||
| 142 | + for _, o := range st.Options { | ||
| 143 | + if o.Detail != "" { | ||
| 144 | + return true | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + return false | ||
| 148 | +} | ||
added
internal/acpcreate/scaffold.go +76 -0 | new file mode 100644 | ||
| @@ -0,0 +1,76 @@ | ||
| 1 | +package acpcreate | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "bytes" | |
| 5 | + "fmt" | |
| 6 | + "io" | |
| 7 | + "os" | |
| 8 | + "path/filepath" | |
| 9 | + "strings" | |
| 10 | + | |
| 11 | + "mm/internal/dockerinit" | |
| 12 | + "mm/internal/sbxinit" | |
| 13 | +) | |
| 14 | + | |
| 15 | +// scaffolder is a command that writes files in the session's project the | |
| 16 | +// way mm sbxinit or mm dockerinit does: in is that command run for a | |
| 17 | +// directory (sbxinit.In, dockerinit.In). | |
| 18 | +type scaffolder struct { | |
| 19 | + name string // the slash command | |
| 20 | + files []string // what it writes, relative to the project | |
| 21 | + run func(dir string, args []string, out io.Writer, overwrite bool) int | |
| 22 | + after string // said when it wrote something | |
| 23 | +} | |
| 24 | + | |
| 25 | +// sbxinit is mm sbxinit for the session's project: sbxenv.yaml in its cwd. | |
| 26 | +func (t *turn) sbxinit(args []string) { | |
| 27 | + t.scaffold(scaffolder{name: "sbxinit", files: []string{"sbxenv.yaml"}, run: sbxinitIn, after: "Run the `sbx` commands from `%s`."}, args) | |
| 28 | +} | |
| 29 | + | |
| 30 | +// dockerinit is mm dockerinit for the session's project: Dockerfile and | |
| 31 | +// compose.yaml in its cwd (ticket 212). | |
| 32 | +func (t *turn) dockerinit(args []string) { | |
| 33 | + t.scaffold(scaffolder{name: "dockerinit", files: []string{"Dockerfile", "compose.yaml"}, run: dockerinitIn, after: "Run the `docker` commands from `%s`."}, args) | |
| 34 | +} | |
| 35 | + | |
| 36 | +// scaffold runs c for the session's project. It needs no answer from the | |
| 37 | +// wizard and works at any time — after the agent file is written, it names | |
| 38 | +// what it writes after it. Nobody can answer "Overwrite?" here: existing | |
| 39 | +// files are kept unless --overwrite is given. | |
| 40 | +func (t *turn) scaffold(c scaffolder, args []string) { | |
| 41 | + cwd := t.s.cwd | |
| 42 | + overwrite := false | |
| 43 | + var flags []string | |
| 44 | + for _, a := range args { | |
| 45 | + if a == "--overwrite" || a == "-overwrite" { | |
| 46 | + overwrite = true | |
| 47 | + continue | |
| 48 | + } | |
| 49 | + flags = append(flags, a) | |
| 50 | + } | |
| 51 | + if !overwrite { | |
| 52 | + var existing []string | |
| 53 | + for _, f := range c.files { | |
| 54 | + if _, err := os.Stat(filepath.Join(cwd, f)); err == nil { | |
| 55 | + existing = append(existing, "`"+f+"`") | |
| 56 | + } | |
| 57 | + } | |
| 58 | + if len(existing) > 0 { | |
| 59 | + t.say(fmt.Sprintf("%s already in `%s`: `/%s --overwrite` replaces it.", strings.Join(existing, " and "), cwd, c.name)) | |
| 60 | + return | |
| 61 | + } | |
| 62 | + } | |
| 63 | + var report bytes.Buffer | |
| 64 | + code := c.run(cwd, flags, &report, overwrite) | |
| 65 | + msg := "```\n" + strings.TrimRight(report.String(), "\n") + "\n```" | |
| 66 | + if code == 0 && strings.Contains(report.String(), "✅ wrote") { | |
| 67 | + msg += "\n\n" + fmt.Sprintf(c.after, cwd) | |
| 68 | + } | |
| 69 | + t.say(msg) | |
| 70 | +} | |
| 71 | + | |
| 72 | +// dockerinitIn is dockerinit.In, beside sbxinitIn. | |
| 73 | +var dockerinitIn = dockerinit.In | |
| 74 | + | |
| 75 | +// sbxinitIn is sbxinit.In; the tests replace it to read no release. | |
| 76 | +var sbxinitIn = sbxinit.In | |
| new file mode 100644 | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | +package acpcreate | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "bytes" | ||
| 5 | + "fmt" | ||
| 6 | + "io" | ||
| 7 | + "os" | ||
| 8 | + "path/filepath" | ||
| 9 | + "strings" | ||
| 10 | + | ||
| 11 | + "mm/internal/dockerinit" | ||
| 12 | + "mm/internal/sbxinit" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +// scaffolder is a command that writes files in the session's project the | ||
| 16 | +// way mm sbxinit or mm dockerinit does: in is that command run for a | ||
| 17 | +// directory (sbxinit.In, dockerinit.In). | ||
| 18 | +type scaffolder struct { | ||
| 19 | + name string // the slash command | ||
| 20 | + files []string // what it writes, relative to the project | ||
| 21 | + run func(dir string, args []string, out io.Writer, overwrite bool) int | ||
| 22 | + after string // said when it wrote something | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +// sbxinit is mm sbxinit for the session's project: sbxenv.yaml in its cwd. | ||
| 26 | +func (t *turn) sbxinit(args []string) { | ||
| 27 | + t.scaffold(scaffolder{name: "sbxinit", files: []string{"sbxenv.yaml"}, run: sbxinitIn, after: "Run the `sbx` commands from `%s`."}, args) | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +// dockerinit is mm dockerinit for the session's project: Dockerfile and | ||
| 31 | +// compose.yaml in its cwd (ticket 212). | ||
| 32 | +func (t *turn) dockerinit(args []string) { | ||
| 33 | + t.scaffold(scaffolder{name: "dockerinit", files: []string{"Dockerfile", "compose.yaml"}, run: dockerinitIn, after: "Run the `docker` commands from `%s`."}, args) | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +// scaffold runs c for the session's project. It needs no answer from the | ||
| 37 | +// wizard and works at any time — after the agent file is written, it names | ||
| 38 | +// what it writes after it. Nobody can answer "Overwrite?" here: existing | ||
| 39 | +// files are kept unless --overwrite is given. | ||
| 40 | +func (t *turn) scaffold(c scaffolder, args []string) { | ||
| 41 | + cwd := t.s.cwd | ||
| 42 | + overwrite := false | ||
| 43 | + var flags []string | ||
| 44 | + for _, a := range args { | ||
| 45 | + if a == "--overwrite" || a == "-overwrite" { | ||
| 46 | + overwrite = true | ||
| 47 | + continue | ||
| 48 | + } | ||
| 49 | + flags = append(flags, a) | ||
| 50 | + } | ||
| 51 | + if !overwrite { | ||
| 52 | + var existing []string | ||
| 53 | + for _, f := range c.files { | ||
| 54 | + if _, err := os.Stat(filepath.Join(cwd, f)); err == nil { | ||
| 55 | + existing = append(existing, "`"+f+"`") | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + if len(existing) > 0 { | ||
| 59 | + t.say(fmt.Sprintf("%s already in `%s`: `/%s --overwrite` replaces it.", strings.Join(existing, " and "), cwd, c.name)) | ||
| 60 | + return | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + var report bytes.Buffer | ||
| 64 | + code := c.run(cwd, flags, &report, overwrite) | ||
| 65 | + msg := "```\n" + strings.TrimRight(report.String(), "\n") + "\n```" | ||
| 66 | + if code == 0 && strings.Contains(report.String(), "✅ wrote") { | ||
| 67 | + msg += "\n\n" + fmt.Sprintf(c.after, cwd) | ||
| 68 | + } | ||
| 69 | + t.say(msg) | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +// dockerinitIn is dockerinit.In, beside sbxinitIn. | ||
| 73 | +var dockerinitIn = dockerinit.In | ||
| 74 | + | ||
| 75 | +// sbxinitIn is sbxinit.In; the tests replace it to read no release. | ||
| 76 | +var sbxinitIn = sbxinit.In | ||
modified
internal/acpcreate/session.go +79 -162 | @@ -4,15 +4,10 @@ import ( | ||
| 4 | 4 | "bytes" |
| 5 | 5 | "context" |
| 6 | 6 | "fmt" |
| 7 | - "io" | |
| 8 | - "os" | |
| 9 | - "path/filepath" | |
| 10 | 7 | "strings" |
| 11 | 8 | "sync" |
| 12 | 9 | |
| 13 | 10 | "mm/internal/agentinit" |
| 14 | - "mm/internal/dockerinit" | |
| 15 | - "mm/internal/sbxinit" | |
| 16 | 11 | "mm/internal/skillcreate" |
| 17 | 12 | |
| 18 | 13 | sdk "github.com/coder/acp-go-sdk" |
| @@ -99,28 +94,30 @@ func (t *turn) handle(text string) { | ||
| 99 | 94 | t.command(name, args, rest) |
| 100 | 95 | return |
| 101 | 96 | } |
| 102 | - s := t.s | |
| 103 | - if s.skill != nil { | |
| 104 | - // A skill is being created: the message answers its question. | |
| 105 | - if s.skill.asked != "" && !t.answer(text) { | |
| 106 | - return | |
| 107 | - } | |
| 97 | + if t.answered(text) { | |
| 108 | 98 | t.next() |
| 109 | - return | |
| 110 | 99 | } |
| 100 | +} | |
| 101 | + | |
| 102 | +// answered takes a message that is not a command, and reports whether the | |
| 103 | +// conversation moves on to the next question: a skill being created reads | |
| 104 | +// it as the answer to its question; a written agent, or one not started | |
| 105 | +// yet, gets a sentence instead; an agent being asked reads it as its answer. | |
| 106 | +func (t *turn) answered(text string) bool { | |
| 107 | + s := t.s | |
| 111 | 108 | switch { |
| 109 | + case s.skill != nil: | |
| 110 | + return s.skill.asked == "" || t.answer(text) | |
| 112 | 111 | case s.written != "": |
| 113 | 112 | t.say(fmt.Sprintf("`%s` is written. `/restart` creates another one, `/skillcreate` a skill for it.", s.written)) |
| 114 | - return | |
| 113 | + return false | |
| 115 | 114 | case !s.started: |
| 116 | 115 | t.start() |
| 117 | - return | |
| 116 | + return false | |
| 118 | 117 | case s.agent.asked != "": |
| 119 | - if !t.answer(text) { | |
| 120 | - return | |
| 121 | - } | |
| 118 | + return t.answer(text) | |
| 122 | 119 | } |
| 123 | - t.next() | |
| 120 | + return true | |
| 124 | 121 | } |
| 125 | 122 | |
| 126 | 123 | // slashCommand recognises one of this mode's commands, the words typed |
| @@ -143,128 +140,84 @@ func slashCommand(text string) (name string, args []string, rest string, ok bool | ||
| 143 | 140 | return "", nil, "", false |
| 144 | 141 | } |
| 145 | 142 | |
| 143 | +// command runs one of this mode's slash commands. | |
| 146 | 144 | func (t *turn) command(name string, args []string, rest string) { |
| 147 | - s := t.s | |
| 148 | - switch name { | |
| 149 | - case "skillcreate": | |
| 150 | - t.skillcreate(rest) | |
| 151 | - case "cancel": | |
| 152 | - if s.skill == nil { | |
| 153 | - t.say("No skill is being created.") | |
| 154 | - return | |
| 155 | - } | |
| 156 | - s.skill, s.skillFlow = nil, nil | |
| 157 | - t.say("Skill given up: nothing written.") | |
| 158 | - t.resumeAgent() | |
| 159 | - case "sbxinit": | |
| 160 | - t.sbxinit(args) | |
| 161 | - case "dockerinit": | |
| 162 | - t.dockerinit(args) | |
| 163 | - case "zedconfig": | |
| 164 | - t.say(zedConfig(s.cwd)) | |
| 165 | - case "start": | |
| 166 | - if s.skill != nil { | |
| 167 | - t.next() // the skill's current question, again | |
| 168 | - return | |
| 169 | - } | |
| 170 | - t.start() | |
| 171 | - case "help": | |
| 172 | - t.say(help()) | |
| 173 | - case "preview": | |
| 174 | - t.say(s.cur().preview()) | |
| 175 | - case "restart": | |
| 176 | - if s.skill != nil { | |
| 177 | - t.skillcreate(s.skillArgs) | |
| 178 | - return | |
| 179 | - } | |
| 180 | - fresh, err := t.ag.newSession(s.cwd) | |
| 181 | - if err != nil { | |
| 182 | - t.say("⚠️ " + err.Error()) | |
| 183 | - return | |
| 184 | - } | |
| 185 | - s.flow, s.agent, s.written, s.started = fresh.flow, fresh.agent, "", true | |
| 186 | - t.say("Starting again.") | |
| 187 | - t.next() | |
| 188 | - case "back": | |
| 189 | - t.back() | |
| 190 | - case "write": | |
| 191 | - if s.skill != nil { | |
| 192 | - t.takeDefaults() | |
| 193 | - t.next() | |
| 194 | - return | |
| 195 | - } | |
| 196 | - if s.written != "" { | |
| 197 | - t.say(fmt.Sprintf("`%s` is already written.", s.written)) | |
| 198 | - return | |
| 199 | - } | |
| 200 | - s.started = true | |
| 201 | - t.takeDefaults() | |
| 202 | - t.next() | |
| 145 | + if run, ok := turnCommands[name]; ok { | |
| 146 | + run(t, args, rest) | |
| 203 | 147 | } |
| 204 | 148 | } |
| 205 | 149 | |
| 206 | -// scaffolder is a command that writes files in the session's project the | |
| 207 | -// way mm sbxinit or mm dockerinit does: in is that command run for a | |
| 208 | -// directory (sbxinit.In, dockerinit.In). | |
| 209 | -type scaffolder struct { | |
| 210 | - name string // the slash command | |
| 211 | - files []string // what it writes, relative to the project | |
| 212 | - run func(dir string, args []string, out io.Writer, overwrite bool) int | |
| 213 | - after string // said when it wrote something | |
| 150 | +// turnCommands are the slash commands, by name (see commands for what they | |
| 151 | +// say in the editor). | |
| 152 | +var turnCommands = map[string]func(t *turn, args []string, rest string){ | |
| 153 | + "skillcreate": func(t *turn, _ []string, rest string) { t.skillcreate(rest) }, | |
| 154 | + "cancel": func(t *turn, _ []string, _ string) { t.cancelSkill() }, | |
| 155 | + "sbxinit": func(t *turn, args []string, _ string) { t.sbxinit(args) }, | |
| 156 | + "dockerinit": func(t *turn, args []string, _ string) { t.dockerinit(args) }, | |
| 157 | + "zedconfig": func(t *turn, _ []string, _ string) { t.say(zedConfig(t.s.cwd)) }, | |
| 158 | + "start": func(t *turn, _ []string, _ string) { t.startCommand() }, | |
| 159 | + "help": func(t *turn, _ []string, _ string) { t.say(help()) }, | |
| 160 | + "preview": func(t *turn, _ []string, _ string) { t.say(t.s.cur().preview()) }, | |
| 161 | + "restart": func(t *turn, _ []string, _ string) { t.restart() }, | |
| 162 | + "back": func(t *turn, _ []string, _ string) { t.back() }, | |
| 163 | + "write": func(t *turn, _ []string, _ string) { t.writeCommand() }, | |
| 214 | 164 | } |
| 215 | 165 | |
| 216 | -// sbxinit is mm sbxinit for the session's project: sbxenv.yaml in its cwd. | |
| 217 | -func (t *turn) sbxinit(args []string) { | |
| 218 | - t.scaffold(scaffolder{name: "sbxinit", files: []string{"sbxenv.yaml"}, run: sbxinitIn, after: "Run the `sbx` commands from `%s`."}, args) | |
| 166 | +// cancelSkill is /cancel: the skill being created is given up, and the | |
| 167 | +// agent's questions resume. | |
| 168 | +func (t *turn) cancelSkill() { | |
| 169 | + s := t.s | |
| 170 | + if s.skill == nil { | |
| 171 | + t.say("No skill is being created.") | |
| 172 | + return | |
| 173 | + } | |
| 174 | + s.skill, s.skillFlow = nil, nil | |
| 175 | + t.say("Skill given up: nothing written.") | |
| 176 | + t.resumeAgent() | |
| 219 | 177 | } |
| 220 | 178 | |
| 221 | -// dockerinit is mm dockerinit for the session's project: Dockerfile and | |
| 222 | -// compose.yaml in its cwd (ticket 212). | |
| 223 | -func (t *turn) dockerinit(args []string) { | |
| 224 | - t.scaffold(scaffolder{name: "dockerinit", files: []string{"Dockerfile", "compose.yaml"}, run: dockerinitIn, after: "Run the `docker` commands from `%s`."}, args) | |
| 179 | +// startCommand is /start: the skill's current question again while one is | |
| 180 | +// being created, else the agent's questions from the start. | |
| 181 | +func (t *turn) startCommand() { | |
| 182 | + if t.s.skill != nil { | |
| 183 | + t.next() // the skill's current question, again | |
| 184 | + return | |
| 185 | + } | |
| 186 | + t.start() | |
| 225 | 187 | } |
| 226 | 188 | |
| 227 | -// scaffold runs c for the session's project. It needs no answer from the | |
| 228 | -// wizard and works at any time — after the agent file is written, it names | |
| 229 | -// what it writes after it. Nobody can answer "Overwrite?" here: existing | |
| 230 | -// files are kept unless --overwrite is given. | |
| 231 | -func (t *turn) scaffold(c scaffolder, args []string) { | |
| 232 | - cwd := t.s.cwd | |
| 233 | - overwrite := false | |
| 234 | - var flags []string | |
| 235 | - for _, a := range args { | |
| 236 | - if a == "--overwrite" || a == "-overwrite" { | |
| 237 | - overwrite = true | |
| 238 | - continue | |
| 239 | - } | |
| 240 | - flags = append(flags, a) | |
| 241 | - } | |
| 242 | - if !overwrite { | |
| 243 | - var existing []string | |
| 244 | - for _, f := range c.files { | |
| 245 | - if _, err := os.Stat(filepath.Join(cwd, f)); err == nil { | |
| 246 | - existing = append(existing, "`"+f+"`") | |
| 247 | - } | |
| 248 | - } | |
| 249 | - if len(existing) > 0 { | |
| 250 | - t.say(fmt.Sprintf("%s already in `%s`: `/%s --overwrite` replaces it.", strings.Join(existing, " and "), cwd, c.name)) | |
| 251 | - return | |
| 252 | - } | |
| 189 | +// restart is /restart: the skill's questions again while one is being | |
| 190 | +// created, else a new agent from scratch. | |
| 191 | +func (t *turn) restart() { | |
| 192 | + s := t.s | |
| 193 | + if s.skill != nil { | |
| 194 | + t.skillcreate(s.skillArgs) | |
| 195 | + return | |
| 253 | 196 | } |
| 254 | - var report bytes.Buffer | |
| 255 | - code := c.run(cwd, flags, &report, overwrite) | |
| 256 | - msg := "```\n" + strings.TrimRight(report.String(), "\n") + "\n```" | |
| 257 | - if code == 0 && strings.Contains(report.String(), "✅ wrote") { | |
| 258 | - msg += "\n\n" + fmt.Sprintf(c.after, cwd) | |
| 197 | + fresh, err := t.ag.newSession(s.cwd) | |
| 198 | + if err != nil { | |
| 199 | + t.say("⚠️ " + err.Error()) | |
| 200 | + return | |
| 259 | 201 | } |
| 260 | - t.say(msg) | |
| 202 | + s.flow, s.agent, s.written, s.started = fresh.flow, fresh.agent, "", true | |
| 203 | + t.say("Starting again.") | |
| 204 | + t.next() | |
| 261 | 205 | } |
| 262 | 206 | |
| 263 | -// dockerinitIn is dockerinit.In, beside sbxinitIn. | |
| 264 | -var dockerinitIn = dockerinit.In | |
| 265 | - | |
| 266 | -// sbxinitIn is sbxinit.In; the tests replace it to read no release. | |
| 267 | -var sbxinitIn = sbxinit.In | |
| 207 | +// writeCommand is /write: the defaults answer what is left, and the file — | |
| 208 | +// the skill's, or the agent's unless it is written already — is written. | |
| 209 | +func (t *turn) writeCommand() { | |
| 210 | + s := t.s | |
| 211 | + if s.skill == nil && s.written != "" { | |
| 212 | + t.say(fmt.Sprintf("`%s` is already written.", s.written)) | |
| 213 | + return | |
| 214 | + } | |
| 215 | + if s.skill == nil { | |
| 216 | + s.started = true | |
| 217 | + } | |
| 218 | + t.takeDefaults() | |
| 219 | + t.next() | |
| 220 | +} | |
| 268 | 221 | |
| 269 | 222 | // start begins the wizard, or — already begun — asks the current question |
| 270 | 223 | // again. |
| @@ -281,12 +234,6 @@ func (t *turn) start() { | ||
| 281 | 234 | t.next() |
| 282 | 235 | } |
| 283 | 236 | |
| 284 | -// welcome is sent once the session exists, before any prompt: a client | |
| 285 | -// that shows it tells the user how to begin. | |
| 286 | -func welcome(cwd string) string { | |
| 287 | - return fmt.Sprintf("**mm init** — this creates an agent.yaml in `%s`. Send `/start` (or any message) to begin.", cwd) | |
| 288 | -} | |
| 289 | - | |
| 290 | 237 | // back takes back the last answer given here and asks it again. |
| 291 | 238 | func (t *turn) back() { |
| 292 | 239 | s := t.s |
| @@ -391,33 +338,3 @@ func (t *turn) write() { | ||
| 391 | 338 | s.written = s.flow.Path(output) |
| 392 | 339 | t.say(report.String() + "\n" + howToUse(s.written, t.ag.client) + "\n`/dockerinit` writes a Dockerfile and a compose.yaml to run this agent in a container, `/sbxinit` a sbxenv.yaml for a Docker Sandbox, `/skillcreate` a skill for it.") |
| 393 | 340 | } |
| 394 | - | |
| 395 | -func intro(cwd string, forms bool) string { | |
| 396 | - how := "I ask the questions one by one here: answer each with its number or its value, `.` for the default." | |
| 397 | - if forms { | |
| 398 | - how = "Your client shows forms: I ask the questions in a few of them." | |
| 399 | - } | |
| 400 | - return fmt.Sprintf("**mm init** — let's create an agent in `%s`.\n\n%s `/preview` shows the file as it stands, `/back` takes back an answer, `/write` takes every default left and writes it.", cwd, how) | |
| 401 | -} | |
| 402 | - | |
| 403 | -func help() string { | |
| 404 | - var b strings.Builder | |
| 405 | - b.WriteString("This is `mm init` over ACP: it writes an agent.yaml (or `.mm/agent.yaml`) in this project, then says how to start the agent.\n\n") | |
| 406 | - for _, c := range commands { | |
| 407 | - fmt.Fprintf(&b, "- `/%s` — %s\n", c.name, c.description) | |
| 408 | - } | |
| 409 | - return b.String() | |
| 410 | -} | |
| 411 | - | |
| 412 | -// howToUse is the closing message: the command line every client can use, | |
| 413 | -// plus a ready snippet for a client mm knows. The snippet is a convenience; | |
| 414 | -// nothing else depends on the client's name. | |
| 415 | -func howToUse(path, client string) string { | |
| 416 | - var b strings.Builder | |
| 417 | - fmt.Fprintf(&b, "Start the agent from your ACP client with the command `mm acp %s`.\n", path) | |
| 418 | - if strings.Contains(strings.ToLower(client), "zed") { | |
| 419 | - fmt.Fprintf(&b, "\nIn Zed's settings.json:\n\n```json\n\"agent_servers\": {\n \"%s\": {\n \"type\": \"custom\",\n \"command\": \"mm\",\n \"args\": [\"acp\", %q]\n }\n}\n```\n", entryName(path), path) | |
| 420 | - } | |
| 421 | - b.WriteString("\n`/zedconfig` shows every way to start it from Zed — here, in a container, in a Docker Sandbox.\n") | |
| 422 | - return b.String() | |
| 423 | -} | |
| @@ -4,15 +4,10 @@ import ( | |||
| 4 | "bytes" | 4 | "bytes" |
| 5 | "context" | 5 | "context" |
| 6 | "fmt" | 6 | "fmt" |
| 7 | - "io" | ||
| 8 | - "os" | ||
| 9 | - "path/filepath" | ||
| 10 | "strings" | 7 | "strings" |
| 11 | "sync" | 8 | "sync" |
| 12 | 9 | ||
| 13 | "mm/internal/agentinit" | 10 | "mm/internal/agentinit" |
| 14 | - "mm/internal/dockerinit" | ||
| 15 | - "mm/internal/sbxinit" | ||
| 16 | "mm/internal/skillcreate" | 11 | "mm/internal/skillcreate" |
| 17 | 12 | ||
| 18 | sdk "github.com/coder/acp-go-sdk" | 13 | sdk "github.com/coder/acp-go-sdk" |
| @@ -99,28 +94,30 @@ func (t *turn) handle(text string) { | |||
| 99 | t.command(name, args, rest) | 94 | t.command(name, args, rest) |
| 100 | return | 95 | return |
| 101 | } | 96 | } |
| 102 | - s := t.s | 97 | + if t.answered(text) { |
| 103 | - if s.skill != nil { | ||
| 104 | - // A skill is being created: the message answers its question. | ||
| 105 | - if s.skill.asked != "" && !t.answer(text) { | ||
| 106 | - return | ||
| 107 | - } | ||
| 108 | t.next() | 98 | t.next() |
| 109 | - return | ||
| 110 | } | 99 | } |
| 100 | +} | ||
| 101 | + | ||
| 102 | +// answered takes a message that is not a command, and reports whether the | ||
| 103 | +// conversation moves on to the next question: a skill being created reads | ||
| 104 | +// it as the answer to its question; a written agent, or one not started | ||
| 105 | +// yet, gets a sentence instead; an agent being asked reads it as its answer. | ||
| 106 | +func (t *turn) answered(text string) bool { | ||
| 107 | + s := t.s | ||
| 111 | switch { | 108 | switch { |
| 109 | + case s.skill != nil: | ||
| 110 | + return s.skill.asked == "" || t.answer(text) | ||
| 112 | case s.written != "": | 111 | case s.written != "": |
| 113 | t.say(fmt.Sprintf("`%s` is written. `/restart` creates another one, `/skillcreate` a skill for it.", s.written)) | 112 | t.say(fmt.Sprintf("`%s` is written. `/restart` creates another one, `/skillcreate` a skill for it.", s.written)) |
| 114 | - return | 113 | + return false |
| 115 | case !s.started: | 114 | case !s.started: |
| 116 | t.start() | 115 | t.start() |
| 117 | - return | 116 | + return false |
| 118 | case s.agent.asked != "": | 117 | case s.agent.asked != "": |
| 119 | - if !t.answer(text) { | 118 | + return t.answer(text) |
| 120 | - return | ||
| 121 | - } | ||
| 122 | } | 119 | } |
| 123 | - t.next() | 120 | + return true |
| 124 | } | 121 | } |
| 125 | 122 | ||
| 126 | // slashCommand recognises one of this mode's commands, the words typed | 123 | // slashCommand recognises one of this mode's commands, the words typed |
| @@ -143,128 +140,84 @@ func slashCommand(text string) (name string, args []string, rest string, ok bool | |||
| 143 | return "", nil, "", false | 140 | return "", nil, "", false |
| 144 | } | 141 | } |
| 145 | 142 | ||
| 143 | +// command runs one of this mode's slash commands. | ||
| 146 | func (t *turn) command(name string, args []string, rest string) { | 144 | func (t *turn) command(name string, args []string, rest string) { |
| 147 | - s := t.s | 145 | + if run, ok := turnCommands[name]; ok { |
| 148 | - switch name { | 146 | + run(t, args, rest) |
| 149 | - case "skillcreate": | ||
| 150 | - t.skillcreate(rest) | ||
| 151 | - case "cancel": | ||
| 152 | - if s.skill == nil { | ||
| 153 | - t.say("No skill is being created.") | ||
| 154 | - return | ||
| 155 | - } | ||
| 156 | - s.skill, s.skillFlow = nil, nil | ||
| 157 | - t.say("Skill given up: nothing written.") | ||
| 158 | - t.resumeAgent() | ||
| 159 | - case "sbxinit": | ||
| 160 | - t.sbxinit(args) | ||
| 161 | - case "dockerinit": | ||
| 162 | - t.dockerinit(args) | ||
| 163 | - case "zedconfig": | ||
| 164 | - t.say(zedConfig(s.cwd)) | ||
| 165 | - case "start": | ||
| 166 | - if s.skill != nil { | ||
| 167 | - t.next() // the skill's current question, again | ||
| 168 | - return | ||
| 169 | - } | ||
| 170 | - t.start() | ||
| 171 | - case "help": | ||
| 172 | - t.say(help()) | ||
| 173 | - case "preview": | ||
| 174 | - t.say(s.cur().preview()) | ||
| 175 | - case "restart": | ||
| 176 | - if s.skill != nil { | ||
| 177 | - t.skillcreate(s.skillArgs) | ||
| 178 | - return | ||
| 179 | - } | ||
| 180 | - fresh, err := t.ag.newSession(s.cwd) | ||
| 181 | - if err != nil { | ||
| 182 | - t.say("⚠️ " + err.Error()) | ||
| 183 | - return | ||
| 184 | - } | ||
| 185 | - s.flow, s.agent, s.written, s.started = fresh.flow, fresh.agent, "", true | ||
| 186 | - t.say("Starting again.") | ||
| 187 | - t.next() | ||
| 188 | - case "back": | ||
| 189 | - t.back() | ||
| 190 | - case "write": | ||
| 191 | - if s.skill != nil { | ||
| 192 | - t.takeDefaults() | ||
| 193 | - t.next() | ||
| 194 | - return | ||
| 195 | - } | ||
| 196 | - if s.written != "" { | ||
| 197 | - t.say(fmt.Sprintf("`%s` is already written.", s.written)) | ||
| 198 | - return | ||
| 199 | - } | ||
| 200 | - s.started = true | ||
| 201 | - t.takeDefaults() | ||
| 202 | - t.next() | ||
| 203 | } | 147 | } |
| 204 | } | 148 | } |
| 205 | 149 | ||
| 206 | -// scaffolder is a command that writes files in the session's project the | 150 | +// turnCommands are the slash commands, by name (see commands for what they |
| 207 | -// way mm sbxinit or mm dockerinit does: in is that command run for a | 151 | +// say in the editor). |
| 208 | -// directory (sbxinit.In, dockerinit.In). | 152 | +var turnCommands = map[string]func(t *turn, args []string, rest string){ |
| 209 | -type scaffolder struct { | 153 | + "skillcreate": func(t *turn, _ []string, rest string) { t.skillcreate(rest) }, |
| 210 | - name string // the slash command | 154 | + "cancel": func(t *turn, _ []string, _ string) { t.cancelSkill() }, |
| 211 | - files []string // what it writes, relative to the project | 155 | + "sbxinit": func(t *turn, args []string, _ string) { t.sbxinit(args) }, |
| 212 | - run func(dir string, args []string, out io.Writer, overwrite bool) int | 156 | + "dockerinit": func(t *turn, args []string, _ string) { t.dockerinit(args) }, |
| 213 | - after string // said when it wrote something | 157 | + "zedconfig": func(t *turn, _ []string, _ string) { t.say(zedConfig(t.s.cwd)) }, |
| 158 | + "start": func(t *turn, _ []string, _ string) { t.startCommand() }, | ||
| 159 | + "help": func(t *turn, _ []string, _ string) { t.say(help()) }, | ||
| 160 | + "preview": func(t *turn, _ []string, _ string) { t.say(t.s.cur().preview()) }, | ||
| 161 | + "restart": func(t *turn, _ []string, _ string) { t.restart() }, | ||
| 162 | + "back": func(t *turn, _ []string, _ string) { t.back() }, | ||
| 163 | + "write": func(t *turn, _ []string, _ string) { t.writeCommand() }, | ||
| 214 | } | 164 | } |
| 215 | 165 | ||
| 216 | -// sbxinit is mm sbxinit for the session's project: sbxenv.yaml in its cwd. | 166 | +// cancelSkill is /cancel: the skill being created is given up, and the |
| 217 | -func (t *turn) sbxinit(args []string) { | 167 | +// agent's questions resume. |
| 218 | - t.scaffold(scaffolder{name: "sbxinit", files: []string{"sbxenv.yaml"}, run: sbxinitIn, after: "Run the `sbx` commands from `%s`."}, args) | 168 | +func (t *turn) cancelSkill() { |
| 169 | + s := t.s | ||
| 170 | + if s.skill == nil { | ||
| 171 | + t.say("No skill is being created.") | ||
| 172 | + return | ||
| 173 | + } | ||
| 174 | + s.skill, s.skillFlow = nil, nil | ||
| 175 | + t.say("Skill given up: nothing written.") | ||
| 176 | + t.resumeAgent() | ||
| 219 | } | 177 | } |
| 220 | 178 | ||
| 221 | -// dockerinit is mm dockerinit for the session's project: Dockerfile and | 179 | +// startCommand is /start: the skill's current question again while one is |
| 222 | -// compose.yaml in its cwd (ticket 212). | 180 | +// being created, else the agent's questions from the start. |
| 223 | -func (t *turn) dockerinit(args []string) { | 181 | +func (t *turn) startCommand() { |
| 224 | - t.scaffold(scaffolder{name: "dockerinit", files: []string{"Dockerfile", "compose.yaml"}, run: dockerinitIn, after: "Run the `docker` commands from `%s`."}, args) | 182 | + if t.s.skill != nil { |
| 183 | + t.next() // the skill's current question, again | ||
| 184 | + return | ||
| 185 | + } | ||
| 186 | + t.start() | ||
| 225 | } | 187 | } |
| 226 | 188 | ||
| 227 | -// scaffold runs c for the session's project. It needs no answer from the | 189 | +// restart is /restart: the skill's questions again while one is being |
| 228 | -// wizard and works at any time — after the agent file is written, it names | 190 | +// created, else a new agent from scratch. |
| 229 | -// what it writes after it. Nobody can answer "Overwrite?" here: existing | 191 | +func (t *turn) restart() { |
| 230 | -// files are kept unless --overwrite is given. | 192 | + s := t.s |
| 231 | -func (t *turn) scaffold(c scaffolder, args []string) { | 193 | + if s.skill != nil { |
| 232 | - cwd := t.s.cwd | 194 | + t.skillcreate(s.skillArgs) |
| 233 | - overwrite := false | 195 | + return |
| 234 | - var flags []string | ||
| 235 | - for _, a := range args { | ||
| 236 | - if a == "--overwrite" || a == "-overwrite" { | ||
| 237 | - overwrite = true | ||
| 238 | - continue | ||
| 239 | - } | ||
| 240 | - flags = append(flags, a) | ||
| 241 | - } | ||
| 242 | - if !overwrite { | ||
| 243 | - var existing []string | ||
| 244 | - for _, f := range c.files { | ||
| 245 | - if _, err := os.Stat(filepath.Join(cwd, f)); err == nil { | ||
| 246 | - existing = append(existing, "`"+f+"`") | ||
| 247 | - } | ||
| 248 | - } | ||
| 249 | - if len(existing) > 0 { | ||
| 250 | - t.say(fmt.Sprintf("%s already in `%s`: `/%s --overwrite` replaces it.", strings.Join(existing, " and "), cwd, c.name)) | ||
| 251 | - return | ||
| 252 | - } | ||
| 253 | } | 196 | } |
| 254 | - var report bytes.Buffer | 197 | + fresh, err := t.ag.newSession(s.cwd) |
| 255 | - code := c.run(cwd, flags, &report, overwrite) | 198 | + if err != nil { |
| 256 | - msg := "```\n" + strings.TrimRight(report.String(), "\n") + "\n```" | 199 | + t.say("⚠️ " + err.Error()) |
| 257 | - if code == 0 && strings.Contains(report.String(), "✅ wrote") { | 200 | + return |
| 258 | - msg += "\n\n" + fmt.Sprintf(c.after, cwd) | ||
| 259 | } | 201 | } |
| 260 | - t.say(msg) | 202 | + s.flow, s.agent, s.written, s.started = fresh.flow, fresh.agent, "", true |
| 203 | + t.say("Starting again.") | ||
| 204 | + t.next() | ||
| 261 | } | 205 | } |
| 262 | 206 | ||
| 263 | -// dockerinitIn is dockerinit.In, beside sbxinitIn. | 207 | +// writeCommand is /write: the defaults answer what is left, and the file — |
| 264 | -var dockerinitIn = dockerinit.In | 208 | +// the skill's, or the agent's unless it is written already — is written. |
| 265 | - | 209 | +func (t *turn) writeCommand() { |
| 266 | -// sbxinitIn is sbxinit.In; the tests replace it to read no release. | 210 | + s := t.s |
| 267 | -var sbxinitIn = sbxinit.In | 211 | + if s.skill == nil && s.written != "" { |
| 212 | + t.say(fmt.Sprintf("`%s` is already written.", s.written)) | ||
| 213 | + return | ||
| 214 | + } | ||
| 215 | + if s.skill == nil { | ||
| 216 | + s.started = true | ||
| 217 | + } | ||
| 218 | + t.takeDefaults() | ||
| 219 | + t.next() | ||
| 220 | +} | ||
| 268 | 221 | ||
| 269 | // start begins the wizard, or — already begun — asks the current question | 222 | // start begins the wizard, or — already begun — asks the current question |
| 270 | // again. | 223 | // again. |
| @@ -281,12 +234,6 @@ func (t *turn) start() { | |||
| 281 | t.next() | 234 | t.next() |
| 282 | } | 235 | } |
| 283 | 236 | ||
| 284 | -// welcome is sent once the session exists, before any prompt: a client | ||
| 285 | -// that shows it tells the user how to begin. | ||
| 286 | -func welcome(cwd string) string { | ||
| 287 | - return fmt.Sprintf("**mm init** — this creates an agent.yaml in `%s`. Send `/start` (or any message) to begin.", cwd) | ||
| 288 | -} | ||
| 289 | - | ||
| 290 | // back takes back the last answer given here and asks it again. | 237 | // back takes back the last answer given here and asks it again. |
| 291 | func (t *turn) back() { | 238 | func (t *turn) back() { |
| 292 | s := t.s | 239 | s := t.s |
| @@ -391,33 +338,3 @@ func (t *turn) write() { | |||
| 391 | s.written = s.flow.Path(output) | 338 | s.written = s.flow.Path(output) |
| 392 | t.say(report.String() + "\n" + howToUse(s.written, t.ag.client) + "\n`/dockerinit` writes a Dockerfile and a compose.yaml to run this agent in a container, `/sbxinit` a sbxenv.yaml for a Docker Sandbox, `/skillcreate` a skill for it.") | 339 | t.say(report.String() + "\n" + howToUse(s.written, t.ag.client) + "\n`/dockerinit` writes a Dockerfile and a compose.yaml to run this agent in a container, `/sbxinit` a sbxenv.yaml for a Docker Sandbox, `/skillcreate` a skill for it.") |
| 393 | } | 340 | } |
| 394 | - | ||
| 395 | -func intro(cwd string, forms bool) string { | ||
| 396 | - how := "I ask the questions one by one here: answer each with its number or its value, `.` for the default." | ||
| 397 | - if forms { | ||
| 398 | - how = "Your client shows forms: I ask the questions in a few of them." | ||
| 399 | - } | ||
| 400 | - return fmt.Sprintf("**mm init** — let's create an agent in `%s`.\n\n%s `/preview` shows the file as it stands, `/back` takes back an answer, `/write` takes every default left and writes it.", cwd, how) | ||
| 401 | -} | ||
| 402 | - | ||
| 403 | -func help() string { | ||
| 404 | - var b strings.Builder | ||
| 405 | - b.WriteString("This is `mm init` over ACP: it writes an agent.yaml (or `.mm/agent.yaml`) in this project, then says how to start the agent.\n\n") | ||
| 406 | - for _, c := range commands { | ||
| 407 | - fmt.Fprintf(&b, "- `/%s` — %s\n", c.name, c.description) | ||
| 408 | - } | ||
| 409 | - return b.String() | ||
| 410 | -} | ||
| 411 | - | ||
| 412 | -// howToUse is the closing message: the command line every client can use, | ||
| 413 | -// plus a ready snippet for a client mm knows. The snippet is a convenience; | ||
| 414 | -// nothing else depends on the client's name. | ||
| 415 | -func howToUse(path, client string) string { | ||
| 416 | - var b strings.Builder | ||
| 417 | - fmt.Fprintf(&b, "Start the agent from your ACP client with the command `mm acp %s`.\n", path) | ||
| 418 | - if strings.Contains(strings.ToLower(client), "zed") { | ||
| 419 | - fmt.Fprintf(&b, "\nIn Zed's settings.json:\n\n```json\n\"agent_servers\": {\n \"%s\": {\n \"type\": \"custom\",\n \"command\": \"mm\",\n \"args\": [\"acp\", %q]\n }\n}\n```\n", entryName(path), path) | ||
| 420 | - } | ||
| 421 | - b.WriteString("\n`/zedconfig` shows every way to start it from Zed — here, in a container, in a Docker Sandbox.\n") | ||
| 422 | - return b.String() | ||
| 423 | -} | ||
added
internal/acpcreate/texts.go +42 -0 | new file mode 100644 | ||
| @@ -0,0 +1,42 @@ | ||
| 1 | +package acpcreate | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "fmt" | |
| 5 | + "strings" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// welcome is sent once the session exists, before any prompt: a client | |
| 9 | +// that shows it tells the user how to begin. | |
| 10 | +func welcome(cwd string) string { | |
| 11 | + return fmt.Sprintf("**mm init** — this creates an agent.yaml in `%s`. Send `/start` (or any message) to begin.", cwd) | |
| 12 | +} | |
| 13 | + | |
| 14 | +func intro(cwd string, forms bool) string { | |
| 15 | + how := "I ask the questions one by one here: answer each with its number or its value, `.` for the default." | |
| 16 | + if forms { | |
| 17 | + how = "Your client shows forms: I ask the questions in a few of them." | |
| 18 | + } | |
| 19 | + return fmt.Sprintf("**mm init** — let's create an agent in `%s`.\n\n%s `/preview` shows the file as it stands, `/back` takes back an answer, `/write` takes every default left and writes it.", cwd, how) | |
| 20 | +} | |
| 21 | + | |
| 22 | +func help() string { | |
| 23 | + var b strings.Builder | |
| 24 | + b.WriteString("This is `mm init` over ACP: it writes an agent.yaml (or `.mm/agent.yaml`) in this project, then says how to start the agent.\n\n") | |
| 25 | + for _, c := range commands { | |
| 26 | + fmt.Fprintf(&b, "- `/%s` — %s\n", c.name, c.description) | |
| 27 | + } | |
| 28 | + return b.String() | |
| 29 | +} | |
| 30 | + | |
| 31 | +// howToUse is the closing message: the command line every client can use, | |
| 32 | +// plus a ready snippet for a client mm knows. The snippet is a convenience; | |
| 33 | +// nothing else depends on the client's name. | |
| 34 | +func howToUse(path, client string) string { | |
| 35 | + var b strings.Builder | |
| 36 | + fmt.Fprintf(&b, "Start the agent from your ACP client with the command `mm acp %s`.\n", path) | |
| 37 | + if strings.Contains(strings.ToLower(client), "zed") { | |
| 38 | + fmt.Fprintf(&b, "\nIn Zed's settings.json:\n\n```json\n\"agent_servers\": {\n \"%s\": {\n \"type\": \"custom\",\n \"command\": \"mm\",\n \"args\": [\"acp\", %q]\n }\n}\n```\n", entryName(path), path) | |
| 39 | + } | |
| 40 | + b.WriteString("\n`/zedconfig` shows every way to start it from Zed — here, in a container, in a Docker Sandbox.\n") | |
| 41 | + return b.String() | |
| 42 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | +package acpcreate | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "strings" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +// welcome is sent once the session exists, before any prompt: a client | ||
| 9 | +// that shows it tells the user how to begin. | ||
| 10 | +func welcome(cwd string) string { | ||
| 11 | + return fmt.Sprintf("**mm init** — this creates an agent.yaml in `%s`. Send `/start` (or any message) to begin.", cwd) | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func intro(cwd string, forms bool) string { | ||
| 15 | + how := "I ask the questions one by one here: answer each with its number or its value, `.` for the default." | ||
| 16 | + if forms { | ||
| 17 | + how = "Your client shows forms: I ask the questions in a few of them." | ||
| 18 | + } | ||
| 19 | + return fmt.Sprintf("**mm init** — let's create an agent in `%s`.\n\n%s `/preview` shows the file as it stands, `/back` takes back an answer, `/write` takes every default left and writes it.", cwd, how) | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func help() string { | ||
| 23 | + var b strings.Builder | ||
| 24 | + b.WriteString("This is `mm init` over ACP: it writes an agent.yaml (or `.mm/agent.yaml`) in this project, then says how to start the agent.\n\n") | ||
| 25 | + for _, c := range commands { | ||
| 26 | + fmt.Fprintf(&b, "- `/%s` — %s\n", c.name, c.description) | ||
| 27 | + } | ||
| 28 | + return b.String() | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +// howToUse is the closing message: the command line every client can use, | ||
| 32 | +// plus a ready snippet for a client mm knows. The snippet is a convenience; | ||
| 33 | +// nothing else depends on the client's name. | ||
| 34 | +func howToUse(path, client string) string { | ||
| 35 | + var b strings.Builder | ||
| 36 | + fmt.Fprintf(&b, "Start the agent from your ACP client with the command `mm acp %s`.\n", path) | ||
| 37 | + if strings.Contains(strings.ToLower(client), "zed") { | ||
| 38 | + fmt.Fprintf(&b, "\nIn Zed's settings.json:\n\n```json\n\"agent_servers\": {\n \"%s\": {\n \"type\": \"custom\",\n \"command\": \"mm\",\n \"args\": [\"acp\", %q]\n }\n}\n```\n", entryName(path), path) | ||
| 39 | + } | ||
| 40 | + b.WriteString("\n`/zedconfig` shows every way to start it from Zed — here, in a container, in a Docker Sandbox.\n") | ||
| 41 | + return b.String() | ||
| 42 | +} | ||