UNPKG

@hasna/projects

Version:

High-level project management CLI, MCP server, SDK, and AI SDK agent loop for coding agents

545 lines • 22.6 kB
import type { Database } from "bun:sqlite"; import type { EventSource, JsonObject, WorkspaceKind } from "../types/workspace.js"; import type { ProjectStore } from "../store/project-store.js"; export declare const PROJECT_REGISTRATION_ROUTE = "projects.full-registration.v1"; export declare const PROJECT_REGISTRATION_GOALS_FILENAME = "GOALS.md"; export declare const PROJECT_REGISTRATION_WORKLOG_FILENAME = "WORKLOG.md"; export declare const PROJECT_REGISTRATION_MAX_RECEIPTS = 32; export declare const PROJECT_REGISTRATION_DEPENDENCY_TASKS: { readonly todos: "317026ea-dc10-422e-af51-206a4ec885f9"; readonly mementos: "7e6a213c-ae3d-420c-a512-94abd1164df8"; readonly conversations: "983c734e-6602-4286-98c5-9c2e6f6d741a"; }; /** * The row that carries the Files project-registration capability identity * (A3-00875). It is deliberately NOT an entry in * {@link PROJECT_REGISTRATION_DEPENDENCY_TASKS}: that map is the registration's * own dependency contract — it is embedded verbatim in every registration * manifest and every capability blocker — and a registration does not depend on * the identity-only Files capability. */ export declare const FILES_PROJECT_REGISTRATION_DEPENDENCY_TASK_ID = "73fc9943-e86e-4d27-977c-76728ccd9069"; /** * These are retirement predicates, not naming templates. New registration * derives its name from the project slug; it never manufactures either prefix. */ export declare const RETIRED_PROJECT_REGISTRATION_PREFIXES: readonly ["internal-iproj-", "iproj-"]; /** * Every authority the projects package can reach through a registration * adapter. `files` is a member of the set but not of the registration * dependency map: it publishes a capability identity and implements no * registration lifecycle, so it is never preflighted and never appears in a * registration manifest's dependency contract. */ export type ProjectRegistrationAuthorityName = keyof typeof PROJECT_REGISTRATION_DEPENDENCY_TASKS | "files"; export type ProjectRegistrationAuthorityTransport = "local" | "api"; export type ProjectRegistrationResourceKind = "project" | "task_list" | "channel"; export type ProjectRegistrationDirection = "forward" | "inverse"; export type ProjectRegistrationOutcome = "accepted" | "duplicate_of_accepted" | "terminal_nonacceptance"; export interface ProjectRegistrationBounds { response_byte_limit: number; time_budget_ms: number; } export interface ProjectRegistrationResponseControl extends ProjectRegistrationBounds { response_bytes: number; elapsed_ms: number; complete: boolean; truncated: boolean; } /** * A path-bearing registration request stays inside this package-owned handle. * It is never serialized into a manifest, receipt, result, argv, or env field. */ export declare class ProjectRegistrationPathHandle { #private; private constructor(); static fromPath(path: string): ProjectRegistrationPathHandle; get digest(): string; withOwnedPath<T>(consumer: (absolutePath: string) => T): T; } export interface ProjectRegistrationAuthorityCapability { authority: ProjectRegistrationAuthorityName; route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; supported_resources: ProjectRegistrationResourceKind[]; conditional_create: boolean; immutable_receipts: boolean; exact_terminal_lookup: boolean; exact_readback: boolean; conditional_inverse: boolean; ambiguous_outcome_reconciliation: boolean; guarded_update?: boolean; guarded_update_route?: string; expected_revision_compare_and_swap?: boolean; caller_idempotency?: boolean; exact_inverse_rollback?: boolean; } export interface ProjectRegistrationAuthorityReceipt { receipt_id: string; authority: ProjectRegistrationAuthorityName; route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; operation_id: string; step_id: string; resource_kind: ProjectRegistrationResourceKind; direction: ProjectRegistrationDirection; idempotency_key: string; request_digest: string; precondition_digest: string; outcome: ProjectRegistrationOutcome; reason: string | null; target_id: string | null; result_revision: string | null; result_digest: string | null; duplicate_of_receipt_id: string | null; accepted_receipt_id: string | null; created_by_operation: boolean; prior_state?: JsonObject | null; created_at: string; } export interface ProjectRegistrationAuthorityRecord { target_id: string; revision: string; digest: string; } export interface ProjectRegistrationAuthorityRequest extends ProjectRegistrationBounds { operation_id: string; step_id: string; resource_kind: ProjectRegistrationResourceKind; direction: ProjectRegistrationDirection; authority_route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; target_selector: string; idempotency_key: string; request_digest: string; precondition_digest: string; project_id: string; project_slug: string; project_name: string; desired: JsonObject; operation_intent?: "create" | "bind_existing" | "adopt_existing"; adopt_existing?: JsonObject; target: ProjectRegistrationPathHandle; accepted_receipt?: ProjectRegistrationAuthorityReceipt; } export interface ProjectRegistrationAuthorityLookupRequest extends ProjectRegistrationBounds { operation_id: string; step_id: string; resource_kind: ProjectRegistrationResourceKind; direction: ProjectRegistrationDirection; authority: ProjectRegistrationAuthorityName; authority_route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; target_selector: string; idempotency_key: string; request_digest: string; precondition_digest: string; target_id?: string; max_items: 1; } export interface ProjectRegistrationAuthorityLookupResult { receipt: ProjectRegistrationAuthorityReceipt; response_control: ProjectRegistrationResponseControl; } export interface ProjectRegistrationAuthorityInverseVerification { target_id: string; accepted_receipt_id: string; absent: true; digest: string; } export interface ProjectRegistrationAuthorityPathRepairReceipt { receipt_id: string; authority: "mementos"; route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; operation_id: string; step_id: string; direction: "forward" | "rollback"; idempotency_key: string; request_digest: string; outcome: "accepted"; target_id: string; expected_revision: string; result_revision: string; result_digest: string; accepted_receipt_id: string | null; created_at: string; } export interface ProjectRegistrationGuardedProjectUpdateRequest extends ProjectRegistrationBounds { authority: "mementos"; authority_route: string; package_version: string; operation_id: string; step_id: string; authority_id: string; tenant_id: string; corpus_id: string; idempotency_key: string; expected_revision: string; updates: { path: ProjectRegistrationPathHandle; }; } export interface ProjectRegistrationGuardedProjectRollbackRequest extends ProjectRegistrationBounds { authority: "mementos"; authority_route: string; package_version: string; operation_id: string; step_id: string; authority_id: string; tenant_id: string; corpus_id: string; idempotency_key: string; expected_revision: string; accepted_receipt: ProjectRegistrationAuthorityPathRepairReceipt; } export interface ProjectRegistrationGuardedProjectReceiptLookupRequest extends ProjectRegistrationBounds { authority: "mementos"; authority_route: string; package_version: string; authority_id: string; tenant_id: string; corpus_id: string; } export interface ProjectRegistrationGuardedProjectUpdateResult { dry_run: false; applied: true; record: ProjectRegistrationAuthorityRecord; receipt: ProjectRegistrationAuthorityPathRepairReceipt; response_control: ProjectRegistrationResponseControl; } export interface ProjectRegistrationGuardedProjectReceiptLookupResult { receipt: ProjectRegistrationAuthorityPathRepairReceipt; response_control: ProjectRegistrationResponseControl; } export interface ProjectRegistrationAuthorityAdapter { readonly authority: ProjectRegistrationAuthorityName; readonly transport?: ProjectRegistrationAuthorityTransport; capability(): Promise<ProjectRegistrationAuthorityCapability>; create(request: ProjectRegistrationAuthorityRequest): Promise<ProjectRegistrationAuthorityReceipt>; readExact(request: { resource_kind: ProjectRegistrationResourceKind; target_id: string; target: ProjectRegistrationPathHandle; response_byte_limit: number; time_budget_ms: number; }): Promise<ProjectRegistrationAuthorityRecord>; lookupReceipt(request: ProjectRegistrationAuthorityLookupRequest): Promise<ProjectRegistrationAuthorityLookupResult>; validateExistingAdoption?(request: ProjectRegistrationAuthorityRequest, receipt: ProjectRegistrationAuthorityReceipt): Promise<boolean>; validatePriorRegistrationAdoption?(sourceRequest: ProjectRegistrationAuthorityRequest, sourceReceipt: ProjectRegistrationAuthorityReceipt, currentRecord: ProjectRegistrationAuthorityRecord): Promise<boolean>; compensate(request: ProjectRegistrationAuthorityRequest): Promise<ProjectRegistrationAuthorityReceipt>; verifyInverse(request: ProjectRegistrationAuthorityRequest): Promise<ProjectRegistrationAuthorityInverseVerification>; guardedUpdateProject?(targetId: string, request: ProjectRegistrationGuardedProjectUpdateRequest): Promise<ProjectRegistrationGuardedProjectUpdateResult>; getGuardedProjectUpdateReceipt?(targetId: string, receiptId: string, request: ProjectRegistrationGuardedProjectReceiptLookupRequest): Promise<ProjectRegistrationGuardedProjectReceiptLookupResult>; rollbackGuardedProjectUpdate?(targetId: string, request: ProjectRegistrationGuardedProjectRollbackRequest): Promise<ProjectRegistrationGuardedProjectUpdateResult>; } export interface ProjectRegistrationAuthorities { todos: ProjectRegistrationAuthorityAdapter; mementos: ProjectRegistrationAuthorityAdapter; conversations: ProjectRegistrationAuthorityAdapter; /** * Optional by design: the Files capability publishes the service identity a * typed Files project link binds to and implements no registration * lifecycle, so it is not part of the mandatory preflight set (which * requires the three lifecycle authorities). A caller that needs the Files * identity reads `files.capability()`; a caller that registers a project * never depends on it. */ files?: ProjectRegistrationAuthorityAdapter; } export interface ProjectRegistrationCapabilityBlocker { authority: ProjectRegistrationAuthorityName; dependency_task_id: string; route: string; package_version: string; missing: string[]; } export interface ProjectRegistrationCapabilityReport { ok: boolean; capabilities: ProjectRegistrationAuthorityCapability[]; blockers: ProjectRegistrationCapabilityBlocker[]; } export interface FullProjectRegistrationProjectInput { id?: string; name: string; slug?: string; description?: string; kind?: WorkspaceKind; root_id?: string; recipe_id?: string; git_remote?: string; s3_bucket?: string; s3_prefix?: string; tags?: string[]; metadata?: JsonObject; agent_id?: string; source?: EventSource; prompt?: string; command?: string; } export interface ProjectRegistrationHistoricalAuthorityIdentity { route: string; package_version: string; authority_id: string; corpus_id: string; } export interface ProjectRegistrationExistingConversationsChannelReconciliation { source_operation_id: string; source_authority_identity?: ProjectRegistrationHistoricalAuthorityIdentity; target_id: string; } export interface ProjectRegistrationPreboundConversationsChannelReconciliation { target_id: string; expected_project_id: string; expected_revision: string; expected_digest: string; expected_message_ownership: JsonObject; } export interface ProjectRegistrationExistingAuthorityReconciliation { source_operation_id: string; source_authority_identity?: ProjectRegistrationHistoricalAuthorityIdentity; target_id: string; } export interface ProjectRegistrationExistingMementosProjectReconciliation extends ProjectRegistrationExistingAuthorityReconciliation { source_target: ProjectRegistrationPathHandle; } export interface FullProjectRegistrationReconciliationInput { conversations_channel?: ProjectRegistrationExistingConversationsChannelReconciliation | ProjectRegistrationPreboundConversationsChannelReconciliation; todos_project?: ProjectRegistrationExistingAuthorityReconciliation; todos_task_list?: ProjectRegistrationExistingAuthorityReconciliation; mementos_project?: ProjectRegistrationExistingMementosProjectReconciliation; } export interface FullProjectRegistrationInput extends ProjectRegistrationBounds { operation_id: string; mode?: "create" | "retrofit"; expected_project_revision?: string; reconcile_existing?: FullProjectRegistrationReconciliationInput; project: FullProjectRegistrationProjectInput; target: ProjectRegistrationPathHandle; goals_markdown: string; worklog_markdown: string; } export interface ProjectRegistrationArtifact { kind: string; authority: string; target_id: string; revision?: string; digest?: string; authority_receipt_id?: string; source_target_path_digest?: string; requested_target_path_digest?: string; } export interface ProjectRegistrationReceipt { receipt_id: string; operation_id: string; sequence: number; step_id: string; authority: string; resource_kind: string; direction: ProjectRegistrationDirection; idempotency_key: string; target_id: string | null; request_digest: string; precondition_digest: string; outcome: ProjectRegistrationOutcome; reason: string | null; result_revision: string | null; result_digest: string | null; duplicate_of_receipt_id: string | null; authority_receipt: ProjectRegistrationAuthorityReceipt | ProjectRegistrationAuthorityPathRepairReceipt | null; artifacts: JsonObject[]; preconditions: JsonObject[]; rollback: JsonObject[]; created_at: string; } export interface ProjectRegistrationReceiptLookupInput extends ProjectRegistrationBounds { operation_id: string; step_id: string; direction: ProjectRegistrationDirection; idempotency_key: string; max_items: 1; } export interface ProjectRegistrationReceiptLookupResult { receipt: ProjectRegistrationReceipt; response_control: ProjectRegistrationResponseControl; } export interface FullProjectRegistrationResult { ok: boolean; outcome: "no_go" | "accepted" | "duplicate_of_accepted" | "rolled_back" | "split_state"; operation_id: string; project_id: string; project_slug: string; failed_step: string | null; reason_code: string | null; dependencies: ProjectRegistrationCapabilityBlocker[]; artifacts: ProjectRegistrationArtifact[]; receipts: ProjectRegistrationReceipt[]; rollback: JsonObject[]; response_control: ProjectRegistrationResponseControl; } export interface ProjectRegistrationManifestRow { operation_id: string; route: string; request_digest: string; project_id: string; project_slug: string; plan_json: string; created_at: string; } export interface ProjectRegistrationReceiptRow { receipt_id: string; operation_id: string; sequence: number; step_id: string; authority: string; resource_kind: string; direction: string; idempotency_key: string; target_id: string | null; request_digest: string; precondition_digest: string; outcome: string; reason: string | null; result_revision: string | null; result_digest: string | null; duplicate_of_receipt_id: string | null; authority_receipt_json: string | null; artifacts_json: string; preconditions_json: string; rollback_json: string; created_at: string; } export interface AppendReceiptInput { operation_id: string; step_id: string; authority: string; resource_kind: string; direction: ProjectRegistrationDirection; idempotency_key: string; target_id?: string | null; request_digest: string; precondition_digest: string; outcome: ProjectRegistrationOutcome; reason?: string | null; result_revision?: string | null; result_digest?: string | null; duplicate_of_receipt_id?: string | null; authority_receipt?: ProjectRegistrationAuthorityReceipt | ProjectRegistrationAuthorityPathRepairReceipt | null; artifacts?: JsonObject[]; preconditions?: JsonObject[]; rollback?: JsonObject[]; } export declare class ProjectRegistrationStepError extends Error { readonly stepId: string; readonly code: string; readonly splitState: boolean; constructor(stepId: string, code: string, splitState?: boolean); } export declare function rowToReceipt(row: ProjectRegistrationReceiptRow): ProjectRegistrationReceipt; export declare function safeAuthorityReceipt(receipt: ProjectRegistrationAuthorityReceipt | ProjectRegistrationAuthorityPathRepairReceipt): ProjectRegistrationAuthorityReceipt | ProjectRegistrationAuthorityPathRepairReceipt; export declare function buildReceiptId(input: AppendReceiptInput): string; export declare function deriveProjectRegistrationIdempotencyKey(input: { operation_id: string; step_id: string; direction: ProjectRegistrationDirection; target_selector: string; request_digest: string; precondition_digest: string; }): string; export declare function lookupProjectRegistrationReceipt(input: ProjectRegistrationReceiptLookupInput, db?: Database): ProjectRegistrationReceiptLookupResult; export declare function listProjectRegistrationReceipts(operationId: string, db?: Database): ProjectRegistrationReceipt[]; /** * The transport-neutral manifest record. `plan` is the parsed immutable plan: * the SQLite row keeps it as canonical JSON text and PostgreSQL keeps it as * JSONB, so every comparison re-canonicalizes both sides instead of comparing * two renderings of the same value. */ export interface ProjectRegistrationManifestRecord { operation_id: string; route: string; request_digest: string; project_id: string; project_slug: string; plan: JsonObject; created_at: string; } export interface ProjectRegistrationManifestCreateInput { operation_id: string; request_digest: string; project_id: string; project_slug: string; plan: JsonObject; } export interface ProjectRegistrationManifestCreateResult { manifest: ProjectRegistrationManifestRecord; created: boolean; } /** The bounded accepted-receipt readback a completion check performs. */ export interface ProjectRegistrationReceiptQuery { operation_id: string; step_id: string; direction: ProjectRegistrationDirection; limit: number; } /** * The registration ledger seam: one immutable manifest per operation and its * immutable, sequenced receipts. Local implements it over the on-box SQLite * tables (`migrations/0005_project_registration_receipts.sql`); hosted * implements it over the projects-serve endpoints backed by the same tables in * PostgreSQL. There is deliberately no third, silently-local mode: a hosted * run builds the hosted ledger from an HTTP store and never opens the on-box * registry (hasna/apps#1720). */ export interface ProjectRegistrationLedger { ensureManifest(input: ProjectRegistrationManifestCreateInput): Promise<ProjectRegistrationManifestCreateResult>; readManifest(operationId: string): Promise<ProjectRegistrationManifestRecord | null>; appendReceipt(input: AppendReceiptInput): Promise<ProjectRegistrationReceipt>; lookupReceipt(input: ProjectRegistrationReceiptLookupInput): Promise<ProjectRegistrationReceiptLookupResult>; listReceipts(operationId: string): Promise<ProjectRegistrationReceipt[]>; findAcceptedReceipts(input: ProjectRegistrationReceiptQuery): Promise<ProjectRegistrationReceipt[]>; } export declare function projectRegistrationManifestFromRow(row: ProjectRegistrationManifestRow): ProjectRegistrationManifestRecord; /** The on-box ledger: the exact SQLite semantics this package already owns. */ export declare function localProjectRegistrationLedger(db?: Database): ProjectRegistrationLedger; /** * The hosted ledger: the same manifest/receipt contract served by * projects-serve against PostgreSQL. Built only from an HTTP store, so a * hosted registration cannot reach the on-box tables even by accident. */ export declare function hostedProjectRegistrationLedger(store: ProjectStore): ProjectRegistrationLedger; export declare function assertCurrentProjectRegistrationSlug(slug: string): void; export declare function preflightProjectRegistrationAuthorities(authorities: ProjectRegistrationAuthorities): Promise<ProjectRegistrationCapabilityReport>; export declare function unavailableProjectRegistrationAuthorities(): ProjectRegistrationAuthorities; /** * The stored plan is canonical JSON text here and JSONB in PostgreSQL, whose * text rendering is not byte-identical; compare the canonicalized values so an * exact retry never reports a false semantic conflict. */ export declare function registrationPlanMatches(stored: string, requestedCanonical: string): boolean; export declare function registerFullProject(input: FullProjectRegistrationInput, options?: { db?: Database; authorities?: ProjectRegistrationAuthorities; projectStore?: ProjectStore; /** * The manifest/receipt authority to write. Defaults to the on-box SQLite * ledger for a local run and to the hosted ledger (projects-serve) when a * hosted project store is supplied — never the other way round. */ ledger?: ProjectRegistrationLedger; }): Promise<FullProjectRegistrationResult>; //# sourceMappingURL=project-registration.d.ts.map