kith-coord 0.1.7 → 0.1.8

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/dist/index.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import * as node_sqlite from 'node:sqlite';
2
2
  import { DatabaseSync } from 'node:sqlite';
3
3
 
4
+ /**
5
+ * Load node:sqlite on first use. A process that never opens a database (a pass-through hook, `kith help`)
6
+ * then neither pays for the module nor prints Node's experimental-feature warning.
7
+ */
8
+ declare function sqliteDatabase(): typeof DatabaseSync;
4
9
  interface CoordEvent {
5
10
  id: number;
6
11
  timestamp: number;
@@ -72,6 +77,7 @@ interface SessionRegistration {
72
77
  declare class FencingAndAgentManager {
73
78
  private readonly coordDb;
74
79
  static readonly DEFAULT_LEASE_MS: number;
80
+ static readonly IDLE_CONFLICT_MS: number;
75
81
  private readonly capabilities;
76
82
  private static ownWindowsStart;
77
83
  private static inspectionFailure;
@@ -97,7 +103,26 @@ declare class FencingAndAgentManager {
97
103
  heartbeat(agentId: string, leaseDurationMs?: number): AgentRecord;
98
104
  getAgent(agentId: string): AgentRecord | null;
99
105
  listAgents(onlyActive?: boolean): AgentRecord[];
106
+ private lastIgnoredPurge;
107
+ /** Fast SQLite probe so startup cleanup does zero Git work on clean repositories. */
108
+ hasIgnoredCleanupTargets(): boolean;
109
+ /**
110
+ * Drop recorded conflicts, file claims, and AST contract/dep rows on paths Git ignores
111
+ * (dev-server logs, traces, build output). Older versions recorded them; they must neither block
112
+ * a session nor survive an upgrade.
113
+ */
114
+ purgeIgnoredClaims(force?: boolean): {
115
+ conflicts: number;
116
+ locks: number;
117
+ };
100
118
  reapDeadAgents(): string[];
119
+ /**
120
+ * Operator escape hatch: release an agent's claims and mark it dead without its session token.
121
+ * Used by `kith session clear` for an auto-session whose capability was lost or is stuck.
122
+ */
123
+ forceReclaimAgent(agentId: string, reason?: string): boolean;
124
+ /** Delete recorded conflicts involving `agentId`, or every conflict when omitted. */
125
+ clearConflicts(agentId?: string): number;
101
126
  completeAgentSession(agentId: string): void;
102
127
  abandonAgentSession(agentId: string): void;
103
128
  private reclaim;
@@ -194,6 +219,104 @@ declare function previewIntegration(repoRoot: string, agent: AgentRecord): {
194
219
  reason?: undefined;
195
220
  };
196
221
 
222
+ /**
223
+ * Handoffs carry what an agent learned across a session boundary. Coordination state alone loses it: when a
224
+ * session ends, its claims are released and its task is requeued as if untouched. This module is storage only,
225
+ * with no Git or filesystem access, so it is safe to call inside a write transaction (session reclaim, task
226
+ * completion). Everything an agent writes into a handoff is untrusted text for the next reader.
227
+ */
228
+ declare const HANDOFF_KINDS: readonly ["progress", "blocked", "done", "abandoned"];
229
+ type HandoffKind = (typeof HANDOFF_KINDS)[number];
230
+ /** Kinds an agent may write itself. `abandoned` is recorded by Kith when a session ends without a note. */
231
+ declare const AGENT_HANDOFF_KINDS: readonly ["progress", "blocked", "done"];
232
+ interface HandoffRecord {
233
+ id: string;
234
+ task_id: string | null;
235
+ task_title: string | null;
236
+ task_status: string | null;
237
+ agent_id: string;
238
+ client: string;
239
+ kind: HandoffKind;
240
+ source: 'agent' | 'auto';
241
+ summary: string;
242
+ done: string[];
243
+ remaining: string[];
244
+ learned: string[];
245
+ failed: string[];
246
+ files: string[];
247
+ scope: string[];
248
+ branch: string | null;
249
+ worktree_path: string | null;
250
+ transcript_ref: string | null;
251
+ created_at: number;
252
+ }
253
+
254
+ interface WriteHandoffParams {
255
+ agentId: string;
256
+ taskId?: string;
257
+ kind: (typeof AGENT_HANDOFF_KINDS)[number];
258
+ summary: string;
259
+ done?: string[];
260
+ remaining?: string[];
261
+ learned?: string[];
262
+ failed?: string[];
263
+ files?: string[];
264
+ transcriptRef?: string;
265
+ /** Hand the task back: requeue it and release its claims so another agent can take it. Not valid with `done`. */
266
+ releaseTask?: boolean;
267
+ }
268
+ declare class HandoffEngine {
269
+ private readonly coordDb;
270
+ private readonly fencing;
271
+ constructor(coordDb: CoordDatabase, fencing: FencingAndAgentManager);
272
+ /** Record what the agent learned. Optionally hand its task back to the queue. */
273
+ write(params: WriteHandoffParams): {
274
+ handoff: HandoffRecord;
275
+ released: boolean;
276
+ };
277
+ recent(sinceMs?: number): HandoffRecord[];
278
+ /** Open handoffs, newest first: what a reader checking status should know is still unfinished. */
279
+ unresolved(limit?: number): HandoffRecord[];
280
+ private normalizeScopes;
281
+ /**
282
+ * Handoffs that matter to a claim: those for the same task first, then unfinished ones whose scope or files overlap
283
+ * the claimed scope, then at most two completion notes for the same area.
284
+ */
285
+ relevantTo(params: {
286
+ taskId?: string | null;
287
+ scopeGlobs: string[];
288
+ limit?: number;
289
+ }): HandoffRecord[];
290
+ list(filter?: {
291
+ taskId?: string;
292
+ agentId?: string;
293
+ scopeGlobs?: string[];
294
+ includeResolved?: boolean;
295
+ limit?: number;
296
+ }): HandoffRecord[];
297
+ }
298
+ interface CompactHandoff {
299
+ id: string;
300
+ kind: HandoffKind;
301
+ source: 'agent' | 'auto';
302
+ agentId: string;
303
+ client: string;
304
+ taskId: string | null;
305
+ taskTitle: string | null;
306
+ summary: string;
307
+ summaryTruncated?: boolean;
308
+ done: string[];
309
+ remaining: string[];
310
+ learned: string[];
311
+ failed: string[];
312
+ files: string[];
313
+ filesOmitted?: number;
314
+ scope: string[];
315
+ branch: string | null;
316
+ transcriptRef: string | null;
317
+ createdAt: number;
318
+ }
319
+
197
320
  type SymbolKind = 'function' | 'type' | 'interface' | 'class' | 'schema' | 'route' | 'const';
198
321
  interface ExtractedSymbol {
199
322
  symbolName: string;
@@ -261,8 +384,9 @@ declare class LockEngine {
261
384
  constructor(coordDb: CoordDatabase, fencing: FencingAndAgentManager);
262
385
  static normalizePattern(repoRoot: string, rawPattern: string): string;
263
386
  static normalizeFile(repoRoot: string, file: string): string;
264
- private static literalScope;
387
+ static literalScope(file: string): string;
265
388
  private rootForAgent;
389
+ private activeWorktreeRoots;
266
390
  private wildcardHasAliases;
267
391
  /** Exact overlap for the documented scope grammar; legacy unsupported locks block conservatively. */
268
392
  static patternsOverlap(rawA: string, rawB: string): boolean;
@@ -344,6 +468,7 @@ declare class DependencyAndContractEngine {
344
468
  * Scans a repository directory to index initial file dependencies and exported contracts.
345
469
  */
346
470
  indexRepositoryFiles(dirPath?: string): number;
471
+ private static readonly SKIP_DIRS;
347
472
  private walkSourceFiles;
348
473
  /**
349
474
  * Automatically parses a modified file's imports and exports, updates the dependency graph
@@ -399,6 +524,7 @@ declare class ShadowGitEngine {
399
524
  private readonly fencing;
400
525
  constructor(coordDb: CoordDatabase, fencing: FencingAndAgentManager);
401
526
  isGitRepository(dir?: string): boolean;
527
+ private blobAt;
402
528
  getHeadCommit(dir?: string): string | null;
403
529
  private getShadowIndexPath;
404
530
  /**
@@ -415,6 +541,12 @@ declare class ShadowGitEngine {
415
541
  }>;
416
542
  worktreeDir?: string;
417
543
  }): string | null;
544
+ /**
545
+ * HEAD moves when anyone commits (including via a temporary index). Entries the agent never
546
+ * touched must follow HEAD, or committed work reads as an uncommitted divergence and later
547
+ * surfaces as a false merge conflict.
548
+ */
549
+ private rebaseShadowIndex;
418
550
  /**
419
551
  * Runs `git merge-tree --write-tree` across `agentId`'s dirty shadow commit and every
420
552
  * other active agent's dirty shadow commit (or branch).
@@ -424,6 +556,8 @@ declare class ShadowGitEngine {
424
556
  content?: string;
425
557
  }>, worktreeDir?: string): DirtyMergeProbeResult;
426
558
  probePairConflict(agentA: string, commitA: string, agentB: string, commitB: string): DirtyMergeProbeResult;
559
+ /** Remove orphaned shadow Git index files left behind by dead or completed sessions. */
560
+ pruneStaleShadowIndexes(dryRun?: boolean): number;
427
561
  listConflicts(): ConflictRecord[];
428
562
  }
429
563
 
@@ -449,6 +583,17 @@ interface BashGuardPostReport {
449
583
  authorizedModifiedFiles: string[];
450
584
  quarantinedViolations: QuarantineRecord[];
451
585
  }
586
+ /**
587
+ * True when a shell command is purely observational (e.g. `ls`, `tail`, `git status`, `stack.mjs status`)
588
+ * and contains no file-redirection or write primitives.
589
+ */
590
+ declare function isReadOnlyShellCommand(command: string): boolean;
591
+ /**
592
+ * True when `command` explicitly references `relPath` (or its filename) and contains a write/mutation
593
+ * indicator. Prevents blaming unrelated or read-only commands for concurrent edits made by the live
594
+ * lock holder in a shared checkout.
595
+ */
596
+ declare function commandTargetsFileForWrite(command: string, relPath: string): boolean;
452
597
  declare class BashMerkleGuard {
453
598
  private readonly coordDb;
454
599
  private readonly fencing;
@@ -486,6 +631,7 @@ declare class BashMerkleGuard {
486
631
  restoreLockedFiles?: boolean;
487
632
  }): BashGuardPostReport;
488
633
  private quarantineAndRevertFile;
634
+ private static readonly SKIP_DIRS;
489
635
  private walkWorkspaceFiles;
490
636
  listQuarantined(): QuarantineRecord[];
491
637
  }
@@ -508,6 +654,7 @@ interface SpeculativeMergeResult {
508
654
  mergedCommitSha: string | null;
509
655
  diagnostics: string;
510
656
  }
657
+ declare function runVerificationCommand(command: string, cwd: string, env: NodeJS.ProcessEnv, timeoutMs?: number): string;
511
658
  declare class SpeculativeMergeTrain {
512
659
  private readonly coordDb;
513
660
  private readonly fencing;
@@ -523,10 +670,19 @@ declare class SpeculativeMergeTrain {
523
670
  worktreePath?: string | null;
524
671
  verificationCmd?: string | null;
525
672
  commitMessage?: string;
673
+ waitTimeoutMs?: number;
674
+ verificationTimeoutMs?: number;
526
675
  }): SpeculativeMergeResult;
527
676
  private gitHead;
528
677
  private gitBranch;
529
- private requireCleanTarget;
678
+ /** Paths with uncommitted changes in the target checkout. Untracked directories end in `/`. Kith's own state is excluded. */
679
+ private dirtyTargetPaths;
680
+ private diffNames;
681
+ /** Paths a merge of `sourceSha` will bring into the target: the source's own changes since the merge base. */
682
+ private pathsChangedBySource;
683
+ private pathsBetween;
684
+ /** Refuse only when the target has uncommitted edits to a file the integration will write. */
685
+ private requireNoTargetOverlap;
530
686
  private cleanupStageWorktree;
531
687
  getEntry(id: string): MergeTrainEntry | null;
532
688
  listQueue(): MergeTrainEntry[];
@@ -705,6 +861,91 @@ declare class IntentAndTaskEngine {
705
861
  }): TaskRecord[];
706
862
  }
707
863
 
864
+ /**
865
+ * How a repository's agents share files. `worktrees` gives each agent an isolated Git worktree and integrates through
866
+ * a merge train. `main` keeps every agent in the one checkout, coordinating through scope claims; it is the model for
867
+ * teams that work on the main branch and treat worktrees as overhead. The mode is repository-wide shared state.
868
+ */
869
+ declare const WORKFLOW_MODES: readonly ["worktrees", "main"];
870
+ type WorkflowMode = (typeof WORKFLOW_MODES)[number];
871
+
872
+ interface BriefAgent {
873
+ agentId: string;
874
+ client: string;
875
+ state: 'live' | 'stale';
876
+ lastSeenMs: number;
877
+ tasks: Array<{
878
+ id: string;
879
+ title: string;
880
+ scope: string[];
881
+ }>;
882
+ claims: number;
883
+ recentFiles?: string[];
884
+ }
885
+ interface BriefHandoff extends CompactHandoff {
886
+ ageMs: number;
887
+ moreItems?: boolean;
888
+ }
889
+ interface Brief {
890
+ repository: string;
891
+ mode: WorkflowMode;
892
+ state: 'ready' | 'none' | 'unavailable';
893
+ error?: string;
894
+ observedAt: number;
895
+ scope?: string[];
896
+ active: BriefAgent[];
897
+ /** Claims held by others that overlap `scope`; only present when a scope was given. */
898
+ blockers: Array<{
899
+ agentId: string;
900
+ pattern: string;
901
+ mode: string;
902
+ }>;
903
+ /** `count` is recent queued work; `stale` is queued work nobody has touched for two weeks, counted but not listed. */
904
+ queued: {
905
+ count: number;
906
+ stale: number;
907
+ next: Array<{
908
+ id: string;
909
+ title: string;
910
+ scope: string[];
911
+ hasHandoff: boolean;
912
+ }>;
913
+ };
914
+ handoffs: BriefHandoff[];
915
+ conflicts: Array<{
916
+ agents: [string, string];
917
+ file: string;
918
+ severity: string;
919
+ }>;
920
+ empty: boolean;
921
+ notice: string;
922
+ }
923
+
924
+ interface CommitParams {
925
+ agentId?: string;
926
+ sessionToken?: string;
927
+ message: string;
928
+ files?: string[];
929
+ callerPid?: number;
930
+ home?: string;
931
+ }
932
+ interface CommitResult {
933
+ ok: boolean;
934
+ commit: string | null;
935
+ branch: string | null;
936
+ files: string[];
937
+ agentId: string | null;
938
+ message: string;
939
+ error?: string;
940
+ }
941
+ /**
942
+ * Commits only the specified (or caller-recorded) files using a temporary Git index,
943
+ * `git commit-tree`, and compare-and-swap `git update-ref`, then syncs those paths in
944
+ * `.git/index` so shared-checkout `main` sessions never sweep sibling edits or leave
945
+ * phantom staged deletions/modifications.
946
+ */
947
+ declare function commitScopedFiles(engine: KithEngine, params: CommitParams): CommitResult;
948
+
708
949
  interface LinkedWorkspaceContract {
709
950
  alias: string;
710
951
  sourceRepo: string;
@@ -773,7 +1014,18 @@ declare class KithEngine {
773
1014
  readonly mergeTrain: SpeculativeMergeTrain;
774
1015
  readonly bashGuard: BashMerkleGuard;
775
1016
  readonly broker: ResourceBroker;
1017
+ readonly handoffs: HandoffEngine;
776
1018
  constructor(repoRoot?: string, customDbPath?: string);
1019
+ /** The repository's workflow mode. Shared by every agent and worktree; `worktrees` unless someone chose `main`. */
1020
+ workflowMode(): WorkflowMode;
1021
+ /** True when `workflow_mode` was explicitly written to `meta` rather than falling back to the default. */
1022
+ workflowModeConfigured(): boolean;
1023
+ setWorkflowMode(mode: WorkflowMode): WorkflowMode;
1024
+ commit(params: CommitParams): CommitResult;
1025
+ /** Read-only situational summary from live state: who is active on what, open handoffs, conflicts, claims that overlap a scope. */
1026
+ brief(options?: {
1027
+ scopeGlobs?: string[];
1028
+ }): Brief;
777
1029
  /**
778
1030
  * Executes the complete PostToolUse pipeline whenever an agent writes or edits a file:
779
1031
  * 1. Extracts AST exports/imports and updates the Contract Blackboard & Import Graph
@@ -811,8 +1063,15 @@ declare class KithEngine {
811
1063
  crossRepoWarnings: string[];
812
1064
  crossRepoComplete: boolean;
813
1065
  resources: ResourceRecord[];
1066
+ workflowMode: "worktrees" | "main";
1067
+ workflowModeConfigured: boolean;
814
1068
  mergeQueue: MergeTrainEntry[];
815
1069
  quarantined: QuarantineRecord[];
1070
+ handoffs: {
1071
+ untrusted: true;
1072
+ notice: string;
1073
+ items: CompactHandoff[];
1074
+ };
816
1075
  mutexWaiters: Record<string, node_sqlite.SQLOutputValue>[];
817
1076
  commandGuards: Record<string, node_sqlite.SQLOutputValue>[];
818
1077
  workspaces: WorkspaceObservation[];
@@ -846,6 +1105,13 @@ declare class KithEngine {
846
1105
  isolateWorktree?: boolean;
847
1106
  }): {
848
1107
  worktree: SpawnedWorktree | null;
1108
+ workflowMode: "worktrees" | "main";
1109
+ notes: string[];
1110
+ handoffs: {
1111
+ untrusted: true;
1112
+ notice: string;
1113
+ items: CompactHandoff[];
1114
+ };
849
1115
  linkedContracts: LinkedWorkspaceContract[];
850
1116
  crossRepoWarnings: string[];
851
1117
  crossRepoComplete: boolean;
@@ -861,6 +1127,13 @@ declare class KithEngine {
861
1127
  isolateWorktree?: boolean;
862
1128
  }): {
863
1129
  worktree: SpawnedWorktree | null;
1130
+ workflowMode: "worktrees" | "main";
1131
+ notes: string[];
1132
+ handoffs: {
1133
+ untrusted: true;
1134
+ notice: string;
1135
+ items: CompactHandoff[];
1136
+ };
864
1137
  publishedContracts: ContractRecord[];
865
1138
  linkedContracts: LinkedWorkspaceContract[];
866
1139
  crossRepoWarnings: string[];
@@ -881,6 +1154,13 @@ declare class KithEngine {
881
1154
  signal?: AbortSignal;
882
1155
  }): Promise<{
883
1156
  worktree: SpawnedWorktree | null;
1157
+ workflowMode: "worktrees" | "main";
1158
+ notes: string[];
1159
+ handoffs: {
1160
+ untrusted: true;
1161
+ notice: string;
1162
+ items: CompactHandoff[];
1163
+ };
884
1164
  publishedContracts: ContractRecord[];
885
1165
  linkedContracts: LinkedWorkspaceContract[];
886
1166
  crossRepoWarnings: string[];
@@ -901,6 +1181,13 @@ declare class KithEngine {
901
1181
  signal?: AbortSignal;
902
1182
  }): Promise<{
903
1183
  worktree: SpawnedWorktree | null;
1184
+ workflowMode: "worktrees" | "main";
1185
+ notes: string[];
1186
+ handoffs: {
1187
+ untrusted: true;
1188
+ notice: string;
1189
+ items: CompactHandoff[];
1190
+ };
904
1191
  linkedContracts: LinkedWorkspaceContract[];
905
1192
  crossRepoWarnings: string[];
906
1193
  crossRepoComplete: boolean;
@@ -928,11 +1215,17 @@ declare class KithEngine {
928
1215
  fencingToken?: number;
929
1216
  mergeBranch?: string;
930
1217
  verificationCmd?: string;
1218
+ waitTimeoutMs?: number;
931
1219
  }): {
932
1220
  ok: boolean;
933
1221
  mergeResult: SpeculativeMergeResult;
934
1222
  error: string;
935
1223
  completedTasks?: undefined;
1224
+ } | {
1225
+ ok: boolean;
1226
+ mergeResult: null;
1227
+ error: string;
1228
+ completedTasks?: undefined;
936
1229
  } | {
937
1230
  ok: boolean;
938
1231
  completedTasks: TaskRecord[];
@@ -955,9 +1248,19 @@ declare function isWithin(root: string, target: string): boolean;
955
1248
  declare function repositoryFile(root: string, file: string): string;
956
1249
  /** Git's common directory identifies shared coordination; Git operations stay in this checkout. */
957
1250
  declare function discoverRepository(input: string): RepositoryLayout;
1251
+ /**
1252
+ * When a workspace directory (such as a multi-repo parent folder) is not itself a Git repository,
1253
+ * discover immediate child directories that are Git repositories.
1254
+ */
1255
+ declare function discoverChildRepositories(input: string): RepositoryLayout[];
958
1256
  /** Read-only probe using an existing directory; uncertain results retain exclusion. */
959
1257
  declare function caseSensitivePaths(root: string): boolean;
960
1258
 
1259
+ declare function extractRecentAgentFiles(rows: Array<{
1260
+ agent_id: string;
1261
+ event_type: string;
1262
+ payload_json: string;
1263
+ }>): Record<string, string[]>;
961
1264
  /** Copies a consistent stopped-state set before opening SQLite, so even SHM reconstruction cannot touch original recovery files. */
962
1265
  declare function readCoordinationState(directory?: string, options?: {
963
1266
  ownersOnly?: boolean;
@@ -990,10 +1293,17 @@ declare function readCoordinationState(directory?: string, options?: {
990
1293
  mutexWaiters: Record<string, unknown>[];
991
1294
  commandGuards: Record<string, unknown>[];
992
1295
  events: Record<string, unknown>[];
1296
+ recentAgentFiles: Record<string, string[]>;
993
1297
  workspaces: ReturnType<typeof observeWorkspaces>;
1298
+ handoffs: HandoffRecord[];
1299
+ workflowMode: WorkflowMode;
1300
+ workflowModeConfigured: boolean;
994
1301
  } | {
995
1302
  state: "ready";
996
1303
  schemaVersion: number;
1304
+ handoffs: HandoffRecord[];
1305
+ workflowMode: "worktrees" | "main";
1306
+ workflowModeConfigured: boolean;
997
1307
  fencingEpoch: number;
998
1308
  agents: AgentRecord[];
999
1309
  tasks: {
@@ -1015,6 +1325,7 @@ declare function readCoordinationState(directory?: string, options?: {
1015
1325
  events: {
1016
1326
  payload: any;
1017
1327
  }[];
1328
+ recentAgentFiles: Record<string, string[]>;
1018
1329
  workspaces: WorkspaceObservation[];
1019
1330
  protocolVersion: string;
1020
1331
  observedAt: number;
@@ -1041,10 +1352,17 @@ declare function readCoordinationState(directory?: string, options?: {
1041
1352
  scope_globs: any;
1042
1353
  }[];
1043
1354
  locks: Record<string, unknown>[];
1355
+ conflicts: {
1356
+ details: any;
1357
+ }[];
1358
+ handoffs: HandoffRecord[];
1359
+ workflowMode: "worktrees" | "main";
1360
+ workflowModeConfigured: boolean;
1044
1361
  resources: Record<string, unknown>[];
1045
1362
  mutexWaiters: Record<string, unknown>[];
1046
1363
  commandGuards: Record<string, unknown>[];
1047
1364
  mergeQueue: Record<string, unknown>[];
1365
+ recentAgentFiles: Record<string, string[]>;
1048
1366
  truncated: boolean;
1049
1367
  protocolVersion: string;
1050
1368
  observedAt: number;
@@ -1058,12 +1376,19 @@ declare function readCoordinationState(directory?: string, options?: {
1058
1376
  };
1059
1377
  error: string | undefined;
1060
1378
  fencingEpoch: number;
1061
- conflicts: Record<string, unknown>[];
1062
1379
  contracts: Record<string, unknown>[];
1063
1380
  quarantined: Record<string, unknown>[];
1064
1381
  events: Record<string, unknown>[];
1065
1382
  workspaces: ReturnType<typeof observeWorkspaces>;
1066
1383
  };
1384
+ /**
1385
+ * The brief, read from a private snapshot: it never creates state, migrates, reaps or writes, so it is safe to run from
1386
+ * any shell, hook or agent whether or not that process ever joined Kith.
1387
+ */
1388
+ declare function readBrief(directory?: string, options?: {
1389
+ scopeGlobs?: string[];
1390
+ handoffLimit?: number;
1391
+ }): Brief;
1067
1392
  /** Recovery is an inspection report: it never clears guards, expires claims, deletes worktrees or restores files. */
1068
1393
  declare function recoveryReport(directory?: string): {
1069
1394
  retainedWorktrees: {
@@ -1108,7 +1433,11 @@ declare function recoveryReport(directory?: string): {
1108
1433
  mutexWaiters: Record<string, unknown>[];
1109
1434
  commandGuards: Record<string, unknown>[];
1110
1435
  events: Record<string, unknown>[];
1436
+ recentAgentFiles: Record<string, string[]>;
1111
1437
  workspaces: ReturnType<typeof observeWorkspaces>;
1438
+ handoffs: HandoffRecord[];
1439
+ workflowMode: WorkflowMode;
1440
+ workflowModeConfigured: boolean;
1112
1441
  } | {
1113
1442
  retainedWorktrees: {
1114
1443
  path: string;
@@ -1127,6 +1456,9 @@ declare function recoveryReport(directory?: string): {
1127
1456
  };
1128
1457
  state: "ready";
1129
1458
  schemaVersion: number;
1459
+ handoffs: HandoffRecord[];
1460
+ workflowMode: "worktrees" | "main";
1461
+ workflowModeConfigured: boolean;
1130
1462
  fencingEpoch: number;
1131
1463
  agents: AgentRecord[];
1132
1464
  tasks: {
@@ -1148,6 +1480,7 @@ declare function recoveryReport(directory?: string): {
1148
1480
  events: {
1149
1481
  payload: any;
1150
1482
  }[];
1483
+ recentAgentFiles: Record<string, string[]>;
1151
1484
  workspaces: WorkspaceObservation[];
1152
1485
  protocolVersion: string;
1153
1486
  observedAt: number;
@@ -1189,10 +1522,17 @@ declare function recoveryReport(directory?: string): {
1189
1522
  scope_globs: any;
1190
1523
  }[];
1191
1524
  locks: Record<string, unknown>[];
1525
+ conflicts: {
1526
+ details: any;
1527
+ }[];
1528
+ handoffs: HandoffRecord[];
1529
+ workflowMode: "worktrees" | "main";
1530
+ workflowModeConfigured: boolean;
1192
1531
  resources: Record<string, unknown>[];
1193
1532
  mutexWaiters: Record<string, unknown>[];
1194
1533
  commandGuards: Record<string, unknown>[];
1195
1534
  mergeQueue: Record<string, unknown>[];
1535
+ recentAgentFiles: Record<string, string[]>;
1196
1536
  truncated: boolean;
1197
1537
  protocolVersion: string;
1198
1538
  observedAt: number;
@@ -1206,14 +1546,47 @@ declare function recoveryReport(directory?: string): {
1206
1546
  };
1207
1547
  error: string | undefined;
1208
1548
  fencingEpoch: number;
1209
- conflicts: Record<string, unknown>[];
1210
1549
  contracts: Record<string, unknown>[];
1211
1550
  quarantined: Record<string, unknown>[];
1212
1551
  events: Record<string, unknown>[];
1213
1552
  workspaces: ReturnType<typeof observeWorkspaces>;
1214
1553
  };
1215
1554
 
1216
- declare const KITH_VERSION = "0.1.7";
1217
- declare const KITH_PROTOCOL_VERSION = "1.5.0";
1555
+ interface GcOptions {
1556
+ dryRun?: boolean;
1557
+ staleDays?: number;
1558
+ force?: boolean;
1559
+ }
1560
+ interface GcPreservedItem {
1561
+ path: string;
1562
+ branch: string | null;
1563
+ reason: 'active-session' | 'open-handoff' | 'dirty' | 'unmerged';
1564
+ }
1565
+ interface GcReport {
1566
+ ok: boolean;
1567
+ dryRun: boolean;
1568
+ repository: string;
1569
+ nothingToClean: boolean;
1570
+ reapedAgents: number;
1571
+ prunedShadowIndexes: number;
1572
+ removedWorktrees: string[];
1573
+ deletedBranches: string[];
1574
+ preservedWorktrees: GcPreservedItem[];
1575
+ prunedExpiredLocks: number;
1576
+ prunedOperations: number;
1577
+ prunedDoneTasks: number;
1578
+ prunedOldEvents: number;
1579
+ prunedDeadAgents: number;
1580
+ prunedArtifacts: number;
1581
+ }
1582
+ /**
1583
+ * Resyncs `.git/index` entries that drifted behind `HEAD` after temporary-index `update-ref` commits
1584
+ * without touching any files in the working tree.
1585
+ */
1586
+ declare function resyncStaleIndexEntries(repoRoot: string): number;
1587
+ declare function gcCoordination(directory?: string, options?: GcOptions): GcReport;
1588
+
1589
+ declare const KITH_VERSION = "0.1.8";
1590
+ declare const KITH_PROTOCOL_VERSION = "1.6.0";
1218
1591
 
1219
- export { type AcquireLockResult, type AgentRecord, type AgentUnreadDelta, AstAnalyzer, type BashGuardPostReport, BashMerkleGuard, type BlastRadiusAlert, CoWWorktreeManager, type ConflictRecord, type ContractRecord, CoordDatabase, type CoordEvent, type DeclareIntentResult, DependencyAndContractEngine, type DirtyMergeProbeResult, type ExtractedImport, type ExtractedSymbol, FencingAndAgentManager, type FileAstAnalysis, type FileModificationReport, type FileSnapshotEntry, IntentAndTaskEngine, KITH_PROTOCOL_VERSION, KITH_VERSION, KithEngine, type LinkedWorkspaceContract, type LockConflict, LockEngine, type LockRecord, type MergeTrainEntry, type PostFileEditHookResult, type QuarantineRecord, type RepositoryLayout, ResourceBroker, type ResourceRecord, SessionOwnershipError, type SessionRegistration, ShadowGitEngine, type SpawnedWorktree, type SpeculativeMergeResult, SpeculativeMergeTrain, StaleFencingTokenError, type SupervisedCommandOptions, type SwarmPrompts, type SymbolKind, type TaskRecord, type WorkspaceContractReport, type WorkspaceObservation, type WorktreeChange, buildSwarmPrompts, caseSensitivePaths, discoverRepository, inspectWorkspaceContracts, isWithin, observeWorkspaces, physicalPath, previewIntegration, readCoordinationState, recoveryReport, repositoryFile, verifyCrossRepoImportsForFile, worktreeChanges };
1592
+ export { type AcquireLockResult, type AgentRecord, type AgentUnreadDelta, AstAnalyzer, type BashGuardPostReport, BashMerkleGuard, type BlastRadiusAlert, CoWWorktreeManager, type CommitParams, type CommitResult, type ConflictRecord, type ContractRecord, CoordDatabase, type CoordEvent, type DeclareIntentResult, DependencyAndContractEngine, type DirtyMergeProbeResult, type ExtractedImport, type ExtractedSymbol, FencingAndAgentManager, type FileAstAnalysis, type FileModificationReport, type FileSnapshotEntry, type GcOptions, type GcPreservedItem, type GcReport, IntentAndTaskEngine, KITH_PROTOCOL_VERSION, KITH_VERSION, KithEngine, type LinkedWorkspaceContract, type LockConflict, LockEngine, type LockRecord, type MergeTrainEntry, type PostFileEditHookResult, type QuarantineRecord, type RepositoryLayout, ResourceBroker, type ResourceRecord, SessionOwnershipError, type SessionRegistration, ShadowGitEngine, type SpawnedWorktree, type SpeculativeMergeResult, SpeculativeMergeTrain, StaleFencingTokenError, type SupervisedCommandOptions, type SwarmPrompts, type SymbolKind, type TaskRecord, type WorkspaceContractReport, type WorkspaceObservation, type WorktreeChange, buildSwarmPrompts, caseSensitivePaths, commandTargetsFileForWrite, commitScopedFiles, discoverChildRepositories, discoverRepository, extractRecentAgentFiles, gcCoordination, inspectWorkspaceContracts, isReadOnlyShellCommand, isWithin, observeWorkspaces, physicalPath, previewIntegration, readBrief, readCoordinationState, recoveryReport, repositoryFile, resyncStaleIndexEntries, runVerificationCommand, sqliteDatabase, verifyCrossRepoImportsForFile, worktreeChanges };