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
address review: dry-run refs, re-plan visibility, sentinel/grammar parity (#2773)
[._.]/ Adam Eivy99ad5dbb9dd7
diff --git a/server/lib/creativeDirectorPrompts.js b/server/lib/creativeDirectorPrompts.jsindex fc1ef4d9d6..012728c6ee 100644--- a/server/lib/creativeDirectorPrompts.js+++ b/server/lib/creativeDirectorPrompts.js@@ -118,8 +118,22 @@ function buildPlanView(project, toolSpecs) {},tools,hasCurrentPlan: currentSteps.length > 0,+ // Serialize `dependsOn` + `args` (not just id/tool/status) so a re-planning+ // agent can keep completed steps verbatim AND see a failed step's authored+ // args — critical when the failure is a bad `{{steps.…}}` result reference,+ // which is only diagnosable from the args + the persisted error. Without the+ // error the re-planner reproduces the broken reference until MAX_REPLAN_ROUNDS.currentPlanJson: JSON.stringify(- currentSteps.map((s) => ({ stepId: s.stepId, toolName: s.toolName, status: s.status })),+ currentSteps.map((s) => ({+ stepId: s.stepId,+ toolName: s.toolName,+ status: s.status,+ dependsOn: s.dependsOn || [],+ args: s.args || {},+ ...(s.result && (s.result.error || s.result.reason)+ ? { error: s.result.error || s.result.reason }+ : {}),+ })),),};}diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.jsindex aca0c6d956..fd6a459eef 100644--- a/server/lib/schemaVersions.js+++ b/server/lib/schemaVersions.js@@ -344,6 +344,14 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({// rewrite is needed — existing legacy projects simply lack both keys and the// advance loop treats an absent key identically to null (falsy → legacy video// flow); migration 175 only seeds the new `cd-plan` prompt stage.+ // NOT bumped to 3 for cross-step result references (`{{steps.<id>.result.<key>}}`+ // in `plan.steps[].args`, #2773): the trigger for a bump is a project-SHAPE+ // change a plan-unaware sanitizer would strip on round-trip. References add no+ // field — they are string VALUES inside `args`, already `z.record(z.any())`,+ // which a v2 sanitizer preserves verbatim (no strip, no LWW loss). A v2 peer+ // merely can't RESOLVE the syntax at execution time, and schema-versioning+ // gates payload integrity, not execution parity across rolling upgrades (a v2+ // peer can't run any v3-added behavior — that's inherent, not a corruption).creativeDirectorProjects: 2,// v1 = Mood boards (PostgreSQL `mood_boards`) federated via the per-record// peer-sync push pipeline (record kind `moodBoard`, sync category `moodBoards`,diff --git a/server/services/creativeDirector/planAdvance.js b/server/services/creativeDirector/planAdvance.jsindex fac0bd150b..5f387fc5c4 100644--- a/server/services/creativeDirector/planAdvance.js+++ b/server/services/creativeDirector/planAdvance.js@@ -119,6 +119,11 @@ export function deriveNextPlanAction(plan) {const STEP_REF_BODY = String.raw`\{\{\s*steps\.([\w-]+)\.result\.([\w.-]+)\s*\}\}`;const STEP_REF_ANCHORED = new RegExp(`^${STEP_REF_BODY}$`);const STEP_REF_GLOBAL = new RegExp(STEP_REF_BODY, 'g');+// Fast-path sentinel — the grammar's opening (`{{`, optional whitespace,+// `steps.`). MUST stay as tolerant as STEP_REF_BODY's prefix or a+// whitespace-padded reference the resolver WOULD match slips past the early-out+// and dispatches as a literal. Non-global so `.test()` carries no lastIndex.+const STEP_REF_SENTINEL = /\{\{\s*steps\./;/*** Resolve `{{steps.<stepId>.result.<path>}}` references in a plan step's `args`@@ -144,10 +149,10 @@ const STEP_REF_GLOBAL = new RegExp(STEP_REF_BODY, 'g');*/export function resolvePlanStepArgs(step, plan) {const args = step?.args || {};- // Fast path: the vast majority of steps carry no references. Every reference- // contains the `{{steps.` sentinel, so a cheap serialize-and-scan returns the- // args untouched without building the step index or walking/cloning the tree.- if (!JSON.stringify(args).includes('{{steps.')) return { args, error: null };+ // Fast path: the vast majority of steps carry no references. A cheap+ // serialize-and-scan for the reference opener returns the args untouched+ // without building the step index or walking/cloning the tree.+ if (!STEP_REF_SENTINEL.test(JSON.stringify(args))) return { args, error: null };const steps = Array.isArray(plan?.steps) ? plan.steps : [];const byId = new Map(steps.map((s) => [s.stepId, s]));@@ -160,6 +165,12 @@ export function resolvePlanStepArgs(step, plan) {errors.push(`references step "${stepId}" which is not complete (status: ${dep.status || 'pending'})`);return undefined;}+ // Dry-run preview: a step dispatched in dry-run mode settles `done` with only+ // `{ planned: true }` and mints no real id, so a reference into it has nothing+ // to resolve. Substitute a synthetic placeholder rather than erroring, so the+ // whole-plan preview walk completes (the downstream step is itself dry-run and+ // never uses the value) instead of failing into a spurious re-plan.+ if (dep.result?.planned === true) return `dry-run:${stepId}.${path}`;let val = dep.result;for (const seg of path.split('.')) val = val == null ? undefined : val[seg];if (val === undefined || val === null) {diff --git a/server/services/creativeDirector/planAdvance.test.js b/server/services/creativeDirector/planAdvance.test.jsindex 96d784c533..939a140c85 100644--- a/server/services/creativeDirector/planAdvance.test.js+++ b/server/services/creativeDirector/planAdvance.test.js@@ -107,6 +107,13 @@ describe('resolvePlanStepArgs (pure) — cross-step result references (#2773)',expect(out.args.n).toBe(3); // number, not "3"});+ it('resolves a whitespace-padded reference (fast-path sentinel matches the grammar)', () => {+ const plan = donePlan({ id: 'ser-42' });+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{ steps.create-series.result.id }}' } }, plan);+ expect(out.error).toBeNull();+ expect(out.args.seriesId).toBe('ser-42'); // not dispatched as a literal+ });+it('interpolates an embedded reference inside a longer string', () => {const plan = donePlan({ name: 'Nova' });const out = resolvePlanStepArgs({ stepId: 'run', args: { title: 'Cover for {{steps.create-series.result.name}}' } }, plan);@@ -145,6 +152,15 @@ describe('resolvePlanStepArgs (pure) — cross-step result references (#2773)',expect(out.error).toMatch(/missing result "id"/);});+ it('resolves a reference into a dry-run predecessor to a placeholder (no spurious error)', () => {+ // In a dry-run preview the create step settles `done` with `{ planned: true }`+ // and mints no id — a downstream reference must not hard-fail the walk.+ const plan = { steps: [{ stepId: 'create-series', status: 'done', result: { planned: true } }] };+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);+ expect(out.error).toBeNull();+ expect(out.args.seriesId).toBe('dry-run:create-series.id');+ });+it('treats a skipped step as a resolvable terminal-success source', () => {const plan = { steps: [{ stepId: 'create-series', status: 'skipped', result: { id: 'ser-7' } }] };const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);