@arnilo/prism-coding-agent 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ import type { ArtifactReference, GitOperations } from "./git.js";
2
+ /** Separate versioned namespace: never collides with coding checkpoint v1 keys. */
3
+ export declare const WORKSPACE_NAMESPACE: "prism.coding-agent.workspace.v1";
4
+ export declare const WORKSPACE_SCHEMA_VERSION: 1;
5
+ export declare const WORKSPACE_LOCK_REASON_PREFIX: "prism-workspace:";
6
+ /** Frozen workspace state machine: active | cleaning | closed | unknown. */
7
+ export type WorkspaceState = "active" | "cleaning" | "closed" | "unknown";
8
+ export declare const WORKSPACE_STATES: readonly WorkspaceState[];
9
+ export type WorkspaceRepositoryState = "active" | "removed" | "unknown";
10
+ export type WorkspaceErrorCode = "ERR_PRISM_WORKSPACE_UNKNOWN" | "ERR_PRISM_WORKSPACE_LIMIT" | "ERR_PRISM_WORKSPACE_OWNERSHIP" | "ERR_PRISM_WORKSPACE_FENCE" | "ERR_PRISM_WORKSPACE_DIRTY" | "ERR_PRISM_WORKSPACE_LOCKED" | "ERR_PRISM_WORKSPACE_MAIN" | "ERR_PRISM_WORKSPACE_PATH_ESCAPE" | "ERR_PRISM_WORKSPACE_FINGERPRINT";
11
+ export declare class WorkspaceError extends Error {
12
+ readonly code: WorkspaceErrorCode;
13
+ constructor(code: WorkspaceErrorCode, message: string);
14
+ }
15
+ /** Host-approved repository registration; `git` must be cwd-bound to `root`. */
16
+ export interface WorkspaceRepositoryRegistration {
17
+ readonly root: string;
18
+ readonly git: GitOperations;
19
+ }
20
+ /** Durable per-repository leg of a workspace record. */
21
+ export interface WorkspaceRepositoryRecord {
22
+ readonly repositoryId: string;
23
+ /** Canonical absolute root; the main worktree is immutable. */
24
+ readonly root: string;
25
+ /** Credential-free remote fingerprint (sha256 hex), never a URL. */
26
+ readonly remoteFingerprint: string;
27
+ readonly defaultBranch?: string;
28
+ readonly branch: string;
29
+ /** Branch base at create time. */
30
+ readonly base: string;
31
+ /** Verified head at create/last verify. */
32
+ readonly head: string;
33
+ readonly worktreeId: string;
34
+ readonly worktreePath: string;
35
+ readonly state: WorkspaceRepositoryState;
36
+ readonly createdAt: string;
37
+ }
38
+ /** Durable workspace record (schemaVersion 1, namespace WORKSPACE_NAMESPACE). */
39
+ export interface CodingWorkspaceRecord {
40
+ readonly schemaVersion: typeof WORKSPACE_SCHEMA_VERSION;
41
+ readonly workspaceId: string;
42
+ readonly taskId: string;
43
+ readonly ownerId: string;
44
+ readonly state: WorkspaceState;
45
+ readonly repositories: readonly WorkspaceRepositoryRecord[];
46
+ /** Artifact references only; never artifact contents or credentials. */
47
+ readonly artifactRefs: readonly ArtifactReference[];
48
+ /** Lease fencing token at last mutation; monotonic per record. */
49
+ readonly fencingToken: number;
50
+ readonly createdAt: string;
51
+ readonly updatedAt: string;
52
+ readonly cleanupAt?: string;
53
+ }
54
+ export interface WorkspaceCreateRequest {
55
+ readonly taskId: string;
56
+ readonly repositories: readonly {
57
+ readonly repositoryId: string;
58
+ readonly branch: string;
59
+ }[];
60
+ readonly artifactRefs?: readonly ArtifactReference[];
61
+ readonly signal?: AbortSignal;
62
+ }
63
+ /** Host policy gates the documented cleanup refusals; all default to refuse. */
64
+ export interface WorkspaceCleanupPolicy {
65
+ /** Allow forced removal of dirty worktrees (potential data loss). */
66
+ readonly allowDirtyCleanup?: boolean;
67
+ /** Allow unlocking worktrees locked by an external actor. */
68
+ readonly allowLockedCleanup?: boolean;
69
+ /** Allow claiming a missing worktree as removed. */
70
+ readonly allowMissingCleanup?: boolean;
71
+ /** Allow unclaiming a path that exists but is not a registered worktree. */
72
+ readonly allowUnownedCleanup?: boolean;
73
+ /** Allow forced removal when the worktree head no longer matches the record. */
74
+ readonly allowMismatchedCleanup?: boolean;
75
+ }
76
+ export interface WorkspaceLimitOptions {
77
+ readonly maxRepositories?: number;
78
+ readonly maxWorktrees?: number;
79
+ readonly maxRecordBytes?: number;
80
+ readonly leaseTtlMs?: number;
81
+ readonly maxCleanupOperations?: number;
82
+ }
83
+ export interface ResolvedWorkspaceLimits {
84
+ readonly maxRepositories: number;
85
+ readonly maxWorktrees: number;
86
+ readonly maxRecordBytes: number;
87
+ readonly leaseTtlMs: number;
88
+ readonly maxCleanupOperations: number;
89
+ }
90
+ export declare function resolveWorkspaceLimits(options?: WorkspaceLimitOptions): ResolvedWorkspaceLimits;
91
+ export interface CreateCodingWorkspaceLifecycleOptions {
92
+ readonly checkpoints: import("@arnilo/prism").CheckpointStore;
93
+ readonly leases: import("@arnilo/prism").LeaseStore;
94
+ /** Replica/worker identity; part of the fencing trust boundary. */
95
+ readonly ownerId: string;
96
+ readonly ownership?: import("@arnilo/prism").OwnershipScope;
97
+ /** Host-approved repositories keyed by repositoryId. */
98
+ readonly repositories: Readonly<Record<string, WorkspaceRepositoryRegistration>>;
99
+ /** Host-approved linked-worktree destination roots (canonicalized). */
100
+ readonly worktreeRoots: readonly string[];
101
+ readonly policy?: WorkspaceCleanupPolicy;
102
+ readonly limits?: WorkspaceLimitOptions;
103
+ }
104
+ export interface CodingWorkspaceLifecycle {
105
+ /**
106
+ * Create linked worktrees for a task and persist the workspace record.
107
+ * Idempotent: an identical active record returns as-is (no Git mutation).
108
+ * Stale or conflicting workers fail with ERR_PRISM_WORKSPACE_FENCE.
109
+ */
110
+ create(request: WorkspaceCreateRequest): Promise<CodingWorkspaceRecord>;
111
+ get(input: {
112
+ readonly taskId: string;
113
+ readonly signal?: AbortSignal;
114
+ }): Promise<CodingWorkspaceRecord | null>;
115
+ list(input?: {
116
+ readonly cursor?: string;
117
+ readonly limit?: number;
118
+ readonly signal?: AbortSignal;
119
+ }): Promise<{
120
+ readonly items: readonly CodingWorkspaceRecord[];
121
+ readonly nextCursor?: string;
122
+ }>;
123
+ /**
124
+ * Resume gate: revalidates repository/worktree identity and fingerprints
125
+ * (root containment, worktree presence, head, remote/default-branch) before
126
+ * tools, processes, index results, patches, or artifacts are reused.
127
+ */
128
+ verify(input: {
129
+ readonly taskId: string;
130
+ readonly signal?: AbortSignal;
131
+ }): Promise<CodingWorkspaceRecord>;
132
+ attachArtifacts(input: {
133
+ readonly taskId: string;
134
+ readonly artifactRefs: readonly ArtifactReference[];
135
+ readonly signal?: AbortSignal;
136
+ }): Promise<CodingWorkspaceRecord>;
137
+ /**
138
+ * Remove owned linked worktrees and close the record. Refuses dirty, locked,
139
+ * unowned, missing, or mismatched trees unless the host policy allows the
140
+ * documented action; partial failure persists state `unknown` and remains
141
+ * reconcilable by retrying.
142
+ */
143
+ cleanup(input: {
144
+ readonly taskId: string;
145
+ readonly signal?: AbortSignal;
146
+ }): Promise<CodingWorkspaceRecord>;
147
+ /** Delete the durable record (no Git mutation); false when absent. */
148
+ remove(input: {
149
+ readonly taskId: string;
150
+ readonly signal?: AbortSignal;
151
+ }): Promise<boolean>;
152
+ }
153
+ export declare function createCodingWorkspaceLifecycle(options: CreateCodingWorkspaceLifecycleOptions): CodingWorkspaceLifecycle;