@prismshadow/penguin-library-project · library/project/src/project-service.ts:68

ProjectService

component

No JSDoc comment in source yet.

API

@Component({ name: "ProjectServiceImpl", key: "@prismshadow/penguin-server#ProjectService" })
export class ProjectService implements ProjectLifecycle {
  @Use() private readonly paths!: ProjectPaths;
  @Use() private readonly access!: Access;
  @Use() private readonly users!: Users;
  @Use() private readonly projects!: Projects;
  @Use() private readonly members!: Members;
  @Use() private readonly agents!: AgentIndex;
  @Use() private readonly sessions!: SessionIndex;
  @Use() private readonly usage!: UsageStore;
  @Use() private readonly errors!: ErrorLog;
  @Use() private readonly schedules!: Schedules;
  @Use() private readonly orgCache!: OrgCache;
  @Use() private readonly projectConfig!: ProjectConfigStore;
  @Use() private readonly manager!: ProjectRuns;
  @Use() private readonly traceIndex!: TraceIndex;
  @Use() private readonly agentApi!: AgentApi;
  @Use() private readonly drafts!: UserDraftsStore;
  @Use() private readonly dataMigrations!: ProjectDataMigrationLedger;
  @Use() private readonly pluginModules!: ProjectPreinstall;
  @Use() private readonly appSeeds!: ProjectAppSeeds;
  requireProjectAccess(userId: string, projectId: string): ProjectRow & { role: ProjectRole };
  canAccess(userId: string, projectId: string): boolean;
  requireProjectOwner(userId: string, projectId: string): ProjectRow;
  accessibleProjectIds(userId: string): string[];
  listProjects(userId: string): Promise<ProjectSummary[]>;
  async createProject(owner: UserRow, projectId: string, name?: string): Promise<ProjectSummary>;
  async takenProjectIds(): Promise<string[]>;
  async provisionInitialProject(user: UserRow, isAdmin: boolean): Promise<void>;
  async renameProject(userId: string, projectId: string, name: string): Promise<ProjectSummary>;
  async deleteProject(userId: string, projectId: string): Promise<void>;
  async destroyProject(projectId: string): Promise<void>;
  listMembers(userId: string, projectId: string): MemberInfo[];
  addMember(userId: string, projectId: string, targetUserId: string): MemberInfo;
  removeMember(userId: string, projectId: string, targetUserId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (19)
paths: ProjectPaths · access: Access · users: Users · projects: Projects · members: Members · agents: AgentIndex · sessions: SessionIndex · usage: UsageStore · errors: ErrorLog · schedules: Schedules · orgCache: OrgCache · projectConfig: ProjectConfigStore · manager: ProjectRuns · traceIndex: TraceIndex · agentApi: AgentApi · drafts: UserDraftsStore · dataMigrations: ProjectDataMigrationLedger · pluginModules: ProjectPreinstall · appSeeds: ProjectAppSeeds

Methods (14)

requireProjectAccess

requireProjectAccess(userId: string, projectId: string): ProjectRow & { role: ProjectRole }
@paramuserIdstring
@paramprojectIdstring
@returnsProjectRow & { role: ProjectRole }

canAccess

canAccess(userId: string, projectId: string): boolean
@paramuserIdstring
@paramprojectIdstring
@returnsboolean

requireProjectOwner

requireProjectOwner(userId: string, projectId: string): ProjectRow
@paramuserIdstring
@paramprojectIdstring
@returnsProjectRow

accessibleProjectIds

accessibleProjectIds(userId: string): string[]
@paramuserIdstring
@returnsstring[]

listProjects

listProjects(userId: string): Promise<ProjectSummary[]>
@paramuserIdstring
@returnsPromise<ProjectSummary[]>

createProject

async createProject(owner: UserRow, projectId: string, name?: string): Promise<ProjectSummary>

Create a Project: the id is chosen by the creator (a semantic id, checked for duplicates against both the DB and the directory — 409 if taken), the initial config is written (display name defaults to the id), the built-in Agent is initialized. A non-admin's id is forced to be "-", where the suffix is lowercase letters, digits, and underscores only — the hyphen is a reserved separator, usernames never contain a hyphen, so the first hyphen is the ownership boundary and the prefix can never be crafted from another username; an admin's id contains no hyphen (occupying no user's namespace). Then the preinstalled built-in modules are listed in the Project's own plugin table (PRFC-0030), which may re-assemble the App: nothing after it reads this generation's state. Last, the seeds built-in plugins ship for their system apps' data are written for the built-in packages that table now lists (app-seeds), from the data root alone.

@paramownerUserRow
@paramprojectIdstring
@paramname?string
@returnsPromise<ProjectSummary>

takenProjectIds

async takenProjectIds(): Promise<string[]>

Every id createProject refuses as taken, as names only: every row, and every name already under the data root's projects/, where the Project's directory would go — a directory with no row included, which no Project list shows. What sits at the data root's top level is the server's own and takes no id.

@returnsPromise<string[]>

provisionInitialProject

async provisionInitialProject(user: UserRow, isAdmin: boolean): Promise<void>

Initial Project provisioned at signup: the built-in admin adopts default_project (if the directory already exists, it's adopted directly without overwriting existing config — shared with the CLI); other users get <username>-default_project created, with display name defaulting to the username.

@paramuserUserRow
@paramisAdminboolean
@returnsPromise<void>

renameProject

async renameProject(userId: string, projectId: string, name: string): Promise<ProjectSummary>

Rename a Project's display name (owner): the id stays immutable — it names the directory, the Workspace paths and every stored reference — so only the label in project_config.toml changes. Returns the refreshed summary so the caller can swap it into its list without a reload.

@paramuserIdstring
@paramprojectIdstring
@paramnamestring
@returnsPromise<ProjectSummary>

deleteProject

async deleteProject(userId: string, projectId: string): Promise<void>

Delete a Project (owner): default_project is refused; deleting the user's last accessible Project is refused too (deleting it would leave the list empty, with no Project to select in the Web client and the page stuck on a skeleton screen — a typical case being a non-first user deleting the initial Project provisioned at signup); active runs are drained first, then the DB and directory are cleared.

@paramuserIdstring
@paramprojectIdstring
@returnsPromise<void>

destroyProject

async destroyProject(projectId: string): Promise<void>

The actual deletion (no authorization or protection checks): shared by deleteProject and the cascade cleanup when an admin deletes a user. Abort follow-up (writing the abort event to Trace, etc.) happens asynchronously: waits for runs to settle (capped at 5s) before deleting the directory, to avoid the Trace writer recreating the directory after deletion.

@paramprojectIdstring
@returnsPromise<void>

listMembers

listMembers(userId: string, projectId: string): MemberInfo[]

Member list: owner (role=owner) + members.

@paramuserIdstring
@paramprojectIdstring
@returnsMemberInfo[]

addMember

addMember(userId: string, projectId: string, targetUserId: string): MemberInfo

Grant member access (owner): invites by username; 404 if the user doesn't exist, 409 for the owner themself or an existing member.

@paramuserIdstring
@paramprojectIdstring
@paramtargetUserIdstring
@returnsMemberInfo

removeMember

removeMember(userId: string, projectId: string, targetUserId: string): void

Revoke member access (owner).

@paramuserIdstring
@paramprojectIdstring
@paramtargetUserIdstring
@returnsvoid