Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: wire LI proposal outcome playbook into task-generation prompt (#2763)

[._.]/ Adam Eivy63ddb5ab5602
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index adbd5c4e21..6843f34ef1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,8 @@
## Added
+- [issue-2763] **Layered Intelligence now reasons from a proposal playbook instead of proposing blind.** Every LI run's prompt now carries a standing **Proposal Playbook** — a distilled rule set for *what* to propose that's present from the very first run, before any per-app outcome data has accumulated. It encodes a Scope Selection Guide (prioritize high-merge scopes like `loop-meta` and `app-data-gap`; only file an `app-improvement` when it clearly serves a named goal), a Success Pattern Catalog and a Rejection Pattern Catalog (a NOT_PLANNED close means a roadmap conflict, so check goals and committed backlog *first*), Task Type Selection Rules (avoid the loop's own chronically-failing self-improvement work; prefer shapes an agent reliably finishes like plan-task / test-coverage / performance), and a Goal Alignment Check against PortOS's core goals and documented non-goals. It's authored as a reviewable markdown file that ships with the code and is injected verbatim into the reasoning prompt; where a live per-app outcome report in the same prompt has real numbers that contradict a general rule, the live data wins. Applies to every app the loop reasons about.
+
- [issue-2769] **Creative Commissions can now make more than video — pick the output type and the params follow.** A commission's editor gains a **Creative output** selector: choose Video, Image, Music, Music video, or Series, and the generation parameters change to fit (an Image commission asks for an image count and aspect ratio with no duration; Music asks for a length; Series asks for an episode count), instead of always showing video controls. Behind the scenes each type also gets its own tailored brief so the Creative Director is told exactly what to make (produce a still image, compose a music bed, start a new series) and which tools to use — rather than being handed the whole menu and left to guess from your intent. Existing video commissions are unchanged and keep running as before; a scheduled run whose type isn't recognized is skipped rather than mis-made as a video.
- [issue-2757] **The "set your birth date" prompt now tells you when your date is broken rather than just missing.** When your Character sheet or the CyberCity level badges can't show a level, they used to always say "set your birth date" — even if you'd already entered one that turned out to be invalid, dated in the future, or stored in a config file that couldn't be read. Now those cases show a distinct "fix your birth date" prompt (with a warning color) so you're not told to set a date you already entered, while a genuinely unset date still gets the original friendly "set" prompt. Every prompt still deep-links to the age editor where the field lives. The distinction is carried as an explicit, per-machine-derived status that's never persisted or synced between machines.
diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.js
index 67f622eab4..28be91cf11 100644
--- a/server/services/layeredIntelligence.js
+++ b/server/services/layeredIntelligence.js
@@ -20,9 +20,10 @@
*/
import { spawn } from 'child_process';
-import { join, resolve, relative, isAbsolute } from 'path';
+import { join, resolve, relative, isAbsolute, dirname } from 'path';
+import { fileURLToPath } from 'url';
import { readFile, writeFile, appendFile, realpath } from 'fs/promises';
-import { existsSync } from 'fs';
+import { existsSync, readFileSync } from 'fs';
import { DAY, tryReadFile, readJSONFile, safeJSONParse, PATHS } from '../lib/fileUtils.js';
import { bufferedSpawn } from '../lib/bufferedSpawn.js';
import { fetchPublicText } from '../lib/safeUrlFetch.js';
@@ -59,6 +60,26 @@ export const PLANNED_WORK_MAX_CHARS = 8000;
// against it".
export const PLANNED_WORK_GUIDANCE = 'Cross-reference your proposal against the user\'s actively-planned work above. If your proposal duplicates or conflicts with an active item, DO NOT file — return proposal: null. Only propose genuinely new work that does NOT overlap with what is already in scope.';
+// The LI Proposal Playbook (#2763): standing, human-authored guidance distilling
+// which proposals actually land vs. get rejected — scope selection, success/rejection
+// pattern catalogs, task-type selection rules, and a goal-alignment check. Loaded
+// once from the co-located markdown file so the prose stays reviewable-as-prose and
+// buildPrompt can render it verbatim as the always-on `liPlaybook` block. It ships in
+// the SOURCE tree (not seeded to data/prompts/), so it is code-versioned guidance that
+// updates with the code — NOT a user-customizable stage prompt, and thus needs no
+// PROMPT_VERSIONS bump or setup-data migration. Read synchronously at module load so
+// the constant is ready before the first buildPrompt call; the file ships with the
+// module, so a miss is a packaging bug worth surfacing loudly rather than swallowing.
+export const LI_PROPOSAL_PLAYBOOK = readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), 'layeredIntelligence.playbook.md'),
+ 'utf-8'
+).trim();
+
+// The instruction that frames the playbook block: apply it as a standing constraint,
+// but let a live per-app data block (liOutcomes / liProposalExecution) override a
+// general rule when it has real numbers that contradict it.
+export const LI_PLAYBOOK_GUIDANCE = 'This playbook is the distilled, standing rule set for choosing WHAT to propose — apply it as a hard constraint on scope, task type, and goal alignment before you commit to a proposal. Where a live report above (liOutcomes / liProposalExecution) contradicts a general rule here with real data for THIS app, the live data wins; absent that data, follow the playbook.';
+
// Rendered when the tracker read SUCCEEDED and the app genuinely has no committed
// backlog. Says so explicitly rather than omitting the block, so "nothing planned"
// is legible to the reasoner as a real answer rather than a missing source.
@@ -1158,6 +1179,9 @@ const BESPOKE_SOURCE_BLOCK_KEYS = new Set(['plannedWork', 'scopeGuidance']);
* `liScopeAwareness` block the same way (#2760). `proposalExecutionReport` (from
* computeProposalExecutionAwareness) is injected as a `liProposalExecution` block —
* the TRUE per-proposal-domain execution record #2760 could only approximate (#2765).
+ * Finally, the static `liPlaybook` block (LI_PROPOSAL_PLAYBOOK, #2763) is ALWAYS
+ * appended: the a-priori scope/task-type/goal rule set LI needs from run one, before
+ * any per-app outcome data exists.
*/
export function buildPrompt({ app, config, sources = {}, openIssues = [], isPortos = false, outcomesReport = '', selfEvalReport = '', proposalExecutionReport = '' }) {
const allowed = (config.allowedScopes || []).filter(s =>
@@ -1238,6 +1262,16 @@ export function buildPrompt({ app, config, sources = {}, openIssues = [], isPort
? `\n### liProposalExecution\n${proposalExecutionReport.trim()}\n\nThis is a DIRECT record of how LI's own proposals in each domain fared once implemented — not directional context. Favor domains LI executes reliably; for a low-execution domain, either narrow the proposal to a slice an agent can finish or justify why it is still the highest-value work despite the track record.\n`
: '';
+ // Proposal Playbook (#2763): the STANDING, a-priori rule set — always rendered.
+ // Unlike the data blocks above (which appear only once enough per-app outcome data
+ // accumulates), the playbook is the guidance LI needs from run one, when it would
+ // otherwise be proposing blind. It sits last so it is the freshest instruction
+ // before the JSON contract, and its guidance sentence defers to any live data block
+ // above that has real numbers contradicting a general rule.
+ const playbookBlock = LI_PROPOSAL_PLAYBOOK
+ ? `\n### liPlaybook\n${LI_PROPOSAL_PLAYBOOK}\n\n${LI_PLAYBOOK_GUIDANCE}\n`
+ : '';
+
return `You are the Layered Intelligence reasoner for the app "${app.name}". Your job is to evaluate how THIS app is performing against its OWN goals and purpose${isPortos ? '' : ', not how well PortOS\'s tooling manages it'}. Decide the SINGLE highest-value improvement to propose this run (signal, not noise), grounded in the app's own goals and its own performance metrics (user success, KPIs, production telemetry). You never write code; you return structured JSON that a deterministic system files as ONE tracker issue.
${handoffNote}${metricsGuidance}
Rules & guidance from the operator:
@@ -1251,7 +1285,7 @@ ${openList}
Gathered sources:
${sourceBlocks || (plannedWorkBlock ? '(no other sources available — you may propose an app-data-gap to add telemetry)' : '(no sources available — you may propose an app-data-gap to add telemetry)')}
-${plannedWorkBlock}${outcomesBlock}${selfEvalBlock}${scopeGuidanceBlock}${proposalExecutionBlock}
+${plannedWorkBlock}${outcomesBlock}${selfEvalBlock}${scopeGuidanceBlock}${proposalExecutionBlock}${playbookBlock}
Respond with JSON only (no markdown fences):
{
"analysis": "brief reasoning summary",
diff --git a/server/services/layeredIntelligence.playbook.md b/server/services/layeredIntelligence.playbook.md
new file mode 100644
index 0000000000..16969bc263
--- /dev/null
+++ b/server/services/layeredIntelligence.playbook.md
@@ -0,0 +1,123 @@
+<!--
+ LI Proposal Playbook (#2763)
+
+ Standing, human-authored rule set that distills what Layered Intelligence has
+ learned about which proposals actually land vs. get rejected — so the reasoner
+ stops proposing blindly. Loaded verbatim by server/services/layeredIntelligence.js
+ as LI_PROPOSAL_PLAYBOOK and rendered as the `liPlaybook` block in every LI
+ reasoning prompt (see buildPrompt). It ships in the source tree, NOT under
+ data/prompts/ — it is code-versioned guidance, not a user-seeded/customizable
+ stage prompt, so it needs no PROMPT_VERSIONS bump or setup-data migration.
+
+ This is the a-priori guidance that applies BEFORE enough per-app outcome data
+ accumulates. Where a live data block in the same prompt (liOutcomes /
+ liProposalExecution) has real numbers for THIS app that contradict a general
+ rule below, the live data wins. Absent that data, follow the playbook.
+
+ Content is derived from LI's own outcome PATTERNS, never from any private
+ record. Keep it generic — no real issue titles, slugs, hostnames, or user data.
+-->
+
+# LI Proposal Playbook
+
+You (the reasoner) file blindly by default: you propose work without checking how
+your past proposals fared, which produces a low merge rate and repeated
+NOT_PLANNED rejections. This playbook is your correction. Treat it as a hard
+constraint on **which scope**, **which kind of work**, and **whether it aligns
+with goals** — applied before you commit to any proposal.
+
+## 1. Scope Selection Guide
+
+Not all proposal scopes land equally. Prioritize scopes that historically merge;
+require extra justification for scopes that historically get rejected.
+
+- **Prefer `loop-meta`** (PortOS install only). Improvements to the LI loop
+ itself — better dedup, better calibration, clearer prompts, fixing a failure
+ mode you can see in your own reports — merge at a high rate because they are
+ concrete, verifiable, and self-contained.
+- **Prefer `app-data-gap`.** Adding the telemetry / metrics / instrumentation
+ needed to reason well (e.g. a missing METRICS.md, an unmeasured KPI) lands
+ reliably: it is unambiguous, low-risk, and unblocks future higher-value work.
+- **De-prioritize `app-improvement` unless alignment is explicit.** A generic
+ "improve the app" proposal without a clear tie to a stated goal, a measured
+ gap, or committed backlog is the single largest source of rejections. Only
+ file it when you can name the specific goal it serves and the signal that
+ says it is the highest-value item now.
+- **`portos-self`** (PortOS install only): scoped, verifiable self-improvements
+ to PortOS as an app — hold to the same bar as `app-improvement`.
+
+If nothing clears this bar, return `proposal: null`. Filing nothing is a
+legitimate, and often the correct, outcome.
+
+## 2. Success Pattern Catalog
+
+Proposals that merge tend to share these traits — bias toward them:
+
+- **Concrete and bounded.** A single, well-scoped change a coding agent can
+ finish end-to-end, not an open-ended "rework X".
+- **Grounded in a real signal.** Cites a measured gap, a goal, a failing metric,
+ or a self-report block above — not a hunch.
+- **Non-duplicative.** Does not overlap the already-open issues or the committed
+ backlog (`plannedWork`). Reuse an existing slug only for genuinely the same work.
+- **Fills a data/telemetry gap** so future runs can reason better (the classic
+ high-merge `app-data-gap`).
+- **Fixes a loop failure you can see** in `liOutcomes` / `liProposalExecution` /
+ `liScopeAwareness` (the classic high-merge `loop-meta`).
+
+## 3. Rejection Pattern Catalog
+
+Proposals get closed for recurring reasons. Before filing, check that yours is
+not one of these:
+
+- **NOT_PLANNED = roadmap conflict.** A NOT_PLANNED close almost always means the
+ work runs against the product's direction, not that it was poorly written.
+ **Check the goals and committed backlog FIRST** — if the proposal is not
+ clearly on-roadmap (or is explicitly out of scope / a non-goal), do not file it.
+- **Duplicate / already-planned.** Overlaps an open issue or committed backlog
+ item. Cross-reference `plannedWork` and the open-issue list before filing.
+- **Too vague / unbounded.** No clear acceptance criteria; a human cannot tell
+ when it is done. Narrow it or drop it.
+- **Speculative "nice to have"** with no goal tie and no measured need. Costs the
+ user triage time and lowers your merge rate further.
+- **Maps to a chronically-failing execution domain** (see the next section).
+
+## 4. Task Type Selection Rules
+
+An LI proposal is later EXECUTED as a coding-agent task. Proposing work that maps
+to a task type that reliably FAILS to complete is systematic waste, even when the
+idea is good.
+
+- **Avoid your own worst scope.** Self-improvement work that maps to LI's own
+ reasoning-run task type (`self-improve:layered-intelligence`) has historically
+ had ~0% completion. Do not propose more of it while your own execution is
+ degraded — the highest-value loop-meta fix is usually the one that repairs
+ the failure mode itself, framed so it is genuinely finishable.
+- **Avoid chronically-failing types** surfaced in `liScopeAwareness` /
+ `liProposalExecution` (e.g. types sitting at 0% completion). If the live block
+ above lists a low-completion type, treat a proposal resembling it as needing a
+ narrower scope or a different framing.
+- **Prefer reliably-completed types.** Work that resembles `plan-task`,
+ `test-coverage`, or `performance` tends to complete near-reliably — bias
+ proposals toward shapes an agent actually finishes.
+- **When a live report and this list disagree,** the live per-app report wins:
+ it is a direct record; this list is the a-priori default before that data exists.
+
+## 5. Goal Alignment Check
+
+Run this check before committing to any proposal. If it fails, return
+`proposal: null`.
+
+1. **Name the goal it serves.** Point to a specific stated goal / purpose of the
+ app. For the PortOS install, that is a Core Goal in GOALS.md (e.g.
+ Self-Improving Intelligence, Autonomous AI Orchestration, Creative Production).
+ If you cannot name one, it is probably `app-improvement` noise — drop it.
+2. **Check it is not a non-goal.** Do not propose work the project has explicitly
+ ruled out (for PortOS: multi-user auth, public-internet hardening, ORM/query
+ builders, cloud hosting — these are documented non-goals and NOT_PLANNED
+ magnets).
+3. **Confirm it is not already committed.** Cross-reference `plannedWork` and the
+ open-issue list — on-roadmap work already in flight is a duplicate, not a
+ proposal.
+4. **Prefer the highest-leverage goal.** Among candidates, favor the one that
+ unblocks or compounds future work (data gaps, loop-meta fixes) over a
+ one-off improvement.
diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.js
index d3c4c233d4..ae382d6b6e 100644
--- a/server/services/layeredIntelligence.test.js
+++ b/server/services/layeredIntelligence.test.js
@@ -29,6 +29,7 @@ import {
filerForTracker,
trackerSupportsPause,
buildPrompt,
+ LI_PROPOSAL_PLAYBOOK,
deriveOutcome,
computeOutcomesReport,
computeSelfEvalSummary,
@@ -676,7 +677,10 @@ describe('buildPrompt', () => {
it('injects the scope-awareness block only when present, under its own heading (#2760)', () => {
const base = { app, isPortos: true, config: { allowedScopes: ['loop-meta'], rules: '' } };
const without = buildPrompt(base);
- expect(without).not.toContain('liScopeAwareness');
+ // Heading form: the always-on liPlaybook block legitimately references the block
+ // id in prose, so assert the block itself (its `### ` heading) is absent, not the
+ // bare token.
+ expect(without).not.toContain('### liScopeAwareness');
const withGuidance = buildPrompt({
...base,
sources: { scopeGuidance: 'LOW-COMPLETION task types:\n- branch-reconcile: 0% completed over 4 runs' }
@@ -690,7 +694,7 @@ describe('buildPrompt', () => {
it('injects the per-proposal-domain execution block only when a report is passed (#2765)', () => {
const base = { app, isPortos: true, config: { allowedScopes: ['loop-meta'], rules: '' } };
- expect(buildPrompt(base)).not.toContain('liProposalExecution');
+ expect(buildPrompt(base)).not.toContain('### liProposalExecution');
const withExec = buildPrompt({
...base,
proposalExecutionReport: 'HIGH-EXECUTION proposal domains — LI reliably implements its own proposals here (at or above 75%):\n- loop-meta: LI implemented 100% of its own loop-meta proposals successfully over 3 executed'
@@ -709,7 +713,7 @@ describe('buildPrompt', () => {
config: { allowedScopes: ['app-improvement'], rules: '' },
sources: { scopeGuidance: 'LOW-COMPLETION task types:\n- plan-task: 0% completed over 9 runs' }
});
- expect(out).not.toContain('liScopeAwareness');
+ expect(out).not.toContain('### liScopeAwareness');
expect(out).not.toContain('plan-task: 0% completed over 9 runs');
});
@@ -718,7 +722,11 @@ describe('buildPrompt', () => {
app, isPortos: false,
config: { allowedScopes: ['app-improvement', 'app-data-gap', 'loop-meta'], rules: '' }
});
- expect(nonPortos).not.toContain('loop-meta'); // gated out by isScopeAllowed
+ // Assert the scope is not OFFERED (absent from the allowed-scope bullet list,
+ // rendered as ` - loop-meta`). The always-on liPlaybook block references loop-meta
+ // by name in its prose — clearly marked "PortOS install only" — so a bare-token
+ // check would spuriously fail; the offered-bullet form is the precise assertion.
+ expect(nonPortos).not.toContain(' - loop-meta'); // gated out by isScopeAllowed
expect(nonPortos).toContain('meta/self scopes are unavailable');
const portos = buildPrompt({
@@ -753,7 +761,7 @@ describe('buildPrompt', () => {
it('injects the outcomes report + calibration guidance only when non-empty', () => {
const base = { app, isPortos: false, config: { allowedScopes: ['app-improvement'], rules: '' } };
const without = buildPrompt(base);
- expect(without).not.toContain('liOutcomes');
+ expect(without).not.toContain('### liOutcomes');
const withReport = buildPrompt({ ...base, outcomesReport: 'Past LI proposals (last 30 days):\n- Total filed: 3' });
expect(withReport).toContain('### liOutcomes');
expect(withReport).toContain('Total filed: 3');
@@ -785,6 +793,30 @@ describe('buildPrompt', () => {
expect(out).toContain('its OWN goals and purpose');
});
+ it('always injects the static proposal playbook block (#2763)', () => {
+ // Unlike the data-driven blocks, the playbook is a-priori guidance that must be
+ // present from run one — even with no sources, outcomes, or self-eval data.
+ const bare = buildPrompt({ app, isPortos: true, config: { allowedScopes: ['loop-meta'], rules: '' } });
+ expect(bare).toContain('### liPlaybook');
+ expect(bare).toContain('# LI Proposal Playbook');
+ // The five deliverables the issue calls for are all present in the rendered block.
+ expect(bare).toContain('Scope Selection Guide');
+ expect(bare).toContain('Success Pattern Catalog');
+ expect(bare).toContain('Rejection Pattern Catalog');
+ expect(bare).toContain('Task Type Selection Rules');
+ expect(bare).toContain('Goal Alignment Check');
+ // NOT_PLANNED = roadmap conflict is the headline rejection heuristic.
+ expect(bare).toContain('NOT_PLANNED');
+ // Rendered under its dedicated heading, never dumped as a generic source block.
+ expect(bare).toContain('apply it as a hard constraint');
+ });
+
+ it('renders the playbook on managed (non-PortOS) apps too — the general rules are universal', () => {
+ const managed = buildPrompt({ app, isPortos: false, config: { allowedScopes: ['app-improvement'], rules: '' } });
+ expect(managed).toContain('### liPlaybook');
+ expect(managed).toContain('Goal Alignment Check');
+ });
+
it('nudges a managed app with no own-performance metrics toward a METRICS.md data gap', () => {
// No appMetrics source gathered → guidance to add a METRICS.md.
const missing = buildPrompt({ app, isPortos: false, config: { allowedScopes: ['app-data-gap'], rules: '' } });