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

refactor([issue-708]): hoist parseBulletList into digital-twin-helpers

[._.]/ Adam Eivyc5fdf5efc3e5
diff --git a/server/services/digital-twin-adversarial-testing.js b/server/services/digital-twin-adversarial-testing.js
index 52ca00ea8e..f380d002f5 100644
--- a/server/services/digital-twin-adversarial-testing.js
+++ b/server/services/digital-twin-adversarial-testing.js
@@ -19,7 +19,7 @@ import { existsSync } from 'fs';
import { join } from 'path';
import { getProviderById } from './providers.js';
import { buildPrompt } from './promptService.js';
-import { DIGITAL_TWIN_DIR, generateId, now, callProviderAI, parseScorerVerdict, resolveTestPersona } from './digital-twin-helpers.js';
+import { DIGITAL_TWIN_DIR, generateId, now, callProviderAI, parseScorerVerdict, resolveTestPersona, parseBulletList } from './digital-twin-helpers.js';
import { loadMeta, saveMeta, cache, CACHE_TTL_MS } from './digital-twin-meta.js';
import { getDigitalTwinForPrompt } from './digital-twin-context.js';
@@ -76,13 +76,6 @@ export async function parseAdversarialSuite() {
return scenarios;
}
-function parseBulletList(block) {
- return block
- .split('\n')
- .map(line => line.replace(/^[-*]\s*/, '').trim())
- .filter(Boolean);
-}
-
export async function runAdversarialTests(providerId, model, testIds = null, personaId = null) {
const scenarios = await parseAdversarialSuite();
// A persona flavors the embodied identity so the scenarios measure boundary
diff --git a/server/services/digital-twin-helpers.js b/server/services/digital-twin-helpers.js
index 8bbca5586e..b0e8273fd5 100644
--- a/server/services/digital-twin-helpers.js
+++ b/server/services/digital-twin-helpers.js
@@ -52,6 +52,18 @@ export function parseScorerVerdict(response, verdicts, fallback = 'partial') {
return { result, reasoning };
}
+/**
+ * Parse a markdown bullet list (`- item` / `* item`) into a trimmed string
+ * array, dropping blanks. Shared by the values-alignment and adversarial-
+ * boundary suite parsers (the "Values at Stake" / "Boundary Tested" blocks).
+ */
+export function parseBulletList(block) {
+ return (block || '')
+ .split('\n')
+ .map(line => line.replace(/^[-*]\s*/, '').trim())
+ .filter(Boolean);
+}
+
/**
* Resolve a persona id (as passed to a test runner) into the fields stamped on
* a test-history entry, so a run can be attributed to the persona it embodied.
diff --git a/server/services/digital-twin-helpers.test.js b/server/services/digital-twin-helpers.test.js
index ea01a99515..77e86f9539 100644
--- a/server/services/digital-twin-helpers.test.js
+++ b/server/services/digital-twin-helpers.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
-import { resolveTestPersona } from './digital-twin-helpers.js';
+import { resolveTestPersona, parseBulletList } from './digital-twin-helpers.js';
// resolveTestPersona maps a persona id (as passed to a test runner) into the
// `{ personaId, personaName }` fields stamped on a run-history entry, so a run
@@ -30,3 +30,24 @@ describe('resolveTestPersona', () => {
expect(resolveTestPersona(null, 'p1')).toEqual({});
});
});
+
+// parseBulletList turns a markdown bullet block (the "Values at Stake" /
+// "Boundary Tested" sections of a suite) into a trimmed string array. Shared by
+// the values-alignment and adversarial-boundary suite parsers.
+describe('parseBulletList', () => {
+ it('parses dash and asterisk bullets, trimming each item', () => {
+ expect(parseBulletList('- integrity\n* craftsmanship\n- reliability ')).toEqual([
+ 'integrity', 'craftsmanship', 'reliability'
+ ]);
+ });
+
+ it('drops blank lines', () => {
+ expect(parseBulletList('- a\n\n- b\n')).toEqual(['a', 'b']);
+ });
+
+ it('returns an empty array for empty or non-string input', () => {
+ expect(parseBulletList('')).toEqual([]);
+ expect(parseBulletList(null)).toEqual([]);
+ expect(parseBulletList(undefined)).toEqual([]);
+ });
+});
diff --git a/server/services/digital-twin-values-testing.js b/server/services/digital-twin-values-testing.js
index 6bccd9fdae..22f141d292 100644
--- a/server/services/digital-twin-values-testing.js
+++ b/server/services/digital-twin-values-testing.js
@@ -18,7 +18,7 @@ import { existsSync } from 'fs';
import { join } from 'path';
import { getProviderById } from './providers.js';
import { buildPrompt } from './promptService.js';
-import { DIGITAL_TWIN_DIR, generateId, now, callProviderAI, parseScorerVerdict, resolveTestPersona } from './digital-twin-helpers.js';
+import { DIGITAL_TWIN_DIR, generateId, now, callProviderAI, parseScorerVerdict, resolveTestPersona, parseBulletList } from './digital-twin-helpers.js';
import { loadMeta, saveMeta, cache, CACHE_TTL_MS } from './digital-twin-meta.js';
import { getDigitalTwinForPrompt } from './digital-twin-context.js';
@@ -75,13 +75,6 @@ export async function parseValuesAlignmentSuite() {
return dilemmas;
}
-function parseBulletList(block) {
- return block
- .split('\n')
- .map(line => line.replace(/^[-*]\s*/, '').trim())
- .filter(Boolean);
-}
-
/**
* Render the user's ranked values into a readable block for the scorer prompt.
* Returns a sentinel string (not empty) when no hierarchy is recorded, so the