Skip to content

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

move Suno song-row picking into a shared lib

Adam Eivyf0f25ddc5e19
diff --git a/server/lib/README.md b/server/lib/README.md
index 7a48623908..9ae8c07281 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -675,6 +675,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `dispatchLabels.js` | slashdo dispatch-hint contract: the `model:` capability and `effort:` reasoning-budget label vocabulary (the tiers themselves live in this module and are deliberately not re-enumerated here — a catalog copy of them is what drifted a tier behind), prescribed forge colors, validation (`normalizeDispatchModel` / `normalizeDispatchEffort`), the read-side inverse (`dispatchHintFromLabels` — recovers `{model, effort}` from a raw label-name list, used by branch-reconcile's per-branch routing hint), the per-forge label separator (`labelSeparator` / `forgeLabelName` — GitLab spells every prefixed label with its native scoped `::`, GitHub keeps `:`, and the read side accepts both; applied once at the `forgeIssueLabels` / `dispatchLabelSpec` boundary so the axis builders stay canonical; Jira keeps the hyphen form), optional contributor labels (`good first issue` / `help wanted`, never implied by `model:light`, and released at claim time by `formatContributorLabelReleaseCommands` — one best-effort command per label, since a forge fails the whole edit when a named label is absent), the one shared volunteer-claim policy (`volunteerClaimLabels` / `formatVolunteerClaimCommands` — a human comment claiming an unassigned issue is resolved by BOTH issueWatcher.js's deterministic pass and the claim prompt's Phase 1 handoff, so both stamp `in-progress` and retire the invitations rather than writing opposite state), the open-ended planner-attribution axis (`planner:<model>`, `normalizePlannerId` / `resolvePlannerId` / `formatPlannerLabelGuidance` — records WHICH model wrote the plan, prefix-matched by `dispatchLabelSpec` so it lazily creates like the fixed labels; a filing agent takes the value from its prompt, never from self-identification), the workflow-state markers (`EPIC_LABEL`/`EPIC_DECOMPOSED_LABEL` and `IN_PROGRESS_LABEL` — state, not hints: shared with perpetualWork.js#isActionableIssue, issueReconcile.js's zombie scan, issueWatcher.js's volunteer assignment, and the claim prompts), lazy-create command text, the optional `--label` slots a rendered `issue create` example offers (`OPTIONAL_ISSUE_LABEL_FLAG_SLOTS` / `formatOptionalIssueLabelFlags` — one list so a new axis reaches every prompt template's copy-pasteable command, not just its prose), and shared dispatch plus issue-quality guidance (`ISSUE_QUALITY_GUIDANCE`, `DISPATCH_HINT_GUIDANCE`, `MANDATORY_DISPATCH_HINT_GUIDANCE`, `JIRA_DISPATCH_HINT_GUIDANCE`, `MANDATORY_JIRA_DISPATCH_HINT_GUIDANCE`, `REFERENCE_WATCH_LABEL_CONTRACT`, plus the consumer-side pair `DISPATCH_HINT_READING_GUIDANCE` / `DISPATCH_HINT_FANOUT_GUIDANCE` — what the labels mean to an agent that RECEIVES them (the preloaded `open-issues` task data input) and, for an orchestrator only, how to route each sub-agent by its own issue (the swarm block); the fan-out form is the reading form plus one line, never a second copy of the vocabulary). All forge filing callers require both dispatch axes and verify labels after creation; help wanted requires specific hardware validation or valuable input from real users; never invent `medium`; reject future-only/speculative work while keeping useful current refactors claimable. Consumed by work-tracker instructions, quota-burn audits, Layered Intelligence filing, and claim follow-up prompts. |
| `distrokidForm.js` | The in-page steps of the DistroKid upload recipe (#10337): `fillDistrokidFields` (genre, language, store profiles, credits, preview start, the track's normal answers), `discloseDistrokidAi` (inline AI checkboxes, gate then parts) and `untickDistrokidExtras` (paid extras). Self-contained so `page.evaluate` can ship them, and tested against a fixture form in the client's DOM tests. |
| `sunoPage.js` | The in-page step of the Suno publish recipe: `markSunoSongMenu(songId)` tags the song page's OWN "More options" button with `data-portos-song-menu` (false when there is none), skipping the menus of other songs the page shows: the "Cover of" card of the song a cover was made from, the Similar / By-artist lists, the playbar. Runs inside the page via `page.evaluate`, so it reads only `document`; fixture tests live in `client/src/lib/sunoPage.test.js`. |
+| `sunoSongPicker.js` | `pickSongRow(rows, { songId, durationSec, title })`: which Suno Hook picker row is the project song: by id when a row carries it, else the one row with the song's length, else the only row; -1 when rows cannot be told apart. |
| `distrokidGenres.js` | DistroKid's store genre list (`DISTROKID_GENRES`) and `suggestDistrokidGenres(project)`, a first primary/secondary genre guess from the song's own style words. Shared by the DistroKid publish payload and the publish panel's genre pickers. |
| `domainAutonomy.js` | Per-domain autonomy guardrails (pure). `AUTONOMY_DOMAINS`/`DOMAIN_IDS`/`DOMAIN_MODES` (`off`/`dry-run`/`execute`), `getDomainMode(config, id)`, and `normalizeDomainAutonomy(raw)` to coerce a hand-edited/partial map. Default per domain is `execute` (reproduces pre-#711 behavior, so no migration needed). Also `CREATIVE_DOMAIN`/`getCreativeAutonomyMode(config)` (#2183) — the Creative Director orchestrator domain, kept out of `DOMAIN_IDS` and defaulting to mirror the `cos` mode. |
| `domainBudgets.js` | Per-domain daily autonomy budgets (pure). `BUDGET_LIMIT_FIELDS` (`maxActionsPerDay`/`maxMinutesPerDay`), `getDomainBudget(config, id)`, `normalizeDomainBudgets(raw)`, `hasBudget(budget)`, and `evaluateBudget(budget, usage)` → `{ withinBudget, exceeded }`. A `null`/non-positive cap means unlimited (default per domain, so no migration needed). Token/$ caps are intentionally absent — CLI subscription providers expose no per-run metering. Usage ledger + gate wiring live in `services/domainUsage.js`. |
diff --git a/server/lib/index.js b/server/lib/index.js
index 11524eb9e9..1e5ec5d375 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -649,6 +649,7 @@ export * from './dispatchLabels.js';
export * from './distrokidForm.js';
export * from './distrokidGenres.js';
export * from './sunoPage.js';
+export * from './sunoSongPicker.js';
export * from './domainAutonomy.js';
export * from './domainBudgets.js';
export * from './eidoverseCreativeToolkit.js';
diff --git a/server/lib/sunoSongPicker.js b/server/lib/sunoSongPicker.js
new file mode 100644
index 0000000000..ff2a39bb4c
--- /dev/null
+++ b/server/lib/sunoSongPicker.js
@@ -0,0 +1,19 @@
+/** Picking a song out of Suno's picker rows (#10375). */
+
+const fmtClock = (sec) => `${Math.floor(sec / 60)}:${String(Math.floor(sec % 60)).padStart(2, '0')}`;
+
+/**
+ * Which picker row is the song: by id when a row carries it, else by the one
+ * row with the song's length, else the only row. Pure; rows are `{ text, html }`.
+ */
+export function pickSongRow(rows, { songId, durationSec, title }) {
+ const byId = rows.findIndex((r) => songId && r.html.toLowerCase().includes(songId.toLowerCase()));
+ if (byId >= 0) return byId;
+ const named = rows.map((r, i) => [r, i]).filter(([r]) => !title || r.text.toLowerCase().includes(title.toLowerCase()));
+ const pool = named.length ? named : rows.map((r, i) => [r, i]);
+ if (pool.length === 1) return pool[0][1];
+ const clock = Number.isFinite(durationSec) ? fmtClock(Math.round(durationSec)) : null;
+ const sameLength = clock ? pool.filter(([r]) => r.text.includes(clock)) : [];
+ if (sameLength.length === 1) return sameLength[0][1];
+ return -1;
+}
diff --git a/server/services/musicVideo/publish/sunoHook.js b/server/services/musicVideo/publish/sunoHook.js
index 4a9fbbb016..8a9664cc07 100644
--- a/server/services/musicVideo/publish/sunoHook.js
+++ b/server/services/musicVideo/publish/sunoHook.js
@@ -9,6 +9,7 @@
* else a drag calibrated at WAVEFORM_PX_PER_SEC. Either way the page's own m:ss
* label is read back and the fill fails rather than post the wrong stretch.
*/
+import { pickSongRow } from '../../../lib/sunoSongPicker.js';
import { PUBLISH_STEP_TIMEOUT_MS as T, clickVisibleText, loginRequired, step } from './browser.js';
const CREATE_URL = 'https://suno.com/hooks/create';
@@ -24,22 +25,6 @@ const parseClock = (text) => {
return m ? Number(m[1]) * 60 + Number(m[2]) : null;
};
-/**
- * Which picker row is the song: by id when a row carries it, else by the one
- * row with the song's length, else the only row. Pure; rows are `{ text, html }`.
- */
-export function pickSongRow(rows, { songId, durationSec, title }) {
- const byId = rows.findIndex((r) => songId && r.html.toLowerCase().includes(songId.toLowerCase()));
- if (byId >= 0) return byId;
- const named = rows.map((r, i) => [r, i]).filter(([r]) => !title || r.text.toLowerCase().includes(title.toLowerCase()));
- const pool = named.length ? named : rows.map((r, i) => [r, i]);
- if (pool.length === 1) return pool[0][1];
- const clock = Number.isFinite(durationSec) ? fmtClock(Math.round(durationSec)) : null;
- const sameLength = clock ? pool.filter(([r]) => r.text.includes(clock)) : [];
- if (sameLength.length === 1) return sameLength[0][1];
- return -1;
-}
-
async function selectSong(page, payload) {
await page.locator('text=Select Song').first().click({ timeout: T });
await page.locator('[role=dialog]').first().waitFor({ timeout: T });
diff --git a/server/services/musicVideo/publish/sunoHook.test.js b/server/services/musicVideo/publish/sunoHook.test.js
index d330ef7f85..28f44f9dfd 100644
--- a/server/services/musicVideo/publish/sunoHook.test.js
+++ b/server/services/musicVideo/publish/sunoHook.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
-import { pickSongRow } from './sunoHook.js';
+import { pickSongRow } from '../../../lib/sunoSongPicker.js';
import { buildPublishPayload } from './payloads.js';
import { captureMusicVideoEvidence } from '../../../lib/musicVideoDependencies.js';