nawabari 0.1.0 → 0.2.0
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.
- package/README.md +213 -5
- package/dist/cli.js +320 -6
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +9 -0
- package/dist/contract.js +172 -0
- package/dist/contract.js.map +1 -0
- package/dist/domain/doctor.d.ts +1 -1
- package/dist/domain/doctor.js +99 -90
- package/dist/domain/doctor.js.map +1 -1
- package/dist/domain/errors.d.ts +1 -1
- package/dist/domain/errors.js +5 -1
- package/dist/domain/errors.js.map +1 -1
- package/dist/domain/session-backend.d.ts +11 -1
- package/dist/domain/session-backend.js +247 -3
- package/dist/domain/session-backend.js.map +1 -1
- package/dist/domain/session.d.ts +131 -0
- package/dist/domain/session.js +6 -0
- package/dist/domain/session.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/git.d.ts +40 -0
- package/dist/git.js +415 -30
- package/dist/git.js.map +1 -1
- package/dist/operation-authorization.d.ts +73 -0
- package/dist/operation-authorization.js +42 -0
- package/dist/operation-authorization.js.map +1 -0
- package/dist/presentation.js +49 -19
- package/dist/presentation.js.map +1 -1
- package/dist/resource-claims.d.ts +65 -0
- package/dist/resource-claims.js +398 -0
- package/dist/resource-claims.js.map +1 -0
- package/dist/session-registry.d.ts +215 -1
- package/dist/session-registry.js +1749 -185
- package/dist/session-registry.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { type GitCommandRunner, type RepositoryContext } from "./git.js";
|
|
1
|
+
import { type GitCommandRunner, type GitWorktreeInfo, type PhysicalExecutionContext, type RepositoryContext } from "./git.js";
|
|
2
2
|
import { type RegistryErrorCode, type RegistryErrorDetails } from "./errors.js";
|
|
3
|
+
import { RESOURCE_CLAIM_SCHEMA_VERSION, type ResourceClaim, type ResourceClaimInput, type ResourceClaimMode } from "./resource-claims.js";
|
|
4
|
+
import { type CheckpointEvidence, type CheckpointOptions, type OperationAuthorizationDecision, type OperationAuthorizationOptions } from "./operation-authorization.js";
|
|
5
|
+
export type { ResourceClaim } from "./resource-claims.js";
|
|
3
6
|
export declare const REGISTRY_SCHEMA_VERSION: 1;
|
|
7
|
+
export { RESOURCE_CLAIM_SCHEMA_VERSION };
|
|
4
8
|
export declare const REGISTRY_DIRECTORY_NAME = "nawabari";
|
|
5
9
|
export declare const REGISTRY_FILE_NAME = "session-registry.json";
|
|
6
10
|
export declare const REGISTRY_LOCK_FILE_NAME = "session-registry.lock";
|
|
7
11
|
export declare const DEFAULT_STALE_AFTER_MS: number;
|
|
12
|
+
export declare const CLEANUP_DECISION_SCHEMA_VERSION: 1;
|
|
13
|
+
export declare const RECONCILIATION_SCHEMA_VERSION: 1;
|
|
8
14
|
export type RegistrySchemaVersion = typeof REGISTRY_SCHEMA_VERSION;
|
|
9
15
|
export type SessionState = "new" | "active" | "closing" | "closed" | "stale";
|
|
10
16
|
export interface SessionRecord {
|
|
@@ -53,6 +59,7 @@ export interface GarbageCollectBlocked {
|
|
|
53
59
|
readonly code: RegistryErrorCode;
|
|
54
60
|
readonly message: string;
|
|
55
61
|
readonly details: RegistryErrorDetails;
|
|
62
|
+
readonly recoveryHints: readonly string[];
|
|
56
63
|
}
|
|
57
64
|
export interface GarbageCollectResult {
|
|
58
65
|
readonly apply: boolean;
|
|
@@ -60,6 +67,83 @@ export interface GarbageCollectResult {
|
|
|
60
67
|
readonly cleaned: readonly SessionRecord[];
|
|
61
68
|
readonly blocked: readonly GarbageCollectBlocked[];
|
|
62
69
|
}
|
|
70
|
+
export interface CleanupBlocker {
|
|
71
|
+
readonly code: RegistryErrorCode;
|
|
72
|
+
readonly message: string;
|
|
73
|
+
readonly details: RegistryErrorDetails;
|
|
74
|
+
readonly recoveryHints: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
export interface CleanupDecision {
|
|
77
|
+
readonly schemaVersion: typeof CLEANUP_DECISION_SCHEMA_VERSION;
|
|
78
|
+
readonly operation: "cleanup";
|
|
79
|
+
readonly allowed: boolean;
|
|
80
|
+
readonly code: "ALLOWED" | RegistryErrorCode;
|
|
81
|
+
readonly repositoryId: string;
|
|
82
|
+
readonly worktreePath: string;
|
|
83
|
+
readonly branchName: string;
|
|
84
|
+
readonly session: SessionRecord;
|
|
85
|
+
readonly claims: readonly ResourceClaim[];
|
|
86
|
+
readonly physicalState: string;
|
|
87
|
+
readonly blockers: readonly CleanupBlocker[];
|
|
88
|
+
readonly recoveryHints: readonly string[];
|
|
89
|
+
}
|
|
90
|
+
export type ReconciliationSessionStatus = "healthy" | "candidate" | "drift" | "closed";
|
|
91
|
+
export interface ReconciliationSession {
|
|
92
|
+
readonly session: SessionRecord;
|
|
93
|
+
readonly status: ReconciliationSessionStatus;
|
|
94
|
+
readonly physicalState: string;
|
|
95
|
+
readonly blockers: readonly CleanupBlocker[];
|
|
96
|
+
}
|
|
97
|
+
export interface ReconciliationIssue {
|
|
98
|
+
readonly code: RegistryErrorCode;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
readonly sessionId: string | null;
|
|
101
|
+
readonly worktreePath: string | null;
|
|
102
|
+
readonly branchName: string | null;
|
|
103
|
+
readonly details: RegistryErrorDetails;
|
|
104
|
+
readonly recoveryHints: readonly string[];
|
|
105
|
+
}
|
|
106
|
+
export interface ReconciliationResult {
|
|
107
|
+
readonly schemaVersion: typeof RECONCILIATION_SCHEMA_VERSION;
|
|
108
|
+
readonly repositoryId: string;
|
|
109
|
+
readonly worktrees: readonly GitWorktreeInfo[];
|
|
110
|
+
readonly sessions: readonly ReconciliationSession[];
|
|
111
|
+
readonly issues: readonly ReconciliationIssue[];
|
|
112
|
+
readonly clean: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface ClaimResourcesOptions {
|
|
115
|
+
readonly sessionId?: string | null;
|
|
116
|
+
readonly session_id?: string | null;
|
|
117
|
+
readonly claims: readonly ResourceClaimInput[];
|
|
118
|
+
readonly repositoryId?: string;
|
|
119
|
+
readonly repository_id?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface UpdateClaimsOptions extends ClaimResourcesOptions {
|
|
122
|
+
}
|
|
123
|
+
export interface ReleaseClaimsOptions {
|
|
124
|
+
readonly sessionId?: string | null;
|
|
125
|
+
readonly session_id?: string | null;
|
|
126
|
+
readonly claimIds?: readonly string[];
|
|
127
|
+
readonly claim_ids?: readonly string[];
|
|
128
|
+
}
|
|
129
|
+
export interface ClaimResourcesResult {
|
|
130
|
+
readonly session: SessionRecord;
|
|
131
|
+
readonly claims: readonly ResourceClaim[];
|
|
132
|
+
readonly added: readonly ResourceClaim[];
|
|
133
|
+
readonly released: readonly ResourceClaim[];
|
|
134
|
+
readonly idempotent: boolean;
|
|
135
|
+
}
|
|
136
|
+
export interface ReleaseClaimsResult {
|
|
137
|
+
readonly sessionId: string;
|
|
138
|
+
readonly released: readonly ResourceClaim[];
|
|
139
|
+
readonly remaining: readonly ResourceClaim[];
|
|
140
|
+
readonly idempotent: boolean;
|
|
141
|
+
}
|
|
142
|
+
export interface RegistryMigrationResult {
|
|
143
|
+
readonly migrated: boolean;
|
|
144
|
+
readonly registrySchemaVersion: typeof REGISTRY_SCHEMA_VERSION;
|
|
145
|
+
readonly claimSchemaVersion: typeof RESOURCE_CLAIM_SCHEMA_VERSION;
|
|
146
|
+
}
|
|
63
147
|
export interface GuardOptions {
|
|
64
148
|
readonly sessionId?: string | null;
|
|
65
149
|
}
|
|
@@ -76,6 +160,50 @@ export interface GuardDecision {
|
|
|
76
160
|
readonly state: SessionState | null;
|
|
77
161
|
readonly details: RegistryErrorDetails;
|
|
78
162
|
}
|
|
163
|
+
export type { CheckpointEvidence, CheckpointOptions, OperationAuthorizationDecision, OperationAuthorizationOptions, } from "./operation-authorization.js";
|
|
164
|
+
export { CHECKPOINT_EVIDENCE_SCHEMA_VERSION, CHECKPOINT_MAX_PATHS, OPERATION_AUTHORIZATION_SCHEMA_VERSION, OPERATION_REQUIRED_ACCESS, OPERATION_VOCABULARY, } from "./operation-authorization.js";
|
|
165
|
+
export interface VerifiedExecutionContext extends PhysicalExecutionContext {
|
|
166
|
+
readonly session: SessionRecord;
|
|
167
|
+
}
|
|
168
|
+
export declare const GOVERNED_GIT_OPERATION_SCHEMA_VERSION: 1;
|
|
169
|
+
export interface CommitOptions {
|
|
170
|
+
readonly sessionId?: string | null;
|
|
171
|
+
readonly session_id?: string | null;
|
|
172
|
+
readonly message: string;
|
|
173
|
+
/** Concrete repository-relative paths. Globs are never accepted here. */
|
|
174
|
+
readonly resources?: readonly string[];
|
|
175
|
+
/** Alias for callers that name the same explicit paths as paths. */
|
|
176
|
+
readonly paths?: readonly string[];
|
|
177
|
+
}
|
|
178
|
+
export interface CommitResult {
|
|
179
|
+
readonly schemaVersion: typeof GOVERNED_GIT_OPERATION_SCHEMA_VERSION;
|
|
180
|
+
readonly commitSha: string;
|
|
181
|
+
readonly message: string;
|
|
182
|
+
readonly resources: readonly string[];
|
|
183
|
+
}
|
|
184
|
+
export type PushRelation = "no-upstream" | "up-to-date" | "ahead" | "behind" | "diverged";
|
|
185
|
+
export interface PushOptions {
|
|
186
|
+
readonly sessionId?: string | null;
|
|
187
|
+
readonly session_id?: string | null;
|
|
188
|
+
/** Explicit claim-covered resources; push never infers these from the registry. */
|
|
189
|
+
readonly resources?: readonly string[];
|
|
190
|
+
readonly remote?: string | null;
|
|
191
|
+
readonly branch?: string | null;
|
|
192
|
+
readonly remoteBranch?: string | null;
|
|
193
|
+
readonly remote_branch?: string | null;
|
|
194
|
+
readonly force?: boolean;
|
|
195
|
+
readonly createUpstream?: boolean;
|
|
196
|
+
readonly create_upstream?: boolean;
|
|
197
|
+
}
|
|
198
|
+
export interface PushResult {
|
|
199
|
+
readonly schemaVersion: typeof GOVERNED_GIT_OPERATION_SCHEMA_VERSION;
|
|
200
|
+
readonly remote: string;
|
|
201
|
+
readonly branch: string;
|
|
202
|
+
readonly target: string;
|
|
203
|
+
readonly relation: PushRelation;
|
|
204
|
+
readonly force: boolean;
|
|
205
|
+
readonly upstreamCreated: boolean;
|
|
206
|
+
}
|
|
79
207
|
export interface SessionRegistryOptions {
|
|
80
208
|
readonly cwd?: string;
|
|
81
209
|
readonly repository?: RepositoryContext;
|
|
@@ -109,10 +237,25 @@ export interface PersistedSessionRecord {
|
|
|
109
237
|
readonly updated_at: string;
|
|
110
238
|
readonly label?: string;
|
|
111
239
|
}
|
|
240
|
+
export interface PersistedResourceClaim {
|
|
241
|
+
readonly schema_version: typeof RESOURCE_CLAIM_SCHEMA_VERSION;
|
|
242
|
+
readonly claim_id: string;
|
|
243
|
+
readonly session_id: string;
|
|
244
|
+
readonly repository_id: string;
|
|
245
|
+
readonly worktree_path: string;
|
|
246
|
+
readonly resource: string;
|
|
247
|
+
readonly mode: ResourceClaimMode;
|
|
248
|
+
readonly created_at: string;
|
|
249
|
+
readonly updated_at: string;
|
|
250
|
+
}
|
|
112
251
|
export interface PersistedRegistry {
|
|
113
252
|
readonly schema_version: RegistrySchemaVersion;
|
|
114
253
|
readonly repository_id: string;
|
|
115
254
|
readonly sessions: readonly PersistedSessionRecord[];
|
|
255
|
+
/** Optional in the TypeScript shape so v0.1.0 fixtures remain readable. */
|
|
256
|
+
readonly claims_schema_version?: typeof RESOURCE_CLAIM_SCHEMA_VERSION;
|
|
257
|
+
/** Optional in the TypeScript shape so v0.1.0 fixtures remain readable. */
|
|
258
|
+
readonly claims?: readonly PersistedResourceClaim[];
|
|
116
259
|
}
|
|
117
260
|
export declare class SessionRegistry {
|
|
118
261
|
readonly repository: RepositoryContext;
|
|
@@ -133,6 +276,22 @@ export declare class SessionRegistry {
|
|
|
133
276
|
read(): readonly SessionRecord[];
|
|
134
277
|
list(): readonly SessionRecord[];
|
|
135
278
|
get(sessionId: string): SessionRecord | undefined;
|
|
279
|
+
/** Return the single authoritative claim set, optionally scoped to a session. */
|
|
280
|
+
listClaims(sessionId?: string | null): readonly ResourceClaim[];
|
|
281
|
+
claims(sessionId?: string | null): readonly ResourceClaim[];
|
|
282
|
+
getClaim(claimId: string): ResourceClaim | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Explicitly materialize the v0.1.0 registry's empty claim section. This is
|
|
285
|
+
* also performed by the first ownership mutation after a legacy read.
|
|
286
|
+
*/
|
|
287
|
+
migrate(): RegistryMigrationResult;
|
|
288
|
+
claim(sessionIdOrOptions: string | ClaimResourcesOptions, inputs?: readonly ResourceClaimInput[]): ClaimResourcesResult;
|
|
289
|
+
acquireClaims(sessionIdOrOptions: string | ClaimResourcesOptions, inputs?: readonly ResourceClaimInput[]): ClaimResourcesResult;
|
|
290
|
+
/** Add claims atomically. Repeating an equivalent operation is idempotent. */
|
|
291
|
+
claimResources(options: ClaimResourcesOptions): ClaimResourcesResult;
|
|
292
|
+
updateClaims(options: UpdateClaimsOptions): ClaimResourcesResult;
|
|
293
|
+
releaseClaims(sessionIdOrOptions: string | ReleaseClaimsOptions, claimIds?: readonly string[]): ReleaseClaimsResult;
|
|
294
|
+
releaseSessionClaims(sessionId: string): ReleaseClaimsResult;
|
|
136
295
|
create(options?: CreateSessionOptions): SessionRecord;
|
|
137
296
|
createSession(options?: CreateSessionOptions): SessionRecord;
|
|
138
297
|
/** Provision one isolated Git worktree and commit its ownership atomically. */
|
|
@@ -143,27 +302,82 @@ export declare class SessionRegistry {
|
|
|
143
302
|
registerSession(record: SessionRecord): SessionRecord;
|
|
144
303
|
resolveCurrentSession(): SessionRecord;
|
|
145
304
|
currentSession(): SessionRecord;
|
|
305
|
+
/**
|
|
306
|
+
* Resolve Git's physical facts and the registry's active owner as one
|
|
307
|
+
* fail-closed observation for governed operations.
|
|
308
|
+
*/
|
|
309
|
+
verifyExecutionContext(options?: GuardOptions): VerifiedExecutionContext;
|
|
310
|
+
/** Shared physical/protected/ownership path for every governed decision. */
|
|
311
|
+
private verifyGovernedExecutionContext;
|
|
312
|
+
private resolveSessionOwnership;
|
|
146
313
|
/**
|
|
147
314
|
* Evaluate the current worktree as a Nawabari mutation context without taking
|
|
148
315
|
* the registry lock or changing Git or registry state.
|
|
149
316
|
*/
|
|
150
317
|
guard(options?: GuardOptions): GuardDecision;
|
|
318
|
+
/**
|
|
319
|
+
* The single claim-aware authorization decision for every governed local
|
|
320
|
+
* operation. Ownership is observed first; caller labels never substitute for
|
|
321
|
+
* the physical repository/worktree/branch facts or persisted claims.
|
|
322
|
+
*/
|
|
323
|
+
authorizeOperation(options: OperationAuthorizationOptions): OperationAuthorizationDecision;
|
|
324
|
+
/**
|
|
325
|
+
* Stage and commit only caller-declared, claim-authorized resources.
|
|
326
|
+
* Authorization, physical observations, and Git mutation are serialized by
|
|
327
|
+
* the existing repository lock; this method does not introduce another
|
|
328
|
+
* ownership or mutation authority.
|
|
329
|
+
*/
|
|
330
|
+
commit(options: CommitOptions): CommitResult;
|
|
331
|
+
commitSession(options: CommitOptions): CommitResult;
|
|
332
|
+
/** Push the currently owned branch to an explicit remote/branch target. */
|
|
333
|
+
push(options: PushOptions): PushResult;
|
|
334
|
+
pushSession(options: PushOptions): PushResult;
|
|
335
|
+
private requireMutationAuthorization;
|
|
336
|
+
/** Capture bounded Git evidence for the current owned session's declaration. */
|
|
337
|
+
checkpoint(options?: CheckpointOptions): CheckpointEvidence;
|
|
338
|
+
captureCheckpoint(options?: CheckpointOptions): CheckpointEvidence;
|
|
339
|
+
/**
|
|
340
|
+
* Produce the authoritative, non-mutating cleanup decision for one session.
|
|
341
|
+
* The decision observes registry claims and current Git/filesystem state in
|
|
342
|
+
* one repository-locked read; it never repairs drift or removes resources.
|
|
343
|
+
*/
|
|
344
|
+
cleanupDecision(sessionIdOrOptions?: string | null | CloseSessionOptions): CleanupDecision;
|
|
345
|
+
/** Compatibility alias for callers that name the same authority an assessment. */
|
|
346
|
+
assessCleanup(sessionIdOrOptions?: string | null | CloseSessionOptions): CleanupDecision;
|
|
347
|
+
/**
|
|
348
|
+
* Reconcile registry ownership with Git's physical worktree inventory.
|
|
349
|
+
* This is deliberately diagnostic-only: no stale metadata is repaired and
|
|
350
|
+
* no physical resource is removed by this method.
|
|
351
|
+
*/
|
|
352
|
+
reconcile(): ReconciliationResult;
|
|
353
|
+
reconcileState(): ReconciliationResult;
|
|
151
354
|
/** Close one session only after its ownership and recoverability are proven safe. */
|
|
152
355
|
close(sessionIdOrOptions?: string | null | CloseSessionOptions): CloseSessionResult;
|
|
153
356
|
closeSession(sessionIdOrOptions?: string | null | CloseSessionOptions): CloseSessionResult;
|
|
154
357
|
/** Detect stale sessions, optionally applying only cleanup that passes close preflight. */
|
|
155
358
|
garbageCollect(options?: GarbageCollectOptions): GarbageCollectResult;
|
|
156
359
|
gc(options?: GarbageCollectOptions): GarbageCollectResult;
|
|
360
|
+
private resolveOwnerSession;
|
|
361
|
+
private selectSessionId;
|
|
362
|
+
private claimOwner;
|
|
363
|
+
private canonicalClaimInputs;
|
|
364
|
+
private addClaimsUnsafe;
|
|
365
|
+
private validateRequestedClaims;
|
|
157
366
|
private closeUnsafe;
|
|
158
367
|
private inspectCleanupResources;
|
|
368
|
+
private cleanupDecisionUnsafe;
|
|
369
|
+
private assertCleanupAllowed;
|
|
370
|
+
private reconcileSessionUnsafe;
|
|
159
371
|
private protectedWorktree;
|
|
160
372
|
private protectedBranch;
|
|
161
373
|
private branchIsReachableFromIntegration;
|
|
162
374
|
private resolveProvisioningResources;
|
|
163
375
|
private resolveCreationResources;
|
|
376
|
+
private readStateUnsafe;
|
|
164
377
|
private readUnsafe;
|
|
165
378
|
private writeUnsafe;
|
|
166
379
|
private mutate;
|
|
167
380
|
private withLock;
|
|
168
381
|
}
|
|
169
382
|
export declare function toPersistedSessionRecord(record: SessionRecord, expectedRepositoryId?: string): PersistedSessionRecord;
|
|
383
|
+
export declare function toPersistedResourceClaim(claim: ResourceClaim, expectedRepositoryId?: string): PersistedResourceClaim;
|