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: resolve GitHub login at run time in repo maintenance job (#12499)
[._.]/ Adam Eivy5405db013603
diff --git a/server/services/autonomousJobs/defaults.js b/server/services/autonomousJobs/defaults.jsindex ce8cf6c4a9..a48f6e0d54 100644--- a/server/services/autonomousJobs/defaults.js+++ b/server/services/autonomousJobs/defaults.js@@ -9,6 +9,7 @@* customizations are preserved.*/+import { createHash } from 'crypto'import { DAY, WEEK, JOB_STRUCTURAL_FIELDS, JOB_ADDITIVE_FIELDS } from './constants.js'import { PORTOS_CATALOG_REFRESH_JOB } from './portosCatalogRefresh.js'import { PORTOS_CLI_CATALOG_REFRESH_JOB } from './portosCliCatalogRefresh.js'@@ -31,7 +32,7 @@ const DEFAULT_JOBS = [You are acting as my Chief of Staff, performing automated maintenance checks across all my GitHub repositories.-My GitHub username is: atomantic+Resolve my GitHub login at run time with \`gh api user -q .login\` and use that login for every query below.Use the \`gh\` CLI to query GitHub.@@ -362,6 +363,35 @@ Focus on actionable findings. The goal is to keep the wiki healthy as it grows.`},]+/**+ * sha256 of promptTemplate bodies that shipped earlier and are retired. A stored+ * copy whose body matches one is an untouched default and is upgraded on merge.+ * Hashes only: the retired text lives in git history, not in code.+ */+const RETIRED_JOB_PROMPT_SHA256 = {+ 'job-github-repo-maintenance': [+ // Pre-#12499 body, which hardcoded a fixed GitHub username.+ 'de63362ff8c5da05a638448d9b0f51a4b1bd59bda02bd9258ee0635748edf095'+ ]+}++const sha256 = (text) => createHash('sha256').update(text).digest('hex')++/**+ * Upgrade a stored promptTemplate that is still an untouched retired default.+ * The snapshot compare in applyAdditiveFields cannot see these: a job that+ * predates _shippedDefaults is bootstrapped to the current body and kept as-is.+ */+function upgradeRetiredPromptTemplate(existing, defaultJob) {+ const retired = RETIRED_JOB_PROMPT_SHA256[defaultJob.id]+ if (!retired || typeof existing.promptTemplate !== 'string') return false+ if (existing.promptTemplate === defaultJob.promptTemplate) return false+ if (!retired.includes(sha256(existing.promptTemplate))) return false+ existing.promptTemplate = defaultJob.promptTemplate+ existing._shippedDefaults = { ...(existing._shippedDefaults || {}), promptTemplate: defaultJob.promptTemplate }+ return true+}+/*** Create initial jobs data with defaults*/@@ -478,6 +508,7 @@ function mergeWithDefaults(loaded) {}// Additive fields: snapshot-aware merge — propagates updates to untouched fields,// preserves user customizations+ if (upgradeRetiredPromptTemplate(existing, defaultJob)) changed = trueif (applyAdditiveFields(existing, defaultJob)) changed = trueif (changed) {existing.updatedAt = nowdiff --git a/server/services/autonomousJobs/defaults.test.js b/server/services/autonomousJobs/defaults.test.jsnew file mode 100644index 0000000000..b651288c9c--- /dev/null+++ b/server/services/autonomousJobs/defaults.test.js@@ -0,0 +1,45 @@+import { describe, it, expect } from 'vitest'+import { DEFAULT_JOBS, mergeWithDefaults } from './defaults.js'++const REPO_MAINTENANCE_ID = 'job-github-repo-maintenance'+const LOGIN_LINE = 'Resolve my GitHub login at run time with `gh api user -q .login` and use that login for every query below.'+const shippedRepoMaintenance = () => DEFAULT_JOBS.find(j => j.id === REPO_MAINTENANCE_ID)++// The body shipped before the fixed-username fix. Rebuilt from the current+// shipped text so the test does not carry a second copy of the prompt.+const retiredRepoMaintenanceBody = () => shippedRepoMaintenance().promptTemplate.replace(+ `${LOGIN_LINE}\n\n`,+ 'My GitHub username is: atomantic\n\n'+)++const storedJob = (promptTemplate, extra = {}) => ({+ ...shippedRepoMaintenance(),+ promptTemplate,+ _shippedDefaults: undefined,+ createdAt: '2025-01-01T00:00:00.000Z',+ updatedAt: '2025-01-01T00:00:00.000Z',+ ...extra+})++const mergedRepoMaintenance = (job) => mergeWithDefaults({ version: 1, jobs: [job] })+ .data.jobs.find(j => j.id === REPO_MAINTENANCE_ID)++describe('GitHub Repo Maintenance shipped default', () => {+ it('resolves the operator login at run time instead of hardcoding one', () => {+ const { promptTemplate } = shippedRepoMaintenance()+ expect(promptTemplate).toContain('gh api user -q .login')+ expect(promptTemplate).not.toMatch(/username is:|atomantic/)+ })++ it('upgrades an untouched pre-snapshot copy of the retired default to the shipped prompt', () => {+ const job = mergedRepoMaintenance(storedJob(retiredRepoMaintenanceBody()))+ expect(job.promptTemplate).toBe(shippedRepoMaintenance().promptTemplate)+ expect(job._shippedDefaults.promptTemplate).toBe(shippedRepoMaintenance().promptTemplate)+ })++ it('leaves a user-edited prompt alone', () => {+ const edited = 'My own maintenance prompt for my repos.'+ const job = mergedRepoMaintenance(storedJob(edited))+ expect(job.promptTemplate).toBe(edited)+ })+})