termi-kids 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,6 +86,14 @@ async function gatherHelpAnswers(idea) {
86
86
  }
87
87
  return answers;
88
88
  }
89
+ /**
90
+ * Merge typed input with an optional draft. Empty typing keeps the draft so
91
+ * kids can run a suggested prompt without retyping it.
92
+ */
93
+ export function resolvePromptInput(typed, draft) {
94
+ const resolved = typed.trim() || draft.trim();
95
+ return resolved.length > 0 ? resolved : null;
96
+ }
89
97
  async function obtainPrompt(idea) {
90
98
  const path = await p.select({
91
99
  message: 'How do you want to tell Termi what to build?',
@@ -110,26 +118,41 @@ async function obtainPrompt(idea) {
110
118
  return null;
111
119
  }
112
120
  draft = suggestPromptFromAnswers(idea, answers);
121
+ }
122
+ // When we already have a draft, do not force a long single-line text field.
123
+ // clack text() is unreliable for long initialValue (looks like a placeholder
124
+ // and Enter can fail validate). Offer a clear Run vs Edit choice first.
125
+ if (draft.length > 0) {
113
126
  p.note(draft, 'Suggested prompt');
127
+ const action = await p.select({
128
+ message: 'Use this prompt?',
129
+ options: [
130
+ { value: 'run', label: 'Run it' },
131
+ { value: 'edit', label: 'Edit it first' },
132
+ ],
133
+ initialValue: 'run',
134
+ });
135
+ if (p.isCancel(action)) {
136
+ return null;
137
+ }
138
+ if (action === 'run') {
139
+ return draft;
140
+ }
114
141
  }
115
- // clack: initialValue pre-fills the field; defaultValue is only applied
116
- // AFTER validate. Empty Enter with only defaultValue fails validate, so
117
- // we pre-fill and also accept empty when a draft already exists.
118
142
  const text = await p.text({
119
- message: path === 'write' ? 'Type your prompt.' : 'Edit the prompt, or press Enter to run it.',
143
+ message: draft.length > 0 ? 'Edit your prompt.' : 'Type your prompt.',
120
144
  initialValue: draft.length > 0 ? draft : undefined,
121
145
  defaultValue: draft.length > 0 ? draft : undefined,
122
146
  placeholder: draft.length > 0 ? undefined : 'Make a fun browser game where...',
123
147
  validate: (value) => {
124
- const resolved = (value ?? '').trim() || draft.trim();
125
- return resolved.length > 0 ? undefined : 'Need a prompt to build.';
148
+ const resolved = resolvePromptInput(value ?? '', draft);
149
+ return resolved !== null ? undefined : 'Need a prompt to build.';
126
150
  },
127
151
  });
128
152
  if (p.isCancel(text)) {
129
153
  return null;
130
154
  }
131
- const resolved = text.trim() || draft.trim();
132
- return resolved.length > 0 ? resolved : null;
155
+ return resolvePromptInput(text, draft);
133
156
  }
134
157
  function listKidFileSummaries(project) {
135
158
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termi-kids",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Termi is a friendly coding buddy for kids. Build browser games with AI prompts, Learn AI lessons, and strong local safety rails.",
5
5
  "keywords": [
6
6
  "kids",