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: give UI audits PortOS browser runtime context
[._.]/ Adam Eivyb30b5a768e62
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex fea8413962..578688be29 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -75,6 +75,29 @@ const CLAIM_FLOW_TASK_TYPES = new Set(['plan-task', 'claim-issue', 'claim-issue-gitlab', 'claim-issue-jira', 'claim-work']);+// These scheduled audits inspect a running web UI. Keep their runtime contract+// in the builder rather than only in the default prompt bodies so customized+// prompts and tasks queued before a prompt revision get the same guidance.+export const UI_AUDIT_TASK_TYPES = Object.freeze([+ 'accessibility', 'console-errors', 'ui-bugs', 'mobile-responsive', 'ux'+]);+const UI_AUDIT_TASK_TYPE_SET = new Set(UI_AUDIT_TASK_TYPES);++export const UI_AUDIT_RUNTIME_RULE = `## UI Audit Runtime (PortOS local system)+This is an unattended run, but it is not browserless. PortOS provides a managed Chromium browser for CoS agents over Chrome DevTools Protocol (CDP). Use the available Playwright/browser tools with that PortOS-managed browser to inspect the target app; do not skip live UI verification or assume the browser is unavailable because no human is present.++- Reuse the PortOS-managed browser over CDP instead of launching a separate browser. Check the browser status/configuration when needed; the CDP endpoint is local and its port is configurable (the shipped default is 127.0.0.1:5556).+- Treat the target as a running local system: discover its actual UI/API URL and ports from the app configuration, PortOS app/process state, and health endpoints, then inspect scoped server logs when diagnosing console or request failures. Do not guess a URL or treat source-only speculation as a UI finding.+- Capture live evidence (snapshots, console/request results, and observed runtime state) before changing code. If the managed browser or target app is genuinely unavailable, record the concrete health/process error and stop the UI audit cleanly.`;++export function isUiAuditTask(task) {+ const taskType = task?.metadata?.analysisType+ || task?.metadata?.taskAnalysisType+ || task?.metadata?.selfImprovementType+ || task?.taskType;+ return UI_AUDIT_TASK_TYPE_SET.has(taskType);+}+export function isClaimFlowTask(task, isTruthyMetaFn = (value) => value === true || value === 'true') {return isTruthyMetaFn(task?.metadata?.claimFlow)|| CLAIM_FLOW_TASK_TYPES.has(task?.metadata?.analysisType);@@ -531,6 +554,7 @@ ${task.metadata.jiraBranch ? 'Commit your changes to this branch. Do NOT switch// template on every install. `metadata.prompt` still travels untouched for a// custom template that wants to address it directly.const contextBlock = taskContextBlock(task);+ const uiAuditRuntimeSection = isUiAuditTask(task) ? UI_AUDIT_RUNTIME_RULE : '';const briefingTask = contextBlock === (task.metadata?.[TASK_CONTEXT_KEY] ?? null)? task: { ...task, metadata: { ...task.metadata, [TASK_CONTEXT_KEY]: contextBlock } };@@ -558,7 +582,7 @@ ${task.metadata.jiraBranch ? 'Commit your changes to this branch. Do NOT switch}).catch(() => null);if (promptData?.prompt) {- return `${promptData.prompt}\n\n${UNATTENDED_RUN_RULE}\n\n${PM2_SAFETY_RULE}`;+ return `${promptData.prompt}\n\n${UNATTENDED_RUN_RULE}${uiAuditRuntimeSection ? `\n\n${uiAuditRuntimeSection}` : ''}\n\n${PM2_SAFETY_RULE}`;}const taskBlock = buildTaskBlock(task, { screenshotsAsList: false });@@ -644,6 +668,7 @@ ${discardWorktree || noCodeOutput || claimFlow ? '' : worktreeInfo ? `- **Your P${task.metadata?.app ? `You are working in the target app directory: \`${workspaceDir}\`. All code changes, research, plans, and docs for this task belong in this directory — NOT in the PortOS repo.` : 'You are working in the project directory.'} Use the available tools to explore, modify, and test code.${UNATTENDED_RUN_RULE}+${uiAuditRuntimeSection ? `\n${uiAuditRuntimeSection}` : ''}${PM2_SAFETY_RULE}@@ -792,6 +817,7 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, isTruthyMet// actually stalled on an approval gate, and "no human will answer you" is not// something the agent can infer from AGENTS.md or its cwd.contractSections.push(UNATTENDED_RUN_RULE);+ if (isUiAuditTask(task)) contractSections.push(UI_AUDIT_RUNTIME_RULE);// --- Worktree ----------------------------------------------------------if (worktreeInfo) {diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 16f7bdbd24..18cad4ff67 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -92,7 +92,7 @@ vi.mock('./codeReview.js', () => ({getCodeReviewDefaults: vi.fn().mockResolvedValue({ reviewers: ['copilot'] }),}));-import { buildLightContextPrompt, buildAgentPrompt, buildCompletionGuidelineBullet, reconcileSplitContext, buildReviewLoopFollowUpSection, getAppWorkspace, getAgentInstructionsContext, detectSkillTemplates, loadSkillTemplates, UNATTENDED_RUN_RULE } from './agentPromptBuilder.js';+import { buildLightContextPrompt, buildAgentPrompt, buildCompletionGuidelineBullet, reconcileSplitContext, buildReviewLoopFollowUpSection, getAppWorkspace, getAgentInstructionsContext, detectSkillTemplates, loadSkillTemplates, UI_AUDIT_RUNTIME_RULE, UI_AUDIT_TASK_TYPES, UNATTENDED_RUN_RULE } from './agentPromptBuilder.js';import { getCodeReviewDefaults } from './codeReview.js'; // mocked above — control the configured defaultimport { isTruthyMeta } from './agentState.js';import { buildPrompt } from './promptService.js'; // mocked above — inspect call args@@ -370,6 +370,57 @@ describe('claim-flow completion handoff', () => {});describe('buildLightContextPrompt', () => {+ describe('UI audit runtime context', () => {+ it.each(UI_AUDIT_TASK_TYPES)('adds browser and local-system guidance to %s', (analysisType) => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { analysisType } }),+ '/repo',+ null,+ isTruthyMeta,+ );++ expect(prompt).toContain(UI_AUDIT_RUNTIME_RULE);+ expect(prompt).toContain('not browserless');+ expect(prompt).toContain('127.0.0.1:5556');+ expect(prompt).toContain('running local system');+ });++ it('adds the same guidance on the full API prompt path', async () => {+ const prompt = await buildAgentPrompt(+ makeTask({ metadata: { analysisType: 'ui-bugs' } }),+ {},+ '/repo',+ null,+ isTruthyMeta,+ { providerType: 'api' },+ );++ expect(prompt).toContain(UI_AUDIT_RUNTIME_RULE);+ });++ it('recognizes the legacy self-improvement task marker', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { selfImprovementType: 'mobile-responsive' } }),+ '/repo',+ null,+ isTruthyMeta,+ );++ expect(prompt).toContain(UI_AUDIT_RUNTIME_RULE);+ });++ it('does not add UI runtime guidance to a non-UI scheduled task', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { analysisType: 'security' } }),+ '/repo',+ null,+ isTruthyMeta,+ );++ expect(prompt).not.toContain('## UI Audit Runtime');+ });+ });+describe('what it omits', () => {it('does NOT include the obsolete "# Chief of Staff Agent Briefing" header', () => {const prompt = buildLightContextPrompt(makeTask(), '/repo', null, isTruthyMeta);