kith-coord 0.1.4 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -863,7 +863,9 @@ declare function discoverRepository(input: string): RepositoryLayout;
863
863
  declare function caseSensitivePaths(root: string): boolean;
864
864
 
865
865
  /** Copies a consistent stopped-state set before opening SQLite, so even SHM reconstruction cannot touch original recovery files. */
866
- declare function readCoordinationState(directory?: string): {
866
+ declare function readCoordinationState(directory?: string, options?: {
867
+ ownersOnly?: boolean;
868
+ }): {
867
869
  protocolVersion: string;
868
870
  observedAt: number;
869
871
  repository: {
@@ -1019,7 +1021,7 @@ declare function recoveryReport(directory?: string): {
1019
1021
  error: string | undefined;
1020
1022
  };
1021
1023
 
1022
- declare const KITH_VERSION = "0.1.4";
1023
- declare const KITH_PROTOCOL_VERSION = "1.3.0";
1024
+ declare const KITH_VERSION = "0.1.6";
1025
+ declare const KITH_PROTOCOL_VERSION = "1.4.0";
1024
1026
 
1025
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 };
package/dist/index.js CHANGED
@@ -30,8 +30,8 @@ async function waitForClaim(params) {
30
30
  }
31
31
 
32
32
  // src/version.ts
33
- var KITH_VERSION = "0.1.4";
34
- var KITH_PROTOCOL_VERSION = "1.3.0";
33
+ var KITH_VERSION = "0.1.6";
34
+ var KITH_PROTOCOL_VERSION = "1.4.0";
35
35
 
36
36
  // src/core/workspace-observation.ts
37
37
  import { execFileSync as execFileSync2, spawnSync } from "child_process";
@@ -1725,7 +1725,7 @@ var ResourceBroker = class _ResourceBroker {
1725
1725
  worker.once("error", reject);
1726
1726
  }), stopped]);
1727
1727
  if (params.signal?.aborted) failure ??= abortError();
1728
- if (failure) throw failure;
1728
+ if (failure) throw Object.assign(failure, { stdout: Buffer.concat(stdout).toString(), stderr: Buffer.concat(stderr).toString() });
1729
1729
  if (!outcome) throw new Error("Command worker exited without a result");
1730
1730
  if (outcome.error) throw new Error(outcome.error);
1731
1731
  return { stdout: Buffer.concat(stdout).toString(), stderr: Buffer.concat(stderr).toString(), exitCode: outcome.exitCode, waitedMs };
@@ -1941,7 +1941,7 @@ var CoordDatabase = class _CoordDatabase {
1941
1941
  }
1942
1942
  if (!tables.some((table) => table.name === "meta")) throw new Error("Missing coordination schema metadata. Preserve the database before repair.");
1943
1943
  const row = db.prepare("SELECT value FROM meta WHERE key='schema_version'").get();
1944
- if (row?.value !== "1" && row?.value !== "2") {
1944
+ if (row?.value !== "1" && row?.value !== "2" && row?.value !== "3") {
1945
1945
  throw new Error(`Unsupported coordination schema version: ${String(row?.value)}. Preserve the database before upgrading or repairing it.`);
1946
1946
  }
1947
1947
  const version = Number(row.value);
@@ -1956,7 +1956,8 @@ var CoordDatabase = class _CoordDatabase {
1956
1956
  "resources",
1957
1957
  "quarantine",
1958
1958
  "events",
1959
- ...version === 2 ? ["agent_sessions", "mutex_waiters", "mutex_runs"] : []
1959
+ ...version >= 2 ? ["agent_sessions", "mutex_waiters", "mutex_runs"] : [],
1960
+ ...version >= 3 ? ["mcp_operations"] : []
1960
1961
  ];
1961
1962
  if (required.some((name) => !tables.some((table) => table.name === name))) {
1962
1963
  throw new Error("Incomplete coordination schema. Preserve the database before repair.");
@@ -1966,11 +1967,12 @@ var CoordDatabase = class _CoordDatabase {
1966
1967
  tasks: "status,owner_agent_id,fencing_token,scope_globs_json,depends_on_json",
1967
1968
  locks: "owner_agent_id,pattern,mode,fencing_token,expires_at",
1968
1969
  resources: "type,name,owner_agent_id,fencing_token,expires_at",
1969
- ...version === 2 ? {
1970
+ ...version >= 2 ? {
1970
1971
  agent_sessions: "agent_id,token_hash,epoch",
1971
1972
  mutex_waiters: "ticket,mutex_name,request_id,owner_agent_id,session_epoch,waiter_pid,waiter_start,expires_at",
1972
1973
  mutex_runs: "mutex_name,run_id,owner_agent_id,session_epoch,fencing_token,supervisor_pid,supervisor_start,worker_pid,worker_start"
1973
- } : {}
1974
+ } : {},
1975
+ ...version >= 3 ? { mcp_operations: "operation_key,request_hash,agent_id,session_epoch,capability_hash,owner_pid,owner_start,result_json,created_at" } : {}
1974
1976
  };
1975
1977
  for (const [table, fields] of Object.entries(columns)) {
1976
1978
  try {
@@ -1985,7 +1987,8 @@ var CoordDatabase = class _CoordDatabase {
1985
1987
  "SELECT fencing_token FROM tasks",
1986
1988
  "SELECT fencing_token FROM resources",
1987
1989
  "SELECT fencing_token FROM merge_queue",
1988
- ...version === 2 ? ["SELECT epoch FROM agent_sessions", "SELECT session_epoch FROM mutex_waiters", "SELECT fencing_token FROM mutex_runs"] : []
1990
+ ...version >= 2 ? ["SELECT epoch FROM agent_sessions", "SELECT session_epoch FROM mutex_waiters", "SELECT fencing_token FROM mutex_runs"] : [],
1991
+ ...version >= 3 ? ["SELECT session_epoch FROM mcp_operations"] : []
1989
1992
  ];
1990
1993
  if (db.prepare(`SELECT 1 FROM (${tokens.join(" UNION ALL ")}) WHERE token IS NOT NULL AND (typeof(token)!='integer' OR token<0 OR token>?) LIMIT 1`).get(epoch)) {
1991
1994
  throw new Error("Invalid or regressed fencing counter. Preserve the database before repair.");
@@ -2163,6 +2166,14 @@ var CoordDatabase = class _CoordDatabase {
2163
2166
  worker_pid INTEGER, worker_start TEXT
2164
2167
  );
2165
2168
  `);
2169
+ this.db.exec(`
2170
+ CREATE TABLE IF NOT EXISTS mcp_operations (
2171
+ operation_key TEXT PRIMARY KEY, request_hash TEXT NOT NULL,
2172
+ agent_id TEXT NOT NULL, session_epoch INTEGER NOT NULL, capability_hash TEXT NOT NULL,
2173
+ owner_pid INTEGER NOT NULL, owner_start TEXT NOT NULL,
2174
+ result_json TEXT, created_at INTEGER NOT NULL
2175
+ );
2176
+ `);
2166
2177
  if (version < 2) {
2167
2178
  this.db.exec(`
2168
2179
  UPDATE tasks SET status='queued', owner_agent_id=NULL, fencing_token=NULL
@@ -2174,6 +2185,7 @@ var CoordDatabase = class _CoordDatabase {
2174
2185
  UPDATE meta SET value='2' WHERE key='schema_version';
2175
2186
  `);
2176
2187
  }
2188
+ this.db.exec("UPDATE meta SET value='3' WHERE key='schema_version'");
2177
2189
  });
2178
2190
  }
2179
2191
  /**
@@ -3699,7 +3711,7 @@ import os from "os";
3699
3711
  import path12 from "path";
3700
3712
  import { createRequire as createRequire2 } from "module";
3701
3713
  var { DatabaseSync: DatabaseSync2 } = createRequire2(import.meta.url)("node:sqlite");
3702
- function readCoordinationState(directory = process.cwd()) {
3714
+ function readCoordinationState(directory = process.cwd(), options = {}) {
3703
3715
  const layout = discoverRepository(directory), observedAt = Date.now();
3704
3716
  const empty = {
3705
3717
  protocolVersion: KITH_PROTOCOL_VERSION,
@@ -3755,9 +3767,13 @@ function readCoordinationState(directory = process.cwd()) {
3755
3767
  if (JSON.stringify(before) !== JSON.stringify(files.map(identity))) throw new Error("Coordination state changed during snapshot; stop writers or retry");
3756
3768
  db = new DatabaseSync2(path12.join(scratch, "state.db"), { readOnly: true });
3757
3769
  db.exec("PRAGMA query_only=ON; PRAGMA busy_timeout=1000; BEGIN");
3758
- if (CoordDatabase.inspectSchema(db) !== 2) throw new Error("Offline observation requires schema 2; preserve state and upgrade with clients stopped");
3770
+ if (CoordDatabase.inspectSchema(db) < 2) throw new Error("Offline observation requires schema 2 or newer; preserve state and upgrade with clients stopped");
3759
3771
  const all = (sql) => db.prepare(sql).all();
3760
3772
  const agents = all("SELECT * FROM agents ORDER BY registered_at DESC");
3773
+ if (options.ownersOnly) {
3774
+ db.exec("COMMIT");
3775
+ return { ...empty, state: "ready", agents };
3776
+ }
3761
3777
  const state = {
3762
3778
  ...empty,
3763
3779
  state: "ready",