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
refactor: collapse the label-creation policy and a redundant scrub pass /simplify surfaced (#7687)
[._.]/ Adam Eivyad910644b8c5
diff --git a/server/services/appIssues.js b/server/services/appIssues.jsindex f92bb2a566..a1e0d21de5 100644--- a/server/services/appIssues.js+++ b/server/services/appIssues.js@@ -344,12 +344,13 @@ export const scrubForgeIssueText = (value) => scrubSecretTokens(scrubHomePath(va* cheap reachability probe (`ensureForgeReachable` is gh-specific), so a* non-`gh` cli is always reported reachable. One definition instead of the* two near-duplicate inline blocks `persistentMindIssueCapability.js` and- * `goalFidelityFollowUp.js` each carried, plus the probe `forgeFiler.js` never- * had at all (#7687).+ * `goalFidelityFollowUp.js` each carried (#7687). `forgeFiler.js`'s callers+ * don't currently resolve a hostname to pass in, so this doesn't by itself+ * close that filer's reachability gap — tracked in #7695.*/export async function probeForgeReachability({ cli, hostname, env = null, label }) {if (cli !== 'gh' || !hostname) return { ok: true };- const forge = await ensureForgeReachable(label, { hostname, ...(env ? { env } : {}) });+ const forge = await ensureForgeReachable(label, { hostname, env });if (forge.ok) return { ok: true };return { ok: false, error: `GitHub is not reachable (${forge.status}); ${forge.remedy || 'check `gh auth status`'}` };}@@ -362,7 +363,7 @@ export async function probeForgeReachability({ cli, hostname, env = null, label* and a caller that already has an injectable exec (`runCli`, or a test* double shaped like it) can pass it straight through instead.*/-async function execForgeIssueCli(cli, args, { cwd = undefined, env = undefined } = {}) {+async function execForgeIssueCli(cli, args, { cwd, env } = {}) {const run = cli === 'glab'? execGlab(args, cwd, undefined, { env, rejectOnError: true }): execGh(args, undefined, { cwd, env });@@ -375,14 +376,16 @@ async function execForgeIssueCli(cli, args, { cwd = undefined, env = undefined }/*** Create every label an issue is about to carry, before the issue itself.* Both CLIs 422 the whole `issue create` on an undefined label, so this always- * runs first. One label-failure policy for every filer (#7687): an "already+ * runs first. One label-failure policy for every filer (#7687) — including+ * `applyBlockingLabel`'s own label-only path in `forgeFiler.js`, which delegates+ * here rather than re-running its own "already exists" check: an "already* exists" reply is expected and fine (label creation is otherwise idempotent),* anything else aborts the file — a permission or auth problem should surface* now rather than let the caller proceed to a create that is doomed anyway (or,* worse, silently ships without the label a caller assumed would exist).* Returns the first hard-failure message, or `null` when every label is ready.*/-async function ensureForgeIssueLabels({ cli, exec, cwd, env, repo, labels }) {+export async function ensureForgeIssueLabels({ cli, exec, cwd, env, repo = null, labels }) {const results = await Promise.all(labels.map(async (spec) => {const { code, stdout, stderr } = await exec(cli, forgeLabelCreateArgs(cli, spec, { repo }), { cwd, env });if (code === 0) return null;diff --git a/server/services/layeredIntelligence/constants.js b/server/services/layeredIntelligence/constants.jsindex e7c99ee1d2..cccf56a98b 100644--- a/server/services/layeredIntelligence/constants.js+++ b/server/services/layeredIntelligence/constants.js@@ -18,6 +18,12 @@ import { extractTaskType } from '../taskLearning/store.js';export const LI_LABEL = 'layered-intelligence';export const LI_BLOCKING_LABEL = 'layered-intelligence:blocking';+// `{ name, color, description }` for the two LI marker labels, so every caller+// that needs to CREATE one (`ensureForgeLabels`, `fileProposalToForge`) shares+// the same literal instead of two copies that can silently drift apart.+export const LI_LABEL_SPEC = Object.freeze({ name: LI_LABEL, color: '1d76db', description: 'Filed by the Layered Intelligence loop' });+export const LI_BLOCKING_LABEL_SPEC = Object.freeze({ name: LI_BLOCKING_LABEL, color: 'b60205', description: 'Layered Intelligence loop is paused on this issue' });+// The tracker label marking an issue as work the user has COMMITTED to — the// `plannedWork` source's filter (#2698). PortOS's own roadmap "lives entirely in// the GitHub issue tracker" as `plan`-labeled issues, and that convention is thediff --git a/server/services/layeredIntelligence/forgeFiler.js b/server/services/layeredIntelligence/forgeFiler.jsindex 6d881935d7..38cc6ae8d9 100644--- a/server/services/layeredIntelligence/forgeFiler.js+++ b/server/services/layeredIntelligence/forgeFiler.js@@ -8,12 +8,11 @@import { dispatchLabelSpec, forgeIssueLabels, isDispatchModel, isDispatchEffort } from '../../lib/dispatchLabels.js';import { safeJSONParse } from '../../lib/fileUtils.js';import { normalizeIssueState } from '../../lib/forgeIssueState.js';-import { LI_LABEL, LI_BLOCKING_LABEL } from './constants.js';+import { LI_LABEL, LI_BLOCKING_LABEL, LI_LABEL_SPEC, LI_BLOCKING_LABEL_SPEC } from './constants.js';import { slugMarker, extractSlugFromBody } from './dedup.js';import { runCli } from './runCli.js';import { withGlabJson } from '../../lib/glabArgs.js';-import { forgeLabelCreateArgs } from '../../lib/forgeIssueCli.js';-import { fileForgeIssue } from '../appIssues.js';+import { fileForgeIssue, ensureForgeIssueLabels } from '../appIssues.js';export { normalizeIssueState };@@ -220,29 +219,21 @@ export async function listBlockingIssues({ cli, cwd, env, exec = runCli } = {})/*** Ensure the layered-intelligence labels exist before the first `issue create`- * (gh/glab both fail creating an issue with a non-existent label). An existing- * label is deliberately left unchanged: it belongs to the repository, so only- * that expected duplicate error is treated as success.+ * (gh/glab both fail creating an issue with a non-existent label). Delegates+ * the actual create-and-tolerate-duplicates loop to `ensureForgeIssueLabels`+ * (#7687) — the same label-failure policy every forge filer now shares —+ * rather than re-running its own "already exists" check, and re-throws its+ * one hard-failure message so this function's own (pre-#7687) throwing+ * contract stays intact for `applyBlockingLabel` below.*/export async function ensureForgeLabels({ cli, cwd, env, extraLabels = [], exec = runCli } = {}) {const labels = [- { name: LI_LABEL, color: '1d76db', desc: 'Filed by the Layered Intelligence loop' },- { name: LI_BLOCKING_LABEL, color: 'b60205', desc: 'Layered Intelligence loop is paused on this issue' },- ...extraLabels.map((name) => dispatchLabelSpec(name, { cli })).filter(Boolean).map((s) => ({- name: s.name, color: s.color, desc: s.description- }))+ LI_LABEL_SPEC,+ LI_BLOCKING_LABEL_SPEC,+ ...extraLabels.map((name) => dispatchLabelSpec(name, { cli })).filter(Boolean),];- for (const l of labels) {- const { code, stdout, stderr } = await exec(- cli,- forgeLabelCreateArgs(cli, { name: l.name, color: l.color, description: l.desc }),- { cwd, env }- );- const output = `${stderr || ''}\n${stdout || ''}`;- if (code !== 0 && !/label.*already exists|already exists.*label/i.test(output)) {- throw new Error(`${cli} label create failed for "${l.name}": ${stderr || `exited with code ${code}`}`);- }- }+ const error = await ensureForgeIssueLabels({ cli, exec, cwd, env, labels });+ if (error) throw new Error(error);}/**@@ -261,8 +252,9 @@ export async function fileProposalToForge({if (!isDispatchModel(model) || !isDispatchEffort(effort)) {return { success: false, error: 'Issue filing requires valid model and effort dispatch labels; investigate and supply both before retrying' };}- const names = [LI_LABEL, ...forgeIssueLabels({ model, effort, goodFirstIssue, helpWanted, planner, cli })];- const labels = names.map((name) => dispatchLabelSpec(name, { cli }) || { name, color: '1d76db', description: 'Filed by the Layered Intelligence loop' });+ const extras = forgeIssueLabels({ model, effort, goodFirstIssue, helpWanted, planner, cli })+ .map((name) => dispatchLabelSpec(name, { cli }));+ const labels = [LI_LABEL_SPEC, ...extras.filter(Boolean)];const result = await fileForgeIssue({ cli, cwd, env, title, body: `${body}\n\n${slugMarker(slug)}`, labels, exec });return result.ok? { success: true, number: result.number, url: result.url }diff --git a/server/services/persistentMindIssueCapability.js b/server/services/persistentMindIssueCapability.jsindex 9521537a99..4ad44d7870 100644--- a/server/services/persistentMindIssueCapability.js+++ b/server/services/persistentMindIssueCapability.js@@ -162,7 +162,10 @@ export async function filePersistentMindIssue(args) {}// Scrubbed BEFORE the duplicate check, not just before the create: the title// that dedupes has to be the title that gets filed, or an issue whose only- // leaked path was in its title would re-file itself on every wake.+ // leaked path was in its title would re-file itself on every wake. Used only+ // for the dedup key here — `fileForgeIssue` below gets the RAW args and+ // scrubs its own copy, so the text is scrubbed exactly once rather than+ // twice for the same request.const title = scrubForgeIssueText(args.title);const body = scrubForgeIssueText(args.body);@@ -193,7 +196,7 @@ export async function filePersistentMindIssue(args) {].filter((name, index, all) => all.indexOf(name) === index);const created = await fileForgeIssue({- cli, title, body, repoPath: app.repoPath,+ cli, title: args.title, body: args.body, repoPath: app.repoPath,repo: cli === 'glab' ? null : app.repoSpec,labels: labels.map((name) => labelSpec(name, cli)).filter(Boolean),});