@wirecat/cli-core 0.658.0 → 0.659.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.659.0 — 14.11.2026
9
+
10
+ ### Added
11
+
12
+ - **The shared config mends its own slips.** When `~/.config/WireCat/config.json` is not JSON only because of a
13
+ byte-order mark, a comment, a trailing comma or a missing comma between two lines, a reader mends it in place,
14
+ keeping every key, and keeps the old file beside it as `config.json.bak-<time>`. Any other damage is refused with
15
+ its line, column, the text around it (every value hidden) and the likely fix: "add a comma after `"tools": true`
16
+ on line 4". It still never makes a tool read-only.
17
+
18
+ ### Changed — may break callers
19
+
20
+ - **Deleting messages and sending rule replies no longer wait for the owner** (owner, 2026-11-14). The built-in
21
+ levels of `messages.delete` and `bot.messages.delete` are now `allow`: `messages delete` deletes without a question
22
+ and without `--allow-dangerous`. `replies.send` is now `allow` (it was `deny`): `serve` sends the replies
23
+ of the rules the owner turned on, and a new rule still starts off. A profile that wants the old behaviour sets
24
+ `messages.delete: ask` or `replies.send: deny`. `mcp.authority` stays `deny`. Over MCP the same levels apply, and
25
+ a write at `ask` goes ahead, as before.
26
+ - **`syncAfterInstallCases` adds a shared config with a missing comma between two lines.** The reader mends it, so
27
+ a CLI's sync must exit 0 there; a CLI that reads the file with its own reader fails the new case.
28
+
8
29
  ## 0.658.0 — 13.11.2026
9
30
 
10
31
  ### Added
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
10
10
  inputSchema: {
11
11
  type: string;
12
12
  properties: {
13
+ limit?: undefined;
13
14
  account_id: {
14
15
  type: string;
15
16
  minimum: number;
16
17
  };
17
18
  query?: undefined;
18
19
  timezone?: undefined;
19
- limit?: undefined;
20
20
  page?: undefined;
21
21
  event?: undefined;
22
22
  } | {
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
45
45
  };
46
46
  event?: undefined;
47
47
  } | {
48
+ limit?: undefined;
48
49
  query?: undefined;
49
50
  timezone?: undefined;
50
- limit?: undefined;
51
51
  page?: undefined;
52
52
  event: {
53
53
  type: string;
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
58
58
  minimum: number;
59
59
  };
60
60
  } | {
61
+ limit?: undefined;
61
62
  query?: undefined;
62
63
  timezone?: undefined;
63
- limit?: undefined;
64
64
  page?: undefined;
65
65
  event?: undefined;
66
66
  account_id?: undefined;
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
80
80
  inputSchema: {
81
81
  type: string;
82
82
  properties: {
83
+ limit?: undefined;
83
84
  account_id: {
84
85
  type: string;
85
86
  minimum: number;
86
87
  };
87
88
  query?: undefined;
88
89
  timezone?: undefined;
89
- limit?: undefined;
90
90
  page?: undefined;
91
91
  event?: undefined;
92
92
  } | {
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
115
115
  };
116
116
  event?: undefined;
117
117
  } | {
118
+ limit?: undefined;
118
119
  query?: undefined;
119
120
  timezone?: undefined;
120
- limit?: undefined;
121
121
  page?: undefined;
122
122
  event: {
123
123
  type: string;
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
128
128
  minimum: number;
129
129
  };
130
130
  } | {
131
+ limit?: undefined;
131
132
  query?: undefined;
132
133
  timezone?: undefined;
133
- limit?: undefined;
134
134
  page?: undefined;
135
135
  event?: undefined;
136
136
  account_id?: undefined;
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
150
150
  inputSchema: {
151
151
  type: string;
152
152
  properties: {
153
+ limit?: undefined;
153
154
  account_id: {
154
155
  type: string;
155
156
  minimum: number;
156
157
  };
157
158
  query?: undefined;
158
159
  timezone?: undefined;
159
- limit?: undefined;
160
160
  page?: undefined;
161
161
  event?: undefined;
162
162
  } | {
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
185
185
  };
186
186
  event?: undefined;
187
187
  } | {
188
+ limit?: undefined;
188
189
  query?: undefined;
189
190
  timezone?: undefined;
190
- limit?: undefined;
191
191
  page?: undefined;
192
192
  event: {
193
193
  type: string;
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
198
198
  minimum: number;
199
199
  };
200
200
  } | {
201
+ limit?: undefined;
201
202
  query?: undefined;
202
203
  timezone?: undefined;
203
- limit?: undefined;
204
204
  page?: undefined;
205
205
  event?: undefined;
206
206
  account_id?: undefined;
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
220
220
  inputSchema: {
221
221
  type: string;
222
222
  properties: {
223
+ limit?: undefined;
223
224
  account_id: {
224
225
  type: string;
225
226
  minimum: number;
226
227
  };
227
228
  query?: undefined;
228
229
  timezone?: undefined;
229
- limit?: undefined;
230
230
  page?: undefined;
231
231
  event?: undefined;
232
232
  } | {
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
255
255
  };
256
256
  event?: undefined;
257
257
  } | {
258
+ limit?: undefined;
258
259
  query?: undefined;
259
260
  timezone?: undefined;
260
- limit?: undefined;
261
261
  page?: undefined;
262
262
  event: {
263
263
  type: string;
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
268
268
  minimum: number;
269
269
  };
270
270
  } | {
271
+ limit?: undefined;
271
272
  query?: undefined;
272
273
  timezone?: undefined;
273
- limit?: undefined;
274
274
  page?: undefined;
275
275
  event?: undefined;
276
276
  account_id?: undefined;
@@ -2,11 +2,12 @@ import { existsSync, readFileSync, statSync } from "node:fs";
2
2
  import { CliError, pathsAreOverridden, writeSecurely } from "@wirecat/cli-base";
3
3
  import { annotate } from "@wirecat/cli-base/commands";
4
4
  import { Command, Option } from "commander";
5
+ import { REPAIR_WORDS, repairConfigText } from "../domain/config-repair.js";
5
6
  import { envName } from "../ports/app.js";
6
7
  import { agentOf } from "../runs/run-context.js";
7
8
  import { AUTHORITY_KEY, BOT_API_KEY, LEVELS, levelFor } from "../sends/permissions.js";
9
+ import { backupPathFor } from "../store/shared-config.js";
8
10
  import { fixVerb } from "./config-issues.js";
9
- import { REPAIR_WORDS, repairConfigText } from "./config-repair.js";
10
11
  import { baseContext, environmentOf } from "./context.js";
11
12
  import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
12
13
  import { itemOf, renderAnswer } from "./envelope.js";
@@ -218,14 +219,6 @@ const repairCommand = (app, config) => profileFree(grantsAuthority(annotate(new
218
219
  if (backup)
219
220
  renderer.note(`the old file is kept as ${backup}`);
220
221
  });
221
- /** Beside the file, so the owner finds it; a second repair in the same millisecond never replaces the first. */
222
- const backupPathFor = (file) => {
223
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
224
- let path = `${file}.bak-${stamp}`;
225
- for (let n = 2; existsSync(path); n++)
226
- path = `${file}.bak-${stamp}-${n}`;
227
- return path;
228
- };
229
222
  /**
230
223
  * A key no command or write is checked against would be saved and do nothing (BUG-137) — whether it
231
224
  * comes as `permissions.<key>` or inside a whole `permissions` object.
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import * as v from "valibot";
3
- import { repairConfigText } from "./config-repair.js";
3
+ import { repairConfigText } from "../domain/config-repair.js";
4
4
  const isNode = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
5
  const SECTIONS = ["personal", "bot"];
6
6
  const SHELL_SAFE = /^[A-Za-z0-9_.:@-]*$/;
@@ -1,7 +1,8 @@
1
1
  import { Command } from "commander";
2
2
  import { type Messenger } from "./context.js";
3
3
  /**
4
- * The guard asks first at the default level, `ask`; `--allow-dangerous` is the yes. For everyone only
4
+ * Deletes without a question at the default level, `allow` (owner, 2026-11-14); a profile at `ask` gets the
5
+ * question, and `--allow-dangerous` is the yes. For everyone only
5
6
  * with `--for-everyone` (max-cli `NEED-239`), and never for an agent (NEED-1423).
6
7
  */
7
8
  export declare const deleteCommand: (messenger: Messenger) => Command;
@@ -8,7 +8,8 @@ import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
8
8
  import { lineOf } from "../steps.js";
9
9
  import { messengerContext } from "./context.js";
10
10
  /**
11
- * The guard asks first at the default level, `ask`; `--allow-dangerous` is the yes. For everyone only
11
+ * Deletes without a question at the default level, `allow` (owner, 2026-11-14); a profile at `ask` gets the
12
+ * question, and `--allow-dangerous` is the yes. For everyone only
12
13
  * with `--for-everyone` (max-cli `NEED-239`), and never for an agent (NEED-1423).
13
14
  */
14
15
  export const deleteCommand = (messenger) => annotate(new Command("delete"), {
@@ -24,3 +24,10 @@ export type RepairResult = {
24
24
  /** What each fix mends, as a person reads it. */
25
25
  export declare const REPAIR_WORDS: Record<RepairKind, string>;
26
26
  export declare const repairConfigText: (text: string) => RepairResult;
27
+ /** Fixes with one reading that a reader may make on its own; the rest change what the owner wrote, so they ask. */
28
+ export declare const SAFE_REPAIRS: ReadonlySet<RepairKind>;
29
+ /**
30
+ * Why `text` is not JSON, for a person: the line and column, the line around it, and the likely fix. Only what a
31
+ * reader may not mend on its own (`SAFE_REPAIRS`) reaches here.
32
+ */
33
+ export declare const explainBrokenJson: (text: string, result: RepairResult) => string;
@@ -250,3 +250,56 @@ const serialise = (node, indent) => {
250
250
  const [open, close] = "object" in node ? ["{", "}"] : ["[", "]"];
251
251
  return parts.length === 0 ? `${open}${close}` : `${open}\n${parts.join(",\n")}\n${indent}${close}`;
252
252
  };
253
+ /** Fixes with one reading that a reader may make on its own; the rest change what the owner wrote, so they ask. */
254
+ export const SAFE_REPAIRS = new Set([
255
+ "byte_order_mark",
256
+ "comment",
257
+ "trailing_comma",
258
+ "missing_comma",
259
+ ]);
260
+ const FIX_FOR = {
261
+ unquoted_key: (line) => `put the key on line ${line} in double quotes`,
262
+ single_quotes: (line) => `use double quotes for the text on line ${line}`,
263
+ missing_closer: (line) => `add the closing } or ] the file lacks after line ${line}, and check that nothing after it was lost`,
264
+ };
265
+ const FIX_FOR_REFUSAL = [
266
+ [/no comma between/, (line, before) => `add a comma after ${before} on line ${line}`],
267
+ [/no colon after/, (line) => `add a colon after the key on line ${line}`],
268
+ [/comma with nothing before/, (line) => `remove the extra comma on line ${line}`],
269
+ [/inside a quoted text/, (line) => `close the quotes on line ${line}`],
270
+ [/value that is not JSON/, (line) => `put the value on line ${line} in double quotes`],
271
+ [/key appears twice/, (line) => `keep one of the two keys named on line ${line}; the file holds both`],
272
+ ];
273
+ /** A line as an error may show it: keys, punctuation and true, false or null stay; any other value becomes "…". */
274
+ const shown = (line) => line
275
+ .trim()
276
+ .replace(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s"',:{}[\]]+)(\s*:)?/g, (token, _value, key) => key || /^(true|false|null)$/.test(token) ? token : '"…"');
277
+ /**
278
+ * Why `text` is not JSON, for a person: the line and column, the line around it, and the likely fix. Only what a
279
+ * reader may not mend on its own (`SAFE_REPAIRS`) reaches here.
280
+ */
281
+ export const explainBrokenJson = (text, result) => {
282
+ const lines = text.replace(/^\uFEFF/u, "").split(/\r?\n/);
283
+ const around = (line) => {
284
+ const near = lines[line - 1]?.trim() ? lines[line - 1] : lines[line - 2];
285
+ return near ? ` — near \`${shown(near)}\`` : "";
286
+ };
287
+ if (result.state === "repaired") {
288
+ const asked = result.fixes.find((one) => !SAFE_REPAIRS.has(one.kind)) ?? result.fixes[0];
289
+ if (!asked)
290
+ return "it is not valid JSON";
291
+ const fix = FIX_FOR[asked.kind]?.(asked.line);
292
+ return `line ${asked.line} has ${REPAIR_WORDS[asked.kind]}${around(asked.line)}${fix ? `; likely fix: ${fix}` : ""}`;
293
+ }
294
+ if (result.state === "valid")
295
+ return "it is valid JSON";
296
+ const { line, why } = result;
297
+ // The column counts a byte-order mark the shown line no longer has.
298
+ const column = line === 1 && text.charCodeAt(0) === 0xfeff ? result.column - 1 : result.column;
299
+ const head = (lines[line - 1] ?? "").slice(0, column - 1);
300
+ // The entry the column follows, not the whole line: `"tools": true`, without the `{"setup": {` before it.
301
+ const entry = head.slice(Math.max(head.lastIndexOf(","), head.lastIndexOf("{"), head.lastIndexOf("[")) + 1);
302
+ const before = shown(entry) || shown(lines[line - 2] ?? "");
303
+ const fix = FIX_FOR_REFUSAL.find(([pattern]) => pattern.test(why))?.[1](line, `\`${before}\``);
304
+ return `line ${line}, column ${column}: ${why}${around(line)}; likely fix: ${fix ?? "correct that part by hand"}`;
305
+ };
@@ -5,6 +5,7 @@ import { join } from "node:path";
5
5
  /**
6
6
  * The shared config (`~/.config/WireCat/config.json`) as a fresh or damaged machine has it. Only an explicit
7
7
  * "read only" answer limits a tool, and even then a sync runs: it only reads the service (owner ruling, 2026-11-13).
8
+ * A slip with one reading is mended in place (2026-11-14), so only `broken` states may fail a step.
8
9
  */
9
10
  const SHARED_CONFIGS = [
10
11
  { state: "no shared config, as on a fresh install" },
@@ -17,6 +18,10 @@ const SHARED_CONFIGS = [
17
18
  state: "a shared config with a byte-order mark",
18
19
  write: (dir) => writeFileSync(join(dir, "config.json"), '{"setup":{"permissions":"allow"}}'),
19
20
  },
21
+ {
22
+ state: "a shared config with a missing comma between two lines",
23
+ write: (dir) => writeFileSync(join(dir, "config.json"), '{\n "setup": {"permissions": "allow"}\n "theme": "dark"\n}\n'),
24
+ },
20
25
  {
21
26
  state: "a folder where the shared config should be",
22
27
  write: (dir) => mkdirSync(join(dir, "config.json")),
@@ -38,7 +38,6 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
- limit?: undefined;
42
41
  event_id?: undefined;
43
42
  series_id?: undefined;
44
43
  page?: undefined;
@@ -54,11 +53,11 @@ export declare const meetingTools: ({
54
53
  format?: undefined;
55
54
  transcript_id?: undefined;
56
55
  query?: undefined;
56
+ limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
- limit?: undefined;
62
61
  event_id?: undefined;
63
62
  series_id?: undefined;
64
63
  page?: undefined;
@@ -76,11 +75,11 @@ export declare const meetingTools: ({
76
75
  format?: undefined;
77
76
  transcript_id?: undefined;
78
77
  query?: undefined;
78
+ limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
- limit?: undefined;
84
83
  event_id?: undefined;
85
84
  series_id?: undefined;
86
85
  page?: undefined;
@@ -102,6 +101,7 @@ export declare const meetingTools: ({
102
101
  minimum: number;
103
102
  };
104
103
  query?: undefined;
104
+ limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,7 +188,6 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
- limit?: undefined;
192
191
  event_id?: undefined;
193
192
  series_id?: undefined;
194
193
  page?: undefined;
@@ -204,11 +203,11 @@ export declare const meetingTools: ({
204
203
  format?: undefined;
205
204
  transcript_id?: undefined;
206
205
  query?: undefined;
206
+ limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
- limit?: undefined;
212
211
  event_id?: undefined;
213
212
  series_id?: undefined;
214
213
  page?: undefined;
@@ -226,11 +225,11 @@ export declare const meetingTools: ({
226
225
  format?: undefined;
227
226
  transcript_id?: undefined;
228
227
  query?: undefined;
228
+ limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
- limit?: undefined;
234
233
  event_id?: undefined;
235
234
  series_id?: undefined;
236
235
  page?: undefined;
@@ -252,6 +251,7 @@ export declare const meetingTools: ({
252
251
  minimum: number;
253
252
  };
254
253
  query?: undefined;
254
+ limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,7 +338,6 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
- limit?: undefined;
342
341
  event_id?: undefined;
343
342
  series_id?: undefined;
344
343
  page?: undefined;
@@ -354,11 +353,11 @@ export declare const meetingTools: ({
354
353
  format?: undefined;
355
354
  transcript_id?: undefined;
356
355
  query?: undefined;
356
+ limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
- limit?: undefined;
362
361
  event_id?: undefined;
363
362
  series_id?: undefined;
364
363
  page?: undefined;
@@ -376,11 +375,11 @@ export declare const meetingTools: ({
376
375
  format?: undefined;
377
376
  transcript_id?: undefined;
378
377
  query?: undefined;
378
+ limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
- limit?: undefined;
384
383
  event_id?: undefined;
385
384
  series_id?: undefined;
386
385
  page?: undefined;
@@ -402,6 +401,7 @@ export declare const meetingTools: ({
402
401
  minimum: number;
403
402
  };
404
403
  query?: undefined;
404
+ limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,7 +488,6 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
- limit?: undefined;
492
491
  event_id?: undefined;
493
492
  series_id?: undefined;
494
493
  page?: undefined;
@@ -504,11 +503,11 @@ export declare const meetingTools: ({
504
503
  format?: undefined;
505
504
  transcript_id?: undefined;
506
505
  query?: undefined;
506
+ limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
- limit?: undefined;
512
511
  event_id?: undefined;
513
512
  series_id?: undefined;
514
513
  page?: undefined;
@@ -526,11 +525,11 @@ export declare const meetingTools: ({
526
525
  format?: undefined;
527
526
  transcript_id?: undefined;
528
527
  query?: undefined;
528
+ limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
- limit?: undefined;
534
533
  event_id?: undefined;
535
534
  series_id?: undefined;
536
535
  page?: undefined;
@@ -552,6 +551,7 @@ export declare const meetingTools: ({
552
551
  minimum: number;
553
552
  };
554
553
  query?: undefined;
554
+ limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,7 +638,6 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
- limit?: undefined;
642
641
  event_id?: undefined;
643
642
  series_id?: undefined;
644
643
  page?: undefined;
@@ -654,11 +653,11 @@ export declare const meetingTools: ({
654
653
  format?: undefined;
655
654
  transcript_id?: undefined;
656
655
  query?: undefined;
656
+ limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
- limit?: undefined;
662
661
  event_id?: undefined;
663
662
  series_id?: undefined;
664
663
  page?: undefined;
@@ -676,11 +675,11 @@ export declare const meetingTools: ({
676
675
  format?: undefined;
677
676
  transcript_id?: undefined;
678
677
  query?: undefined;
678
+ limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
- limit?: undefined;
684
683
  event_id?: undefined;
685
684
  series_id?: undefined;
686
685
  page?: undefined;
@@ -702,6 +701,7 @@ export declare const meetingTools: ({
702
701
  minimum: number;
703
702
  };
704
703
  query?: undefined;
704
+ limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -157,7 +157,7 @@ export type ReplyRuleFile = v.InferInput<typeof rule>;
157
157
  /**
158
158
  * Who may get an answer at all, whatever a rule says: everyone, or only those listed in `allow`; and
159
159
  * never anyone in `deny`, which wins when an id is in both. Tasks are not limited by it. A file that
160
- * does not say answers everyone a rule matches; `replies.send` is what keeps a new file silent.
160
+ * does not say answers everyone a rule matches; a new rule starts off, which keeps a new file silent.
161
161
  */
162
162
  declare const audienceShape: v.OptionalSchema<v.StrictObjectSchema<{
163
163
  readonly reply: v.OptionalSchema<v.PicklistSchema<["all", "listed"], undefined>, "all">;
@@ -76,7 +76,7 @@ const side = v.optional(v.strictObject({ people: v.optional(ids, []), chats: v.o
76
76
  /**
77
77
  * Who may get an answer at all, whatever a rule says: everyone, or only those listed in `allow`; and
78
78
  * never anyone in `deny`, which wins when an id is in both. Tasks are not limited by it. A file that
79
- * does not say answers everyone a rule matches; `replies.send` is what keeps a new file silent.
79
+ * does not say answers everyone a rule matches; a new rule starts off, which keeps a new file silent.
80
80
  */
81
81
  const audienceShape = v.optional(v.strictObject({ reply: v.optional(v.picklist(["all", "listed"]), "all"), allow: side, deny: side }), { reply: "all", allow: { people: [], chats: [] }, deny: { people: [], chats: [] } });
82
82
  const file = v.pipe(v.strictObject({ audience: audienceShape, rules: v.array(rule) }), v.check(({ rules }) => new Set(rules.map((one) => one.id)).size === rules.length, "two rules share an id; each needs its own"));
@@ -7,15 +7,16 @@ const DANGEROUS = new Set(["messages.delete", "bot.messages.delete", "topics.del
7
7
  export const skipFlagFor = (key) => DANGEROUS.has(key) ? "--allow-dangerous" : "--yes";
8
8
  /** Only what cannot be undone asks; the tool is meant to work without questions (owner, NEED-460). */
9
9
  export const DEFAULT_PERMISSIONS = {
10
- "messages.delete": "ask",
10
+ // Owner, 2026-11-14: deleting a message does not ask; a profile that wants the question sets `ask`.
11
+ "messages.delete": "allow",
11
12
  "account.sessions.end": "ask",
12
- "bot.messages.delete": "ask",
13
+ "bot.messages.delete": "allow",
13
14
  "topics.enable": "ask",
14
15
  "topics.delete": "ask",
15
16
  "chats.delete": "ask",
16
17
  "chats.clear": "ask",
17
- // NEED-568: a rule writes to people with nobody typing a command; it waits for the owner's own allow.
18
- "replies.send": "deny",
18
+ // Owner, 2026-11-14 (replaces NEED-568): a rule the owner enabled may send; `deny` stops every automatic reply.
19
+ "replies.send": "allow",
19
20
  // NEED-1662: an agent that changes settings, schedules or recipients could lift its own limits; the owner opts in.
20
21
  "mcp.authority": "deny",
21
22
  // NEED-1663: writes no level stopped before, so MCP could not offer them; over MCP `ask` goes ahead.
@@ -6,6 +6,8 @@ export type TaskCategoryEdits = Record<string, string | null>;
6
6
  * A store moved by `MESSAGING_STORE` (tests, `bin/tg`) reads the one beside it, so it never reads the owner's.
7
7
  */
8
8
  export declare const sharedConfigPath: (store: string, env?: NodeJS.ProcessEnv) => string;
9
+ /** Beside the file, so the owner finds it; a second repair in the same millisecond never replaces the first. */
10
+ export declare const backupPathFor: (file: string) => string;
9
11
  /** The `task_categories` section, or `undefined` when the file or the section is missing. */
10
12
  export declare const readTaskCategoryEdits: (path: string) => TaskCategoryEdits | undefined;
11
13
  /** `base` with the edits applied: a text sets the category (a new one goes before `other`), `null` drops it. */
@@ -1,6 +1,7 @@
1
- import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
- import { CliError, resolvePaths } from "@wirecat/cli-base";
3
+ import { CliError, resolvePaths, writeSecurely } from "@wirecat/cli-base";
4
+ import { explainBrokenJson, repairConfigText, SAFE_REPAIRS } from "../domain/config-repair.js";
4
5
  import { DEFAULT_TASK_CATEGORIES, FALLBACK_CATEGORY, taskCategoryValue, withTaskCategory, } from "../domain/task-categories.js";
5
6
  import { storePath } from "./path.js";
6
7
  const SECTION = "task_categories";
@@ -16,10 +17,40 @@ export const sharedConfigPath = (store, env = process.env) => {
16
17
  ? join(paths.config, "config.json")
17
18
  : join(dirname(store), "config.json");
18
19
  };
20
+ /** Beside the file, so the owner finds it; a second repair in the same millisecond never replaces the first. */
21
+ export const backupPathFor = (file) => {
22
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
23
+ let path = `${file}.bak-${stamp}`;
24
+ for (let n = 2; existsSync(path); n++)
25
+ path = `${file}.bak-${stamp}-${n}`;
26
+ return path;
27
+ };
28
+ /**
29
+ * A slip with one reading (a byte-order mark, a comment, a trailing or a missing comma between lines) is mended in
30
+ * the file, the old one kept beside it (owner, 2026-11-14); anything else is refused with its line and likely fix.
31
+ */
32
+ const mended = (path, bytes) => {
33
+ const text = bytes.toString("utf8");
34
+ const result = repairConfigText(text);
35
+ if (result.state === "repaired" && result.fixes.every((one) => SAFE_REPAIRS.has(one.kind))) {
36
+ try {
37
+ writeSecurely(backupPathFor(path), bytes, statSync(path).mode & 0o777);
38
+ writeSecurely(path, result.text, 0o600);
39
+ }
40
+ catch {
41
+ // A file this run cannot write is still read as mended; the next run that can write mends it.
42
+ }
43
+ return JSON.parse(result.text);
44
+ }
45
+ throw new CliError("configuration_error", `${path} is not valid JSON, ${explainBrokenJson(text, result)}`, {
46
+ reason: "config.invalid_json",
47
+ file: path,
48
+ });
49
+ };
19
50
  const readJson = (path) => {
20
- let text;
51
+ let bytes;
21
52
  try {
22
- text = readFileSync(path, "utf8");
53
+ bytes = readFileSync(path);
23
54
  }
24
55
  catch (error) {
25
56
  if (error.code === "ENOENT")
@@ -28,11 +59,10 @@ const readJson = (path) => {
28
59
  }
29
60
  let parsed;
30
61
  try {
31
- // Windows editors save JSON with a byte-order mark, which JSON.parse refuses.
32
- parsed = JSON.parse(text.replace(/^\uFEFF/u, ""));
62
+ parsed = JSON.parse(bytes.toString("utf8"));
33
63
  }
34
- catch (error) {
35
- throw new CliError("configuration_error", `${path} is not valid JSON: ${error.message}`);
64
+ catch {
65
+ parsed = mended(path, bytes);
36
66
  }
37
67
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
38
68
  throw new CliError("configuration_error", `${path} must hold a JSON object`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.658.0",
3
+ "version": "0.659.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",