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
feat: label claim PRs with the opening model (#13282)
[._.]/5f38a810f43a
diff --git a/AGENTS.md b/AGENTS.mdindex 35b2d92026..3f97f67d56 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -259,6 +259,7 @@ This policy governs code comments, not user-facing guides or product copy.## Git Workflow+- **Label PRs with the opening agent's model.** Every PR opened by a scheduled `claim-issue` run or a manual direct claim carries `implementer:<model>` (`implementer::<model>` for GitLab MRs). Use the exact label supplied by the run's **PR Model Attribution** section; outside PortOS, use the model verified by the host's execution context and normalize it with `normalizePlannerId` in `server/lib/dispatchLabels.js`. Create the repository label if missing, pass it when opening the PR, and read the PR labels back to verify it. This records the opening agent, independently of issue `model:` capability tiers and `planner:` authorship. A delegated opener uses its own model. Preserve an existing PR's original attribution on resume; repair it only from evidence of the original opener. Never guess a model from the provider, reviewer, issue labels, or self-identification; report missing model evidence or label failures explicitly in the handoff.- **main**: active development. **release**: merge a frozen candidate into `release` to trigger publication. **Release procedure:** [docs/VERSIONING.md](docs/VERSIONING.md#creating-a-release) is canonical and overrides the generic slashdo promotion recipe. Pin current `main` once at release kickoff in an isolated candidate branch, persist its cutoff, and resume that same candidate after interruption. Later merges and unrelated open issues/PRs belong to the next release. Only preparation and evidenced candidate-gating fixes may advance it; never rebase/merge live `main` into it. Promote the validated candidate, then synchronize the published release back to `main` through a normal PR.- **Before pushing**: inspect branch/upstream and working-tree state, preserve unrelated changes, and commit the intended work. Fetch the workflow's intended base explicitly for comparison; a feature branch's tracking branch is not necessarily the default branch. Integrate it only when needed under the merge policy below. Run `npm run pregate` on the resulting commits, then push. Re-run it after any subsequent rebase; do not blindly pull with autostash.- **Merge ready branches without chasing `main`.** A branch that is behind the default branch may merge when it is conflict-free, required checks pass for its current head, and configured reviews are satisfied. Default-branch movement alone does not invalidate those results or require a rebase, branch update, or another CI run. Before every managed merge (including `/do:next` single-issue and swarm Phase C, `/do:pr --merge`, and CoS claims), fetch the actual PR base branch and run `node scripts/pregate.js --guards-only --merged-with origin/<base>` against the committed head and that fetched base (`main` for development PRs; `release` for candidate promotion). This runs only the planner’s always-run and diff-selected structural guards on the combined tree, with test-memo reuse disabled; it does not replace head CI or write an attestation receipt. Run it outside repository merge admission. Retain the checked head and base SHAs; inside admission, re-read the live base as well as the PR head. If either changed, release admission and repeat the guard check outside the lease before retrying. A failed guard leaves the PR open with the failing test named; do not merge. These instructions are the repository pre-merge hook for the bundled slashdo [merge gate](lib/slashdo/lib/merge-gate.md) and override any direct-merge fallback in that shared procedure. Rebase only for actual conflicts, an enforced up-to-date branch policy, or evidenced integration risk (including semantic overlap without textual conflicts); after changing the head, rerun affected validation and required reviews/checks. Keep implementation, review, and CI concurrent; hold repository merge admission only for the final live-state check, merge attempt, and readback, releasing it before recovery or further CI waits. Never bypass required checks or confuse a queued merge with `MERGED`. This policy overrides mandatory base-sync instructions in delegated slashdo workflows.diff --git a/server/lib/dispatchLabels.js b/server/lib/dispatchLabels.jsindex 66f9d9ffa6..5f946b7133 100644--- a/server/lib/dispatchLabels.js+++ b/server/lib/dispatchLabels.js@@ -259,6 +259,19 @@ export function plannerLabelSpec(name) {};}+/** PR authorship is separate from issue planning and future dispatch hints. */+function implementerLabelSpec(name) {+ if (typeof name !== 'string') return null;+ const canonical = forgeLabelName(name);+ if (!canonical.startsWith('implementer:')) return null;+ const id = normalizePlannerId(canonical.slice('implementer:'.length));+ return id ? {+ name: `implementer:${id}`,+ color: '0075CA',+ description: `PR opened by the ${id} model`,+ } : null;+}+/*** The planner-attribution instruction for one run, ready to paste into an* issue-filing prompt. `plannerId` is this run's own identity (see@@ -560,10 +573,9 @@ export function dispatchLabelSpec(name, { cli = 'gh' } = {}) {};}}- // Prefix-matched last: the planner axis has no enumerable table, so it must- // not shadow a fixed label that happens to start with the same characters.- const planner = plannerLabelSpec(name);- return planner ? { ...planner, name: forgeLabelName(planner.name, { cli }) } : null;+ // Attribution axes are open-ended and must not shadow fixed labels.+ const attribution = plannerLabelSpec(name) || implementerLabelSpec(name);+ return attribution ? { ...attribution, name: forgeLabelName(attribution.name, { cli }) } : null;}/** All slashdo dispatch-label specs, in axis-then-ramp order. */diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex f12e6b4ae7..09ef6246f1 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -36,6 +36,7 @@ import { applySlashdoInvocation } from './promptSections/slashdo.js';import { manualForgeCli, resolveManualForgeCli } from './promptSections/forge.js';import { buildOrchestrationDoctrineSection } from './promptSections/orchestrationDoctrine.js';import { buildIssueFilingSection } from './promptSections/plannerAttribution.js';+import { buildPrAttributionSection } from './promptSections/prAttribution.js';import { buildSecurityAuditRuntimeSection } from './promptSections/securityAudit.js';import { isPublicReviewNoToolProfile, isPublicReviewRestrictedProfile } from '../lib/agentExecutionProfiles.js';import { COMPLETION_MODES, resolveCompletionMode } from '../lib/agentCompletionMode.js';@@ -422,8 +423,7 @@ export async function buildAgentPrompt(task, config, workspaceDir, worktreeInfoconst providerId = options.providerId || null;const providerCommand = options.providerCommand || null;const agentId = options.agentId || null;- // The model this run was actually dispatched with — the planner identity a- // filing agent stamps as `planner:<model>`. It cannot self-report this.+ // The dispatched model supplies issue-planner and PR-opener attribution.const providerModel = options.providerModel || null;const isTui = providerType === PROVIDER_TYPES.TUI;const leanMode = options.leanMode === true;@@ -641,14 +641,18 @@ ${buildResumeSection(task, worktreeInfo)}` : '';// reviewer-visible projection so a Security Scan report meant for the human// never reaches a pipeline reviewer's prompt.const contextBlock = taskContextBlock(taskVisibleToPipelineReviewer(task));- // Issue filing and planner attribution. Skipped for Creative Director runs- // alongside the rest of the dev context — a scene evaluation files no issue.- // The forge is left at the default here rather than probed: this path is- // API-provider-only, and the two CLIs' `label create` idioms differ only in- // flag spelling, which the guidance spells out for whichever the agent has.+ // Resolve the code forge even for Jira claims; attribution labels live on+ // the PR/MR, not the ticket. Creative Director runs need no dev contracts.+ const attributionOptions = skipDevContext ? null : {+ providerId, model: providerModel,+ forgeCli: await resolveManualForgeCli(workspaceDir, worktreeInfo, task),+ };const issueFilingSection = skipDevContext? ''- : buildIssueFilingSection({ providerId, model: providerModel, taskBody: [task.description, contextBlock] });+ : [+ buildIssueFilingSection({ ...attributionOptions, taskBody: [task.description, contextBlock] }),+ buildPrAttributionSection(attributionOptions),+ ].filter(Boolean).join('\n\n');const uiAuditRuntimeSection = isUiAuditTask(task) ? UI_AUDIT_RUNTIME_RULE : '';return finalizePrompt(buildFullAgentPrompt({@@ -1124,6 +1128,7 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, { isTui = t// and a model cannot name itself.const lightFilingSection = buildIssueFilingSection({ providerId, model: providerModel, forgeCli: resolvedForgeCli, taskBody: [task.description, context] });if (lightFilingSection) contractSections.push(lightFilingSection);+ contractSections.push(buildPrAttributionSection({ model: providerModel, forgeCli: resolvedForgeCli }));// --- Orchestrated execution ---------------------------------------------// Sits directly after planner attribution and before the worktree/completiondiff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex f200320494..733885e583 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -4627,6 +4627,47 @@ describe('TUI reviewLoopFollowUp completion instructions', () => {});});+describe('PR model attribution', () => {+ // Both entry points deliberately disable CoS PR provisioning: the claim+ // prompt owns creation, so gating attribution on openPR loses these runs.+ it.each([+ ['scheduled CLI', 'cli', { analysisType: 'claim-issue' }, 'gh'],+ ['manual TUI', 'tui', { claimFlow: true }, 'gh'],+ ['scheduled API', 'api', { analysisType: 'claim-issue' }, 'gh'],+ ['manual GitLab API', 'api', { claimFlow: true, workTracker: 'gitlab' }, 'glab'],+ ])('labels PRs from %s claims with the dispatched model', async (_name, providerType, metadata, forgeCli) => {+ const task = makeTask({+ description: 'Custom claim prompt: implement and open a PR.',+ metadata: { ...metadata, useWorktree: false, openPR: false },+ });+ const worktreeInfo = forgeCli === 'glab' ? { forgeCli } : null;+ const result = await buildAgentPrompt(task, {}, '/repo', worktreeInfo, {+ providerType, providerId: 'example-runner', providerModel: 'claude-opus-5',+ });+ const prompt = typeof result === 'string' ? result : result.userPrompt;+ const label = forgeCli === 'glab' ? 'implementer::opus-5' : 'implementer:opus-5';+ expect(prompt).toContain('## PR Model Attribution');+ expect(prompt).toContain(`--label ${label}`);+ expect(prompt).toContain(forgeCli === 'glab' ? `glab label create --name ${label}` : `gh label create ${label}`);+ expect(prompt).toContain(forgeCli === 'glab' ? 'glab mr create' : 'gh pr create');+ expect(prompt).toContain(forgeCli === 'glab' ? `glab mr update <mr> --label ${label}` : `gh pr edit <pr> --add-label ${label}`);+ expect(prompt).toContain('read the PR/MR labels back');+ expect(prompt).toContain('opening agent must use its own trusted runtime model');+ expect(prompt).toContain('preserve its original opener attribution');+ expect(prompt).not.toContain('implementer:example-runner');+ });++ it('reports unknown attribution instead of calling a provider the model', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { claimFlow: true, openPR: false } }), '/repo', null,+ { providerId: 'example-runner' },+ );+ expect(prompt).toContain('PortOS did not resolve a model for this run');+ expect(prompt).toContain('report the missing attribution');+ expect(prompt).not.toContain('implementer:example-runner');+ });+});+// A filing agent cannot reliably name its own model, so PortOS resolves the// planner identity from the provider/model the run was actually dispatched with// and hands the agent the finished label. The regression this catches is thediff --git a/server/services/promptSections/README.md b/server/services/promptSections/README.mdindex 5f933885e9..1780032815 100644--- a/server/services/promptSections/README.md+++ b/server/services/promptSections/README.md@@ -11,6 +11,7 @@ Leaf modules used by `agentPromptBuilder.js`. The builder remains the public fac| `instructions.js` | Skill-template routing and bounded instruction-file discovery. || `orchestrationDoctrine.js` | The architect doctrine an orchestrated run (#5992) gets — role/provider/model table, delegate-exploration and emit-specs rules, and the six-part spec contract incl. the pass-through `REASONING:` rung. Empty for a `direct` task. || `plannerAttribution.js` | Runtime issue-filing contract for every CLI/API task, plus the `planner:<model>` label resolved from the run's own provider/model. |+| `prAttribution.js` | PR/MR opener model label (`implementer:<model>`), supplied at runtime for scheduled and manual claims, including custom prompts. || `reviewLifecycle.js` | Reviewer, CI-gate, and merge sections. || `slashdo.js` | Slashdo invocation and procedure expansion. || `taskContext.js` | Task, attachment, split-context, and compaction sections. |diff --git a/server/services/promptSections/prAttribution.js b/server/services/promptSections/prAttribution.jsnew file mode 100644index 0000000000..a31eb00b75--- /dev/null+++ b/server/services/promptSections/prAttribution.js@@ -0,0 +1,17 @@+import { forgeLabelName, formatLabelCreateCommand, normalizePlannerId } from '../../lib/dispatchLabels.js';+import { shellQuote } from '../../lib/shellQuote.js';++/** Runtime identity reaches stored/custom claim prompts without rewriting them. */+export function buildPrAttributionSection({ model = null, forgeCli = 'gh' } = {}) {+ // A provider name identifies a runner, not the model that opened the PR.+ const id = normalizePlannerId(model);+ const heading = '## PR Model Attribution';+ if (!id) return `${heading}\n\nWhen opening a PR/MR, use the model supplied by your trusted execution context for an implementer:<model> label (implementer::<model> on GitLab). PortOS did not resolve a model for this run. Never guess from your provider name, issue routing labels, reviewer model, or self-identification. If no model can be verified, report the missing attribution in your completion summary.`;+ const cli = forgeCli === 'glab' ? 'glab' : 'gh';+ const label = forgeLabelName(`implementer:${id}`, { cli });+ const create = cli === 'glab' ? 'glab mr create' : 'gh pr create';+ const edit = cli === 'glab' ? `glab mr update <mr> --label ${shellQuote(label)}` : `gh pr edit <pr> --add-label ${shellQuote(label)}`;+ return `${heading}\n\nPR opener model for this run: ${id}. When YOU open a PR/MR (including scheduled claim-issue and manual direct claims), add \`--label ${shellQuote(label)}\` to \`${create}\`. This is independent of issue dispatch tiers (model:/effort:) and planner attribution; never copy those as PR authorship.+Create the repository label if missing: \`${formatLabelCreateCommand(label, { cli })}\`. After creation, read the PR/MR labels back and verify that \`${label}\` is present. If missing, apply \`${edit}\` and verify again. Report any unresolved label failure in your completion summary; do not claim attribution succeeded.+If you delegate PR creation, the opening agent must use its own trusted runtime model, not this coordinator's label or a reviewer's model. When resuming an existing PR, preserve its original opener attribution; repair a missing label only with evidence of the original opener's model.`;+}