The agent service's component declaration: it keeps the server's manifest key
(@prismshadow/penguin-server#AgentService, the one plugins require) while the class lives
in this package; the server's provider node — named AgentService, as the component was —
builds and binds it, so this declaration is not itself an assembled node.
API
@Component({ name: "AgentServiceImpl", key: "@prismshadow/penguin-server#AgentService" })
export class AgentService implements AgentLifecycle {
@Use() private readonly paths!: AgentPaths;
@Use() private readonly agents!: AgentIndex;
@Use() private readonly agentConfig!: AgentConfig;
@Use() private readonly snapshots!: Snapshots;
@Use() private readonly library!: AgentPluginLibrary;
@Use() private readonly pluginInstaller!: AgentPluginInstaller;
@Use() private readonly pluginModules!: AgentPluginModules;
@Use() private readonly workbenches!: AgentWorkbenches;
@Use() private readonly directorySkills!: AgentDirectorySkills;
setup(ctx: ClassCtx);
async listAgents(projectId: string): Promise<AgentListItem[]>;
async takenAgentIds(projectId: string): Promise<string[]>;
async pluginVersion(projectId: string, agentId: string, pluginName: string): Promise<{ installed: string | null; library: string | null }>;
async updatePlugin(projectId: string, agentId: string, pluginName: string): Promise<void>;
async deleteAgent(projectId: string, agentId: string): Promise<AgentDeletionInfo>;
agentDeletion(projectId: string, deletionId: string): AgentDeletionInfo | null;
async resumeDeletions(): Promise<void>;
async createAgent(projectId: string, agentId: string, creation: AgentCreation = {}): Promise<AgentListItem>;
}Dependencies & Wiring
Extracted from class decoratorspaths: AgentPaths · agents: AgentIndex · agentConfig: AgentConfig · snapshots: Snapshots · library: AgentPluginLibrary · pluginInstaller: AgentPluginInstaller · pluginModules: AgentPluginModules · workbenches: AgentWorkbenches · directorySkills: AgentDirectorySkillsMethods (9)
listAgents
async listAgents(projectId: string): Promise<AgentListItem[]>Union of DB index ∪ directory scan; unmanaged directory Agents are backfilled into the DB.
Only what AgentConfig.exists accepts is listed — the rule every route checks. A Project
made before the system Agent existed is given it first (see ensureSystemAgent).
stringPromise<AgentListItem[]>takenAgentIds
async takenAgentIds(projectId: string): Promise<string[]>Every id createAgent refuses as taken, as names only: the index rows and every entry under
agents/. Unlike listAgents, this includes a folder with no system_config.yaml, and it
opens no Agent.
stringPromise<string[]>pluginVersion
async pluginVersion(projectId: string, agentId: string, pluginName: string): Promise<{ installed: string | null; library: string | null }>Where one library plugin stands on one Agent, as one pair of dated versions of the same
part — so library newer than installed is exactly "some part is behind", the rule
installedPlugins draws the list cards' hints from. Each part the Agent carries (a
skill, the hook package) is paired with the library's same part; among the parts that are
behind — or, when none is, among all of them — the one with the OLDEST installed version
answers. installed is null when the Agent carries none of the plugin's parts, with
library then the plugin's content version; both are null when the library has no such
plugin. Only the head of each SKILL.md is read (see SKILL_HEAD_BYTES), so the answer costs
one small read per skill the plugin ships.
The organization runtime asks this per employee per pass to keep company plugins current. A skill the Agent does not carry — never installed, or removed by hand — counts for nothing: a plugin whose carried skills are all current reads as current even where one of them is missing. Restoring a deleted skill is the Agents page's business, not a pass's.
stringstringstringPromise<{ installed: string | null; library: string | null }>updatePlugin
async updatePlugin(projectId: string, agentId: string, pluginName: string): Promise<void>Reinstall one library plugin over an Agent's copy: the same whole-plugin update the
Agents page performs, through the same plugin writer the plugin-installer port binds,
which overwrites every skill the plugin ships and its hook package with library content.
A server name another
owner holds refuses the write with core's own McpServerNameTakenError — the holder's
server, agent and ownership ride the error, untranslated, for the org's reconcile to
record. Throws 404
unknown_plugin when the library does not carry the name. Callers that may hold a cached
runtime for the Agent invalidate it afterwards — hook packages are bound when a core
Session is built, unlike skills, which are read from disk on demand. The plugin's server
modules are the caller's to bring along, after everything else it does with this generation
(the plugin-modules port's ensure re-assembles the App; company mode's reconcile calls it last).
stringstringstringPromise<void>deleteAgent
async deleteAgent(projectId: string, agentId: string): Promise<AgentDeletionInfo>Delete an Agent: the built-in Agents cannot be deleted; callers must first drain any active
run (the session manager's beginAgentDeletion) and let go of what holds the folder open.
The folder (Agent State, Traces, scratchpads, temporary Workspaces) is moved to
agents/.deleting/<id>-<time> in one rename and the index row dropped: from then on no list
shows the Agent and no route accepts it, and a new Agent may take its id. The move is the
whole of what the caller waits for — the contents are removed in the background, reported by
the deletion returned (and by agentDeletion as it goes). A folder that cannot be moved is
refused with nothing deleted (409 agent_folder_busy). Usage records are kept (historical
stats are unaffected); the caller drops the Agent's other index rows.
stringstringPromise<AgentDeletionInfo>agentDeletion
agentDeletion(projectId: string, deletionId: string): AgentDeletionInfo | nullstringstringAgentDeletionInfo | nullresumeDeletions
async resumeDeletions(): Promise<void>Every folder left under a Project's agents/.deleting/ — a deletion the last process did
not finish, or one that met an entry it could not remove — is removed again, one after
another. Folders a deletion of this process is already removing are left to it.
Promise<void>createAgent
async createAgent(projectId: string, agentId: string, creation: AgentCreation = {}): Promise<AgentListItem>Create an Agent: the id is chosen by the creator (a semantic id, checked for
duplicates against both the DB and the directory within the Project — a 409
if taken, which naturally also blocks built-in Agent ids, and 409 agent_id_reserved for
the system Agent's id where the Project does not have it yet) → initialize State →
write name/description (name defaults to the id) → install the seed plugins.
pluginNames are library plugin names picked at creation; they go through the same
installPlugin writer the plugin routes use, inside the same cleanup window as the rest
of initialization, so an Agent never survives with only part of its picked set. They are
resolved before anything is created, so an unknown name creates no directory at all. The
library's default-install plugins join them (the seed port) only when defaultPlugins is
explicitly true — installing plugins the creator did not ask for is a download they did not
consent to, so nothing is seeded by omission. The system Agent is provisioned by core's
presets, never through here.
archive is an Agent package (the import route's): the fresh Agent takes its State, name,
description and version instead of the template's, and its Traces land once the State is
in. An invalid package fails the whole creation inside the same cleanup window, leaving no
empty Agent behind.
author says how this Agent came to be, user when the creator names none, and is written
into a template-made Agent. An imported Agent keeps the package's own author (none reads
as user): an import moves an existing Agent, it does not make a new one.
stringstringAgentCreationPromise<AgentListItem>