Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

[bug] Prompting RenderTemplate: eq block helper and missing output directory

Open IvanLeontev-stack opened this issue 1 week ago • 1 comments

What happened

8.761.0: two defects in the Prompting RenderTemplate tool: the eq block helper and a missing output directory

Summary

LifeOS 8.761.0 (tag v8.761.0, fb9aef46). Every location below was read in that tag. Paths are from the repository root. Where a step says "sandbox", the code was run from a copy of LifeOS/install/ with HOME set to a temporary directory and no network.

Related issues are linked where they exist. None of these is a duplicate as far as I can find.


1. Prompting: {{#eq}} blocks in Briefing.hbs never render

Where: LifeOS/install/skills/Prompting/Tools/RenderTemplate.ts:57. The template is skills/Prompting/Templates/Primitives/Briefing.hbs:115-123.

Handlebars.registerHelper('eq', (a: unknown, b: unknown) => a === b);

What happens. Briefing.hbs uses eq as a block helper ({{#eq output_format.type "json"}}…{{/eq}}). The helper returns a boolean and never calls options.fn, so the block body is dropped.

Steps: run bun add [email protected] in the config root first (see #2431). Then create brief.yaml containing output_format: { type: json } and run bun skills/Prompting/Tools/RenderTemplate.ts -t Primitives/Briefing.hbs -d brief.yaml.

Expected: Return valid JSON matching the expected schema. under **Format:** json. Actual: a bare 1. The same happens for markdown and structured.

Minimal fix: make eq work both inline and as a block:

-Handlebars.registerHelper('eq', (a: unknown, b: unknown) => a === b);
+Handlebars.registerHelper('eq', function (this: unknown, a: unknown, b: unknown, options?: Handlebars.HelperOptions) {
+  if (options && typeof options.fn === 'function') return a === b ? options.fn(this) : options.inverse(this);
+  return a === b;
+});

With this helper, all three hints render (checked).


2. Prompting: the documented -o Compiled/... commands fail with ENOENT

Where: LifeOS/install/skills/Prompting/Tools/RenderTemplate.ts:238-239

    const outputFullPath = resolveTemplatePath(options.outputPath);
    writeFileSync(outputFullPath, rendered);

What happens. A relative output path that does not exist resolves to Templates/<path> (:152-158). Templates/Compiled/ is not shipped (Templates/README.md:24 calls it ignored), and nothing creates it. The header commands in Templates/Primitives/Gate.hbs:29 and Roster.hbs:29, and the examples in Templates/README.md:102,203, all write there.

Steps: after bun add [email protected], run from skills/Prompting/Tools: bun RenderTemplate.ts -t Primitives/Gate.hbs -d Data/ValidationGates.yaml -o Compiled/Gates.md

Expected: ✓ Rendered to: …/Templates/Compiled/Gates.md Actual: Error: ENOENT: no such file or directory, open '…/Templates/Compiled/Gates.md', exit 1.

Minimal fix:

-import { readFileSync, writeFileSync, existsSync } from 'fs';
+import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
@@
     const outputFullPath = resolveTemplatePath(options.outputPath);
+    mkdirSync(dirname(outputFullPath), { recursive: true });
     writeFileSync(outputFullPath, rendered);

Already reported, not repeated here

  • The root package.json lacks handlebars. This is #2431, fixed in source. The two items above use its workaround.

Details

  • Kind: bug
  • LifeOS version: 8.761.0

Filed with the LifeOS /feedback command. The reporter approved this exact text before it was sent; paths, secrets and personal details were stripped locally.

IvanLeontev-stack avatar Nov 26 '26 09:11 IvanLeontev-stack

[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler

Thanks for both finds. The eq helper now works as a block as well as inline (a73832b891), and you're credited in the code and on the commit. We left the output-directory part alone on purpose: a relative output path resolves under the templates folder, so creating directories there could write somewhere you didn't mean. Create the directory first and the render works. Closing.

danielmiessler avatar Dec 01 '26 09:12 danielmiessler