kith-coord 0.1.6 → 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[];
@@ -685,10 +841,12 @@ declare class IntentAndTaskEngine {
685
841
  * Orchestrator Mode: Atomically claims the highest-priority unblocked task whose scope locks are available.
686
842
  */
687
843
  claimNextTask(agentId: string): {
844
+ ok: boolean;
688
845
  claimed: boolean;
689
846
  task: TaskRecord | null;
690
847
  fencingToken: number | null;
691
848
  locks: LockRecord[];
849
+ activeSiblingIntents: TaskRecord[];
692
850
  reason?: string;
693
851
  };
694
852
  completeTask(params: {
@@ -703,6 +861,136 @@ declare class IntentAndTaskEngine {
703
861
  }): TaskRecord[];
704
862
  }
705
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
+
949
+ interface LinkedWorkspaceContract {
950
+ alias: string;
951
+ sourceRepo: string;
952
+ sourceRepoName: string;
953
+ filePath: string;
954
+ absolutePath: string;
955
+ symbols: Array<{
956
+ symbolName: string;
957
+ kind: ExtractedSymbol['kind'];
958
+ signature: string;
959
+ astHash: string;
960
+ }>;
961
+ dirtyInCheckout: boolean | null;
962
+ exportsComplete: boolean;
963
+ ownershipAvailable: boolean;
964
+ lockedByAgent: string | null;
965
+ activeWorktreeDrifts: Array<{
966
+ agentId: string;
967
+ worktreePath: string;
968
+ changedSymbols: string[];
969
+ removedSymbols: string[];
970
+ }>;
971
+ }
972
+ interface WorkspaceContractReport {
973
+ linkedContracts: LinkedWorkspaceContract[];
974
+ warnings: string[];
975
+ complete: boolean;
976
+ }
977
+ interface SwarmPrompts {
978
+ architect: string;
979
+ worker: string;
980
+ }
981
+ declare function buildSwarmPrompts(repoRoot: string): SwarmPrompts;
982
+ /** Inspect explicit local TS/JS path aliases, never arbitrary directories or a global file crawl.
983
+ * Wildcards are resolved against concrete imports at edit time, not unioned across a folder.
984
+ * This is advisory static inspection, not a compiler or a cross-language compatibility verdict.
985
+ */
986
+ declare function inspectWorkspaceContracts(repoRoot: string, worktreeDir?: string, imports?: string[]): WorkspaceContractReport;
987
+ declare function verifyCrossRepoImportsForFile(params: {
988
+ repoRoot: string;
989
+ worktreeDir?: string;
990
+ filePath: string;
991
+ content: string;
992
+ }): string[];
993
+
706
994
  interface AgentUnreadDelta {
707
995
  events: CoordEvent[];
708
996
  activeConflicts: ConflictRecord[];
@@ -726,7 +1014,18 @@ declare class KithEngine {
726
1014
  readonly mergeTrain: SpeculativeMergeTrain;
727
1015
  readonly bashGuard: BashMerkleGuard;
728
1016
  readonly broker: ResourceBroker;
1017
+ readonly handoffs: HandoffEngine;
729
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;
730
1029
  /**
731
1030
  * Executes the complete PostToolUse pipeline whenever an agent writes or edits a file:
732
1031
  * 1. Extracts AST exports/imports and updates the Contract Blackboard & Import Graph
@@ -760,9 +1059,19 @@ declare class KithEngine {
760
1059
  tasks: TaskRecord[];
761
1060
  conflicts: ConflictRecord[];
762
1061
  contracts: ContractRecord[];
1062
+ linkedContracts: LinkedWorkspaceContract[];
1063
+ crossRepoWarnings: string[];
1064
+ crossRepoComplete: boolean;
763
1065
  resources: ResourceRecord[];
1066
+ workflowMode: "worktrees" | "main";
1067
+ workflowModeConfigured: boolean;
764
1068
  mergeQueue: MergeTrainEntry[];
765
1069
  quarantined: QuarantineRecord[];
1070
+ handoffs: {
1071
+ untrusted: true;
1072
+ notice: string;
1073
+ items: CompactHandoff[];
1074
+ };
766
1075
  mutexWaiters: Record<string, node_sqlite.SQLOutputValue>[];
767
1076
  commandGuards: Record<string, node_sqlite.SQLOutputValue>[];
768
1077
  workspaces: WorkspaceObservation[];
@@ -796,6 +1105,16 @@ declare class KithEngine {
796
1105
  isolateWorktree?: boolean;
797
1106
  }): {
798
1107
  worktree: SpawnedWorktree | null;
1108
+ workflowMode: "worktrees" | "main";
1109
+ notes: string[];
1110
+ handoffs: {
1111
+ untrusted: true;
1112
+ notice: string;
1113
+ items: CompactHandoff[];
1114
+ };
1115
+ linkedContracts: LinkedWorkspaceContract[];
1116
+ crossRepoWarnings: string[];
1117
+ crossRepoComplete: boolean;
799
1118
  ok: boolean;
800
1119
  task: TaskRecord | null;
801
1120
  fencingToken: number;
@@ -803,11 +1122,75 @@ declare class KithEngine {
803
1122
  lockConflicts: LockConflict[];
804
1123
  activeSiblingIntents: TaskRecord[];
805
1124
  };
1125
+ claimNextTask(params: {
1126
+ agentId: string;
1127
+ isolateWorktree?: boolean;
1128
+ }): {
1129
+ worktree: SpawnedWorktree | null;
1130
+ workflowMode: "worktrees" | "main";
1131
+ notes: string[];
1132
+ handoffs: {
1133
+ untrusted: true;
1134
+ notice: string;
1135
+ items: CompactHandoff[];
1136
+ };
1137
+ publishedContracts: ContractRecord[];
1138
+ linkedContracts: LinkedWorkspaceContract[];
1139
+ crossRepoWarnings: string[];
1140
+ crossRepoComplete: boolean;
1141
+ ok: boolean;
1142
+ claimed: boolean;
1143
+ task: TaskRecord | null;
1144
+ fencingToken: number | null;
1145
+ locks: LockRecord[];
1146
+ activeSiblingIntents: TaskRecord[];
1147
+ reason?: string;
1148
+ };
1149
+ private claimWorktree;
1150
+ claimNextTaskWhenAvailable(params: {
1151
+ agentId: string;
1152
+ isolateWorktree?: boolean;
1153
+ waitTimeoutMs: number;
1154
+ signal?: AbortSignal;
1155
+ }): Promise<{
1156
+ worktree: SpawnedWorktree | null;
1157
+ workflowMode: "worktrees" | "main";
1158
+ notes: string[];
1159
+ handoffs: {
1160
+ untrusted: true;
1161
+ notice: string;
1162
+ items: CompactHandoff[];
1163
+ };
1164
+ publishedContracts: ContractRecord[];
1165
+ linkedContracts: LinkedWorkspaceContract[];
1166
+ crossRepoWarnings: string[];
1167
+ crossRepoComplete: boolean;
1168
+ ok: boolean;
1169
+ claimed: boolean;
1170
+ task: TaskRecord | null;
1171
+ fencingToken: number | null;
1172
+ locks: LockRecord[];
1173
+ activeSiblingIntents: TaskRecord[];
1174
+ reason?: string;
1175
+ } & {
1176
+ waitedMs: number;
1177
+ waitTimedOut: boolean;
1178
+ }>;
806
1179
  beginWorkWhenAvailable(params: Parameters<KithEngine['beginWork']>[0] & {
807
1180
  waitTimeoutMs: number;
808
1181
  signal?: AbortSignal;
809
1182
  }): Promise<{
810
1183
  worktree: SpawnedWorktree | null;
1184
+ workflowMode: "worktrees" | "main";
1185
+ notes: string[];
1186
+ handoffs: {
1187
+ untrusted: true;
1188
+ notice: string;
1189
+ items: CompactHandoff[];
1190
+ };
1191
+ linkedContracts: LinkedWorkspaceContract[];
1192
+ crossRepoWarnings: string[];
1193
+ crossRepoComplete: boolean;
811
1194
  ok: boolean;
812
1195
  task: TaskRecord | null;
813
1196
  fencingToken: number;
@@ -832,11 +1215,17 @@ declare class KithEngine {
832
1215
  fencingToken?: number;
833
1216
  mergeBranch?: string;
834
1217
  verificationCmd?: string;
1218
+ waitTimeoutMs?: number;
835
1219
  }): {
836
1220
  ok: boolean;
837
1221
  mergeResult: SpeculativeMergeResult;
838
1222
  error: string;
839
1223
  completedTasks?: undefined;
1224
+ } | {
1225
+ ok: boolean;
1226
+ mergeResult: null;
1227
+ error: string;
1228
+ completedTasks?: undefined;
840
1229
  } | {
841
1230
  ok: boolean;
842
1231
  completedTasks: TaskRecord[];
@@ -859,12 +1248,23 @@ declare function isWithin(root: string, target: string): boolean;
859
1248
  declare function repositoryFile(root: string, file: string): string;
860
1249
  /** Git's common directory identifies shared coordination; Git operations stay in this checkout. */
861
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[];
862
1256
  /** Read-only probe using an existing directory; uncertain results retain exclusion. */
863
1257
  declare function caseSensitivePaths(root: string): boolean;
864
1258
 
1259
+ declare function extractRecentAgentFiles(rows: Array<{
1260
+ agent_id: string;
1261
+ event_type: string;
1262
+ payload_json: string;
1263
+ }>): Record<string, string[]>;
865
1264
  /** Copies a consistent stopped-state set before opening SQLite, so even SHM reconstruction cannot touch original recovery files. */
866
1265
  declare function readCoordinationState(directory?: string, options?: {
867
1266
  ownersOnly?: boolean;
1267
+ coordinationOnly?: boolean;
868
1268
  }): {
869
1269
  protocolVersion: string;
870
1270
  observedAt: number;
@@ -878,6 +1278,9 @@ declare function readCoordinationState(directory?: string, options?: {
878
1278
  };
879
1279
  state: "ready" | "missing" | "unavailable";
880
1280
  error: string | undefined;
1281
+ sessionEpochs: Record<string, number>;
1282
+ truncated: boolean;
1283
+ schemaVersion: number;
881
1284
  fencingEpoch: number;
882
1285
  agents: AgentRecord[];
883
1286
  tasks: Record<string, unknown>[];
@@ -890,9 +1293,17 @@ declare function readCoordinationState(directory?: string, options?: {
890
1293
  mutexWaiters: Record<string, unknown>[];
891
1294
  commandGuards: Record<string, unknown>[];
892
1295
  events: Record<string, unknown>[];
1296
+ recentAgentFiles: Record<string, string[]>;
893
1297
  workspaces: ReturnType<typeof observeWorkspaces>;
1298
+ handoffs: HandoffRecord[];
1299
+ workflowMode: WorkflowMode;
1300
+ workflowModeConfigured: boolean;
894
1301
  } | {
895
1302
  state: "ready";
1303
+ schemaVersion: number;
1304
+ handoffs: HandoffRecord[];
1305
+ workflowMode: "worktrees" | "main";
1306
+ workflowModeConfigured: boolean;
896
1307
  fencingEpoch: number;
897
1308
  agents: AgentRecord[];
898
1309
  tasks: {
@@ -914,6 +1325,7 @@ declare function readCoordinationState(directory?: string, options?: {
914
1325
  events: {
915
1326
  payload: any;
916
1327
  }[];
1328
+ recentAgentFiles: Record<string, string[]>;
917
1329
  workspaces: WorkspaceObservation[];
918
1330
  protocolVersion: string;
919
1331
  observedAt: number;
@@ -926,7 +1338,57 @@ declare function readCoordinationState(directory?: string, options?: {
926
1338
  node: string;
927
1339
  };
928
1340
  error: string | undefined;
1341
+ sessionEpochs: Record<string, number>;
1342
+ truncated: boolean;
1343
+ } | {
1344
+ state: "ready";
1345
+ schemaVersion: number;
1346
+ agents: AgentRecord[];
1347
+ sessionEpochs: {
1348
+ [k: string]: number;
1349
+ };
1350
+ tasks: {
1351
+ depends_on: any;
1352
+ scope_globs: any;
1353
+ }[];
1354
+ locks: Record<string, unknown>[];
1355
+ conflicts: {
1356
+ details: any;
1357
+ }[];
1358
+ handoffs: HandoffRecord[];
1359
+ workflowMode: "worktrees" | "main";
1360
+ workflowModeConfigured: boolean;
1361
+ resources: Record<string, unknown>[];
1362
+ mutexWaiters: Record<string, unknown>[];
1363
+ commandGuards: Record<string, unknown>[];
1364
+ mergeQueue: Record<string, unknown>[];
1365
+ recentAgentFiles: Record<string, string[]>;
1366
+ truncated: boolean;
1367
+ protocolVersion: string;
1368
+ observedAt: number;
1369
+ repository: {
1370
+ root: string;
1371
+ commonGitDir: string | null;
1372
+ coordDir: string;
1373
+ };
1374
+ runtime: {
1375
+ node: string;
1376
+ };
1377
+ error: string | undefined;
1378
+ fencingEpoch: number;
1379
+ contracts: Record<string, unknown>[];
1380
+ quarantined: Record<string, unknown>[];
1381
+ events: Record<string, unknown>[];
1382
+ workspaces: ReturnType<typeof observeWorkspaces>;
929
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;
930
1392
  /** Recovery is an inspection report: it never clears guards, expires claims, deletes worktrees or restores files. */
931
1393
  declare function recoveryReport(directory?: string): {
932
1394
  retainedWorktrees: {
@@ -956,6 +1418,9 @@ declare function recoveryReport(directory?: string): {
956
1418
  };
957
1419
  state: "ready" | "missing" | "unavailable";
958
1420
  error: string | undefined;
1421
+ sessionEpochs: Record<string, number>;
1422
+ truncated: boolean;
1423
+ schemaVersion: number;
959
1424
  fencingEpoch: number;
960
1425
  agents: AgentRecord[];
961
1426
  tasks: Record<string, unknown>[];
@@ -968,7 +1433,11 @@ declare function recoveryReport(directory?: string): {
968
1433
  mutexWaiters: Record<string, unknown>[];
969
1434
  commandGuards: Record<string, unknown>[];
970
1435
  events: Record<string, unknown>[];
1436
+ recentAgentFiles: Record<string, string[]>;
971
1437
  workspaces: ReturnType<typeof observeWorkspaces>;
1438
+ handoffs: HandoffRecord[];
1439
+ workflowMode: WorkflowMode;
1440
+ workflowModeConfigured: boolean;
972
1441
  } | {
973
1442
  retainedWorktrees: {
974
1443
  path: string;
@@ -986,6 +1455,10 @@ declare function recoveryReport(directory?: string): {
986
1455
  present: boolean;
987
1456
  };
988
1457
  state: "ready";
1458
+ schemaVersion: number;
1459
+ handoffs: HandoffRecord[];
1460
+ workflowMode: "worktrees" | "main";
1461
+ workflowModeConfigured: boolean;
989
1462
  fencingEpoch: number;
990
1463
  agents: AgentRecord[];
991
1464
  tasks: {
@@ -1007,6 +1480,7 @@ declare function recoveryReport(directory?: string): {
1007
1480
  events: {
1008
1481
  payload: any;
1009
1482
  }[];
1483
+ recentAgentFiles: Record<string, string[]>;
1010
1484
  workspaces: WorkspaceObservation[];
1011
1485
  protocolVersion: string;
1012
1486
  observedAt: number;
@@ -1019,9 +1493,100 @@ declare function recoveryReport(directory?: string): {
1019
1493
  node: string;
1020
1494
  };
1021
1495
  error: string | undefined;
1496
+ sessionEpochs: Record<string, number>;
1497
+ truncated: boolean;
1498
+ } | {
1499
+ retainedWorktrees: {
1500
+ path: string;
1501
+ symlink: boolean;
1502
+ agentIds: string[];
1503
+ }[];
1504
+ expiredClaims: Record<string, unknown>[];
1505
+ unfinishedIntegrations: Record<string, unknown>[];
1506
+ setupLock: {
1507
+ path: string;
1508
+ present: boolean;
1509
+ };
1510
+ integrationLock: {
1511
+ path: string;
1512
+ present: boolean;
1513
+ };
1514
+ state: "ready";
1515
+ schemaVersion: number;
1516
+ agents: AgentRecord[];
1517
+ sessionEpochs: {
1518
+ [k: string]: number;
1519
+ };
1520
+ tasks: {
1521
+ depends_on: any;
1522
+ scope_globs: any;
1523
+ }[];
1524
+ locks: Record<string, unknown>[];
1525
+ conflicts: {
1526
+ details: any;
1527
+ }[];
1528
+ handoffs: HandoffRecord[];
1529
+ workflowMode: "worktrees" | "main";
1530
+ workflowModeConfigured: boolean;
1531
+ resources: Record<string, unknown>[];
1532
+ mutexWaiters: Record<string, unknown>[];
1533
+ commandGuards: Record<string, unknown>[];
1534
+ mergeQueue: Record<string, unknown>[];
1535
+ recentAgentFiles: Record<string, string[]>;
1536
+ truncated: boolean;
1537
+ protocolVersion: string;
1538
+ observedAt: number;
1539
+ repository: {
1540
+ root: string;
1541
+ commonGitDir: string | null;
1542
+ coordDir: string;
1543
+ };
1544
+ runtime: {
1545
+ node: string;
1546
+ };
1547
+ error: string | undefined;
1548
+ fencingEpoch: number;
1549
+ contracts: Record<string, unknown>[];
1550
+ quarantined: Record<string, unknown>[];
1551
+ events: Record<string, unknown>[];
1552
+ workspaces: ReturnType<typeof observeWorkspaces>;
1022
1553
  };
1023
1554
 
1024
- declare const KITH_VERSION = "0.1.6";
1025
- declare const KITH_PROTOCOL_VERSION = "1.4.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";
1026
1591
 
1027
- 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 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 SymbolKind, type TaskRecord, type WorkspaceObservation, type WorktreeChange, caseSensitivePaths, discoverRepository, isWithin, observeWorkspaces, physicalPath, previewIntegration, readCoordinationState, recoveryReport, repositoryFile, 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 };