@cobia/pi-onward 0.2.0 → 0.3.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobia/pi-onward",
3
- "version": "0.2.0",
4
- "description": "Keep a pi run going after it ends in an error or an empty reply: user-written rules decide whether to send a visible message or silently resend, with per-rule budgets, backoff and a same-error stop.",
3
+ "version": "0.3.1",
4
+ "description": "pi 出错或空回停止时,按规则自动续跑",
5
5
  "keywords": [
6
6
  "pi",
7
7
  "pi-package",
@@ -44,7 +44,7 @@
44
44
  "@earendil-works/pi-tui": "*"
45
45
  },
46
46
  "devDependencies": {
47
- "@biomejs/biome": "^2.6.3",
47
+ "@biomejs/biome": "^2.6.4",
48
48
  "@earendil-works/pi-coding-agent": "^1.4.0",
49
49
  "@earendil-works/pi-tui": "^1.4.0",
50
50
  "@types/node": "^22.20.5",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * `/onward <动作> [参数]`:动作在前,参数写成 `字段=值`,字段名和设置文件一样。动作、字段、取值和选项都区分大小写,
3
- * 和设置文件、pi 自己的命令名一样。`set` 全有或全无:任何一项不合法就一项都不写。不写动作时弹出菜单,标题是现在的状态。
3
+ * 和设置文件、pi 自己的命令名一样。`set` 全有或全无:任何一项不合法就一项都不写。不写动作时弹出菜单,标明当前状态和修改目标。
4
4
  *
5
5
  * `--help` 是结束:写在哪都只显示帮助、不执行,跟在动作后面时显示这个动作的帮助。补全在每个动作后面都给它,
6
6
  * 写了它之后什么都不再给,后面有没有空格都一样。
@@ -26,6 +26,7 @@ import {
26
26
  layerNotice,
27
27
  menuTitle,
28
28
  type Notice,
29
+ quietLine,
29
30
  resetLine,
30
31
  rulesNotice,
31
32
  SCOPE,
@@ -52,6 +53,18 @@ export type Command =
52
53
  | { kind: "error"; message: string; topic?: string };
53
54
 
54
55
  const HELP = "--help";
56
+ /** 启动提示的开关:不是规则的参数,只能写在全局设置。 */
57
+ const QUIET = "quietStartup";
58
+ /** 帮助的字段表里 quietStartup 那一行。 */
59
+ const QUIET_HELP: [string, string] = [
60
+ QUIET,
61
+ [
62
+ "启动时的提示(用上了项目级设置、没有可用的规则);设置有问题时照样警告。只能写在全局设置",
63
+ "true:不显示",
64
+ "false:照常显示,不管 pi 的 quietStartup",
65
+ "不写:跟着 pi 的 quietStartup(默认)",
66
+ ].join("\n"),
67
+ ];
55
68
 
56
69
  /** 改设置的动作的帮助里都有这一行。不写路径:设置文件放在哪只由 index.ts 决定,实际的路径在 status 里。 */
57
70
  const SCOPE_HELP = `${SCOPE} 写在动作前:不写或 global 改全局设置,project 改当前目录的项目级设置;两份在哪见 /${COMMAND} status`;
@@ -134,7 +147,7 @@ const ACTIONS: readonly ActionSpec[] = [
134
147
  args: "字段 …",
135
148
  description: "去掉开关或参数,继承下一层",
136
149
  details: [
137
- "可以一次写几个,开关 enabled 也能去掉;有不认识或写了两次的字段就一项都不改",
150
+ "可以一次写几个,开关 enabled、启动提示 quietStartup 也能去掉;有不认识或写了两次的字段就一项都不改",
138
151
  "规则里写的同名字段不受影响",
139
152
  SCOPE_FALLBACK,
140
153
  ],
@@ -152,7 +165,11 @@ const ACTIONS: readonly ActionSpec[] = [
152
165
  name: "reset",
153
166
  args: "",
154
167
  description: "去掉开关和参数,保留手写的 rules",
155
- details: ["开关和参数都去掉;rules 和其他手写的内容留着", "正在等的续跑立刻打断,计数清零", SCOPE_FALLBACK],
168
+ details: [
169
+ "开关、参数和 quietStartup 都去掉;rules 和其他手写的内容留着",
170
+ "正在等的续跑立刻打断,计数清零",
171
+ SCOPE_FALLBACK,
172
+ ],
156
173
  scoped: "write",
157
174
  },
158
175
  ];
@@ -180,7 +197,7 @@ export function registerCommand(pi: ExtensionAPI, settings: Settings, onward: On
180
197
  }
181
198
 
182
199
  /**
183
- * `/onward` 不写动作:弹出菜单,标题是现在的状态。返回选中的命令;要写参数的(set、unset)填进输入框接着写,
200
+ * `/onward` 不写动作:弹出菜单,标明当前状态和修改目标。返回选中的命令;要写参数的(set、unset)填进输入框接着写,
184
201
  * 返回 undefined。写了 `--scope` 时只列改这一份的动作,选中的命令带着它。没有界面时不弹,什么都不做。
185
202
  */
186
203
  async function choose(ctx: ExtensionContext, settings: Settings, scope?: Scope): Promise<string | undefined> {
@@ -247,14 +264,16 @@ function execute(
247
264
  onward.stop(ctx);
248
265
  const saved = settings.reset(command.scope);
249
266
  const kept = saved.kind === "saved" && Array.isArray(saved.value.rules) && saved.value.rules.length > 0;
250
- const done = note(resetLine(settings, command.scope, kept), shadowLine(settings, command.scope, COMMAND_KEYS));
267
+ const done = note(resetLine(command.scope, kept), shadowLine(settings, command.scope, COMMAND_KEYS));
251
268
  return changedNotice(saved, settings, onward.progress(), done);
252
269
  }
253
270
  case "update": {
254
271
  const saved = settings.update(command.scope, command.change);
272
+ const keys = changedKeys(command.change);
255
273
  const done = note(
256
- scopeLine(settings, command.scope),
257
- shadowLine(settings, command.scope, changedKeys(command.change)),
274
+ scopeLine(command.scope),
275
+ keys.includes(QUIET) ? quietLine(settings.config.quietStartup) : undefined,
276
+ shadowLine(settings, command.scope, keys),
258
277
  );
259
278
  return changedNotice(saved, settings, onward.progress(), done);
260
279
  }
@@ -406,7 +425,7 @@ function none(action: string, rest: string[]): Command | undefined {
406
425
 
407
426
  function parseSet(tokens: string[], scope: Scope): Command {
408
427
  if (!tokens.length)
409
- return { kind: "error", message: `set 要写 字段=值;可用 ${FIELD_NAMES.join("、")}`, topic: "set" };
428
+ return { kind: "error", message: `set 要写 字段=值;可用 ${settable(scope).join("、")}`, topic: "set" };
410
429
  const problems: string[] = [];
411
430
  const values: Record<string, unknown> = {};
412
431
  for (const token of tokens) {
@@ -417,23 +436,39 @@ function parseSet(tokens: string[], scope: Scope): Command {
417
436
  }
418
437
  const key = token.slice(0, equals);
419
438
  const text = token.slice(equals + 1);
420
- const known = paramField(key, scope);
421
- if (typeof known === "string") {
422
- problems.push(known);
423
- continue;
424
- }
425
- if (known.name in values) {
426
- problems.push(`${known.name} 写了两次`);
439
+ if (Object.hasOwn(values, key)) {
440
+ problems.push(`${key} 写了两次`);
427
441
  continue;
428
442
  }
429
- const value = known.fromText(text);
430
- const read = known.read(value);
431
- if ("problem" in read) problems.push(`${known.name} ${read.problem}`);
432
- else values[known.name] = value;
443
+ const parsed = key === QUIET ? quietValue(text, scope) : paramValue(key, text, scope);
444
+ if ("problem" in parsed) problems.push(parsed.problem);
445
+ else values[parsed.name] = parsed.value;
433
446
  }
434
447
  return problems.length ? rejected(problems, "set") : { kind: "update", scope, change: { set: values } };
435
448
  }
436
449
 
450
+ type Parsed = { name: string; value: unknown } | { problem: string };
451
+
452
+ function paramValue(key: string, text: string, scope: Scope): Parsed {
453
+ const known = paramField(key, scope, settable(scope));
454
+ if (typeof known === "string") return { problem: known };
455
+ const value = known.fromText(text);
456
+ const read = known.read(value);
457
+ return "problem" in read ? { problem: `${known.name} ${read.problem}` } : { name: known.name, value };
458
+ }
459
+
460
+ /** quietStartup 只认 true、false,只能写在全局:项目级的能关掉「用上了项目级设置」这句提醒。 */
461
+ function quietValue(text: string, scope: Scope): Parsed {
462
+ if (scope !== "global") return { problem: `${QUIET} 只能写在全局设置,不写 ${SCOPE} 就是全局` };
463
+ if (text !== "true" && text !== "false") return { problem: `${QUIET} 需要 true 或 false` };
464
+ return { name: QUIET, value: text === "true" };
465
+ }
466
+
467
+ /** set 能写的字段:参数,全局还有 quietStartup。 */
468
+ function settable(scope: Scope): readonly string[] {
469
+ return scope === "global" ? [...FIELD_NAMES, QUIET] : FIELD_NAMES;
470
+ }
471
+
437
472
  /**
438
473
  * unset 能去掉的:参数,和开关 enabled。开关有两份设置时也要能去掉:去掉项目级的才继承全局的。
439
474
  */
@@ -452,7 +487,8 @@ function parseUnset(tokens: string[], scope: Scope): Command {
452
487
  }
453
488
 
454
489
  function unsetKey(token: string, scope: Scope): { name: string } | { problem: string } {
455
- if (token === "enabled") return { name: "enabled" };
490
+ // quietStartup 在哪一份都能去掉:项目级写了它是一处问题,去掉就好了。
491
+ if (token === "enabled" || token === QUIET) return { name: token };
456
492
  const known = paramField(token, scope, COMMAND_KEYS);
457
493
  return typeof known === "string" ? { problem: known } : { name: known.name };
458
494
  }
@@ -492,7 +528,7 @@ function overallHelp(): string {
492
528
  `用法:/${COMMAND} [${SCOPE} <${SCOPES.join("|")}>] [动作] [参数] [${HELP}]`,
493
529
  ...section("动作", table(ACTIONS.map((item) => [item.name, item.description]))),
494
530
  "",
495
- ` 不写动作时弹出菜单,标题是现在的状态;菜单里的 ${SCOPE} <层> … 进到只看、只改那一份的菜单`,
531
+ ` 不写动作时弹出菜单,标题区分当前状态和修改目标;菜单里的 ${SCOPE} <层> … 进到只看、只改那一份的菜单`,
496
532
  ` ${scopedActions("write")} 改哪一份设置由 ${SCOPE} 定,写在动作前:不写或 global 是全局,project 是当前目录的项目级`,
497
533
  ` show 不写 ${SCOPE} 时看合并后的结果,写了只看那一份`,
498
534
  ` 每个动作的用法:/${COMMAND} <动作> ${HELP}(只显示帮助,不执行)`,
@@ -508,7 +544,9 @@ function actionHelp(spec: ActionSpec): string {
508
544
  "说明",
509
545
  [...spec.details, ...(spec.scoped === "write" ? [SCOPE_HELP] : [])].map((line) => ` ${line}`),
510
546
  ),
511
- ...(spec.fields ? section("字段", table(FIELDS.map((item) => [item.name, fieldHelp(item)]))) : []),
547
+ ...(spec.fields
548
+ ? section("字段", table([...FIELDS.map((item): [string, string] => [item.name, fieldHelp(item)]), QUIET_HELP]))
549
+ : []),
512
550
  ...section(
513
551
  "示例",
514
552
  (spec.examples ?? []).map((line) => ` ${line}`),
@@ -633,44 +671,66 @@ function candidates(typed: string[], current: string): Candidate[] {
633
671
  ];
634
672
  const spec = actionNamed(first);
635
673
  if (!spec || (scoped && !spec.scoped)) return [];
636
- const args = argumentCandidates(spec.name, rest, current);
674
+ const args = argumentCandidates(spec.name, rest, current, scoped ? scopeNamed(words[1])! : "global");
637
675
  return args ? [...args, { value: HELP, description: `显示 ${spec.name} 的帮助,不执行` }] : [];
638
676
  }
639
677
 
640
678
  /** 动作后面的参数;`undefined`:这里已经写错了,执行时会被拒绝,--help 也不给。 */
641
- function argumentCandidates(action: string, rest: string[], current: string): Candidate[] | undefined {
679
+ function argumentCandidates(action: string, rest: string[], current: string, scope: Scope): Candidate[] | undefined {
642
680
  switch (action) {
643
681
  case "show":
644
682
  if (!rest.length) return [{ value: "rules", description: "只看规则" }];
645
683
  return rest.length === 1 && rest[0] === "rules" ? [] : undefined;
646
684
  case "set":
647
685
  case "unset":
648
- return fieldCandidates(action, rest, current);
686
+ return fieldCandidates(action, rest, current, scope);
649
687
  default:
650
688
  return rest.length ? undefined : [];
651
689
  }
652
690
  }
653
691
 
654
- function fieldCandidates(action: string, rest: string[], current: string): Candidate[] | undefined {
692
+ /** quietStartup= 后面能写的。 */
693
+ const QUIET_CHOICES: readonly Candidate[] = [
694
+ { value: "true", description: "启动时不显示 onward 的提示;设置有问题时照样警告" },
695
+ { value: "false", description: "照常显示,不管 pi 的 quietStartup" },
696
+ ];
697
+
698
+ function fieldCandidates(action: string, rest: string[], current: string, scope: Scope): Candidate[] | undefined {
699
+ // quietStartup 只能写在全局:项目级的 set 不收它,也不给;unset 哪一份都收,项目级的不给。
700
+ const offered = scope === "global";
701
+ const named = (name: string) =>
702
+ fieldNamed(name) !== undefined || (name === QUIET && (offered || action === "unset"));
655
703
  // 前面有执行时会被拒绝的词(不认识的字段、大小写不对的、没写 = 或值的),什么都不给。
656
704
  const valid = (word: string) => {
657
- if (action === "unset") return word === "enabled" || fieldNamed(word) !== undefined;
705
+ if (action === "unset") return word === "enabled" || named(word);
658
706
  const equals = word.indexOf("=");
659
- return equals > 0 && equals < word.length - 1 && fieldNamed(word.slice(0, equals)) !== undefined;
707
+ return equals > 0 && equals < word.length - 1 && named(word.slice(0, equals));
660
708
  };
661
709
  if (!rest.every(valid)) return undefined;
662
710
  // 写过的字段不再给:再写一次,执行时会被拒绝。
663
- const written = new Set(rest.map((word) => fieldNamed(word.split("=")[0])?.name));
711
+ const written = new Set(rest.map((word) => word.split("=")[0]));
664
712
  const unwritten = FIELDS.filter((item) => !written.has(item.name));
713
+ const quiet = offered && !written.has(QUIET);
665
714
  if (action === "unset") {
666
- const toggle = rest.includes("enabled") ? [] : [{ value: "enabled", description: "开关:去掉之后继承下一层" }];
667
- return [...toggle, ...unwritten.map((item) => ({ value: item.name, description: item.description }))];
715
+ const toggle = written.has("enabled") ? [] : [{ value: "enabled", description: "开关:去掉之后继承下一层" }];
716
+ return [
717
+ ...toggle,
718
+ ...unwritten.map((item) => ({ value: item.name, description: item.description })),
719
+ ...(quiet ? [{ value: QUIET, description: "启动提示:去掉之后跟着 pi 的 quietStartup" }] : []),
720
+ ];
668
721
  }
669
722
  const equals = current.indexOf("=");
670
723
  if (equals < 0)
671
- return unwritten.map((item) => ({ value: `${item.name}=`, description: `${item.syntax}:${item.description}` }));
672
- const known = fieldNamed(current.slice(0, equals));
673
- if (!known || written.has(known.name)) return undefined;
724
+ return [
725
+ ...unwritten.map((item) => ({ value: `${item.name}=`, description: `${item.syntax}:${item.description}` })),
726
+ ...(quiet ? [{ value: `${QUIET}=`, description: "true 或 false:启动时的提示显示不显示" }] : []),
727
+ ];
728
+ const name = current.slice(0, equals);
729
+ if (written.has(name)) return undefined;
730
+ if (name === QUIET)
731
+ return quiet ? QUIET_CHOICES.map((choice) => ({ ...choice, value: `${QUIET}=${choice.value}` })) : undefined;
732
+ const known = fieldNamed(name);
733
+ if (!known) return undefined;
674
734
  return (known.choices ?? []).map((choice) => ({
675
735
  value: `${known.name}=${choice.value}`,
676
736
  description: choice.description,
@@ -5,7 +5,7 @@ import { registerCommand } from "./command.ts";
5
5
  import { CUSTOM_TYPE, Onward } from "./onward.ts";
6
6
  import { renderContinue } from "./render.ts";
7
7
  import { type ConfigPaths, Settings } from "./settings.ts";
8
- import { say, startupNotices } from "./text.ts";
8
+ import { say, startupNotice } from "./text.ts";
9
9
 
10
10
  export function install(pi: ExtensionAPI, paths: ConfigPaths): void {
11
11
  const settings = new Settings(paths);
@@ -16,7 +16,8 @@ export function install(pi: ExtensionAPI, paths: ConfigPaths): void {
16
16
  settings.bind(ctx.cwd);
17
17
  // reload 和切换会话时 pi 会清掉扩展装的补全,所以每次都装。
18
18
  ctx.ui.addAutocompleteProvider(argumentTabCompletion);
19
- for (const notice of startupNotices(settings)) say(ctx, notice);
19
+ const notice = startupNotice(settings, () => quietStartup(pi, settings));
20
+ if (notice) say(ctx, notice);
20
21
  });
21
22
  pi.on("agent_start", (_event, ctx) => onward.agentStart(ctx));
22
23
  pi.on("message_end", (event, ctx) => onward.messageEnd(event, ctx));
@@ -27,3 +28,11 @@ export function install(pi: ExtensionAPI, paths: ConfigPaths): void {
27
28
  registerCommand(pi, settings, onward);
28
29
  pi.registerMessageRenderer(CUSTOM_TYPE, renderContinue);
29
30
  }
31
+
32
+ /** 启动时的提示收不收起:onward 自己的 quietStartup 写了就按它,没写跟着 pi 的,pi 的 true 和 "header" 都收起。 */
33
+ function quietStartup(pi: ExtensionAPI, settings: Settings): boolean {
34
+ const own = settings.config.quietStartup;
35
+ if (own !== undefined) return own;
36
+ const fromPi = pi.getSettings().quietStartup;
37
+ return fromPi === true || fromPi === "header";
38
+ }
@@ -5,7 +5,7 @@
5
5
  * 项目级要等 `session_start` 才知道:pi 那时才定下当前目录。不看 pi 对项目的信任:有这个文件就读,和它旁边有没有
6
6
  * `.pi/settings.json` 无关。
7
7
  *
8
- * `rules` 只能手写;命令只改 `enabled` 和顶层的参数字段,改哪一份由 `--scope` 定,不写就是全局。每次写之前重读
8
+ * `rules` 只能手写;命令只改 `enabled`、`quietStartup` 和顶层的参数字段,改哪一份由 `--scope` 定,不写就是全局。每次写之前重读
9
9
  * 要改的那份,在它当前的内容上合并,免得盖掉加载之后才手改的内容;文件读不了(不是合法 JSON、顶层不是对象)
10
10
  * 时拒绝写,让用户自己修。
11
11
  */
@@ -53,8 +53,8 @@ export type Saved =
53
53
  | { kind: "unbound" }
54
54
  | { kind: "unwritten"; error: string };
55
55
 
56
- /** reset 去掉的键:开关和顶层的参数。 */
57
- export const COMMAND_KEYS: readonly string[] = ["enabled", ...FIELD_NAMES];
56
+ /** 命令能改、reset 去掉的键:开关、顶层的参数和 quietStartup。 */
57
+ export const COMMAND_KEYS: readonly string[] = ["enabled", ...FIELD_NAMES, "quietStartup"];
58
58
 
59
59
  const EMPTY: ConfigLayer = { defaults: {}, problems: [] };
60
60
 
@@ -120,7 +120,7 @@ export class Settings {
120
120
  // 两份都重读:显示的状态和磁盘上的一致。
121
121
  this.reload();
122
122
  if (current.kind === "missing" && Object.keys(next).length === 0) return { kind: "saved", value: next };
123
- this.loaded[scope] = { scope, path, source: { kind: "file" }, layer: parseLayer(next) };
123
+ this.loaded[scope] = { scope, path, source: { kind: "file" }, layer: parseLayer(next, scope === "project") };
124
124
  this.remerge();
125
125
  try {
126
126
  writeJson(path, next);
@@ -130,7 +130,7 @@ export class Settings {
130
130
  return { kind: "saved", value: next };
131
131
  }
132
132
 
133
- /** 去掉开关和顶层的参数,手写的 rules 和其他内容留着。 */
133
+ /** 去掉开关、顶层的参数和 quietStartup,手写的 rules 和其他内容留着。 */
134
134
  reset(scope: Scope): Saved {
135
135
  return this.update(scope, { unset: COMMAND_KEYS });
136
136
  }
@@ -142,6 +142,7 @@ export class Settings {
142
142
  const layer = this.loaded[scope]?.layer;
143
143
  if (!layer) return false;
144
144
  if (key === "enabled") return layer.enabled !== undefined;
145
+ if (key === "quietStartup") return layer.quietStartup !== undefined;
145
146
  if (key === "rules") return layer.rules !== undefined;
146
147
  return Object.hasOwn(layer.defaults, key);
147
148
  }
@@ -164,7 +165,7 @@ function readFile(scope: Scope, path: string): SettingsFile {
164
165
  const current = readJson(path);
165
166
  switch (current.kind) {
166
167
  case "ok":
167
- return { scope, path, source: { kind: "file" }, layer: parseLayer(current.value) };
168
+ return { scope, path, source: { kind: "file" }, layer: parseLayer(current.value, scope === "project") };
168
169
  case "missing":
169
170
  return { scope, path, source: { kind: "none" }, layer: EMPTY };
170
171
  case "broken":
@@ -9,7 +9,7 @@
9
9
  * 停手说为什么、怎么办,不重复图标、次数和规则名。错误本身 pi 已经在上面用红字显示,提示里也不再摘。
10
10
  */
11
11
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
12
- import type { Config, Hit } from "../policy/config.ts";
12
+ import { type Config, configWarnings, type Hit } from "../policy/config.ts";
13
13
  import { formatDelay, retryDelay, totalDelay } from "../policy/delay.ts";
14
14
  import { EMPTY_REPLY, errorSignature, type Failure } from "../policy/failure.ts";
15
15
  import { DEFAULT_POLICY, FIELDS, type Field, type Policy, type PolicyPatch, resolvePolicy } from "../policy/policy.ts";
@@ -41,7 +41,8 @@ const IDLE = "💤";
41
41
  const STOPPED = "🛑";
42
42
 
43
43
  const UNTIL_FIXED = "修好之前不会自动续跑";
44
- const addRules = (where = "设置文件") => `在${where}的 rules 里写规则(常见规则见 README),再 /${COMMAND} reload`;
44
+ const addRules = () => `在设置文件的 rules 里写规则(常见规则见 README),再 /${COMMAND} reload`;
45
+ const SEE_SHOW = `/${COMMAND} show 查看`;
45
46
 
46
47
  /** 两份设置文件给人看的名字:表格、来源和问题前面都用它。 */
47
48
  const SCOPE_NAMES: Readonly<Record<Scope, string>> = { global: "全局", project: "项目级" };
@@ -90,10 +91,10 @@ export function commandErrorNotice(message: string, topic?: string): Notice {
90
91
  return warning(`onward:${message};用法见 /${COMMAND}${topic ? ` ${topic}` : ""} --help`);
91
92
  }
92
93
 
93
- /** `/onward` 菜单的标题:现在的状态;写了 `--scope` 时补上这个菜单看、改的是哪一份。 */
94
+ /** 菜单标题区分运行状态与修改目标;默认菜单只说修改默认写全局,不把查看合并结果也标成全局。 */
94
95
  export function menuTitle(settings: Settings, scope?: Scope): string {
95
- const headline = statusHeadline(settings);
96
- return scope ? `${headline} · ${SCOPE_NAMES[scope]}设置` : headline;
96
+ const target = scope ? `${SCOPE_NAMES[scope]}设置` : `修改默认写入:${SCOPE_NAMES.global}设置`;
97
+ return `${statusHeadline(settings)} · ${target}`;
97
98
  }
98
99
 
99
100
  /** `/onward` 菜单里进到这一份的菜单的那一项的说明。 */
@@ -101,7 +102,7 @@ export function layerMenuText(scope: Scope): string {
101
102
  return `只看、只改${SCOPE_NAMES[scope]}设置`;
102
103
  }
103
104
 
104
- /** 一行说清现在会不会续跑:`/onward status` 的第一行,也是 `/onward` 菜单的标题。 */
105
+ /** 一行说清现在会不会续跑:`/onward status` 的第一行,也是 `/onward` 菜单标题里的状态部分。 */
105
106
  export function statusHeadline(settings: Settings): string {
106
107
  const { config } = settings;
107
108
  if (brokenFiles(settings).length) return `${STOPPED} onward:设置文件读不了,${UNTIL_FIXED}`;
@@ -116,7 +117,7 @@ export function statusHeadline(settings: Settings): string {
116
117
  }
117
118
 
118
119
  export function statusNotice(settings: Settings, progress: Progress, note?: string): Notice {
119
- return { message: statusText(settings, progress, note), level: needsFix(settings) ? "warning" : "info" };
120
+ return settingsNotice(settings, statusText(settings, progress, note));
120
121
  }
121
122
 
122
123
  /**
@@ -130,6 +131,8 @@ function statusText(settings: Settings, { used, streak }: Progress, note?: strin
130
131
  // 读不了的文件也记成一处问题,所以这里不用另外看。
131
132
  const usable = !config.problems.length;
132
133
  if (usable) lines.push(...section("规则没写的参数", table(policyRows(resolvePolicy(config.defaults)))));
134
+ const reminders = ruleWarningSummary(config);
135
+ if (reminders) lines.push("", `${reminders}(${SEE_SHOW})`);
133
136
  lines.push(...section("设置文件", table(fileRows(settings.files))), "");
134
137
  if (!usable) lines.push(`改好之后 /${COMMAND} reload;问题见 /${COMMAND} show`);
135
138
  else if (!config.enabled)
@@ -171,7 +174,8 @@ export function showNotice(settings: Settings): Notice {
171
174
  const where = from ? `${SCOPE_NAMES[from]}设置` : "内置默认值";
172
175
  return [item.name, `${(item as Field<typeof item.name>).show(value)}(${where})`];
173
176
  });
174
- return info(
177
+ return settingsNotice(
178
+ settings,
175
179
  [
176
180
  "规则没写的参数",
177
181
  ...table(rows),
@@ -207,6 +211,7 @@ export function layerNotice(settings: Settings, scope: Scope, rulesOnly: boolean
207
211
  item.name,
208
212
  shown(item, layer.defaults),
209
213
  ]),
214
+ ...(layer.quietStartup === undefined ? [] : [["quietStartup", String(layer.quietStartup)] as [string, string]]),
210
215
  ];
211
216
  const rules =
212
217
  layer.rules === undefined
@@ -238,8 +243,9 @@ function shown(item: Field, values: PolicyPatch): string {
238
243
  /** `/onward show rules`。设置文件读不了时说读不了:规则一条也没读到,不是没写。 */
239
244
  export function rulesNotice(settings: Settings): Notice {
240
245
  const broken = brokenFiles(settings);
241
- if (!broken.length) return info(rulesText(settings));
242
- return info(
246
+ if (!broken.length) return settingsNotice(settings, rulesText(settings));
247
+ return settingsNotice(
248
+ settings,
243
249
  [`设置文件读不了,${UNTIL_FIXED}`, ...table(fileRows(broken)), "", `改好之后 /${COMMAND} reload`].join("\n"),
244
250
  );
245
251
  }
@@ -261,9 +267,17 @@ function rulesFrom(settings: Settings): string | undefined {
261
267
  return `规则来自${SCOPE_NAMES[origin]}设置${replaced ? ",全局的 rules 不生效" : ""}`;
262
268
  }
263
269
 
264
- /** 改了开关或参数之后:有项目级设置在用、或者改的就是项目级时,说改的是哪一份;只有一份时说了也多余。 */
265
- export function scopeLine(settings: Settings, scope: Scope): string | undefined {
266
- return scope === "project" || settings.projectFile !== undefined ? `改的是${SCOPE_NAMES[scope]}设置` : undefined;
270
+ /** 改了 quietStartup 之后:onward 的启动提示现在怎么显示。 */
271
+ export function quietLine(quiet: boolean | undefined): string {
272
+ if (quiet === undefined) return "onward 的启动提示跟着 pi 的 quietStartup";
273
+ return quiet
274
+ ? "onward 的启动提示不显示;设置有问题时照样警告"
275
+ : "onward 的启动提示照常显示,不管 pi 的 quietStartup";
276
+ }
277
+
278
+ /** 改了开关或参数之后,总是说清目标层级,和有没有项目级设置无关。 */
279
+ export function scopeLine(scope: Scope): string {
280
+ return `改的是${SCOPE_NAMES[scope]}设置`;
267
281
  }
268
282
 
269
283
  /**
@@ -277,12 +291,9 @@ export function shadowLine(settings: Settings, scope: Scope, keys: readonly stri
277
291
  : undefined;
278
292
  }
279
293
 
280
- /** reset 之后说做了什么。有项目级设置在用时,「恢复默认」不对:去掉的那份之外,另一份还在。 */
281
- export function resetLine(settings: Settings, scope: Scope, keptRules: boolean): string {
282
- const done =
283
- scope === "project" || settings.projectFile !== undefined
284
- ? `已去掉${SCOPE_NAMES[scope]}的开关和参数`
285
- : "已恢复默认";
294
+ /** reset 只去掉目标层的开关和参数,不能笼统地说「恢复默认」。 */
295
+ export function resetLine(scope: Scope, keptRules: boolean): string {
296
+ const done = `已去掉${SCOPE_NAMES[scope]}的开关和参数`;
286
297
  return keptRules ? `${done},手写的 rules 保留` : done;
287
298
  }
288
299
 
@@ -362,22 +373,35 @@ export function describeRules(config: Config, from?: string): string {
362
373
  ...table(rows).map((line) => ` ${line}`),
363
374
  ];
364
375
  });
365
- return [...source, "规则(按顺序,第一条命中的生效;没命中的错误和空回复不处理)", ...blocks.flat()].join("\n");
376
+ return [
377
+ ...source,
378
+ "规则(按顺序,第一条命中的生效;没命中的错误和空回复不处理)",
379
+ ...blocks.flat(),
380
+ ...section(
381
+ "规则提醒(不影响设置生效)",
382
+ configWarnings(config).map((text) => `- ${text}`),
383
+ ),
384
+ ].join("\n");
366
385
  }
367
386
 
368
387
  function describeWhen({ when }: Rule): string {
369
388
  const parts = [
370
- when.empty && "空回复",
371
- when.error && `错误匹配 /${when.error.source}/i`,
389
+ when.failure && `失败匹配 /${when.failure.source}/i`,
372
390
  when.provider && `provider=${when.provider}`,
373
391
  when.model && `model=${when.model}`,
374
392
  ].filter(Boolean);
375
- return parts.length ? parts.join(",") : "任何错误";
393
+ return parts.length ? parts.join(",") : "任何失败";
376
394
  }
377
395
 
378
- /** 文件读不了,或者内容有读不懂的地方:读不了也记成一处问题。 */
379
- function needsFix(settings: Settings): boolean {
380
- return settings.config.problems.length > 0;
396
+ /** 配置错误和非阻断的规则提醒都用 warning;是否能续跑仍由 config.problems 决定。 */
397
+ function settingsNotice(settings: Settings, message: string): Notice {
398
+ const attention = settings.config.problems.length > 0 || configWarnings(settings.config).length > 0;
399
+ return { message, level: attention ? "warning" : "info" };
400
+ }
401
+
402
+ function ruleWarningSummary(config: Config): string | undefined {
403
+ const count = configWarnings(config).length;
404
+ return count ? `规则有 ${count} 处提醒,不影响设置生效` : undefined;
381
405
  }
382
406
 
383
407
  function usableRules(config: Config): number {
@@ -387,39 +411,27 @@ function usableRules(config: Config): number {
387
411
  // ── 运行中的通知 ──
388
412
 
389
413
  /**
390
- * 启动时值得说的事:用上了项目级设置(仓库里带的设置能让 onward 替你给模型发消息,要让人知道);设置文件读不了
391
- * 或有问题,说是哪一份(关着也说,可能就是 enabled 写错了);没有可用的规则。
414
+ * 启动时最多一条:配置错误说是哪一份(关着也说,可能就是 enabled 写错了);规则提醒不阻止续跑。
415
+ * 两者都不受 quietStartup 影响。用上了项目级设置、没有可用规则这两种平常提示才问 quiet()。
416
+ * 不写路径和报错原文,细节用 `/onward show` 查看;pi 只留下连着的提示里的最后一条,分开发会互相顶掉。
392
417
  */
393
- export function startupNotices(settings: Settings): Notice[] {
418
+ export function startupNotice(settings: Settings, quiet: () => boolean): Notice | undefined {
394
419
  const { config } = settings;
395
- const project = settings.file("project");
396
- // 读不了的项目级文件不说「用上了」:下面的警告已经写了它的路径。
397
- const notices: Notice[] =
398
- project?.source.kind === "file" ? [info(`onward:用上了项目级设置 ${project.path},它写了的字段覆盖全局的`)] : [];
399
- const broken = brokenFiles(settings);
400
- if (broken.length)
401
- return [
402
- ...notices,
403
- ...broken.map((file) =>
404
- warning(`${STOPPED} onward:${file.path} 读不了:${file.source.error},${UNTIL_FIXED}`),
405
- ),
406
- ];
407
- if (config.problems.length)
408
- return [
409
- ...notices,
410
- ...settings.files
411
- .filter((file) => file.layer.problems.length)
412
- .map((file) =>
413
- warning(
414
- `${STOPPED} onward:${file.path} 有 ${file.layer.problems.length} 处问题,${UNTIL_FIXED}(/${COMMAND} show 查看)`,
415
- ),
416
- ),
417
- ];
418
- if (config.enabled && !usableRules(config)) {
419
- const where = (settings.origin("rules") === "project" && project) || settings.file("global");
420
- notices.push(info(`${IDLE} onward:没有可用的规则,出错时不会自动续跑;${addRules(` ${where.path} `)}`));
421
- }
422
- return notices;
420
+ const bad = settings.files.flatMap((file) => {
421
+ const name = `${SCOPE_NAMES[file.scope]}设置`;
422
+ if (file.source.kind === "broken") return [`${name}读不了`];
423
+ return file.layer.problems.length ? [`${name}有 ${file.layer.problems.length} 处问题`] : [];
424
+ });
425
+ if (bad.length) return warning(`${STOPPED} onward:${bad.join(",")},${UNTIL_FIXED}(${SEE_SHOW})`);
426
+ const project = settings.file("project")?.source.kind === "file";
427
+ const reminders = ruleWarningSummary(config);
428
+ if (reminders) return warning(`onward:${project ? "用上了项目级设置;" : ""}${reminders}(${SEE_SHOW})`);
429
+ const idle = config.enabled && !usableRules(config);
430
+ if (!(project || idle) || quiet()) return undefined;
431
+ if (project && idle)
432
+ return info(`${IDLE} onward:用上了项目级设置;没有可用的规则,出错时不会自动续跑(${SEE_SHOW})`);
433
+ if (project) return info(`onward:用上了项目级设置(${SEE_SHOW})`);
434
+ return info(`${IDLE} onward:没有可用的规则,出错时不会自动续跑(${SEE_SHOW})`);
423
435
  }
424
436
 
425
437
  /**