Extract global agent doctrine source
This commit is contained in:
parent
2c75beb449
commit
4617f3b320
7 changed files with 89 additions and 41 deletions
32
apps/persona-scheduler/src/global-agent-doctrine-source.ts
Normal file
32
apps/persona-scheduler/src/global-agent-doctrine-source.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
export type GlobalAgentDoctrineObservation =
|
||||
| { status: "ok"; path: string; doctrine: string; attemptedPaths: string[] }
|
||||
| { status: "unavailable"; attemptedPaths: string[]; errors: string[] };
|
||||
|
||||
export async function readGlobalAgentDoctrine(input: {
|
||||
codexHome?: string;
|
||||
userProfile?: string;
|
||||
homeDirectory?: string;
|
||||
readText?: (path: string) => Promise<string>;
|
||||
} = {}): Promise<GlobalAgentDoctrineObservation> {
|
||||
const attemptedPaths = [...new Set([
|
||||
input.codexHome ? resolve(input.codexHome, "AGENTS.md") : undefined,
|
||||
input.userProfile ? resolve(input.userProfile, ".codex", "AGENTS.md") : undefined,
|
||||
resolve(input.homeDirectory ?? homedir(), ".codex", "AGENTS.md"),
|
||||
].filter((value): value is string => Boolean(value?.trim())))];
|
||||
const errors: string[] = [];
|
||||
const readText = input.readText ?? ((path) => readFile(path, "utf8"));
|
||||
for (const path of attemptedPaths) {
|
||||
try {
|
||||
const doctrine = (await readText(path)).trim();
|
||||
if (doctrine) return { status: "ok", path, doctrine, attemptedPaths };
|
||||
errors.push(`${path}: empty file`);
|
||||
} catch (error) {
|
||||
errors.push(`${path}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
return { status: "unavailable", attemptedPaths, errors };
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import type { RepoDiscordIdentity, RepoFacePendingMention } from "@voidbot/core"
|
|||
import type { PromptImageAttachment, SourceMessage } from "@voidbot/shared";
|
||||
|
||||
import type { BifrostGovernanceDigest } from "./bifrost-governance-source.js";
|
||||
import type { GlobalAgentDoctrineObservation } from "./global-agent-doctrine-source.js";
|
||||
import type { InitiativeParticipant } from "./initiative-engine.js";
|
||||
import { projectPersonaConversation, type PersonaConversationProjection } from "./persona-conversation-projector.js";
|
||||
import type { PersonaHumanPronounGuidance } from "./persona-social-context-projector.js";
|
||||
|
|
@ -24,7 +25,7 @@ export interface PersonaTurnAssemblyInput {
|
|||
humanPronounGuidance?: PersonaHumanPronounGuidance[];
|
||||
bifrostDigest?: BifrostGovernanceDigest;
|
||||
githubActionsEnabled: boolean;
|
||||
globalAgentDoctrine: string;
|
||||
globalAgentDoctrine: GlobalAgentDoctrineObservation;
|
||||
}
|
||||
|
||||
export interface PersonaTurnAssembly {
|
||||
|
|
@ -57,7 +58,7 @@ export function assemblePersonaTurn(input: PersonaTurnAssemblyInput): PersonaTur
|
|||
pendingMentions: input.pendingMentions,
|
||||
jurisdictionDive: buildPersonaJurisdictionDiveDirective(input.identity, input.participant),
|
||||
githubActionsEnabled: input.githubActionsEnabled,
|
||||
globalAgentDoctrine: input.globalAgentDoctrine,
|
||||
globalAgentDoctrine: renderGlobalAgentDoctrine(input.globalAgentDoctrine),
|
||||
});
|
||||
return {
|
||||
prompt,
|
||||
|
|
@ -66,6 +67,19 @@ export function assemblePersonaTurn(input: PersonaTurnAssemblyInput): PersonaTur
|
|||
};
|
||||
}
|
||||
|
||||
function renderGlobalAgentDoctrine(observation: GlobalAgentDoctrineObservation): string {
|
||||
if (observation.status === "ok") return observation.doctrine;
|
||||
return [
|
||||
"# Global Agent Instructions Unavailable",
|
||||
"",
|
||||
"The global Codex AGENTS.md source returned no readable doctrine.",
|
||||
"This is an inspection failure, not replacement guidance. Do not claim global guidance was available for this turn.",
|
||||
"",
|
||||
"Attempted paths:",
|
||||
...observation.errors.map((error) => `- ${error}`),
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function collectPromptImages(messages: SourceMessage[]): PromptImageAttachment[] {
|
||||
const seen = new Set<string>();
|
||||
const images: PromptImageAttachment[] = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue