mini-coder 0.5.13 → 0.5.14

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.
package/src/prompt.ts CHANGED
@@ -251,7 +251,13 @@ function buildCorePrompt(opts: BuildSystemPromptOpts): string {
251
251
  "- Avoid creating extra files, systems or documentation outside of what was asked.",
252
252
  "- Check requirements, and plan your changes before editing code.",
253
253
  "- Implement the necessary changes, following good practices and proper error handling.",
254
+ "- Prefer the smallest path that leaves the requested end state already true; do not stop at helper scripts, instructions, or half-finished setup when the user asked for the live result itself.",
254
255
  "- Always verify your changes using compilation, testing, and manual verification when possible.",
256
+ "- Before you finish, re-check the explicit deliverables and current state. If the user named files, paths, ports, services, commands, or output values, make sure they already exist and work now.",
257
+ "- If the request includes structural constraints on files or outputs (for example allowed commands, required lines, exact formats, or counts), treat those as acceptance criteria too and verify them directly against what you produced, not just through downstream behavior.",
258
+ "- Treat concrete command sequences and expected outputs in the user's request as acceptance criteria for the end state. If you verify that flow during the task, do not roll the environment back afterward unless the user explicitly asked for a reset.",
259
+ "- If a check or tool result contradicts your expectation, trust the evidence and resolve the mismatch before you answer.",
260
+ "- When multiple outputs or end states seem plausible, do not guess or swap in a cleaner alternative after verification. Run the smallest check that distinguishes them, and if you change the state later, verify again.",
255
261
  "- When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.",
256
262
  "- Do not leave helpers, tests, or any other form of temporary files; clean up after yourself and leave no trace.",
257
263
  "- Ensure you match the requested output exactly. This applies to file names, directory structure, number of files, output formats, and all other details.",
@@ -266,7 +272,9 @@ function buildCorePrompt(opts: BuildSystemPromptOpts): string {
266
272
  "- A todo item is only complete if the requested work is actually finished and verified to the degree the task requires.",
267
273
  "- Use `cancelled` to remove tasks that are no longer relevant.",
268
274
  "- Skip todo tools for single trivial tasks and purely conversational/informational requests.",
269
- '- You have the option to delegate tasks to copies of yourself with `mc -p "subtask prompt"` in the shell.',
275
+ "- Use the `delegate` tool for bounded subtasks when another focused agent pass would help.",
276
+ "- Prefer `delegate` over shelling out to `mc -p` unless you specifically need to exercise the CLI itself.",
277
+ "- Do not re-delegate the whole task, spin on repeated self-review prompts, or ask a delegated child to delegate again.",
270
278
  "- Delegate when you are orchestrating a large to-do/plan execution.",
271
279
  "",
272
280
  );
@@ -126,23 +126,61 @@ function isToolCallContentBlock(
126
126
  );
127
127
  }
128
128
 
129
- function isAssistantUsage(value: unknown): value is AssistantMessage["usage"] {
129
+ /**
130
+ * Parse and validate an assistant usage payload from unknown input.
131
+ *
132
+ * @param value - Unknown value to validate.
133
+ * @returns The parsed assistant usage, or `null` when invalid.
134
+ */
135
+ export function readAssistantUsage(
136
+ value: unknown,
137
+ ): AssistantMessage["usage"] | null {
130
138
  const usageRecord = toRecord(value);
131
139
  const costRecord = toRecord(usageRecord?.cost);
132
- return (
133
- usageRecord !== null &&
134
- costRecord !== null &&
135
- readFiniteNumber(usageRecord, "input") !== null &&
136
- readFiniteNumber(usageRecord, "output") !== null &&
137
- readFiniteNumber(usageRecord, "cacheRead") !== null &&
138
- readFiniteNumber(usageRecord, "cacheWrite") !== null &&
139
- readFiniteNumber(usageRecord, "totalTokens") !== null &&
140
- readFiniteNumber(costRecord, "input") !== null &&
141
- readFiniteNumber(costRecord, "output") !== null &&
142
- readFiniteNumber(costRecord, "cacheRead") !== null &&
143
- readFiniteNumber(costRecord, "cacheWrite") !== null &&
144
- readFiniteNumber(costRecord, "total") !== null
145
- );
140
+ if (!usageRecord || !costRecord) {
141
+ return null;
142
+ }
143
+
144
+ const input = readFiniteNumber(usageRecord, "input");
145
+ const output = readFiniteNumber(usageRecord, "output");
146
+ const cacheRead = readFiniteNumber(usageRecord, "cacheRead");
147
+ const cacheWrite = readFiniteNumber(usageRecord, "cacheWrite");
148
+ const totalTokens = readFiniteNumber(usageRecord, "totalTokens");
149
+ const costInput = readFiniteNumber(costRecord, "input");
150
+ const costOutput = readFiniteNumber(costRecord, "output");
151
+ const costCacheRead = readFiniteNumber(costRecord, "cacheRead");
152
+ const costCacheWrite = readFiniteNumber(costRecord, "cacheWrite");
153
+ const costTotal = readFiniteNumber(costRecord, "total");
154
+
155
+ if (
156
+ input === null ||
157
+ output === null ||
158
+ cacheRead === null ||
159
+ cacheWrite === null ||
160
+ totalTokens === null ||
161
+ costInput === null ||
162
+ costOutput === null ||
163
+ costCacheRead === null ||
164
+ costCacheWrite === null ||
165
+ costTotal === null
166
+ ) {
167
+ return null;
168
+ }
169
+
170
+ return {
171
+ input,
172
+ output,
173
+ cacheRead,
174
+ cacheWrite,
175
+ totalTokens,
176
+ cost: {
177
+ input: costInput,
178
+ output: costOutput,
179
+ cacheRead: costCacheRead,
180
+ cacheWrite: costCacheWrite,
181
+ total: costTotal,
182
+ },
183
+ };
146
184
  }
147
185
 
148
186
  function isStopReason(value: unknown): value is AssistantMessage["stopReason"] {
@@ -206,9 +244,9 @@ function parseAssistantMessageRecord(value: unknown): AssistantMessage | null {
206
244
  api,
207
245
  provider,
208
246
  model,
209
- usage: isAssistantUsage(record.usage)
210
- ? record.usage
211
- : structuredClone(EMPTY_ASSISTANT_USAGE),
247
+ usage:
248
+ readAssistantUsage(record.usage) ??
249
+ structuredClone(EMPTY_ASSISTANT_USAGE),
212
250
  stopReason: record.stopReason,
213
251
  ...(errorMessage !== null ? { errorMessage } : {}),
214
252
  timestamp,
@@ -343,51 +381,5 @@ export function getAssistantUsage(
343
381
  return null;
344
382
  }
345
383
 
346
- const messageRecord = toRecord(message);
347
- const usageRecord = toRecord(messageRecord?.usage);
348
- const costRecord = toRecord(usageRecord?.cost);
349
- if (!usageRecord || !costRecord) {
350
- return null;
351
- }
352
-
353
- const input = readFiniteNumber(usageRecord, "input");
354
- const output = readFiniteNumber(usageRecord, "output");
355
- const cacheRead = readFiniteNumber(usageRecord, "cacheRead");
356
- const cacheWrite = readFiniteNumber(usageRecord, "cacheWrite");
357
- const totalTokens = readFiniteNumber(usageRecord, "totalTokens");
358
- const costInput = readFiniteNumber(costRecord, "input");
359
- const costOutput = readFiniteNumber(costRecord, "output");
360
- const costCacheRead = readFiniteNumber(costRecord, "cacheRead");
361
- const costCacheWrite = readFiniteNumber(costRecord, "cacheWrite");
362
- const costTotal = readFiniteNumber(costRecord, "total");
363
-
364
- if (
365
- input === null ||
366
- output === null ||
367
- cacheRead === null ||
368
- cacheWrite === null ||
369
- totalTokens === null ||
370
- costInput === null ||
371
- costOutput === null ||
372
- costCacheRead === null ||
373
- costCacheWrite === null ||
374
- costTotal === null
375
- ) {
376
- return null;
377
- }
378
-
379
- return {
380
- input,
381
- output,
382
- cacheRead,
383
- cacheWrite,
384
- totalTokens,
385
- cost: {
386
- input: costInput,
387
- output: costOutput,
388
- cacheRead: costCacheRead,
389
- cacheWrite: costCacheWrite,
390
- total: costTotal,
391
- },
392
- };
384
+ return readAssistantUsage(toRecord(message)?.usage);
393
385
  }