@hasna/projects
Version:
High-level project management CLI, MCP server, SDK, and AI SDK agent loop for coding agents
284 lines • 17.9 kB
TypeScript
import { type RootMatchInput, type RootMatchResult, type WorkspaceFilter } from "../db/workspaces.js";
import type { CredentialChainOptions } from "../types/client-types.js";
import { type ProjectResolverOptions } from "../lib/project-resolver.js";
import { type CreateProjectDataModelInput, type CreateProjectDataRecordInput, type LinkProjectLoopInput, type ProjectDataModel, type ProjectDataRecord, type ProjectLoopLink, type ProjectLoopSummary, type ProjectStoreSummary } from "../db/project-store.js";
import { type CreateProjectBudgetInput, type ProjectBudget, type ProjectBudgetContext, type ProjectBudgetSpend, type ProjectBudgetStatus, type ProjectSpendInput } from "../lib/budget.js";
import { type ProjectChannelEnsureResult, type StoreEnsureChannelOptions } from "../lib/project-channel.js";
import { type ProductionProjectRegistrationAuthorityOptions } from "../lib/production-project-registration-authorities.js";
import type { AppendReceiptInput, ProjectRegistrationManifestCreateInput, ProjectRegistrationManifestCreateResult, ProjectRegistrationManifestRecord, ProjectRegistrationReceipt, ProjectRegistrationReceiptLookupInput, ProjectRegistrationReceiptLookupResult, ProjectRegistrationReceiptQuery } from "../lib/project-registration.js";
import type { Agent, AgentRun, CreateAgentInput, CreateRecipeInput, CreateRootInput, CreateWorkspaceInput, EventSource, GuardedProjectMutationReceiptLookupInput, GuardedProjectMutationReceiptLookupResult, GuardedProjectReadRequest, GuardedProjectReadResult, GuardedProjectMutationRequest, GuardedProjectMutationResult, GuardedProjectMutationRollbackRequest, JsonObject, ProjectQuarantineRequest, ProjectQuarantineReadRequest, ProjectQuarantineReadResult, ProjectQuarantineResult, ProjectQuarantineRollbackRequest, ProjectResourceLinkMutationRequest, ProjectResourceLinkMutationResult, ProjectRelationMutationRequest, ProjectRelationMutationResult, ProjectRelationReadRequest, ProjectRelationReadResult, ProjectResourceLinkMigrationAdvanceRequest, ProjectResourceLinkMigrationPlanRequest, ProjectResourceLinkMigrationReadRequest, ProjectResourceLinkMigrationResult, ProjectResourceLinkMigrationRollbackRequest, ProjectResourceLinkReadRequest, ProjectResourceLinkReadResult, ProjectResourceLinkRollbackRequest, CreateTmuxProfileInput, CreateTmuxProfileWindowInput, Recipe, Root, TmuxProfile, TmuxProfileWindow, UpdateRootInput, UpdateWorkspaceInput, Workspace, WorkspaceAgentAssignment, WorkspaceEvent, WorkspaceLocation, WorkspaceLock, Machine } from "../types/workspace.js";
/** Process-environment shape accepted by the shared @hasna/contracts seam. */
type Env = Record<string, string | undefined>;
export type ProjectStoreTransport = "local" | "http";
/** Mutation provenance carried on every write (agent + audit trail). */
export interface MutationContext {
agentId?: string;
source?: EventSource;
command?: string;
prompt?: string;
reason?: string;
}
export interface DeleteProjectResult {
/** The deleted project row when the transport can return it (always local). */
workspace: Workspace | null;
hard: boolean;
/** Stable identifier for the deleted project (id or slug). */
id: string;
}
export interface DeleteRootResult {
root: Root;
detached_workspaces: number;
}
/** Explicit audit-event write (routes through the Store, never raw sqlite). */
export interface RecordEventInput {
event_type: string;
source: EventSource;
agentId?: string;
prompt?: string;
command?: string;
before?: JsonObject | null;
after?: JsonObject | null;
metadata?: JsonObject;
}
/** Filter for the prompt-agent run ledger read (on-box sub-resource). */
export interface AgentRunFilter {
workspace_id?: string;
agent_id?: string;
status?: AgentRun["status"];
limit?: number;
}
/** Assign a registered agent to a project role (on-box sub-resource). */
export interface AssignAgentInput {
/** Already-resolved agent id. */
agentId: string;
role?: string;
assignedBy?: string;
metadata?: JsonObject;
source?: EventSource;
command?: string;
}
/** Register another on-disk location for a project (on-box sub-resource). */
export interface AddLocationInput {
path: string;
machineId?: string;
label?: string;
kind?: string;
isPrimary?: boolean;
metadata?: JsonObject;
agentId?: string;
source?: EventSource;
command?: string;
}
export interface AddLocationResult {
project: Workspace;
location: WorkspaceLocation;
}
/** Acquire a project mutation lock (machine-local coordination primitive). */
export interface AcquireLockInput {
key: string;
workspaceId?: string;
agentId?: string;
reason?: string;
ttlSeconds?: number;
}
/**
* Operations that only exist on-box. Agent assignments, extra disk locations
* and mutation locks are modeled by the hosted /v1 API; project budgets and
* spend, the per-project app store (data models/records, loop links, `store
* inspect`) and tmux profiles live in on-box SQLite files with no hosted
* routes. Under a hosted credential no code path may open SQLite (owner ruling
* 2026-09-07, hasna/apps#1720), so every such access in the hosted transport
* throws this — a `REMOTE_COMMAND_UNSUPPORTED` refusal naming the explicit
* local opt-in — rather than silently reading/writing a local file the hosted
* project does not own, or returning an empty ledger (split-brain).
*/
export declare class LocalOnlyOperationError extends Error {
readonly code = "REMOTE_COMMAND_UNSUPPORTED";
constructor(operation: string);
}
/**
* A project list plus the metadata a caller needs to know whether it is the
* whole set. `projects list --json` used to emit a bare array that was capped
* server-side, so a truncated read and a complete one looked identical; every
* bounded read now carries `total`/`has_more`/`complete`.
*/
export interface ProjectListPage {
readonly projects: Workspace[];
/** Rows returned in this page. */
readonly count: number;
/** Rows matching the filter, ignoring limit/offset. */
readonly total: number;
/** Offset this page started at. */
readonly offset: number;
/** Caller-requested bound, or null when the caller asked for everything. */
readonly limit: number | null;
/** More rows exist past this page. */
readonly has_more: boolean;
/** Every matching row is present (i.e. `offset === 0 && !has_more`). */
readonly complete: boolean;
}
export interface CompleteProjectPopulation {
readonly projects: Workspace[];
readonly total: number;
readonly pages: number;
readonly complete: true;
}
export interface ProjectStore {
readonly transport: ProjectStoreTransport;
/** Base `<url>/v1` for the hosted transport; null for local. Never contains the key. */
readonly baseUrl: string | null;
/**
* List projects. With no `limit` this returns EVERY matching row — the store
* walks the server's pages itself rather than handing back one capped page.
*/
listProjects(filter?: WorkspaceFilter): Promise<Workspace[]>;
/** Full population read with a stable producer total and terminal invariant. */
listProjectsComplete(filter?: Omit<WorkspaceFilter, "limit" | "offset">): Promise<CompleteProjectPopulation>;
/** As `listProjects`, plus the totals that make a bounded read detectable. */
listProjectsPage(filter?: WorkspaceFilter): Promise<ProjectListPage>;
getProject(idOrSlug: string): Promise<Workspace | null>;
/**
* Resolve a caller-supplied target to a single project, throwing if none
* matches. Local resolves by id/slug/name and — as a machine-local
* convenience — by on-disk path/marker. Api resolves by id/slug server-side.
*/
resolveTarget(target: string | undefined, options?: ProjectResolverOptions): Promise<Workspace>;
createProject(input: CreateWorkspaceInput): Promise<Workspace>;
updateProject(id: string, patch: UpdateWorkspaceInput): Promise<Workspace>;
guardedReadProject(input: GuardedProjectReadRequest): Promise<GuardedProjectReadResult>;
readProjectResourceLinks(input: ProjectResourceLinkReadRequest): Promise<ProjectResourceLinkReadResult>;
mutateProjectResourceLinks(input: ProjectResourceLinkMutationRequest): Promise<ProjectResourceLinkMutationResult>;
rollbackProjectResourceLinks(input: ProjectResourceLinkRollbackRequest): Promise<ProjectResourceLinkMutationResult>;
/**
* Typed project-to-project relations (A27-00022 / C02). Local reads and
* writes the on-box SQLite `project_relations` table; api goes to
* projects-serve, which owns the PostgreSQL table. Both sides run the same
* `src/lib/project-relations.ts` identity and validation rules.
*/
readProjectRelations(input: ProjectRelationReadRequest): Promise<ProjectRelationReadResult>;
mutateProjectRelation(input: ProjectRelationMutationRequest): Promise<ProjectRelationMutationResult>;
/**
* The full-registration ledger (manifest + immutable receipts), the same
* contract `migrations/0005_project_registration_receipts.sql` defines.
* Local reads/writes the on-box SQLite tables; api calls projects-serve,
* which owns the PostgreSQL tables. A hosted registration MUST come through
* here: the on-box registry is refused outright once a hosted authority
* resolves (hasna/apps#1720), so there is no local fallback to reach for.
*/
createProjectRegistrationManifest(input: ProjectRegistrationManifestCreateInput): Promise<ProjectRegistrationManifestCreateResult>;
readProjectRegistrationManifest(operationId: string): Promise<ProjectRegistrationManifestRecord | null>;
appendProjectRegistrationReceipt(input: AppendReceiptInput): Promise<ProjectRegistrationReceipt>;
lookupProjectRegistrationReceipt(input: ProjectRegistrationReceiptLookupInput): Promise<ProjectRegistrationReceiptLookupResult>;
listProjectRegistrationReceipts(operationId: string): Promise<ProjectRegistrationReceipt[]>;
findProjectRegistrationReceipts(input: ProjectRegistrationReceiptQuery): Promise<ProjectRegistrationReceipt[]>;
readDuplicateProjectQuarantinePreimage(input: ProjectQuarantineReadRequest): Promise<ProjectQuarantineReadResult>;
quarantineDuplicateProject(input: ProjectQuarantineRequest): Promise<ProjectQuarantineResult>;
rollbackDuplicateProjectQuarantine(input: ProjectQuarantineRollbackRequest): Promise<ProjectQuarantineResult>;
planProjectResourceLinkMigration(input: ProjectResourceLinkMigrationPlanRequest): Promise<ProjectResourceLinkMigrationResult>;
readProjectResourceLinkMigration(input: ProjectResourceLinkMigrationReadRequest): Promise<ProjectResourceLinkMigrationResult>;
advanceProjectResourceLinkMigration(input: ProjectResourceLinkMigrationAdvanceRequest): Promise<ProjectResourceLinkMigrationResult>;
rollbackProjectResourceLinkMigration(input: ProjectResourceLinkMigrationRollbackRequest): Promise<ProjectResourceLinkMigrationResult>;
guardedUpdateProject(input: GuardedProjectMutationRequest): Promise<GuardedProjectMutationResult>;
lookupGuardedProjectMutationReceipt(input: GuardedProjectMutationReceiptLookupInput): Promise<GuardedProjectMutationReceiptLookupResult>;
rollbackGuardedProjectMutation(input: GuardedProjectMutationRollbackRequest): Promise<GuardedProjectMutationResult>;
archiveProject(id: string, ctx?: MutationContext): Promise<Workspace>;
unarchiveProject(id: string, ctx?: MutationContext): Promise<Workspace>;
deleteProject(id: string, opts: {
hard?: boolean;
}, ctx?: MutationContext): Promise<DeleteProjectResult>;
listEvents(idOrSlug: string, limit?: number): Promise<WorkspaceEvent[]>;
/** Record an explicit audit event. Local writes sqlite; api POSTs to /projects/:id/events. */
recordEvent(idOrSlug: string, input: RecordEventInput): Promise<WorkspaceEvent>;
/** Per-project agent assignments. Readable from both registry transports. */
getProjectAgents(id: string): Promise<WorkspaceAgentAssignment[]>;
/** Assign a registered agent to a project role (both registry transports; hosted: /v1/projects/:id/agents). */
assignAgent(idOrSlug: string, input: AssignAgentInput): Promise<WorkspaceAgentAssignment>;
/** Per-project registered locations. Readable from both registry transports. */
getProjectLocations(id: string): Promise<WorkspaceLocation[]>;
/** Registry of canonical machines (roles: mirror-hub | assignable | avoid). */
listMachines(): Promise<Machine[]>;
/** Register another on-disk location for a project (both registry transports; hosted: /v1/projects/:id/locations). */
addLocation(idOrSlug: string, input: AddLocationInput): Promise<AddLocationResult>;
listLocks(): Promise<WorkspaceLock[]>;
acquireLock(input: AcquireLockInput): Promise<WorkspaceLock>;
releaseLock(key: string, lockId: string): Promise<boolean>;
forceReleaseLock(key: string): Promise<boolean>;
listRoots(): Promise<Root[]>;
getRoot(idOrSlug: string): Promise<Root | null>;
createRoot(input: CreateRootInput): Promise<Root>;
updateRoot(idOrSlug: string, patch: UpdateRootInput): Promise<Root>;
deleteRoot(idOrSlug: string, opts?: {
detachProjects?: boolean;
}): Promise<DeleteRootResult>;
/** Score registered roots by path/kind/tags/github_org (behaves identically in both transports). */
matchRoots(input: RootMatchInput): Promise<RootMatchResult[]>;
listAgents(): Promise<Agent[]>;
getAgent(idOrSlug: string): Promise<Agent | null>;
createAgent(input: CreateAgentInput): Promise<Agent>;
listRecipes(): Promise<Recipe[]>;
getRecipe(idOrSlug: string): Promise<Recipe | null>;
createRecipe(input: CreateRecipeInput): Promise<Recipe>;
listAgentRuns(filter?: AgentRunFilter): Promise<AgentRun[]>;
listDataModels(project: Workspace): Promise<ProjectDataModel[]>;
createDataModel(project: Workspace, input: CreateProjectDataModelInput, ctx?: MutationContext): Promise<ProjectDataModel>;
listDataRecords(project: Workspace, modelId: string): Promise<ProjectDataRecord[]>;
createDataRecord(project: Workspace, input: CreateProjectDataRecordInput, ctx?: MutationContext): Promise<ProjectDataRecord>;
listLoopLinks(project: Workspace): Promise<ProjectLoopLink[]>;
linkLoop(project: Workspace, input: LinkProjectLoopInput, ctx?: MutationContext): Promise<ProjectLoopLink>;
listLoopSummaries(project: Workspace, options?: {
includeRuns?: boolean;
runLimit?: number;
}): Promise<ProjectLoopSummary[]>;
inspectAppStore(project: Workspace): Promise<ProjectStoreSummary>;
inspectAppStoreWithLoops(project: Workspace, options?: {
includeRuns?: boolean;
}): Promise<ProjectStoreSummary>;
createBudget(input: CreateProjectBudgetInput): Promise<ProjectBudget>;
listBudgets(context?: ProjectBudgetContext): Promise<ProjectBudget[]>;
getBudgetStatuses(context?: ProjectBudgetContext): Promise<ProjectBudgetStatus[]>;
resetBudget(id: string): Promise<ProjectBudget>;
recordSpend(input: ProjectSpendInput): Promise<ProjectBudgetSpend>;
listTmuxProfiles(): Promise<TmuxProfile[]>;
getTmuxProfile(idOrSlug: string): Promise<TmuxProfile | null>;
createTmuxProfile(input: CreateTmuxProfileInput): Promise<TmuxProfile>;
addTmuxProfileWindow(input: CreateTmuxProfileWindowInput & {
profile_id: string;
}): Promise<TmuxProfileWindow>;
listTmuxProfileWindows(profileId: string): Promise<TmuxProfileWindow[]>;
ensureChannel(project: Workspace, options?: StoreEnsureChannelOptions): Promise<ProjectChannelEnsureResult>;
}
export interface ResolveProjectStoreOptions {
producerAuthorityOptions?: ProductionProjectRegistrationAuthorityOptions;
producerVerifierNow?: () => string;
/** Tier-1/Tier-3 controls handed to the shared resolver (a key, a profile, a fake Keychain runner). */
credentials?: CredentialChainOptions;
/** Where the one-line local-mode notice goes. Defaults to stderr. */
notify?: (line: string) => void;
}
/** Test seam: forget that the local-mode line was already printed. */
export declare function __resetLocalModeNotice(): void;
/**
* Resolve the active projects Store.
*
* ROUTES ON URL + KEY ONLY (owner rulings 2026-09-04, hasna/apps#1720): the
* shared @hasna/contracts resolver decides, there is no mode switch, and there
* is no implicit local fallback. A credential from any tier — argument, env
* pointer, Keychain, `~/.hasna/projects/config/credentials`, or a plain
* `HASNA_PROJECTS_API_KEY` — selects the hosted store against the configured
* authority or, by default, `https://api.hasna.com/projects`.
*
* A station that declares an authority but resolves no credential FAILS LOUD:
* the seam's error propagates, the caller exits non-zero, no local store is
* opened and no local-fallback event is written. A station that configures
* NOTHING at all fails the same way UNLESS the operator opted in explicitly
* with `HASNA_PROJECTS_LOCAL=1` (alias `PROJECTS_LOCAL`) — the one deliberate
* route to the on-box registry, which says "local" in one line on stderr. The
* opt-in is answered BEFORE the resolver runs, so it never touches the
* Keychain or a credentials file, and any env-declared authority or credential
* outranks it (a half-configured opt-in run still fails loud, never local).
*/
export declare function resolveProjectStore(env?: Env, fetchImpl?: (input: string, init?: RequestInit) => Promise<Response>, options?: ResolveProjectStoreOptions): ProjectStore;
/** Test/di seam: clear the process-env cached store and lift the hosted local-store refusal. */
export declare function __resetProjectStore(): void;
export {};
//# sourceMappingURL=project-store.d.ts.map