@promptctl/cc-candybar 1.41.1 → 1.41.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptctl/cc-candybar",
3
- "version": "1.41.1",
3
+ "version": "1.41.2",
4
4
  "description": "Statusline renderer for Claude Code — a JSON5-configurable DSL with daemon-cached data sources, byte-clean palette-aware composition, and OSC8 click verbs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -85,15 +85,15 @@
85
85
  "tsdown": "^0.21.4",
86
86
  "tsx": "^4.21.0",
87
87
  "typescript": "^5.0.0",
88
- "@promptctl/go-template-js": "^0.7.0",
88
+ "@promptctl/go-template-js": "^0.8.0",
89
89
  "@promptctl/rich-js": "^0.7.0",
90
90
  "json5": "^2.2.3",
91
91
  "mobx": "^6.15.0"
92
92
  },
93
93
  "optionalDependencies": {
94
- "@promptctl/cc-candybar-darwin-arm64": "1.41.1",
95
- "@promptctl/cc-candybar-darwin-x64": "1.41.1",
96
- "@promptctl/cc-candybar-linux-x64": "1.41.1",
97
- "@promptctl/cc-candybar-linux-arm64": "1.41.1"
94
+ "@promptctl/cc-candybar-darwin-arm64": "1.41.2",
95
+ "@promptctl/cc-candybar-darwin-x64": "1.41.2",
96
+ "@promptctl/cc-candybar-linux-x64": "1.41.2",
97
+ "@promptctl/cc-candybar-linux-arm64": "1.41.2"
98
98
  }
99
99
  }
@@ -181,9 +181,9 @@ export interface RawDslConfig {
181
181
  // per session exactly like theme/style (session key `look`).
182
182
  readonly looks?: Readonly<Record<string, ThemeKey>>;
183
183
  // [LAW:single-enforcer] Config-level shared helper templates: name → Go-template
184
- // body. Each compiles to one `{{ define "name" }}body{{ end }}` block, and the
185
- // whole set into a single output-neutral preamble prepended to every template
186
- // this config parses — so a formatter (`{{ template "formatCost" .x }}`) is
184
+ // body. Each compiles to one `{{ define "name" }}body{{ end }}` unit, and the
185
+ // whole set into one shared define set every template this config parses
186
+ // inherits — so a formatter (`{{ template "formatCost" .x }}`) is
187
187
  // defined ONCE and callable from any segment/predicate, never re-inlined per
188
188
  // segment. Absent ≡ no helpers; merges by-name (user overrides a helper).
189
189
  readonly helpers?: Readonly<Record<string, string>>;
@@ -240,7 +240,7 @@ export interface DslConfig {
240
240
  // [LAW:dataflow-not-control-flow].
241
241
  readonly editGlobals: Partial<Globals>;
242
242
  // [LAW:single-enforcer] The effective helper set: a name → template-body map
243
- // compiled to a defines-preamble at registerDslConfig. Empty when no config
243
+ // compiled to one shared define set at registerDslConfig. Empty when no config
244
244
  // declares helpers — an absent `helpers` key merges to `{}` (same cascade as
245
245
  // actions). The single definition site for each formatter/transform a template
246
246
  // calls via `{{ template "name" .arg }}`.
@@ -2,7 +2,7 @@
2
2
  // record of name → template-body STRING. Each value is a Go-template source the
3
3
  // renderer compiles into a `{{ define }}` block; whether the body PARSES (and
4
4
  // whether a `{{ template "name" }}` reference resolves) is a render-time concern
5
- // (registerDslConfig parses the preamble and throws a per-helper diagnostic).
5
+ // (registerDslConfig parses each helper and throws a per-helper diagnostic).
6
6
  // This file changes only if the helper authoring shape changes.
7
7
 
8
8
  import { findKeyLine } from "./diagnostics.js";
@@ -21,17 +21,18 @@ import { dlog, type DaemonLogger } from "./log";
21
21
  // The cap sits at HEAP_CAP_OVER_RSS × the backstop, a margin wide enough that
22
22
  // the graceful path fires first under any growth the 60 s poll can see (a
23
23
  // burst that doubles RSS inside one poll window can still reach the hard cap).
24
- // Before this the two were unrelated literals (400 MB heap in
25
- // each spawner, 512 MB RSS here): a cold daemon seeding a large transcript tree
26
- // for a dozen sessions blew the heap in seconds, aborted silently, and crash-
27
- // looped on every render tick while the backstop — a 60 s poll — never got a
28
- // turn. Raising the env override raises BOTH, because both spawners derive the
29
- // cap through heapCapMb below. The Rust client mirrors RSS_LIMIT_ENV,
30
- // DEFAULT_RSS_LIMIT_MB, and HEAP_CAP_OVER_RSS as literals
24
+ // Before this the two were unrelated literals (400 MB heap in each spawner,
25
+ // 512 MB RSS here), and the 2026-09-03 outage found the gap: a daemon holding
26
+ // twenty configs' worth of duplicated helper-template ASTs (since fixed in
27
+ // src/dsl/render.ts compileHelpers) blew the heap in seconds, aborted
28
+ // silently, and crash-looped on every render tick while the backstop — a 60 s
29
+ // poll — never got a turn. Raising the env override raises BOTH, because both
30
+ // spawners derive the cap through heapCapMb below. The Rust client mirrors
31
+ // RSS_LIMIT_ENV, DEFAULT_RSS_LIMIT_MB, and HEAP_CAP_OVER_RSS as literals
31
32
  // (rust-client/src/launch.rs); scripts/check-protocol.mjs fails the build on
32
33
  // drift.
33
34
  export const RSS_LIMIT_ENV = "CC_CANDYBAR_RSS_LIMIT_MB";
34
- export const DEFAULT_RSS_LIMIT_MB = 2048;
35
+ export const DEFAULT_RSS_LIMIT_MB = 512;
35
36
  export const HEAP_CAP_OVER_RSS = 2;
36
37
 
37
38
  // [LAW:parse-dont-validate] Absent → default; a positive integer → that; present
package/src/dsl/render.ts CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  import type { RichText, Palette, ThemeKey } from "@promptctl/rich-js";
15
15
  import { ColorSpec, Style, lighten, IDENTITY } from "@promptctl/rich-js";
16
- import type { Engine, Template } from "@promptctl/go-template-js";
16
+ import { Defines, type Engine, type Template } from "@promptctl/go-template-js";
17
17
  import type {
18
18
  ValidatedConfig,
19
19
  VariableDecl,
@@ -213,38 +213,40 @@ function declareOne(
213
213
  }
214
214
  }
215
215
 
216
- // ─── Helper preamble ─────────────────────────────────────────────────────────
216
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
217
217
 
218
218
  // [LAW:single-enforcer] Compile the config's shared helper templates into ONE
219
- // output-neutral preamble: each name→body becomes a `{{ define "name" }}body{{ end }}`
220
- // block, concatenated with no interstitial text so the preamble emits nothing.
221
- // Prepended to every template this config parses, the defines resolve a
222
- // `{{ template "name" .arg }}` call locally — go-template-js scopes defines to a
223
- // single parse unit, so the define and the call MUST share one parse.
224
- // [LAW:no-silent-fallbacks] Each body is parsed in ISOLATION first, so a malformed
225
- // helper surfaces a per-helper diagnostic rather than a confusing error blamed on
226
- // the first segment that happens to call it.
227
- // [LAW:dataflow-not-control-flow] Empty helpers ⇒ "" ⇒ `engine.parse("" + src)`
228
- // is byte-identical to `engine.parse(src)`: existing configs are unaffected with
229
- // no special-case branch.
230
- function compileHelperPreamble(
219
+ // define set: each name→body is parsed as its own `{{ define "name" }}body{{ end }}`
220
+ // unit, chained onto the previous helpers' set, so the result is one `Defines`
221
+ // every template this config parses inherits (`engine.parse(src, helpers)`).
222
+ // [LAW:one-source-of-truth] Inherited by link, never by copy. The previous
223
+ // shape — the defines' SOURCE prepended to every parse — re-parsed the whole
224
+ // helper block into every template: ~100 KB of AST per parse for the 2 KB
225
+ // stdlib block, ~287 parses per config, ~30 MB per config, and a daemon
226
+ // holding twenty configs sat at 600 MB of nothing but duplicated helper ASTs
227
+ // (the 2026-09-02 RSS-breach snapshot and the 2026-09-03 crash-loop).
228
+ // [LAW:no-silent-fallbacks] Each body is parsed in ISOLATION, so a malformed
229
+ // helper surfaces a per-helper diagnostic rather than a confusing error blamed
230
+ // on the first segment that happens to call it; the redefinition check the
231
+ // parser applies against the inherited set is what makes helper names unique.
232
+ function compileHelpers(
231
233
  engine: Engine<RichText>,
232
234
  helpers: Readonly<Record<string, string>>,
233
- ): string {
234
- let preamble = "";
235
+ ): Defines {
236
+ let defines = Defines.EMPTY;
235
237
  for (const [name, body] of Object.entries(helpers)) {
236
- const define = `{{ define "${name}" }}${body}{{ end }}`;
237
238
  try {
238
- engine.parse(define);
239
+ defines = engine
240
+ .parse(`{{ define "${name}" }}${body}{{ end }}`, defines)
241
+ .defines();
239
242
  } catch (e) {
240
243
  throw new Error(
241
244
  `Template parse error in helpers.${name}: ${(e as Error).message}`,
242
245
  { cause: e },
243
246
  );
244
247
  }
245
- preamble += define;
246
248
  }
247
- return preamble;
249
+ return defines;
248
250
  }
249
251
 
250
252
  // ─── registerDslConfig ────────────────────────────────────────────────────────
@@ -379,16 +381,14 @@ export function registerDslConfig(
379
381
  },
380
382
  opts?.clock,
381
383
  );
382
- // [LAW:single-enforcer] THE one parse path for this config: prepend the helper
383
- // preamble so every template — segment template/when/bg/fg, node `when`, and
384
- // action copy/open — resolves `{{ template "name" }}` calls against the same
385
- // shared helpers. One closure, not raw engine.parse scattered across sites, so
386
- // there is exactly one boundary where helpers come into scope (and one place a
387
- // helper could fail to be visible). The preamble is compiled ONCE here, not per
388
- // parse, and is "" when no helpers are declared.
389
- const helperPreamble = compileHelperPreamble(engine, config.helpers);
390
- const parse = (src: string): Template<RichText> =>
391
- engine.parse(helperPreamble + src);
384
+ // [LAW:single-enforcer] THE one parse path for this config: every template —
385
+ // segment template/when/bg/fg, node `when`, and action copy/open — inherits
386
+ // the same helper define set, so `{{ template "name" }}` resolves against one
387
+ // shared AST. One closure, not raw engine.parse scattered across sites, so
388
+ // there is exactly one boundary where helpers come into scope (and one place
389
+ // a helper could fail to be visible). The helpers are parsed ONCE here.
390
+ const helpers = compileHelpers(engine, config.helpers);
391
+ const parse = (src: string): Template<RichText> => engine.parse(src, helpers);
392
392
  // [LAW:one-source-of-truth] Map each SessionState key → the variable that
393
393
  // reads it, so an option picker marks its current selection by reading the
394
394
  // SAME value the templates read — independent of whether the config named the