@sabaiway/agent-workflow-kit 14.1.0 → 14.3.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.
@@ -6,7 +6,10 @@ import { readFileBytesNoFollow } from './fs-read-nofollow.mjs';
6
6
  import { parseLedger, isSweep, PLAN_HEADINGS } from './plan-shape.mjs';
7
7
  import { expandSweepPaths } from './plan-shape-facts.mjs';
8
8
  import { readStoryLine, PIN_FILE } from './plan-shape-ownership.mjs';
9
- import { parseDispatchContract } from './dispatch-record.mjs';
9
+ import { parseDispatchContract, isThreadTerminalRecord } from './dispatch-record.mjs';
10
+ import { runBaseDiff } from './dispatch-baseline.mjs';
11
+ import { readDelegationLedger } from './dispatch-store-read.mjs';
12
+ import { claimedPaths } from './task-thread.mjs';
10
13
  import { newestCheckpoint, verifyCheckpoint } from './checkpoint.mjs';
11
14
  import { withRepository, readGit } from './checkpoint-core.mjs';
12
15
  import { isDirectRun } from './direct-run.mjs';
@@ -19,6 +22,7 @@ const START = 0;
19
22
  const ONE = 1;
20
23
  const EMPTY = '';
21
24
  const NL = '\n';
25
+ const NUL = '\0';
22
26
  const CR_END = /\r$/;
23
27
  const UTF8 = 'utf8';
24
28
  const STRING = 'string';
@@ -49,6 +53,9 @@ const GROUP_SEPARATOR = ', ';
49
53
  const PARENT = '..';
50
54
  const CURRENT = '.';
51
55
  const READ_OK = 'ok';
56
+ const READ_ERROR = 'error';
57
+ const CHECKPOINT_KIND = 'checkpoint';
58
+ const CHANGED_PATH_ARGS = ['--name-only', '--no-renames', '-z'];
52
59
  const SCHEMA = 1;
53
60
  const BINDING_KEYS = ['schema', 'plan', 'reads', 'checkpoint', 'head'];
54
61
  const FILE_KEYS = ['path', 'sha256'];
@@ -243,7 +250,18 @@ export const checkBrief = (cwd, briefPath, { dispatchPath } = {}, io = {}) => wi
243
250
  entry.path !== binding.reads[index].path || entry.sha256 !== binding.reads[index].sha256)) reject(NAMES.read);
244
251
  if (binding.checkpoint !== newest.oid) reject(NAMES.checkpoint);
245
252
  const verified = verifyCheckpoint(cwd, binding.checkpoint, context.io);
246
- if (!verified.ok || !verified.clean) reject(NAMES.stale, verified.reason);
253
+ if (!verified.ok) reject(NAMES.stale, verified.reason);
254
+ if (!verified.clean) {
255
+ const changed = runBaseDiff(context.top, { kind: CHECKPOINT_KIND, treeOid: binding.checkpoint }, CHANGED_PATH_ARGS, context.io);
256
+ if (changed === null) reject(NAMES.stale, verified.reason);
257
+ const paths = changed.toString(UTF8).split(NUL).filter(Boolean);
258
+ const ledger = readDelegationLedger(context.cwd, context.env);
259
+ if (ledger.state === READ_ERROR) reject(NAMES.stale, ledger.reason);
260
+ const claimed = new Set(ledger.state === READ_OK
261
+ ? claimedPaths(ledger.records, binding.checkpoint, ledger.head, isThreadTerminalRecord) : []);
262
+ const ownFiles = new Set(brief.files.map(({ path }) => path));
263
+ if (!paths.every((path) => claimed.has(path) && !ownFiles.has(path))) reject(NAMES.stale, verified.reason);
264
+ }
247
265
  if (binding.head !== readHead(context, NAMES.boundHead)) reject(NAMES.boundHead);
248
266
  if (dispatchPath !== undefined) checkDispatch(context, dispatchPath, briefPath, file.sha256);
249
267
  return { ok: true, digest: file.sha256 };