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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: reconcile LI outcomes for the plan (PLAN.md) tracker (#2435)
Adam Eivy76f534e7a39d
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 72b5a7fa59..1b20e3e2ad 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -8,6 +8,8 @@## Fixes+- **Layered Intelligence's outcome feedback loop now reconciles the `plan` (PLAN.md) tracker too (#2435).** After #2428 closed the loop for forge (gh/glab) and jira trackers, the `plan` tracker stayed excluded because `readIssues` mapped every `[lil-*]` PLAN.md item to `state: 'open'` regardless of its `- [ ]` / `- [x]` checkbox, so a completed proposal could never resolve. `extractPlanSlugs` now preserves each item's checkbox state — a checked `- [x]` reads `closed` (which `deriveOutcome` maps to *merged*) and an unchecked `- [ ]` (or a bare tag with no checkbox — absent ≠ done) reads `open` — so a checked item both reconciles as an outcome and falls out of the dedup window to become re-proposable, while open items stay suppressed as before. The `outcomesTrackerSupported()` gate now includes `plan`, so PLAN-tracked apps learn from their own merge rate like forge/jira apps.+- **Character Sheet name edits can no longer be reverted by a stale blur-save that fires while the prior save is still in flight (#2409).** Committing a name change (Enter or blur) starts a PUT and immediately returns the header to its button view. If you reopened the editor before that PUT landed, the reopened input seeded from the pre-save name — and a subsequent blur could persist that stale value straight back over the change you just made. The name trigger now disables while a save is in flight (tracked via a `nameSaving` flag set before the PUT and cleared in `finally`) and `startNameEdit` refuses to reopen until the save settles, so exactly one write wins and no stale revert can slip through.- **HuggingFace model downloads (Flux and every other image/video/music pull) now log to the server console.** Triggering a base-model download showed a progress bar in the UI but left no trace in the server log — the entire download path emitted progress *only* over the SSE stream to the browser, and PortOS has no HTTP access logger, so a headless/PM2 log had no record the multi-GB fetch ever ran. The shared SSE driver (`server/lib/sseDownload.js#startHfDownloadStream`, the single chokepoint behind the image, video, and music download endpoints) now writes single-line, emoji-prefixed log lines for the start of each repo pull (`⬇️`, with a forced-re-fetch marker), each file as it streams, a cache hit that skips the download (`📦`), the outcome (`✅` complete with byte count / `❌` failed with the error message), and client-disconnect cancellation (`🛑`) — while cancelled results are deliberately not logged as failures.diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.jsindex bd5d432e3d..bb75753fab 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js@@ -57,11 +57,13 @@ import {import { recordFiledProposal, listOutcomes, reconcileOutcomes } from '../layeredIntelligenceOutcomes.js'// The outcome feedback loop (#2428) can only reconcile a proposal's fate on a-// tracker that reports closed-state: a forge (gh/glab issues) or jira. A `plan`-// tracker maps every PLAN.md item to `state: 'open'`, so there's nothing to learn-// from — skip recording/reconciling there rather than accrete unresolvable rows.+// tracker that reports closed-state. All three now qualify: a forge (gh/glab+// issues) and jira report a real closed state, and since #2435 the `plan`+// tracker preserves each `[lil-*]` item's checkbox — a `- [x]` item reads+// `closed` (deriveOutcome → 'merged'), so a completed PLAN proposal reconciles+// like any other. (A `- [ ]` item stays open and unresolved, as before.)function outcomesTrackerSupported(filer) {- return filer === 'forge' || filer === 'jira'+ return filer === 'forge' || filer === 'jira' || filer === 'plan'}import { resolveAppWorkTracker } from '../../lib/workTracker.js'import { tryReadFile } from '../../lib/fileUtils.js'@@ -119,8 +121,10 @@ async function readIssues({ filer, forgeCli, cwd, jira, config }) {if (config.sources?.openIssues !== false) openIssues = existingIssues.filter(i => i.state === 'open')} else if (filer === 'plan' && cwd) {const planContent = await tryReadFile(join(cwd, 'PLAN.md'))- const planSlugs = extractPlanSlugs(planContent || '')- existingIssues = planSlugs.map(slug => ({ slug, state: 'open' }))+ // extractPlanSlugs preserves each tag's checkbox state ({ slug, state }): a+ // `- [x]` item reads 'closed' (with no closedAt) so the outcome loop can+ // reconcile it and it falls out of the dedup window, while `- [ ]` stays open.+ existingIssues = extractPlanSlugs(planContent || '')}return { openIssues, existingIssues, trackerReadFailed }}@@ -224,10 +228,9 @@ export async function buildTaskInput({ app } = {}) {// Feedback loop (#2428): reconcile past proposals' outcomes against the fresh// tracker read, then fold the merge-rate report into the prompt so the reasoner// calibrates on its own history. Gated on the per-app `outcomes` source toggle- // AND a forge/jira tracker — a `plan` tracker reports every item as open (no- // closed-state to reconcile), so tracking there would only accrete permanently-- // unresolved records. A failed tracker read skips reconciliation (never mark- // closed on a blind read).+ // AND an outcomes-capable tracker (forge / jira / plan — #2435 taught the plan+ // parse to read a checked `- [x]` item as closed). A failed tracker read skips+ // reconciliation (never mark closed on a blind read).let outcomesReport = ''if (config.sources?.outcomes && outcomesTrackerSupported(filer)) {if (!trackerReadFailed) await reconcileOutcomes({ appId: app.id, existingIssues })@@ -369,8 +372,9 @@ export async function processTaskOutput({ appId, success, payload, agentId } = {const ref = filedRef(filedKey, filedNumber) ?? ''console.log(`📌 Layered Intelligence: ${app.name} filed "${proposal.title}" [${proposal.slug}]${ref ? ` (${ref})` : ''}`)// Feedback loop (#2428): remember what we just filed so a later run can- // read back its outcome. Gated on the app's `outcomes` source toggle AND a- // forge/jira tracker (a `plan` item has no readable closed-state).+ // read back its outcome. Gated on the app's `outcomes` source toggle AND+ // an outcomes-capable tracker (forge / jira / plan — a checked `- [x]`+ // PLAN item now reconciles, #2435).if (config.sources?.outcomes && outcomesTrackerSupported(filer)) {await recordFiledProposal({appId: app.id, slug: proposal.slug, tracker: tracker.resolved,diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.jsindex 354bac7925..9bac94896b 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js@@ -70,6 +70,7 @@ import * as li from '../layeredIntelligence.js';import { recordFiledProposal, listOutcomes, reconcileOutcomes } from '../layeredIntelligenceOutcomes.js';import * as apps from '../apps.js';import { resolveAppWorkTracker } from '../../lib/workTracker.js';+import { tryReadFile } from '../../lib/fileUtils.js';import { getProviderById } from '../providers.js';import { loadSchedule } from '../taskSchedule.js';@@ -167,13 +168,21 @@ describe('buildTaskInput', () => {expect(li.buildPrompt).toHaveBeenCalledWith(expect.objectContaining({ outcomesReport: expect.stringContaining('Total filed: 1') }));});- it('skips the feedback loop on a plan tracker even when outcomes is enabled', async () => {+ it('runs the feedback loop on a plan tracker when outcomes is enabled (#2435)', async () => {resolveAppWorkTracker.mockResolvedValue({ resolved: 'plan', forge: null });li.getEffectiveConfig.mockReturnValue({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: { outcomes: true } });+ // The plan branch reads PLAN.md → a checked item reconciles like a forge issue.+ tryReadFile.mockResolvedValue('- [x] [lil-add-metrics] done');+ li.extractPlanSlugs.mockReturnValue([{ slug: 'add-metrics', state: 'closed' }]);+ listOutcomes.mockResolvedValue([{ slug: 'add-metrics', outcome: 'merged', scope: 'app-improvement' }]);+ li.computeOutcomesReport.mockReturnValue('Recent LI proposals:\n- Total filed: 1');await buildTaskInput({ app: APP });- expect(reconcileOutcomes).not.toHaveBeenCalled();- expect(listOutcomes).not.toHaveBeenCalled();- expect(li.buildPrompt).toHaveBeenCalledWith(expect.objectContaining({ outcomesReport: '' }));+ expect(reconcileOutcomes).toHaveBeenCalledWith(expect.objectContaining({+ appId: 'app-1',+ existingIssues: [{ slug: 'add-metrics', state: 'closed' }]+ }));+ expect(listOutcomes).toHaveBeenCalledWith(expect.objectContaining({ appId: 'app-1' }));+ expect(li.buildPrompt).toHaveBeenCalledWith(expect.objectContaining({ outcomesReport: expect.stringContaining('Total filed: 1') }));});});@@ -227,6 +236,24 @@ describe('processTaskOutput', () => {}));});+ it('records a plan-filed proposal for the feedback loop (#2435)', async () => {+ // A `plan` tracker now reconciles outcomes too — a proposal appended to+ // PLAN.md is recorded so a later run can read back its checked/unchecked fate.+ resolveAppWorkTracker.mockResolvedValue({ resolved: 'plan', forge: null });+ li.validateReasonerResponse.mockReturnValue({+ proposal: { scope: 'app-improvement', slug: 'add-metrics', title: 'Add metrics', body: 'do it' },+ pause: null+ });+ li.appendProposalToPlan.mockResolvedValue({ success: true });+ li.getEffectiveConfig.mockReturnValue({ allowedScopes: ['app-improvement'], sources: { outcomes: true } });+ const out = await processTaskOutput({ appId: 'app-1', success: true, payload: { proposal: {} } });+ expect(li.appendProposalToPlan).toHaveBeenCalled();+ expect(out).toMatchObject({ action: 'filed', reason: null });+ expect(recordFiledProposal).toHaveBeenCalledWith(expect.objectContaining({+ appId: 'app-1', slug: 'add-metrics', scope: 'app-improvement', tracker: 'plan'+ }));+ });+it('suppresses an exact-duplicate proposal without filing', async () => {li.validateReasonerResponse.mockReturnValue({proposal: { scope: 'app-improvement', slug: 'dup', title: 'Dup', body: 'x' },diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.jsindex 9c803c20ac..1777e5a14f 100644--- a/server/services/layeredIntelligence.js+++ b/server/services/layeredIntelligence.js@@ -983,12 +983,32 @@ export async function appendProposalToPlan({ repoPath, appName, slug, title, bodreturn { success: true, duplicate: false };}-/** Scan a PLAN.md string for existing `[lil-<slug>]` tags → array of slugs. */+/**+ * Scan a PLAN.md string for `[lil-<slug>]` tags → array of `{ slug, state }`.+ * Preserves each tag's list-item checkbox so the outcome loop (#2435) can+ * reconcile a completed PLAN proposal: `- [x] [lil-foo]` reads as `closed`,+ * `- [ ] [lil-foo]` as `open`.+ *+ * Absent ≠ done (the CLAUDE.md sentinel rule): a bare tag with NO preceding+ * checkbox stays `open` (still tracked/suppressed) rather than collapsing to+ * `closed` — a missing checkbox must not silently make an item re-proposable.+ * A `closed` item carries no `closedAt` (PLAN.md checkboxes have no timestamp),+ * which `isIssueWithinDedupWindow` already treats as out-of-window → the item+ * becomes re-proposable, exactly the desired behavior for a completed proposal.+ */export function extractPlanSlugs(planContent) {if (typeof planContent !== 'string') return [];- const slugs = [];- const re = /\[lil-([a-z0-9][a-z0-9-]*)\]/gi;+ const items = [];+ // Alt 1: a list item `- [ ]`/`- [x]` whose line also carries the tag (state+ // from the checkbox char). Alt 2: a bare tag with no checkbox (state 'open').+ const re = /^[ \t]*[-*][ \t]*\[([ xX])\][^\n]*?\[lil-([a-z0-9][a-z0-9-]*)\]|\[lil-([a-z0-9][a-z0-9-]*)\]/gim;let m;- while ((m = re.exec(planContent))) slugs.push(m[1].toLowerCase());- return slugs;+ while ((m = re.exec(planContent))) {+ if (m[2]) {+ items.push({ slug: m[2].toLowerCase(), state: m[1].toLowerCase() === 'x' ? 'closed' : 'open' });+ } else {+ items.push({ slug: m[3].toLowerCase(), state: 'open' });+ }+ }+ return items;}diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex 34a4f5fd57..bd003d5060 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -203,6 +203,16 @@ describe('isProposalDuplicate (dedup)', () => {expect(isProposalDuplicate({ slug: 'add-metrics', existingIssues: existing, now })).toBe(false);});+ it('ALLOWS re-file for a checked PLAN item (closed with no closedAt — #2435)', () => {+ // A `- [x]` PLAN item reads as closed with no timestamp; it must fall OUT of+ // the dedup window so a completed proposal can be re-proposed, while an+ // unchecked `- [ ]` item (state: 'open') stays suppressed.+ const closed = [{ slug: 'add-metrics', state: 'closed' }];+ const open = [{ slug: 'add-metrics', state: 'open' }];+ expect(isProposalDuplicate({ slug: 'add-metrics', existingIssues: closed, now })).toBe(false);+ expect(isProposalDuplicate({ slug: 'add-metrics', existingIssues: open, now })).toBe(true);+ });+it('matches slug embedded in a body marker (no parsed slug field)', () => {const existing = [{ body: `stuff ${slugMarker('add-metrics')}`, state: 'open' }];expect(isProposalDuplicate({ slug: 'add-metrics', existingIssues: existing, now })).toBe(true);@@ -499,9 +509,34 @@ describe('computeOutcomesReport', () => {});describe('extractPlanSlugs', () => {- it('collects lil-tagged slugs from PLAN.md content', () => {+ it('collects lil-tagged slugs with their checkbox state from PLAN.md content', () => {const plan = `## Next Up\n- [ ] [lil-add-metrics] Add metrics\n- [ ] [lil-fix-thing] Fix\n- [ ] [ref-watch-other] not ours`;- expect(extractPlanSlugs(plan)).toEqual(['add-metrics', 'fix-thing']);+ expect(extractPlanSlugs(plan)).toEqual([+ { slug: 'add-metrics', state: 'open' },+ { slug: 'fix-thing', state: 'open' }+ ]);+ });++ it('reads a checked `- [x]` item as closed and an unchecked one as open (#2435)', () => {+ const plan = `## Done\n- [x] [lil-add-metrics] Add metrics\n## Next Up\n- [ ] [lil-fix-thing] Fix`;+ expect(extractPlanSlugs(plan)).toEqual([+ { slug: 'add-metrics', state: 'closed' },+ { slug: 'fix-thing', state: 'open' }+ ]);+ });++ it('treats an uppercase `- [X]` checkbox as closed', () => {+ expect(extractPlanSlugs('- [X] [lil-shipped] done')).toEqual([+ { slug: 'shipped', state: 'closed' }+ ]);+ });++ it('treats a bare tag with no checkbox as open (absent ≠ done)', () => {+ // A tag mentioned inline, with no list checkbox, must NOT collapse to closed+ // (which would make it re-proposable) — it stays open/suppressed.+ expect(extractPlanSlugs('see [lil-inline-ref] elsewhere')).toEqual([+ { slug: 'inline-ref', state: 'open' }+ ]);});it('returns [] for non-string / empty', () => {