@hasna/projects
Version:
High-level project management CLI, MCP server, SDK, and AI SDK agent loop for coding agents
266 lines • 16.1 kB
TypeScript
import type { Database } from "bun:sqlite";
import { type ProjectResourceLinkProducerEvidenceVerifier } from "../lib/project-resource-link-migrations.js";
import type { Agent, AgentRun, CreateAgentInput, CreateRecipeInput, CreateRootInput, CreateTmuxProfileInput, CreateTmuxProfileWindowInput, CreateWorkspaceInput, EventSource, GuardedProjectMutationReceipt, GuardedProjectMutationReceiptLookupInput, GuardedProjectMutationRequest, GuardedProjectMutationResult, GuardedProjectMutationRollbackRequest, JsonObject, Machine, ProjectResourceLink, ProjectResourceLinkMutationRequest, ProjectResourceLinkMutationResult, ProjectResourceLinkMigrationAdvanceRequest, ProjectResourceLinkMigrationPlanRequest, ProjectResourceLinkMigrationReadRequest, ProjectResourceLinkMigrationResult, ProjectResourceLinkMigrationRollbackRequest, ProjectResourceLinkReadRequest, ProjectResourceLinkReadResult, ProjectResourceLinkRollbackRequest, ProjectQuarantineRequest, ProjectQuarantineReadRequest, ProjectQuarantineReadResult, ProjectQuarantineResult, ProjectQuarantineRollbackRequest, Recipe, RecordWorkspaceEventInput, Root, TmuxProfile, TmuxProfileWindow, UpdateWorkspaceInput, UpdateRootInput, Workspace, WorkspaceAgentAssignment, WorkspaceEvent, WorkspaceIntegrations, WorkspaceKind, WorkspaceLocation, WorkspaceLock, WorkspaceStatus } from "../types/workspace.js";
import type { ProjectQueryScope } from "../lib/project-list-output.js";
export declare function generateWorkspaceId(): string;
export declare function generateRootId(): string;
export declare function generateRecipeId(): string;
export declare function generateAgentId(): string;
export declare function generateWorkspaceEventId(): string;
export declare function generateAgentRunId(): string;
export declare function generateLocationId(): string;
export declare function generateTmuxProfileId(): string;
export declare function generateTmuxProfileWindowId(): string;
export declare function generateWorkspaceLockId(): string;
export declare function workspaceSlugify(name: string): string;
export declare function renderTemplate(template: string, values: Record<string, string | null | undefined>): string;
export declare function createRoot(input: CreateRootInput, db?: Database): Root;
export declare function getRoot(id: string, db?: Database): Root | null;
export declare function getRootBySlug(slug: string, db?: Database): Root | null;
export declare function listRoots(db?: Database): Root[];
export declare function updateRoot(id: string, input: UpdateRootInput, db?: Database): Root;
export declare function deleteRoot(id: string, options?: {
detachWorkspaces?: boolean;
}, db?: Database): {
root: Root;
detached_workspaces: number;
};
export interface RootMatchInput {
path?: string;
tags?: string[];
kind?: WorkspaceKind;
github_org?: string;
}
export interface RootMatchResult {
root: Root;
score: number;
reasons: string[];
}
/**
* Pure root scoring over an in-memory list — no db access. Shared by the local
* `scoreRoots` (which reads sqlite) and the api transport (which scores roots
* fetched over HTTP), so matching behaves identically in both modes.
*/
export declare function rankRoots(roots: Root[], input?: RootMatchInput): RootMatchResult[];
export declare function scoreRoots(input?: RootMatchInput, db?: Database): RootMatchResult[];
export declare function matchRoot(input: RootMatchInput, db?: Database): Root | null;
export declare function matchRootForPath(path: string, db?: Database): Root | null;
export declare function createAgent(input: CreateAgentInput, db?: Database): Agent;
export declare function getAgent(id: string, db?: Database): Agent | null;
export declare function getAgentBySlug(slug: string, db?: Database): Agent | null;
export declare function listAgents(db?: Database): Agent[];
export declare function getMachine(slug: string, db?: Database): Machine | null;
export declare function listMachines(db?: Database): Machine[];
export declare function mergeAgentPermissions(agentId: string, permissions: string[], db?: Database): Agent;
export declare function ensureCliAgent(db?: Database): Agent;
export declare function assertAgentPermission(agentId: string | undefined, permission: string, db?: Database): void;
export declare function createRecipe(input: CreateRecipeInput, db?: Database): Recipe;
export declare function getRecipe(id: string, db?: Database): Recipe | null;
export declare function getRecipeBySlug(slug: string, db?: Database): Recipe | null;
export declare function listRecipes(db?: Database): Recipe[];
export declare function createTmuxProfile(input: CreateTmuxProfileInput, db?: Database): TmuxProfile;
export declare function getTmuxProfile(id: string, db?: Database): TmuxProfile | null;
export declare function getTmuxProfileBySlug(slug: string, db?: Database): TmuxProfile | null;
export declare function resolveTmuxProfile(idOrSlug: string, db?: Database): TmuxProfile | null;
export declare function listTmuxProfiles(db?: Database): TmuxProfile[];
export declare function addTmuxProfileWindow(input: CreateTmuxProfileWindowInput & {
profile_id: string;
}, db?: Database): TmuxProfileWindow;
export declare function listTmuxProfileWindows(profileId: string, db?: Database): TmuxProfileWindow[];
export declare function createWorkspace(input: CreateWorkspaceInput, db?: Database): Workspace;
export declare function getWorkspace(id: string, db?: Database): Workspace | null;
export declare function getWorkspaceBySlug(slug: string, db?: Database): Workspace | null;
export declare function getWorkspaceByPath(path: string, db?: Database): Workspace | null;
export declare function listWorkspacesByPath(path: string, db?: Database): Workspace[];
export interface WorkspaceFilter {
status?: WorkspaceStatus;
kind?: WorkspaceKind;
root_id?: string;
query?: string;
query_scope?: ProjectQueryScope;
/** Internal client requirement: hosted pages must attest the v2 filter contract. */
require_list_v2_contract?: boolean;
tags?: string[];
exclude_eval_artifacts?: boolean;
exclude_registry_fixtures?: boolean;
limit?: number;
offset?: number;
}
/**
* List workspaces.
*
* `filter.limit` is optional and, when omitted, means EVERY matching row.
* It used to silently default to 100, so a caller asking for "all projects"
* quietly received the first hundred with nothing in the result to say so —
* the local twin of the server's 1000-row cap. SQLite's `LIMIT -1` is the
* documented "no limit" sentinel and keeps OFFSET usable.
*/
export declare function listWorkspaces(filter?: WorkspaceFilter, db?: Database): Workspace[];
/** Rows matching `filter`, ignoring its limit/offset. */
export declare function countWorkspaces(filter?: WorkspaceFilter, db?: Database): number;
export declare function resolveWorkspace(idOrSlug: string, db?: Database): Workspace | null;
export declare function updateWorkspace(id: string, input: UpdateWorkspaceInput, db?: Database): Workspace;
/**
* Idempotent receipt writer — the guarded-mutation receipt contract.
*
* `receipt_id` is derived deterministically from the operation identity
* (`buildReceiptId`), so retrying an operation-id after a FAILED attempt
* derives the SAME primary key. The first attempt already recorded that
* outcome; the retry must read that immutable row back instead of racing the
* primary key into the reported 500
* (`duplicate key value violates unique constraint
* "guarded_project_mutation_receipts_pkey"`, A3-00870).
*
* `ON CONFLICT (receipt_id) DO NOTHING` + read-back (not a bare pre-read) is
* what makes the write idempotent: the conflict is settled by the database, so
* two writers of the same derived id cannot both insert. The read-back returns
* the FIRST recorded row for that id: a receipt is immutable evidence, so its
* `before_json`/`created_at` stay those of the attempt that actually produced
* the outcome.
*
* The conflict path is not a free pass for the row constraints. The database
* still refuses a bad NOT NULL or CHECK there, but NOT the `target_id` foreign
* key (see {@link assertGuardedReceiptTargetExists}), so the writer runs that
* check itself whenever the insert inserted nothing. A candidate naming a
* missing target is refused on both paths — never accepted because a receipt
* with the same id already existed.
*
* Idempotent write, NOT a promoted response: the caller keeps computing its own
* fail-closed outcome, so a retried `terminal_nonacceptance` still returns
* `terminal_nonacceptance` carrying the originally recorded receipt, and a
* retry can never claim success for an attempt that failed. A retry whose
* derived id differs — a different request digest, precondition/revision or
* outcome — is a different logical attempt and records its own row.
*
* Exported for the receipt-writer contract tests. It is not part of the curated
* package surface (`src/index.ts`), which is the only public entry point.
*
* The hosted writer `PgStore.insertGuardedReceipt` holds the same contract.
*/
export declare function insertGuardedProjectMutationReceipt(input: Omit<GuardedProjectMutationReceipt, "created_at">, db: Database): GuardedProjectMutationReceipt;
export declare function listProjectResourceLinks(projectId: string, maxItems?: number, db?: Database): ProjectResourceLink[];
export declare function readProjectResourceLinks(input: ProjectResourceLinkReadRequest, db?: Database, startedAt?: number): ProjectResourceLinkReadResult;
export declare function mutateProjectResourceLinks(input: ProjectResourceLinkMutationRequest, db?: Database): ProjectResourceLinkMutationResult;
export declare function mutateProjectResourceLinksForRegistration(input: ProjectResourceLinkMutationRequest, integrations: WorkspaceIntegrations, db?: Database): ProjectResourceLinkMutationResult;
export declare function rollbackProjectResourceLinks(input: ProjectResourceLinkRollbackRequest, db?: Database): ProjectResourceLinkMutationResult;
export declare function readDuplicateProjectQuarantinePreimage(input: ProjectQuarantineReadRequest, db?: Database): ProjectQuarantineReadResult;
export declare function quarantineDuplicateProject(input: ProjectQuarantineRequest, db?: Database): ProjectQuarantineResult;
export declare function rollbackDuplicateProjectQuarantine(input: ProjectQuarantineRollbackRequest, db?: Database): ProjectQuarantineResult;
export declare function planProjectResourceLinkMigration(input: ProjectResourceLinkMigrationPlanRequest, db?: Database): ProjectResourceLinkMigrationResult;
export declare function readProjectResourceLinkMigration(input: ProjectResourceLinkMigrationReadRequest, db?: Database): ProjectResourceLinkMigrationResult;
export declare function advanceProjectResourceLinkMigration(input: ProjectResourceLinkMigrationAdvanceRequest, db?: Database, producerEvidenceVerifier?: ProjectResourceLinkProducerEvidenceVerifier): ProjectResourceLinkMigrationResult;
export declare function rollbackProjectResourceLinkMigration(input: ProjectResourceLinkMigrationRollbackRequest, db?: Database, producerEvidenceVerifier?: ProjectResourceLinkProducerEvidenceVerifier): ProjectResourceLinkMigrationResult;
export declare function guardedUpdateWorkspace(input: GuardedProjectMutationRequest, db?: Database): GuardedProjectMutationResult;
export declare function lookupGuardedWorkspaceMutationReceipt(input: GuardedProjectMutationReceiptLookupInput, db?: Database): GuardedProjectMutationReceipt;
export declare function rollbackGuardedWorkspaceMutation(input: GuardedProjectMutationRollbackRequest, db?: Database): GuardedProjectMutationResult;
export declare function linkWorkspaceIntegrations(id: string, integrations: WorkspaceIntegrations, input?: Pick<UpdateWorkspaceInput, "agent_id" | "source" | "prompt" | "command">, db?: Database): Workspace;
export declare function archiveWorkspace(id: string, input?: Omit<UpdateWorkspaceInput, "status">, db?: Database): Workspace;
export declare function unarchiveWorkspace(id: string, input?: Omit<UpdateWorkspaceInput, "status">, db?: Database): Workspace;
export declare function deleteWorkspace(id: string, input?: Omit<UpdateWorkspaceInput, "status"> & {
hard?: boolean;
recordEvent?: boolean;
}, db?: Database): {
workspace: Workspace;
hard: boolean;
};
export interface AddWorkspaceLocationInput {
workspace_id: string;
path: string;
machine_id?: string;
label?: string;
kind?: string;
is_primary?: boolean;
metadata?: JsonObject;
agent_id?: string;
source?: EventSource;
prompt?: string;
command?: string;
}
export declare function addWorkspaceLocation(input: AddWorkspaceLocationInput, db?: Database): WorkspaceLocation;
export declare function listWorkspaceLocations(workspaceId: string, db?: Database): WorkspaceLocation[];
export declare function getWorkspaceLocationByPath(path: string, db?: Database): WorkspaceLocation | null;
export declare function assignAgentToWorkspace(workspaceId: string, agentId: string, role?: string, assignedBy?: string, metadata?: JsonObject, db?: Database): WorkspaceAgentAssignment;
export declare function listWorkspaceAgents(workspaceId: string, db?: Database): WorkspaceAgentAssignment[];
export declare function recordWorkspaceEvent(input: RecordWorkspaceEventInput, db?: Database): WorkspaceEvent;
export declare function listWorkspaceEvents(workspaceId: string, db?: Database): WorkspaceEvent[];
export declare function listStartedWorkspaceEvents(options?: {
limit?: number;
}, db?: Database): Array<{
event: WorkspaceEvent;
project_slug: string;
}>;
export declare function startAgentRun(input: {
agent_id?: string;
workspace_id?: string;
provider?: string;
model?: string;
prompt: string;
plan?: JsonObject;
metadata?: JsonObject;
}, db?: Database): AgentRun;
export declare function completeAgentRun(runId: string, input: {
status?: "completed" | "failed";
workspace_id?: string;
result?: JsonObject;
error?: string;
tool_calls?: JsonObject[];
}, db?: Database): AgentRun;
export declare function listAgentRuns(filter?: {
workspace_id?: string;
agent_id?: string;
status?: AgentRun["status"];
limit?: number;
}, db?: Database): AgentRun[];
export declare function acquireWorkspaceLock(input: {
lock_key: string;
workspace_id?: string;
agent_id?: string;
reason?: string;
ttl_seconds?: number;
}, db?: Database): WorkspaceLock;
export declare function releaseWorkspaceLock(lockKey: string, lockId: string, db?: Database): boolean;
export declare function forceReleaseWorkspaceLock(lockKey: string, db?: Database): boolean;
export declare function listWorkspaceLocks(db?: Database): WorkspaceLock[];
export declare function inferWorkspaceKind(slug: string, path: string, tags?: string[]): WorkspaceKind;
export interface MigrationResult {
migrated: number;
skipped: number;
roots_created_or_reused: number;
workdirs_migrated: number;
workdirs_skipped: number;
before: MigrationCounts;
after: MigrationCounts;
validation: MigrationValidation;
samples: MigrationSample[];
}
export interface MigrationCounts {
legacy_projects: number;
legacy_workdirs: number;
migration_map: number;
workspaces: number;
workspace_locations: number;
}
export interface MigrationValidation {
valid: boolean;
expected_legacy_projects: number;
accounted_projects: number;
missing_projects: number;
workdir_source_count: number;
workdir_migrated: number;
workdir_skipped: number;
expected_migration_map_rows: number;
actual_migration_map_rows: number;
missing_migration_map_rows: number;
expected_workspace_locations_at_least: number;
actual_workspace_locations: number;
}
export interface MigrationSample {
old_project_id: string;
workspace_id: string;
old_slug: string;
workspace_slug: string;
old_path: string;
workspace_path: string | null;
}
export declare function migrateLegacyProjectsToWorkspaces(db?: Database): MigrationResult;
//# sourceMappingURL=workspaces.d.ts.map