@prismshadow/penguin-library-agent · library/agent/src/agent-config-service.ts:126

AgentConfigService

component

No JSDoc comment in source yet.

API

@Component()
export class AgentConfigService implements AgentConfig {
  @Use() private readonly paths!: AgentPaths;
  async exists(projectId: string, agentId: string): Promise<boolean>;
  async requireExists(projectId: string, agentId: string): Promise<void>;
  isSystemAgent(projectId: string, agentId: string): Promise<boolean>;
  isBuiltinAgent(projectId: string, agentId: string): Promise<boolean>;
  async readCardMeta(projectId: string, agentId: string): Promise<{
    name?: string;
    description?: string;
    author: AgentAuthor;
    toolCount: number;
    /** Package owners from valid stored MCP entries, omitted if the config could not be read. */
    mcpPluginNames?: string[];
    version: number;
    kernelOutdated: boolean;
    system?: true;
  }>;
  async getConfig(projectId: string, agentId: string): Promise<AgentConfigView>;
  async updateConfig(projectId: string, agentId: string, req: AgentConfigUpdateRequest): Promise<void>;
  async stampMissingAuthor(projectId: string, agentId: string, author: AgentAuthor): Promise<boolean>;
  async resetConfig(projectId: string, agentId: string): Promise<void>;
  async kernelUpdate(projectId: string, agentId: string): Promise<AgentKernelUpdateResponse>;
  static applyConfigFields(doc: Document, config: NonNullable<AgentConfigUpdateRequest["config"]>): void;
  async insertTemplatePlaceholder(projectId: string, agentId: string, feature: "vault" | "skills" | "schedules"): Promise<AgentConfigView>;
  async getVault(projectId: string, agentId: string): Promise<VaultResponse>;
  async updateVault(projectId: string, agentId: string, req: VaultUpdateRequest): Promise<VaultResponse>;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
paths: AgentPaths

Methods (14)

exists

async exists(projectId: string, agentId: string): Promise<boolean>

Whether the Agent exists (determined by the presence of system_config.yaml, matching the CLI's convention).

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<boolean>

requireExists

async requireExists(projectId: string, agentId: string): Promise<void>
@paramprojectIdstring
@paramagentIdstring
@returnsPromise<void>

isSystemAgent

isSystemAgent(projectId: string, agentId: string): Promise<boolean>
@paramprojectIdstring
@paramagentIdstring
@returnsPromise<boolean>

isBuiltinAgent

isBuiltinAgent(projectId: string, agentId: string): Promise<boolean>
@paramprojectIdstring
@paramagentIdstring
@returnsPromise<boolean>

readCardMeta

async readCardMeta(projectId: string, agentId: string): Promise<{ name?: string; description?: string; author: AgentAuthor; toolCount: number; mcpPluginNames?: string[]; version: number; kernelOutdated: boolean; system?: true; }>

Read list-card metadata: name / description + tool count (sum of tools.builtin and tools.mcpServers entries; MCP counted per server), and system on the system Agent. Silently falls back to empty / 0 if the file is corrupt.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<{ name?: string; description?: string; author: AgentAuthor; toolCount: number; mcpPluginNames?: string[]; version: number; kernelOutdated: boolean; system?: true; }>

getConfig

async getConfig(projectId: string, agentId: string): Promise<AgentConfigView>

Structured config view (matching the edit form's shape) + raw text + AGENTS.md + State path.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<AgentConfigView>

updateConfig

async updateConfig(projectId: string, agentId: string, req: AgentConfigUpdateRequest): Promise<void>

PUT accepts any subset: only the provided keys are updated (parseDocument preserves comments and untouched content); agentsMd is overwritten in full. Numeric validation: >0 or -1; thinkingLevel / mode are validated as enums. The system Agent's name, description and author are refused (409 builtin_agent_locked).

@paramprojectIdstring
@paramagentIdstring
@paramreqAgentConfigUpdateRequest
@returnsPromise<void>

stampMissingAuthor

async stampMissingAuthor(projectId: string, agentId: string, author: AgentAuthor): Promise<boolean>

Writes author into the Agent's config only when the file has none, in place like a PUT (comments and formatting kept). Answers whether it wrote: false when the file already names an author, whatever its value, and when there is no config to write into — the file is never created, nor rewritten when it does not parse.

@paramprojectIdstring
@paramagentIdstring
@paramauthorAgentAuthor
@returnsPromise<boolean>

resetConfig

async resetConfig(projectId: string, agentId: string): Promise<void>

Overwrites system_config.yaml with the current code defaults (core's resetSystemConfigToDefaults) — same semantics as updating an installed skill: only the identity fields (name / description / author / version) survive; the system prompt, max_turns, model/compaction settings and the tool list (incl. MCP servers) become the current defaults. AGENTS.md, skills and the vault are untouched.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<void>

kernelUpdate

async kernelUpdate(projectId: string, agentId: string): Promise<AgentKernelUpdateResponse>

Smart-merges the config up to the current defaults generation (core's applyKernelUpdate): a settings tab still carrying a recorded generation's default follows the new defaults, a tab the user changed is kept whole and reported; the config is stamped with the new kernel version. The destructive full-refresh alternative stays resetConfig.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<AgentKernelUpdateResponse>

applyConfigFields

applyConfigFields(doc: Document, config: NonNullable<AgentConfigUpdateRequest["config"]>): void

A config write's checks and edits on doc: each provided key is checked (400) and set.

@paramdocDocument
@paramconfigNonNullable<AgentConfigUpdateRequest["config"]>
@returnsvoid

insertTemplatePlaceholder

async insertTemplatePlaceholder(projectId: string, agentId: string, feature: "vault" | "skills" | "schedules"): Promise<AgentConfigView>

Inserts a feature's section placeholder into the Agent's prompt template — the explicit adoption path mirroring the Memory tab's endpoint; nothing ever inserts automatically. For skills/vault the insert is migration-first (core's helpers): a stored template still carrying the legacy hardcoded section verbatim gets it replaced in place by the placeholder, otherwise the placeholder is inserted before # Environment. Idempotent; returns the refreshed config view (the route picks out the feature's DTO).

@paramprojectIdstring
@paramagentIdstring
@paramfeature"vault" | "skills" | "schedules"
@returnsPromise<AgentConfigView>

getVault

async getVault(projectId: string, agentId: string): Promise<VaultResponse>

Read the Agent vault (agent_state/.vault.toml): values are always masked, plaintext is never sent to the client.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<VaultResponse>

updateVault

async updateVault(projectId: string, agentId: string, req: VaultUpdateRequest): Promise<VaultResponse>

PUT replaces the whole vault table (same semantics as models): keys absent from the body are deleted; omitting value keeps the existing value (a new key must provide a value). Key names are validated against shell environment variable naming rules (same rule as core); deleting everything removes the whole .vault.toml file.

@paramprojectIdstring
@paramagentIdstring
@paramreqVaultUpdateRequest
@returnsPromise<VaultResponse>