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

feat: add repo study context to brain capture

[._.]/ Adam Eivye9a18d778667
diff --git a/client/src/components/QuickBrainCapture.jsx b/client/src/components/QuickBrainCapture.jsx
index 818a2728a3..76c5f65042 100644
--- a/client/src/components/QuickBrainCapture.jsx
+++ b/client/src/components/QuickBrainCapture.jsx
@@ -220,6 +220,8 @@ export default function QuickBrainCapture() {
managedApps={repoIntake.managedApps}
targetAppId={repoIntake.targetAppId}
onTargetAppChange={repoIntake.setTargetAppId}
+ studyContext={repoIntake.studyContext}
+ onStudyContextChange={repoIntake.setStudyContext}
onToggle={repoIntake.toggle}
/>
diff --git a/client/src/components/QuickBrainCapture.test.jsx b/client/src/components/QuickBrainCapture.test.jsx
index cb87116640..6f226510a3 100644
--- a/client/src/components/QuickBrainCapture.test.jsx
+++ b/client/src/components/QuickBrainCapture.test.jsx
@@ -166,6 +166,24 @@ describe('QuickBrainCapture', () => {
});
});
+ it('sends optional study context with the repo study request', async () => {
+ renderWidget();
+ type(REPO);
+ fireEvent.click(screen.getByLabelText('Study for app ideas'));
+ fireEvent.change(screen.getByLabelText(/study context/i), {
+ target: { value: 'Look for the indexing approach and where it could fit in search.' },
+ });
+ fireEvent.click(screen.getByLabelText('Capture'));
+
+ await waitFor(() => expect(captureBrainThought).toHaveBeenCalled());
+ expect(captureBrainThought.mock.calls[0][3].repoIntake).toEqual({
+ malwareScan: false,
+ learn: true,
+ targetAppId: 'portos-default',
+ studyContext: 'Look for the indexing approach and where it could fit in search.',
+ });
+ });
+
it('remembers the choice across mounts', () => {
const { unmount } = renderWidget();
type(REPO);
diff --git a/client/src/components/brain/RepoIntakeOptions.jsx b/client/src/components/brain/RepoIntakeOptions.jsx
index 246299b2b0..5458c18311 100644
--- a/client/src/components/brain/RepoIntakeOptions.jsx
+++ b/client/src/components/brain/RepoIntakeOptions.jsx
@@ -32,9 +32,11 @@ export const REPO_INTAKE_OPTIONS = [
* @param {{owner: string, repo: string}|null} props.repo parsed repo, or null to
* render nothing (the capture isn't a bare repo URL)
* @param {{malwareScan: boolean, learn: boolean}} props.options
+ * @param {string} props.studyContext
+ * @param {(context: string) => void} props.onStudyContextChange
* @param {(key: string) => void} props.onToggle
*/
-export default function RepoIntakeOptions({ idPrefix, repo, options, managedApps = [], targetAppId, onTargetAppChange, onToggle }) {
+export default function RepoIntakeOptions({ idPrefix, repo, options, managedApps = [], targetAppId, onTargetAppChange, studyContext = '', onStudyContextChange, onToggle }) {
if (!repo) return null;
return (
@@ -71,6 +73,22 @@ export default function RepoIntakeOptions({ idPrefix, repo, options, managedApps
</select>
</label>
)}
+ {options.learn && (
+ <div>
+ <label htmlFor={`${idPrefix}-study-context`} className="block text-xs text-gray-400 mb-1">
+ Study context <span className="text-gray-600">(optional)</span>
+ </label>
+ <textarea
+ id={`${idPrefix}-study-context`}
+ rows={3}
+ maxLength={5000}
+ value={studyContext}
+ onChange={e => onStudyContextChange?.(e.target.value)}
+ placeholder="What should the agent look for, and where might an implementation fit?"
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ />
+ </div>
+ )}
{REPO_INTAKE_OPTIONS.some(({ key }) => options[key]) && (
<p className="text-xs text-gray-500">
A CoS agent starts once the clone finishes — track it in Chief of Staff.
diff --git a/client/src/components/brain/tabs/InboxTab.jsx b/client/src/components/brain/tabs/InboxTab.jsx
index 48e96dc0b7..10140508bb 100644
--- a/client/src/components/brain/tabs/InboxTab.jsx
+++ b/client/src/components/brain/tabs/InboxTab.jsx
@@ -369,6 +369,8 @@ export default function InboxTab({ onRefresh, settings }) {
managedApps={repoIntake.managedApps}
targetAppId={repoIntake.targetAppId}
onTargetAppChange={repoIntake.setTargetAppId}
+ studyContext={repoIntake.studyContext}
+ onStudyContextChange={repoIntake.setStudyContext}
onToggle={repoIntake.toggle}
/>
</form>
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 8e85a14e2a..4cc77b1f55 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -182,7 +182,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useSongTraining` | Drives a song training run over one scope (whole song or a sliced section) on top of `useColorMatch`: counts in, walks + grades the scope's score, then folds the finished take into the rolling progress history (`songProgress.recordAttempt`) and surfaces the next aggregate via `onProgress`. Supports looping (auto-restart after a run) and keeps a `lastSummary`. Exposes `{ running, countingIn, noteColors, activeIndex, lastSummary, start, stop }`; cancels pending loop relaunches on stop/unmount. | The Song editor's Training panel. |
| `useSyncIntegrity` | Fetches per-kind integrity diff from every eligible online peer; reduces to worst-case `statusById` + `byPeer` breakdown maps. | Federated media sync integrity UI — badges, drawers, peer breakdown. |
| `useTwinEvaluationSuite` | Shared lifecycle for the three Digital Twin evaluation-suite panels (Values-Alignment, Adversarial-Boundary, Multi-Turn): loads suite + recent history (silenced), runs every selected provider/model in parallel, prepends fresh runs, and handles the stale-persona / partial-failure toast fan-out. `countField` names the suite's pass-count key so history stays generic. Returns `{ items, history, loading, running, results, expanded, setExpanded, run, reload }`. | The Digital Twin `TwinEvaluationSuitePanel` presentation shell — don't re-roll the load/run/history dance per suite. |
-| `useRepoIntake` | The Brain capture boxes' GitHub-repo state: `repo` (the parsed `{owner,repo}` when the ENTIRE capture text is a repo URL — i.e. exactly when the server will clone it), the two sticky post-clone agent opt-ins (`options`/`toggle`, persisted to `localStorage`), and `intakeFor(submittedText)` which re-derives at submit time so a sticky tick can't ride along on a capture retyped into a plain thought. Also exports the pure `capturedGitHubRepo(text)`. | Any capture surface that should offer the malware-scan / repo-study runs. Render with `components/brain/RepoIntakeOptions`; don't re-parse the text in the component. |
+| `useRepoIntake` | The Brain capture boxes' GitHub-repo state: `repo` (the parsed `{owner,repo}` when the ENTIRE capture text is a repo URL — i.e. exactly when the server will clone it), the two sticky post-clone agent opt-ins (`options`/`toggle`, persisted to `localStorage`), per-capture repo-study context, and `intakeFor(submittedText)` which re-derives at submit time so a sticky tick can't ride along on a capture retyped into a plain thought. Also exports the pure `capturedGitHubRepo(text)`. | Any capture surface that should offer the malware-scan / repo-study runs. Render with `components/brain/RepoIntakeOptions`; don't re-parse the text in the component. |
| `useRenderJobQueue` | Per-entry render-job queue for the Universe Builder — `pendingByEntryId` (entryId → jobId[]), `pendingHeadByEntryId` (first jobId per entry for single-subscription thumbs), `enqueueEntryJobs` (append variation/canon jobs), `clearPendingForEntry` (shift a jobId out, or drop the entry). | Universe Builder render orchestration. Don't re-roll the per-entry pending-jobs reducer. |
| `useUniverse` | Loads the universe record for a `universeId` with mount/cancel guards; returns `[universe, setUniverse, loading, error]` (setter exposed for optimistic post-mutation updates). | Any surface that loads a linked universe (pipeline stages, etc.) — use instead of re-rolling the getUniverse-on-mount effect. |
| `useUniverseAction` | LLM-driven universe mutation scaffolding. | Universe Builder action UIs. |
diff --git a/client/src/hooks/useRepoIntake.js b/client/src/hooks/useRepoIntake.js
index 0b48948db7..3243f7f9a7 100644
--- a/client/src/hooks/useRepoIntake.js
+++ b/client/src/hooks/useRepoIntake.js
@@ -37,7 +37,8 @@ export function capturedGitHubRepo(text) {
/**
* @param {string} text the current capture text
- * @returns {{ repo: object|null, options: object, toggle: (key: string) => void,
+ * @returns {{ repo: object|null, options: object, studyContext: string,
+ * setStudyContext: (context: string) => void, toggle: (key: string) => void,
* intakeFor: (text: string) => object|undefined }}
* `repo` is the parsed `{ owner, repo }` (null when the text isn't a bare repo
* URL) — both the panel and the host's hint read it, so the text is parsed
@@ -51,6 +52,7 @@ export function useRepoIntake(text) {
const [learn, setLearn] = useLocalStorageBool(STORAGE_KEYS.learn, false);
const [managedApps, setManagedApps] = useState([{ id: PORTOS_APP_ID, name: 'PortOS' }]);
const [targetAppId, setTargetAppId] = useState(PORTOS_APP_ID);
+ const [studyContext, setStudyContext] = useState('');
const repo = useMemo(() => capturedGitHubRepo(text), [text]);
const options = useMemo(() => ({ malwareScan, learn }), [malwareScan, learn]);
@@ -75,9 +77,14 @@ export function useRepoIntake(text) {
managedApps,
targetAppId,
setTargetAppId,
+ studyContext,
+ setStudyContext,
toggle: (key) => setters[key](v => !v),
intakeFor: (submitted) => (capturedGitHubRepo(submitted)
- ? { ...options, ...(learn ? { targetAppId } : {}) }
+ ? { ...options, ...(learn ? {
+ targetAppId,
+ ...(studyContext.trim() ? { studyContext: studyContext.trim() } : {}),
+ } : {}) }
: undefined),
};
}
diff --git a/client/src/services/apiBrain.js b/client/src/services/apiBrain.js
index 6b1f52af9a..3f9738cd6a 100644
--- a/client/src/services/apiBrain.js
+++ b/client/src/services/apiBrain.js
@@ -10,8 +10,9 @@ export const updateBrainSettings = (settings, options = {}) => request('/brain/s
});
// Brain - Capture & Inbox
-// `repoIntake` ({ malwareScan, learn }) is the capture box's post-clone agent
-// opt-in; the server ignores it unless the text is a bare GitHub repo URL.
+// `repoIntake` ({ malwareScan, learn, targetAppId, studyContext }) is the
+// capture box's post-clone agent opt-in; the server ignores it unless the text
+// is a bare GitHub repo URL.
export const captureBrainThought = (text, providerOverride, modelOverride, { creative, repoIntake } = {}, options = {}) => request('/brain/capture', {
method: 'POST',
body: JSON.stringify({ text, providerOverride, modelOverride, creative, repoIntake }),
diff --git a/server/lib/brainValidation.js b/server/lib/brainValidation.js
index efda6b82cf..ce14efe02c 100644
--- a/server/lib/brainValidation.js
+++ b/server/lib/brainValidation.js
@@ -192,7 +192,8 @@ export const reviewRecordSchema = z.object({
// from REPO_INTAKE_KEYS so the wire contract can't drift from the normalizer
// that reads it (server/lib/repoIntakeActions.js).
export const repoIntakeSchema = z.object(optionalBooleanMap(REPO_INTAKE_KEYS)).extend({
- targetAppId: z.string().trim().min(1).max(200).optional()
+ targetAppId: z.string().trim().min(1).max(200).optional(),
+ studyContext: z.string().trim().max(5000).optional()
});
const repoIntakeInputSchema = repoIntakeSchema.optional();
diff --git a/server/lib/repoIntakeActions.js b/server/lib/repoIntakeActions.js
index 88d55ecff4..66a5a04e29 100644
--- a/server/lib/repoIntakeActions.js
+++ b/server/lib/repoIntakeActions.js
@@ -22,7 +22,7 @@ export const REPO_INTAKE_KEYS = ['malwareScan', 'learn'];
* from scheduling a no-op intake pass after each clone.
*
* @param {unknown} input
- * @returns {{ malwareScan: boolean, learn: boolean } | null}
+ * @returns {{ malwareScan: boolean, learn: boolean, targetAppId?: string, studyContext?: string } | null}
*/
export function normalizeRepoIntake(input) {
if (!isPlainObject(input)) return null;
@@ -31,5 +31,8 @@ export function normalizeRepoIntake(input) {
if (normalized.learn && typeof input.targetAppId === 'string' && input.targetAppId.trim()) {
normalized.targetAppId = input.targetAppId.trim();
}
+ if (normalized.learn && typeof input.studyContext === 'string' && input.studyContext.trim()) {
+ normalized.studyContext = input.studyContext.trim();
+ }
return normalized;
}
diff --git a/server/lib/repoIntakeActions.test.js b/server/lib/repoIntakeActions.test.js
index 79d03ff4ab..326ed00c62 100644
--- a/server/lib/repoIntakeActions.test.js
+++ b/server/lib/repoIntakeActions.test.js
@@ -40,6 +40,18 @@ describe('normalizeRepoIntake', () => {
expect(normalizeRepoIntake(true)).toBeNull();
});
+ it('keeps trimmed study context only for repo study', () => {
+ expect(normalizeRepoIntake({ learn: true, studyContext: ' Find the best seam. ' })).toEqual({
+ malwareScan: false,
+ learn: true,
+ studyContext: 'Find the best seam.',
+ });
+ expect(normalizeRepoIntake({ malwareScan: true, studyContext: 'ignored' })).toEqual({
+ malwareScan: true,
+ learn: false,
+ });
+ });
+
it('covers exactly the two documented actions', () => {
expect(REPO_INTAKE_KEYS).toEqual(['malwareScan', 'learn']);
});
diff --git a/server/services/repoIntake.js b/server/services/repoIntake.js
index 69200343ad..b72b053549 100644
--- a/server/services/repoIntake.js
+++ b/server/services/repoIntake.js
@@ -102,8 +102,11 @@ Use that path as SCAN_DIR. Adhere to every Operational Invariant in the workflow
* Build the `repo-study` agent context. Kept separate from the queueing so the
* wording is assertable without going through the task store.
*/
-export function buildRepoStudyContext(link, { appName, repoPath, trackerInstructions }) {
- return `A GitHub repository was captured into the Brain and cloned locally. Study it as a source of IDEAS for ${appName} and record the adoptable ones in the work tracker.
+export function buildRepoStudyContext(link, { appName, repoPath, trackerInstructions, studyContext }) {
+ const requesterContext = typeof studyContext === 'string' && studyContext.trim()
+ ? `\n## Additional context from the requester\n\n${studyContext.trim()}\n`
+ : '';
+ return `A GitHub repository was captured into the Brain and cloned locally. Study it as a source of IDEAS for ${appName} and record the adoptable ones in the work tracker.${requesterContext}
## The repository under study
@@ -142,7 +145,7 @@ End with: the studied repo, its license, how many proposals you filed (with thei
*
* @returns {Promise<{ queued: boolean, reason?: string, taskId?: string, linkPatch?: object }>}
*/
-export async function queueRepoStudy(link, targetAppId = PORTOS_APP_ID) {
+export async function queueRepoStudy(link, targetAppId = PORTOS_APP_ID, studyContext) {
if (!isCloneReadable(link)) return { queued: false, reason: 'not-cloned' };
const app = await getAppById(targetAppId || PORTOS_APP_ID);
@@ -171,6 +174,7 @@ export async function queueRepoStudy(link, targetAppId = PORTOS_APP_ID) {
trackerInstructions: trackerInstructions
.replace(/\{appName\}/g, () => app.name)
.replace(/\{repoPath\}/g, () => app.repoPath),
+ studyContext,
}),
// The deliverable is tracker items, not code — the agent reads PortOS and
// the clone, then files. No worktree, no PR, no review loop.
@@ -218,7 +222,7 @@ export async function runRepoIntake(link, intake) {
for (const [key, queue] of Object.entries(INTAKE_QUEUERS)) {
if (!requested[key]) continue;
const result = key === 'learn'
- ? await queue(link, requested.targetAppId).catch(err => ({ queued: false, reason: err.message }))
+ ? await queue(link, requested.targetAppId, requested.studyContext).catch(err => ({ queued: false, reason: err.message }))
: await queue(link).catch(err => ({ queued: false, reason: err.message }));
if (result.queued) patch = { ...patch, ...result.linkPatch };
else console.error(`❌ Capture-time ${key} not queued for link ${link.id}: ${result.reason}`);
diff --git a/server/services/repoIntake.test.js b/server/services/repoIntake.test.js
index 9769d1abe8..09f1bc7524 100644
--- a/server/services/repoIntake.test.js
+++ b/server/services/repoIntake.test.js
@@ -181,6 +181,17 @@ describe('buildRepoStudyContext', () => {
expect(body).toMatch(/Clean-room/);
expect(body).toMatch(/LICENSE/);
});
+
+ it('includes requester context as guidance for the study', () => {
+ const body = buildRepoStudyContext(LINK, {
+ appName: 'PortOS',
+ repoPath: '/srv/portos',
+ trackerInstructions: 'FILE HERE',
+ studyContext: 'Look for indexing improvements and where they fit in search.',
+ });
+ expect(body).toContain('## Additional context from the requester');
+ expect(body).toContain('Look for indexing improvements and where they fit in search.');
+ });
});
describe('runRepoIntake', () => {
@@ -196,6 +207,11 @@ describe('runRepoIntake', () => {
expect(patch.repoStudy).toEqual({ taskId: 'task-abc', queuedAt: expect.any(String) });
});
+ it('passes requester context into the queued repo study', async () => {
+ await runRepoIntake(LINK, { learn: true, studyContext: 'Focus on the search architecture.' });
+ expect(addTask.mock.calls[0][0].context).toContain('Focus on the search architecture.');
+ });
+
it('stamps a queued scan as `queued`, so the UI does not link at a missing report', async () => {
const patch = await runRepoIntake(LINK, { malwareScan: true });
expect(patch.malwareScan).toEqual({