pi-cc-loop 0.7.3 → 0.7.4

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/README.md CHANGED
@@ -96,12 +96,13 @@ Ctrl+O 展开后多一行元信息(任务 id、节奏)。`compactMessages`
96
96
  "footer": true, // 底部摘要:loop 的一行和 Monitor 的 `monitor N`
97
97
  "draft": true, // pi-cc-plugins:Ctrl+C 找回
98
98
  "turnSummary": true, // pi-cc-plugins:回合摘要一行
99
+ "ccKeys": true, // pi-cc-plugins:Enter 排队、Ctrl+Enter 直发
99
100
  "compaction": true, // pi-cc-compaction:Claude Code 的压缩
100
101
  "idleCompaction": true // pi-cc-compaction:空闲压缩
101
102
  }
102
103
  ```
103
104
 
104
- draft、turnSummary 只被 pi-cc-plugins 读取,compaction、idleCompaction 只被 pi-cc-compaction 读取;没装对应包的会话里,面板中的这些项不生效,值原样保留。
105
+ draft、turnSummary、ccKeys 只被 pi-cc-plugins 读取,compaction、idleCompaction 只被 pi-cc-compaction 读取;没装对应包的会话里,面板中的这些项不生效,值原样保留。
105
106
 
106
107
  在 TUI 里输入 `/pi_cc` 会打开设置面板,和 pi-cc-extensions 的 `/ccstyle` 一样按页组织,每个插件一页:
107
108
  **Loop & Monitor**(消息样式、底部摘要,两个包共用)、**Plugins**(pi-cc-plugins)、**Compact**(pi-cc-compaction)。
@@ -128,7 +129,7 @@ Loop & Monitor / Plugins / Compact ~/.pi/agent/pi-cc.json
128
129
  也可以用文字命令:`/pi_cc messages on|off`、`/pi_cc footer on|off`,适合脚本和 RPC;
129
130
  非 TUI 模式下,不带参数的 `/pi_cc` 按页输出当前设置。命令只写改动的那一项,文件里的其他内容原样保留。
130
131
 
131
- 环境变量 `PI_CC_FOOTER`、`PI_CC_COMPACT_MESSAGES`(pi-cc-plugins 的两项是 `PI_CC_DRAFT`、`PI_CC_TURN_SUMMARY`,pi-cc-compaction 的两项是 `PI_CC_COMPACTION`、`PI_CC_IDLE_COMPACTION`)优先于文件,但不会被写进文件。设着的时候,面板里这一项显示实际生效的值、不能切换,
132
+ 环境变量 `PI_CC_FOOTER`、`PI_CC_COMPACT_MESSAGES`(pi-cc-plugins 的三项是 `PI_CC_DRAFT`、`PI_CC_TURN_SUMMARY`、`PI_CC_KEYS`,pi-cc-compaction 的两项是 `PI_CC_COMPACTION`、`PI_CC_IDLE_COMPACTION`)优先于文件,但不会被写进文件。设着的时候,面板里这一项显示实际生效的值、不能切换,
132
133
  说明里写出是哪个变量;文字输出会在对应项后面标出来(如 `hidden (PI_CC_FOOTER=0)`);用文字命令切换会写进文件,但提示会说明变量还在覆盖它。
133
134
 
134
135
  ## 底部摘要
package/config.ts CHANGED
@@ -13,12 +13,13 @@
13
13
  * "footer": true,
14
14
  * "draft": true,
15
15
  * "turnSummary": true,
16
+ * "ccKeys": true,
16
17
  * "compaction": true,
17
18
  * "idleCompaction": true
18
19
  * }
19
20
  *
20
- * compactMessages and footer drive loop and monitor; draft and turnSummary
21
- * drive pi-cc-plugins; compaction and idleCompaction drive pi-cc-compaction. A package that is not installed simply ignores its
21
+ * compactMessages and footer drive loop and monitor; draft, turnSummary and
22
+ * ccKeys drive pi-cc-plugins; compaction and idleCompaction drive pi-cc-compaction. A package that is not installed simply ignores its
22
23
  * keys, and they are kept as the user left them.
23
24
  *
24
25
  * Environment overrides (useful for tests and quick experiments) win over the
@@ -28,6 +29,7 @@
28
29
  * PI_CC_FOOTER=0|1
29
30
  * PI_CC_DRAFT=0|1
30
31
  * PI_CC_TURN_SUMMARY=0|1
32
+ * PI_CC_KEYS=0|1
31
33
  * PI_CC_COMPACTION=0|1
32
34
  * PI_CC_IDLE_COMPACTION=0|1
33
35
  */
@@ -48,6 +50,8 @@ export interface PiCcConfig {
48
50
  draft: boolean;
49
51
  /** pi-cc-plugins: one line closes every agent run. */
50
52
  turnSummary: boolean;
53
+ /** pi-cc-plugins: Claude Code's Enter queues, Ctrl+Enter sends now. */
54
+ ccKeys: boolean;
51
55
  /** pi-cc-compaction: Claude Code's compaction replaces Pi's summary request. */
52
56
  compaction: boolean;
53
57
  /** pi-cc-compaction: compact while idle, before a long prompt cache expires. */
@@ -59,6 +63,7 @@ export const DEFAULT_CONFIG: PiCcConfig = {
59
63
  footer: true,
60
64
  draft: true,
61
65
  turnSummary: true,
66
+ ccKeys: true,
62
67
  compaction: true,
63
68
  idleCompaction: true,
64
69
  };
@@ -69,6 +74,7 @@ const ENV_OVERRIDES: Record<keyof PiCcConfig, string> = {
69
74
  footer: "PI_CC_FOOTER",
70
75
  draft: "PI_CC_DRAFT",
71
76
  turnSummary: "PI_CC_TURN_SUMMARY",
77
+ ccKeys: "PI_CC_KEYS",
72
78
  compaction: "PI_CC_COMPACTION",
73
79
  idleCompaction: "PI_CC_IDLE_COMPACTION",
74
80
  };
@@ -93,6 +99,11 @@ export function configPath(): string {
93
99
  return path.join(getAgentDir(), "pi-cc.json");
94
100
  }
95
101
 
102
+ /** One setting: an environment override, else the file's boolean, else the default. */
103
+ function readSetting(file: Partial<PiCcConfig>, key: keyof PiCcConfig): boolean {
104
+ return envBool(ENV_OVERRIDES[key]) ?? (typeof file[key] === "boolean" ? (file[key] as boolean) : DEFAULT_CONFIG[key]);
105
+ }
106
+
96
107
  function readConfig(): PiCcConfig {
97
108
  let file: Partial<PiCcConfig> = {};
98
109
  try {
@@ -101,23 +112,11 @@ function readConfig(): PiCcConfig {
101
112
  } catch {
102
113
  // Missing or malformed files fall back to defaults.
103
114
  }
104
- return {
105
- compactMessages:
106
- envBool(ENV_OVERRIDES.compactMessages) ??
107
- (typeof file.compactMessages === "boolean" ? file.compactMessages : DEFAULT_CONFIG.compactMessages),
108
- footer:
109
- envBool(ENV_OVERRIDES.footer) ?? (typeof file.footer === "boolean" ? file.footer : DEFAULT_CONFIG.footer),
110
- draft: envBool(ENV_OVERRIDES.draft) ?? (typeof file.draft === "boolean" ? file.draft : DEFAULT_CONFIG.draft),
111
- turnSummary:
112
- envBool(ENV_OVERRIDES.turnSummary) ??
113
- (typeof file.turnSummary === "boolean" ? file.turnSummary : DEFAULT_CONFIG.turnSummary),
114
- compaction:
115
- envBool(ENV_OVERRIDES.compaction) ??
116
- (typeof file.compaction === "boolean" ? file.compaction : DEFAULT_CONFIG.compaction),
117
- idleCompaction:
118
- envBool(ENV_OVERRIDES.idleCompaction) ??
119
- (typeof file.idleCompaction === "boolean" ? file.idleCompaction : DEFAULT_CONFIG.idleCompaction),
120
- };
115
+ // One loop over the defaults, so a setting added to DEFAULT_CONFIG is read
116
+ // without a second edit here.
117
+ const config = { ...DEFAULT_CONFIG };
118
+ for (const key of Object.keys(config) as Array<keyof PiCcConfig>) config[key] = readSetting(file, key);
119
+ return config;
121
120
  }
122
121
 
123
122
  let cached: PiCcConfig | undefined;
package/cron.ts CHANGED
@@ -158,27 +158,6 @@ export function isUnreachable(expression: string): boolean {
158
158
  return nextFireAfter(fields, new Date(), 366) === null;
159
159
  }
160
160
 
161
- /**
162
- * The divisor of `total` closest to `n`.
163
- *
164
- * Claude Code rounds a non-dividing interval to the nearest clean one: "If the
165
- * interval doesn't cleanly divide its unit, round to the nearest clean interval
166
- * and tell the user what you rounded to."
167
- */
168
- function nearestDivisor(n: number, total: number): number {
169
- let best = 1;
170
- let bestDistance = Number.POSITIVE_INFINITY;
171
- for (let d = 1; d <= total; d++) {
172
- if (total % d !== 0) continue;
173
- const distance = Math.abs(d - n);
174
- if (distance < bestDistance) {
175
- best = d;
176
- bestDistance = distance;
177
- }
178
- }
179
- return best;
180
- }
181
-
182
161
  const DAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
183
162
 
184
163
 
package/index.ts CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  parseCron,
37
37
  } from "./cron.ts";
38
38
  import { DurableRuntime, type Placement } from "./durable.ts";
39
- import { displayPrompt, isLoopFileSentinel, LoopFileDelivery, type TickMode } from "./loopfile.ts";
39
+ import { displayPrompt, isLoopFileSentinel, LoopFileDelivery } from "./loopfile.ts";
40
40
  import {
41
41
  CRON_CREATE_DESCRIPTION,
42
42
  CRON_CREATE_SNIPPET,
@@ -453,8 +453,8 @@ export default function piCcLoopExtension(pi: ExtensionAPI): void {
453
453
  }
454
454
 
455
455
  /** The text the model gets for a prompt: the loop.md sentinel expands at fire time. */
456
- function resolvePrompt(prompt: string, mode: TickMode): string {
457
- return isLoopFileSentinel(prompt) ? loopFile.resolve(lastCtx?.cwd ?? process.cwd(), mode) : prompt;
456
+ function resolvePrompt(prompt: string): string {
457
+ return isLoopFileSentinel(prompt) ? loopFile.resolve(lastCtx?.cwd ?? process.cwd()) : prompt;
458
458
  }
459
459
 
460
460
  /**
@@ -464,7 +464,7 @@ export default function piCcLoopExtension(pi: ExtensionAPI): void {
464
464
  */
465
465
  function deliverTick(job: LoopJob): void {
466
466
  const tick = Math.max(tickCounters.get(job.prompt) ?? 0, job.tickCount ?? 0) + 1;
467
- const body = resolvePrompt(job.prompt, job.kind === "cron" ? "cron" : "wakeup");
467
+ const body = resolvePrompt(job.prompt);
468
468
  // A fixed-interval tick is what it is - a scheduled task - and a
469
469
  // self-paced tick keeps the loop framing. The rules for the run are
470
470
  // rebuilt from `details` in before_agent_start.
@@ -574,7 +574,7 @@ export default function piCcLoopExtension(pi: ExtensionAPI): void {
574
574
  handler: async (args: string, ctx: ExtensionCommandContext) => {
575
575
  lastCtx = ctx;
576
576
  const raw = args.trim();
577
- const [head, ...rest] = raw.split(/\s+/);
577
+ const [head] = raw.split(/\s+/);
578
578
 
579
579
  // Settings moved to /pi_cc: these words stay recognized so they cannot
580
580
  // start a loop by mistake (everything else is a loop request).
@@ -1101,8 +1101,10 @@ export default function piCcLoopExtension(pi: ExtensionAPI): void {
1101
1101
 
1102
1102
  if (event.message.customType === MONITOR_EVENT_TYPE) {
1103
1103
  // A monitor bound to a loop woke the agent: the run belongs to that loop.
1104
+ // The monitor stores the prompt the model gave it; the chain is keyed
1105
+ // without a leading `/loop`, so both spellings find it.
1104
1106
  const loopPrompt = (event.message.details as { loopPrompt?: unknown } | undefined)?.loopPrompt;
1105
- const chain = typeof loopPrompt === "string" ? scheduler.findChain(loopPrompt) : undefined;
1107
+ const chain = typeof loopPrompt === "string" ? scheduler.findChain(normalizePrompt(loopPrompt)) : undefined;
1106
1108
  if (chain) currentRun.chainId = chain.id;
1107
1109
  return;
1108
1110
  }
package/loopfile.ts CHANGED
@@ -59,8 +59,6 @@ function truncate(content: string): string {
59
59
  return `${content.slice(0, cut > 0 ? cut : LOOP_FILE_MAX_CHARS)}\n> WARNING: loop.md was truncated to ${LOOP_FILE_MAX_CHARS} bytes. Keep the task list concise.`;
60
60
  }
61
61
 
62
- export type TickMode = "cron" | "wakeup";
63
-
64
62
  /** Remembers what a session was last given, so unchanged tasks are not resent. */
65
63
  export class LoopFileDelivery {
66
64
  private lastDelivered: string | null = null;
@@ -71,7 +69,7 @@ export class LoopFileDelivery {
71
69
  }
72
70
 
73
71
  /** The text of one tick for the loop.md sentinel. */
74
- resolve(cwd: string, mode: TickMode): string {
72
+ resolve(cwd: string): string {
75
73
  const file = readLoopFile(cwd);
76
74
  if (file) {
77
75
  if (this.lastDelivered === file.content) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cc-loop",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Claude Code compatible /loop for the Pi coding agent: cron-scheduled fixed intervals, self-paced chains, and the same dispatch semantics as Claude Code.",
5
5
  "author": "tarnish233",
6
6
  "type": "module",
package/prompts.ts CHANGED
@@ -45,19 +45,12 @@ const DELAY_ADVICE = [
45
45
  " fallback (1200s+) instead.",
46
46
  ].join("\n");
47
47
 
48
- /**
49
- * The rules for a `/loop <prompt>` whose interval the command layer could not
50
- * parse. Claude Code's /loop is a skill: the model reads the input and works
51
- * the schedule out itself, so an interval written in any language works.
52
- */
53
48
  /**
54
49
  * The instructions for one `/loop` request. Claude Code's `/loop` is a skill:
55
50
  * the command turns into a user message carrying these rules, and the model
56
51
  * drives CronCreate / CronList / CronDelete / ScheduleWakeup itself. Nothing is
57
52
  * created by code, so the conversation shows what was asked and what was done.
58
53
  */
59
- const LOOP_FILE_SENTINEL_PLACEHOLDER = "__loop_md_sentinel__";
60
-
61
54
  const LOOP_COMMAND_GUIDELINES = [
62
55
  "This is a `/loop` request from the user: {raw}",
63
56
  "",
@@ -91,7 +84,7 @@ const LOOP_COMMAND_GUIDELINES = [
91
84
  "- `--max N`: pass `maxFires: N`.",
92
85
  "",
93
86
  "## loop.md",
94
- "When the request has no task of its own (bare `/loop`, or an interval alone), pass the literal sentinel " + LOOP_FILE_SENTINEL_PLACEHOLDER + " as the prompt: it expands at fire time to `.pi/loop.md`, or to the built-in maintenance pass when there is no loop.md.",
87
+ "When the request has no task of its own (bare `/loop`, or an interval alone), pass the literal sentinel {sentinel} as the prompt: it expands at fire time to `.pi/loop.md`, or to the built-in maintenance pass when there is no loop.md.",
95
88
  "For the run you do right now, read `.pi/loop.md` (or `~/.pi/loop.md`) yourself and do those tasks; the sentinel only expands on later fires.",
96
89
  ].join("\n");
97
90
 
@@ -155,12 +148,12 @@ export function scheduledTaskProvenance(id: string, schedule: string): string {
155
148
  }
156
149
 
157
150
  export function loopCommandGuidelines(raw: string): string {
158
- const quoted = quote(raw || LOOP_FILE_SENTINEL);
159
151
  return fill(LOOP_COMMAND_GUIDELINES, {
160
152
  raw: raw ? `${quote(raw)}` : "(empty: the loop.md tasks)",
161
- quoted,
153
+ quoted: quote(raw || LOOP_FILE_SENTINEL),
162
154
  delayAdvice: DELAY_ADVICE,
163
- }).replace(LOOP_FILE_SENTINEL_PLACEHOLDER, quote(LOOP_FILE_SENTINEL));
155
+ sentinel: quote(LOOP_FILE_SENTINEL),
156
+ });
164
157
  }
165
158
 
166
159
  export function loopGuidelines(prompt: string): string {
package/render.ts CHANGED
@@ -36,11 +36,6 @@ export function contentText(content: unknown): string {
36
36
  return "";
37
37
  }
38
38
 
39
- /** Remove the provenance line the model needs but the reader does not. */
40
- export function stripProvenance(text: string, pattern: RegExp): string {
41
- return text.replace(pattern, "");
42
- }
43
-
44
39
  /** Cap a string for a display line, with an ellipsis. */
45
40
  export function truncate(text: string, max: number): string {
46
41
  const flat = text.replace(/\s+/g, " ").trim();
package/renderers.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { Theme } from "@earendil-works/pi-coding-agent";
8
- import { bodyLines, contentText, formatStamp, renderBlock, renderCard, stripProvenance } from "./render.ts";
8
+ import { bodyLines, contentText, formatStamp, renderBlock, renderCard } from "./render.ts";
9
9
  import { loadConfig } from "./config.ts";
10
10
  import { humanSchedule } from "./cron.ts";
11
11
  import { displayPrompt } from "./loopfile.ts";
@@ -56,7 +56,8 @@ export interface ScheduledDetails {
56
56
  */
57
57
  export function renderScheduledMessage(message: any, options: any, theme: Theme): any {
58
58
  const details = (message.details ?? {}) as ScheduledDetails;
59
- const prompt = details.prompt ?? stripProvenance(contentText(message.content), /^\[[^\]]*\]\n?/);
59
+ // The provenance line is addressed to the model, not the reader.
60
+ const prompt = details.prompt ?? contentText(message.content).replace(/^\[[^\]]*\]\n?/, "");
60
61
  // A fixed interval fires a scheduled task; only a self-paced tick is a loop.
61
62
  const label = details.missed
62
63
  ? "\u273b loop \u00b7 missed jobs"
package/settings.ts CHANGED
@@ -100,6 +100,14 @@ const PAGES: SettingsPage[] = [
100
100
  off: "off",
101
101
  description: "One line closes every agent run \u2014 tools, duration, done time.",
102
102
  },
103
+ {
104
+ field: "ccKeys",
105
+ label: "CC keys",
106
+ on: "on",
107
+ off: "off",
108
+ description:
109
+ "Enter queues while Pi works and Ctrl+Enter sends now, as in Claude Code. off: Pi's keys (Enter sends, Alt+Enter queues).",
110
+ },
103
111
  ],
104
112
  },
105
113
  {
@@ -262,27 +270,32 @@ function overrideNote(key: keyof PiCcConfig): string {
262
270
  return override ? ` (${override})` : "";
263
271
  }
264
272
 
273
+ /**
274
+ * The word the text summary uses for a setting: the first alias in KEYS. The
275
+ * panel shows the description label instead.
276
+ */
277
+ function commandWord(field: keyof PiCcConfig): string {
278
+ return Object.keys(KEYS).find((word) => KEYS[word].field === field) ?? field;
279
+ }
280
+
281
+ /**
282
+ * The summary a non-TUI /pi_cc prints, generated from the same pages the panel
283
+ * draws: a setting added to PAGES cannot go missing here.
284
+ */
265
285
  function showSettings(ctx: ExtensionContext): void {
266
286
  const config = loadConfig();
267
- const lines = [
268
- `pi-cc settings \u00b7 ${configPath()}`,
269
- PAGES[0].label,
270
- ` messages: ${config.compactMessages ? "compact" : "card"}${overrideNote("compactMessages")}`,
271
- ` footer: ${config.footer ? "summary" : "hidden"}${overrideNote("footer")}`,
272
- PAGES[1].label,
273
- ` draft: ${config.draft ? "on" : "off"}${overrideNote("draft")}`,
274
- ` summary: ${config.turnSummary ? "on" : "off"}${overrideNote("turnSummary")}`,
275
- PAGES[2].label,
276
- ` compact: ${config.compaction ? "on" : "off"}${overrideNote("compaction")}`,
277
- ` idle: ${config.idleCompaction ? "on" : "off"}${overrideNote("idleCompaction")}`,
287
+ const lines = [`pi-cc settings \u00b7 ${configPath()}`];
288
+ for (const page of PAGES) {
289
+ lines.push(page.label);
290
+ for (const spec of page.settings) {
291
+ const value = config[spec.field] ? spec.on : spec.off;
292
+ lines.push(` ${commandWord(spec.field)}:`.padEnd(13) + value + overrideNote(spec.field));
293
+ }
294
+ }
295
+ lines.push(
278
296
  "",
279
- "Usage: /pi_cc messages on|off",
280
- " /pi_cc footer on|off",
281
- " /pi_cc draft on|off",
282
- " /pi_cc summary on|off",
283
- " /pi_cc compact on|off",
284
- " /pi_cc idle on|off",
285
- ];
297
+ `Usage: /pi_cc <item> on|off (${SETTINGS.map((spec) => commandWord(spec.field)).join(", ")})`,
298
+ );
286
299
  notify(ctx, lines.join("\n"), "info");
287
300
  }
288
301
 
@@ -327,6 +340,8 @@ const KEYS: Record<string, { field: keyof PiCcConfig; label: string }> = {
327
340
  draft: { field: "draft", label: "Draft recall" },
328
341
  summary: { field: "turnSummary", label: "Turn summary" },
329
342
  turnsummary: { field: "turnSummary", label: "Turn summary" },
343
+ keys: { field: "ccKeys", label: "CC keys" },
344
+ keymap: { field: "ccKeys", label: "CC keys" },
330
345
  compact: { field: "compaction", label: "CC compaction" },
331
346
  compaction: { field: "compaction", label: "CC compaction" },
332
347
  idle: { field: "idleCompaction", label: "Idle compaction" },
@@ -381,7 +396,7 @@ export function registerPiCcCommand(pi: ExtensionAPI, owner: string): void {
381
396
  };
382
397
 
383
398
  pi.registerCommand("pi_cc", {
384
- description: "pi-cc settings: message style, footer, draft, turn summary, compaction",
399
+ description: "pi-cc settings: message style, footer, draft, turn summary, CC keys, compaction",
385
400
  handler: async (args: string, ctx: ExtensionCommandContext) => {
386
401
  const words = args.trim().split(/\s+/).filter(Boolean);
387
402
  // "/pi_cc settings footer on" reads like the old /loop settings: drop the noun.