ushman-ledger 1.2.2 → 1.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.
Files changed (56) hide show
  1. package/AGENTS.md +7 -5
  2. package/ARCHITECTURE.md +8 -2
  3. package/CHANGELOG.md +11 -0
  4. package/README.md +27 -5
  5. package/TROUBLESHOOTING.md +17 -3
  6. package/dist/blobs.d.ts.map +1 -1
  7. package/dist/blobs.js +1 -1
  8. package/dist/builders.d.ts +33 -0
  9. package/dist/builders.d.ts.map +1 -1
  10. package/dist/builders.js +10 -1
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +91 -32
  13. package/dist/doctor.d.ts +1 -1
  14. package/dist/doctor.d.ts.map +1 -1
  15. package/dist/doctor.js +45 -11
  16. package/dist/handle.d.ts.map +1 -1
  17. package/dist/handle.js +67 -30
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -3
  21. package/dist/list.d.ts +32 -0
  22. package/dist/list.d.ts.map +1 -1
  23. package/dist/list.js +1 -1
  24. package/dist/patch-resolver.d.ts.map +1 -1
  25. package/dist/patch-resolver.js +1 -1
  26. package/dist/process.d.ts +2 -0
  27. package/dist/process.d.ts.map +1 -0
  28. package/dist/process.js +16 -0
  29. package/dist/read-index.d.ts +7 -7
  30. package/dist/read-index.d.ts.map +1 -1
  31. package/dist/read-index.js +13 -9
  32. package/dist/record.d.ts.map +1 -1
  33. package/dist/record.js +1 -2
  34. package/dist/recovery.d.ts +8 -0
  35. package/dist/recovery.d.ts.map +1 -1
  36. package/dist/recovery.js +142 -30
  37. package/dist/render/retro.d.ts.map +1 -1
  38. package/dist/render/retro.js +4 -1
  39. package/dist/runtime-config.d.ts +2 -0
  40. package/dist/runtime-config.d.ts.map +1 -1
  41. package/dist/runtime-config.js +14 -0
  42. package/dist/schema/entry-core.d.ts +5 -2
  43. package/dist/schema/entry-core.d.ts.map +1 -1
  44. package/dist/schema/entry-core.js +3 -0
  45. package/dist/schema/entry-read.d.ts +57 -0
  46. package/dist/schema/entry-read.d.ts.map +1 -1
  47. package/dist/schema/entry-read.js +9 -1
  48. package/dist/schema/entry-write.d.ts +51 -0
  49. package/dist/schema/entry-write.d.ts.map +1 -1
  50. package/dist/schema/entry-write.js +9 -1
  51. package/dist/storage/filesystem.d.ts +14 -2
  52. package/dist/storage/filesystem.d.ts.map +1 -1
  53. package/dist/storage/filesystem.js +206 -39
  54. package/dist/storage/lock.d.ts.map +1 -1
  55. package/dist/storage/lock.js +38 -16
  56. package/package.json +1 -1
package/dist/doctor.js CHANGED
@@ -4,11 +4,12 @@ import { resolveBlobPath } from "./blobs.js";
4
4
  import { sha256File } from "./json.js";
5
5
  import { getOrderedEntryLocations, readManifestEntryBatch } from "./list.js";
6
6
  import { isReadIndexCurrent, readReadIndex } from "./read-index.js";
7
- import { loadLedgerState } from "./recovery.js";
7
+ import { listPendingCommitQuarantines, loadLedgerState } from "./recovery.js";
8
8
  import { getLedgerRuntimeConfig } from "./runtime-config.js";
9
9
  import { readManifest } from "./storage/filesystem.js";
10
- const CHECKPOINT_MAX_AGE_MS = 24 * 60 * 60 * 1_000;
11
- const OPEN_ISSUE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1_000;
10
+ const HOUR_MS = 60 * 60 * 1_000;
11
+ const DAY_MS = 24 * HOUR_MS;
12
+ const MINUTE_MS = 60 * 1_000;
12
13
  export const DOCTOR_FINDING_CODES = [
13
14
  'blob-corrupt',
14
15
  'blob-missing',
@@ -23,11 +24,12 @@ export const DOCTOR_FINDING_CODES = [
23
24
  'manifest-phase-mismatch',
24
25
  'manifest-sequence-mismatch',
25
26
  'open-issue-stale',
27
+ 'pending-commit-quarantined',
26
28
  'phase-prev-entry-mismatch',
27
29
  'pre-change-checkpoint-stale',
28
30
  'read-failure',
29
31
  ];
30
- const createFinding = ({ code, message, metadata, remediation, }) => ({
32
+ const createFinding = ({ code, message, metadata, remediation }) => ({
31
33
  code,
32
34
  message,
33
35
  metadata,
@@ -40,6 +42,19 @@ const buildDoctorReport = (findings) => ({
40
42
  issues: findings.map((finding) => finding.message),
41
43
  ok: findings.length === 0,
42
44
  });
45
+ const formatAgeThreshold = (ageMs) => {
46
+ if (ageMs >= DAY_MS && ageMs % DAY_MS === 0) {
47
+ const days = ageMs / DAY_MS;
48
+ return `${days} day${days === 1 ? '' : 's'}`;
49
+ }
50
+ if (ageMs >= HOUR_MS && ageMs % HOUR_MS === 0) {
51
+ return `${ageMs / HOUR_MS}h`;
52
+ }
53
+ if (ageMs >= MINUTE_MS && ageMs % MINUTE_MS === 0) {
54
+ return `${ageMs / MINUTE_MS}m`;
55
+ }
56
+ return `${ageMs}ms`;
57
+ };
43
58
  const pushFinding = (findings, finding) => {
44
59
  findings.push(finding);
45
60
  };
@@ -50,7 +65,7 @@ const isMissingPathError = (error) => {
50
65
  const buildReadFailure = (error) => buildDoctorReport([
51
66
  createFinding({
52
67
  code: 'read-failure',
53
- message: `Failed to read ledger state: ${error instanceof Error ? error.message ?? error.name : String(error)}.`,
68
+ message: `Failed to read ledger state: ${error instanceof Error ? (error.message ?? error.name) : String(error)}.`,
54
69
  remediation: 'Re-open the ledger or rerun the command first so recovery can reconcile pending state. If the error persists, repair or restore the invalid manifest/read-index JSON before archiving.',
55
70
  }),
56
71
  ]);
@@ -130,6 +145,20 @@ const checkBlobPresence = async (workspaceRoot, blobChecks) => {
130
145
  });
131
146
  return results.flat();
132
147
  };
148
+ const checkPendingCommitQuarantines = async (workspaceRoot) => {
149
+ const quarantines = await listPendingCommitQuarantines(workspaceRoot);
150
+ return quarantines.map((quarantine) => createFinding({
151
+ code: 'pending-commit-quarantined',
152
+ message: `Pending commit journal ${quarantine.originalFileName} is quarantined: ${quarantine.reason}`,
153
+ metadata: {
154
+ commitPath: quarantine.commitPath,
155
+ metadataPath: quarantine.metadataPath,
156
+ originalFileName: quarantine.originalFileName,
157
+ quarantinedAt: quarantine.quarantinedAt,
158
+ },
159
+ remediation: 'Inspect the quarantined journal under .lab/ledger/pending-quarantine/. Restore it to .lab/ledger/pending/ only if its entry, sequence, and manifest base are known to be safe; otherwise keep or remove it after recording an operator decision.',
160
+ }));
161
+ };
133
162
  const checkManifestCounts = (findings, manifest, entryCount) => {
134
163
  if (manifest.entryCount !== entryCount) {
135
164
  pushFinding(findings, createFinding({
@@ -218,10 +247,11 @@ const trackIdempotencyEntry = (entry, entriesByIdempotencyKey) => {
218
247
  existingEntries.push({ id: entry.id, ts: entry.ts });
219
248
  entriesByIdempotencyKey.set(idempotencyKey, existingEntries);
220
249
  };
221
- const checkChangeLogWarnings = ({ checkpointEntries, entriesByIdempotencyKey, findings, nowMs, openIssueEntries, resolvedLedgerIds, }) => {
250
+ const checkChangeLogWarnings = ({ checkpointEntries, checkpointMaxAgeMs, entriesByIdempotencyKey, findings, nowMs, openIssueMaxAgeMs, openIssueEntries, resolvedLedgerIds, }) => {
251
+ const checkpointMaxAgeLabel = formatAgeThreshold(checkpointMaxAgeMs);
222
252
  for (const checkpointEntry of checkpointEntries) {
223
253
  const ageMs = nowMs - Date.parse(checkpointEntry.ts);
224
- if (ageMs <= CHECKPOINT_MAX_AGE_MS) {
254
+ if (ageMs <= checkpointMaxAgeMs) {
225
255
  continue;
226
256
  }
227
257
  const idempotencyKey = checkpointEntry.links.idempotencyKey;
@@ -230,7 +260,7 @@ const checkChangeLogWarnings = ({ checkpointEntries, entriesByIdempotencyKey, fi
230
260
  if (!hasFollowUp) {
231
261
  pushFinding(findings, createFinding({
232
262
  code: 'pre-change-checkpoint-stale',
233
- message: `Pre-change checkpoint ${checkpointEntry.id} is older than 24h and has no follow-up entry with matching idempotencyKey.`,
263
+ message: `Pre-change checkpoint ${checkpointEntry.id} is older than ${checkpointMaxAgeLabel} and has no follow-up entry with matching idempotencyKey.`,
234
264
  metadata: {
235
265
  entryId: checkpointEntry.id,
236
266
  idempotencyKey: idempotencyKey ?? null,
@@ -239,14 +269,15 @@ const checkChangeLogWarnings = ({ checkpointEntries, entriesByIdempotencyKey, fi
239
269
  }));
240
270
  }
241
271
  }
272
+ const openIssueMaxAgeLabel = formatAgeThreshold(openIssueMaxAgeMs);
242
273
  for (const openIssueEntry of openIssueEntries) {
243
274
  const ageMs = nowMs - Date.parse(openIssueEntry.ts);
244
- if (ageMs <= OPEN_ISSUE_MAX_AGE_MS || resolvedLedgerIds.has(openIssueEntry.id)) {
275
+ if (ageMs <= openIssueMaxAgeMs || resolvedLedgerIds.has(openIssueEntry.id)) {
245
276
  continue;
246
277
  }
247
278
  pushFinding(findings, createFinding({
248
279
  code: 'open-issue-stale',
249
- message: `Open issue note ${openIssueEntry.id} is older than 30 days and has no resolution link.`,
280
+ message: `Open issue note ${openIssueEntry.id} is older than ${openIssueMaxAgeLabel} and has no resolution link.`,
250
281
  metadata: { entryId: openIssueEntry.id },
251
282
  remediation: 'Append a correction or superseding note that links back to the open issue once the follow-up is complete.',
252
283
  }));
@@ -351,7 +382,7 @@ const collectDoctorState = async (workspaceRoot, manifest, readIndex) => {
351
382
  const resolvedLedgerIds = new Set();
352
383
  let entryCount = 0;
353
384
  const nowMs = Date.now();
354
- const { scanBatchSize, scanConcurrency } = getLedgerRuntimeConfig();
385
+ const { doctorCheckpointMaxAgeMs, doctorOpenIssueMaxAgeMs, scanBatchSize, scanConcurrency } = getLedgerRuntimeConfig();
355
386
  const orderedEntries = getOrderedEntryLocations(manifest, readIndex, {});
356
387
  checkManifestSequenceOrder(orderedEntries, findings);
357
388
  for (let index = 0; index < orderedEntries.length; index += scanBatchSize) {
@@ -384,9 +415,11 @@ const collectDoctorState = async (workspaceRoot, manifest, readIndex) => {
384
415
  }
385
416
  checkChangeLogWarnings({
386
417
  checkpointEntries,
418
+ checkpointMaxAgeMs: doctorCheckpointMaxAgeMs,
387
419
  entriesByIdempotencyKey,
388
420
  findings,
389
421
  nowMs,
422
+ openIssueMaxAgeMs: doctorOpenIssueMaxAgeMs,
390
423
  openIssueEntries,
391
424
  resolvedLedgerIds,
392
425
  });
@@ -427,6 +460,7 @@ export const runLedgerDoctor = async (workspaceRoot, options = {}) => {
427
460
  return buildReadFailure(error);
428
461
  }
429
462
  const { blobChecks, entryCount, findings, latestByPhase, unseenManifestEntryIds } = doctorState;
463
+ findings.push(...(await checkPendingCommitQuarantines(workspaceRoot)));
430
464
  findings.push(...(await checkBlobPresence(workspaceRoot, blobChecks)));
431
465
  finalizeManifestChecks({
432
466
  entryCount,
@@ -1 +1 @@
1
- {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAA8B,KAAK,YAAY,EAAe,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAStD,OAAO,KAAK,EAAE,WAAW,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG9E,MAAM,MAAM,YAAY,GAClB,kBAAkB,GAClB,OAAO,GACP,kBAAkB,GAClB,OAAO,GACP,eAAe,GACf,wBAAwB,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnE,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,2HAA2H;AAC3H,MAAM,MAAM,qBAAqB,GAAG;IAChC,QAAQ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,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACnE,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,UAAU,GAAU,eAAe,MAAM,KAAG,OAAO,CAAC,YAAY,CA6E5E,CAAC"}
package/dist/handle.js CHANGED
@@ -13,7 +13,7 @@ import { renderMigrationLogMarkdown } from "./render/migration-log.js";
13
13
  import { renderRetroMarkdown } from "./render/retro.js";
14
14
  import { renderTimelineHtml } from "./render/timeline-html.js";
15
15
  import { renderWorkspaceNarrativeMarkdown } from "./render/workspace-narrative.js";
16
- import { createAtomicTextFileWriter, resolveLedgerPaths, writeAtomicTextFile } from "./storage/filesystem.js";
16
+ import { createAtomicTextFileWriter, createExternalTempFileRegistrar, resolveLedgerPaths, writeAtomicTextFile, } from "./storage/filesystem.js";
17
17
  const createEntryIteratorFactory = ({ filter, state, workspaceRoot, }) => {
18
18
  return (entryOptions = {}) => iterateEntriesFromManifest(workspaceRoot, state.manifest, state.readIndex, {
19
19
  kind: entryOptions.kind,
@@ -29,6 +29,22 @@ const collectRenderedText = async (emit) => {
29
29
  });
30
30
  return chunks.join('');
31
31
  };
32
+ const attachCleanupCause = (error, cleanupError) => {
33
+ if (error instanceof Error) {
34
+ const errorWithCause = error;
35
+ if (errorWithCause.cause === undefined) {
36
+ Object.defineProperty(errorWithCause, 'cause', {
37
+ configurable: true,
38
+ enumerable: false,
39
+ value: cleanupError,
40
+ writable: true,
41
+ });
42
+ }
43
+ return error;
44
+ }
45
+ return new Error(String(error), { cause: cleanupError });
46
+ };
47
+ const getExternalTempRegistrar = (workspaceRoot, outPath) => outPath ? createExternalTempFileRegistrar(workspaceRoot) : undefined;
32
48
  const emitRenderedTarget = async ({ createEntries, manifest, target, write, workspaceName, }) => {
33
49
  switch (target) {
34
50
  case 'dependency-graph':
@@ -82,6 +98,40 @@ const resolveRenderOutputPath = (workspaceRoot, target) => {
82
98
  return null;
83
99
  }
84
100
  };
101
+ const runRenderToWriters = async ({ atomicWriter, createEntries, manifest, target, workspaceName, writer, }) => {
102
+ let hasWrittenContent = false;
103
+ let endsWithNewline = false;
104
+ try {
105
+ await emitRenderedTarget({
106
+ createEntries,
107
+ manifest,
108
+ target,
109
+ workspaceName,
110
+ write: async (chunk) => {
111
+ if (chunk.length > 0) {
112
+ hasWrittenContent = true;
113
+ endsWithNewline = chunk.endsWith('\n');
114
+ }
115
+ await writer?.(chunk);
116
+ await atomicWriter?.write(chunk);
117
+ },
118
+ });
119
+ if (!hasWrittenContent || !endsWithNewline) {
120
+ await writer?.('\n');
121
+ await atomicWriter?.write('\n');
122
+ }
123
+ await atomicWriter?.close();
124
+ }
125
+ catch (error) {
126
+ try {
127
+ await atomicWriter?.abort();
128
+ }
129
+ catch (cleanupError) {
130
+ throw attachCleanupCause(error, cleanupError);
131
+ }
132
+ throw error;
133
+ }
134
+ };
85
135
  /** Open a workspace ledger handle after reconciling any pending crash-recovery state. */
86
136
  export const openLedger = async (workspaceRoot) => {
87
137
  await readLabManifestMin(workspaceRoot);
@@ -115,7 +165,9 @@ export const openLedger = async (workspaceRoot) => {
115
165
  }));
116
166
  const outputPath = options.out ?? resolveRenderOutputPath(workspaceRoot, options.to);
117
167
  if (outputPath) {
118
- await writeAtomicTextFile(outputPath, `${content}${content.endsWith('\n') ? '' : '\n'}`);
168
+ await writeAtomicTextFile(outputPath, `${content}${content.endsWith('\n') ? '' : '\n'}`, {
169
+ registerTempFile: getExternalTempRegistrar(workspaceRoot, options.out),
170
+ });
119
171
  }
120
172
  return content;
121
173
  },
@@ -127,38 +179,23 @@ export const openLedger = async (workspaceRoot) => {
127
179
  workspaceRoot,
128
180
  });
129
181
  const outputPath = options.out ?? resolveRenderOutputPath(workspaceRoot, options.to);
130
- const atomicWriter = outputPath ? await createAtomicTextFileWriter(outputPath) : null;
182
+ const atomicWriter = outputPath
183
+ ? await createAtomicTextFileWriter(outputPath, {
184
+ registerTempFile: getExternalTempRegistrar(workspaceRoot, options.out),
185
+ })
186
+ : null;
131
187
  const writer = options.write;
132
- let hasWrittenContent = false;
133
- let endsWithNewline = false;
134
188
  if (!atomicWriter && !writer) {
135
189
  throw new Error(`Render target ${options.to} requires either a writer callback or an output path.`);
136
190
  }
137
- try {
138
- await emitRenderedTarget({
139
- createEntries,
140
- manifest: state.manifest,
141
- target: options.to,
142
- workspaceName: path.basename(workspaceRoot),
143
- write: async (chunk) => {
144
- if (chunk.length > 0) {
145
- hasWrittenContent = true;
146
- endsWithNewline = chunk.endsWith('\n');
147
- }
148
- await writer?.(chunk);
149
- await atomicWriter?.write(chunk);
150
- },
151
- });
152
- if (!hasWrittenContent || !endsWithNewline) {
153
- await writer?.('\n');
154
- await atomicWriter?.write('\n');
155
- }
156
- await atomicWriter?.close();
157
- }
158
- catch (error) {
159
- await atomicWriter?.abort();
160
- throw error;
161
- }
191
+ await runRenderToWriters({
192
+ atomicWriter,
193
+ createEntries,
194
+ manifest: state.manifest,
195
+ target: options.to,
196
+ workspaceName: path.basename(workspaceRoot),
197
+ writer,
198
+ });
162
199
  },
163
200
  show: async (entryId) => {
164
201
  const { manifest } = await loadLedgerState(workspaceRoot);
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export { type BuildRecordInput, buildChangeLogRecord, buildCorrectionRecord, buildOperatorDecisionRecord, buildStripDecisionRevertedRecord, buildValidatorResultRecord, } from './builders.ts';
1
+ export { type BuildRecordInput, buildChangeLogRecord, buildCorrectionRecord, buildOperatorDecisionRecord, buildStageWriteRecord, buildStripDecisionRevertedRecord, buildValidatorResultRecord, } from './builders.ts';
2
2
  export { runLedgerCli } from './cli.ts';
3
3
  export { type CoverageReport, computeCoverage } from './coverage.ts';
4
4
  export { DOCTOR_FINDING_CODES, type DoctorFinding, type DoctorFindingCode, type DoctorFindingMetadataValue, type DoctorReport, runLedgerDoctor, } from './doctor.ts';
5
5
  export { type LedgerHandle, type LedgerRenderOptions, type LedgerRenderToOptions, openLedger, type RenderTarget, type RenderWriter, } from './handle.ts';
6
6
  export type { LedgerFilter } from './list.ts';
7
- export { type LedgerRuntimeConfig, getLedgerRuntimeConfig, validateLedgerRuntimeConfig } from './runtime-config.ts';
8
7
  export { appendCleanupWaveNote, appendDecompositionWaveNote, appendNote, appendOpenIssueNote, appendSemanticCleanupSummaryNote, appendVerifiedFlowNote, type NoteBody, } from './note.ts';
9
8
  export { deriveFilesChangedFromPatch } from './patch-resolver.ts';
10
- export { type AgentPatchDiff, AgentPatchDiffSchema, AgentPatchEntrySchema, AgentPatchRecordSchema, type ChangeLogEntry, ChangeLogEntrySchema, type ChangeLogFileChange, ChangeLogFileChangeSchema, type ChangeLogParityStatus, ChangeLogParityStatusSchema, type ChangeLogRecord, ChangeLogRecordSchema, type ChangeLogSmokeResult, ChangeLogSmokeResultSchema, type ChangeLogSubkind, ChangeLogSubkindSchema, CorrectionEntrySchema, CorrectionRecordSchema, EmitterSchema, type LedgerEntry, LedgerEntrySchema, type LedgerKind, type LedgerLinks, LedgerLinksSchema, type LedgerPhase, LedgerPhaseSchema, type LedgerRecord, LedgerRecordSchema, type NoteEntry, NoteEntrySchema, type OperatorDecisionAction, OperatorDecisionActionSchema, OperatorDecisionEntrySchema, type OperatorDecisionPayload, OperatorDecisionPayloadSchema, OperatorDecisionRecordSchema, OperatorPatchEntrySchema, OperatorPatchRecordSchema, parseLedgerEntry, parseLedgerRecord, RuntimeEventEntrySchema, StripDecisionRevertedEntrySchema, type StripDecisionRevertedPayload, StripDecisionRevertedPayloadSchema, StripDecisionRevertedRecordSchema, ToolInvocationEntrySchema, ToolInvocationRecordSchema, ValidatorResultEntrySchema, ValidatorResultRecordSchema, } from './schema/entry.ts';
9
+ export { getLedgerRuntimeConfig, type LedgerRuntimeConfig, validateLedgerRuntimeConfig } from './runtime-config.ts';
10
+ export { type AgentPatchDiff, AgentPatchDiffSchema, AgentPatchEntrySchema, AgentPatchRecordSchema, type ChangeLogEntry, ChangeLogEntrySchema, type ChangeLogFileChange, ChangeLogFileChangeSchema, type ChangeLogParityStatus, ChangeLogParityStatusSchema, type ChangeLogRecord, ChangeLogRecordSchema, type ChangeLogSmokeResult, ChangeLogSmokeResultSchema, type ChangeLogSubkind, ChangeLogSubkindSchema, CorrectionEntrySchema, CorrectionRecordSchema, EmitterSchema, type LedgerEntry, LedgerEntrySchema, type LedgerKind, type LedgerLinks, LedgerLinksSchema, type LedgerPhase, LedgerPhaseSchema, type LedgerRecord, LedgerRecordSchema, type NoteEntry, NoteEntrySchema, type OperatorDecisionAction, OperatorDecisionActionSchema, OperatorDecisionEntrySchema, type OperatorDecisionPayload, OperatorDecisionPayloadSchema, OperatorDecisionRecordSchema, OperatorPatchEntrySchema, OperatorPatchRecordSchema, parseLedgerEntry, parseLedgerRecord, RuntimeEventEntrySchema, STAGE_WRITE_STAGES, type StageWriteStage, StageWriteEntrySchema, StageWriteRecordSchema, StripDecisionRevertedEntrySchema, type StripDecisionRevertedPayload, StripDecisionRevertedPayloadSchema, StripDecisionRevertedRecordSchema, ToolInvocationEntrySchema, ToolInvocationRecordSchema, ValidatorResultEntrySchema, ValidatorResultRecordSchema, } from './schema/entry.ts';
11
11
  export { type NoteSubkind, NoteSubkindSchema } from './schema/note.ts';
12
12
  export { resolveLedgerPaths } from './storage/filesystem.ts';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,gBAAgB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC3B,gCAAgC,EAChC,0BAA0B,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,KAAK,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACH,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KA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B,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,KAAK,cAAc,EACnB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,SAAS,EACd,eAAe,EACf,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC3B,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,eAAe,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gCAAgC,EAChC,KAAK,4BAA4B,EACjC,kCAAkC,EAClC,iCAAiC,EACjC,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- export { buildChangeLogRecord, buildCorrectionRecord, buildOperatorDecisionRecord, buildStripDecisionRevertedRecord, buildValidatorResultRecord, } from "./builders.js";
1
+ export { buildChangeLogRecord, buildCorrectionRecord, buildOperatorDecisionRecord, buildStageWriteRecord, buildStripDecisionRevertedRecord, buildValidatorResultRecord, } from "./builders.js";
2
2
  export { runLedgerCli } from "./cli.js";
3
3
  export { computeCoverage } from "./coverage.js";
4
4
  export { DOCTOR_FINDING_CODES, runLedgerDoctor, } from "./doctor.js";
5
5
  export { openLedger, } from "./handle.js";
6
- export { getLedgerRuntimeConfig, validateLedgerRuntimeConfig } from "./runtime-config.js";
7
6
  export { appendCleanupWaveNote, appendDecompositionWaveNote, appendNote, appendOpenIssueNote, appendSemanticCleanupSummaryNote, appendVerifiedFlowNote, } from "./note.js";
8
7
  export { deriveFilesChangedFromPatch } from "./patch-resolver.js";
9
- export { AgentPatchDiffSchema, AgentPatchEntrySchema, AgentPatchRecordSchema, ChangeLogEntrySchema, ChangeLogFileChangeSchema, ChangeLogParityStatusSchema, ChangeLogRecordSchema, ChangeLogSmokeResultSchema, ChangeLogSubkindSchema, CorrectionEntrySchema, CorrectionRecordSchema, EmitterSchema, LedgerEntrySchema, LedgerLinksSchema, LedgerPhaseSchema, LedgerRecordSchema, NoteEntrySchema, OperatorDecisionActionSchema, OperatorDecisionEntrySchema, OperatorDecisionPayloadSchema, OperatorDecisionRecordSchema, OperatorPatchEntrySchema, OperatorPatchRecordSchema, parseLedgerEntry, parseLedgerRecord, RuntimeEventEntrySchema, StripDecisionRevertedEntrySchema, StripDecisionRevertedPayloadSchema, StripDecisionRevertedRecordSchema, ToolInvocationEntrySchema, ToolInvocationRecordSchema, ValidatorResultEntrySchema, ValidatorResultRecordSchema, } from "./schema/entry.js";
8
+ export { getLedgerRuntimeConfig, validateLedgerRuntimeConfig } from "./runtime-config.js";
9
+ export { AgentPatchDiffSchema, AgentPatchEntrySchema, AgentPatchRecordSchema, ChangeLogEntrySchema, ChangeLogFileChangeSchema, ChangeLogParityStatusSchema, ChangeLogRecordSchema, ChangeLogSmokeResultSchema, ChangeLogSubkindSchema, CorrectionEntrySchema, CorrectionRecordSchema, EmitterSchema, LedgerEntrySchema, LedgerLinksSchema, LedgerPhaseSchema, LedgerRecordSchema, NoteEntrySchema, OperatorDecisionActionSchema, OperatorDecisionEntrySchema, OperatorDecisionPayloadSchema, OperatorDecisionRecordSchema, OperatorPatchEntrySchema, OperatorPatchRecordSchema, parseLedgerEntry, parseLedgerRecord, RuntimeEventEntrySchema, STAGE_WRITE_STAGES, StageWriteEntrySchema, StageWriteRecordSchema, StripDecisionRevertedEntrySchema, StripDecisionRevertedPayloadSchema, StripDecisionRevertedRecordSchema, ToolInvocationEntrySchema, ToolInvocationRecordSchema, ValidatorResultEntrySchema, ValidatorResultRecordSchema, } from "./schema/entry.js";
10
10
  export { NoteSubkindSchema } from "./schema/note.js";
11
11
  export { resolveLedgerPaths } from "./storage/filesystem.js";
package/dist/list.d.ts CHANGED
@@ -76,6 +76,38 @@ export declare const readManifestEntryBatch: ({ allowMissing, entryLocations, en
76
76
  schemaVersion: "ushman-ledger-entry/v1";
77
77
  summary: string;
78
78
  ts: string;
79
+ } | {
80
+ filePath: string;
81
+ kind: "stage-write";
82
+ rationale: string;
83
+ stage: "intake" | "seed" | "vendor-extract" | "cleanup" | "candidate-promotion";
84
+ details?: {
85
+ [x: string]: unknown;
86
+ } | undefined;
87
+ emitter: {
88
+ tool: string;
89
+ user?: string | undefined;
90
+ version: string;
91
+ };
92
+ id: string;
93
+ links: {
94
+ affectedFiles?: string[] | undefined;
95
+ blobs?: string[] | undefined;
96
+ briefId?: string | undefined;
97
+ correctsLedgerId?: string | undefined;
98
+ gitRef?: string | undefined;
99
+ idempotencyKey?: string | undefined;
100
+ stripDecisionId?: string | undefined;
101
+ supersedesLedgerId?: string | undefined;
102
+ validatorVerdictId?: string | undefined;
103
+ } & {
104
+ [key: string]: unknown;
105
+ };
106
+ phase: "capture" | "intake" | "seed" | "vendor-extract" | "cleanup" | "parity" | "characterize" | "equiv" | "analyze" | "recover" | "ship" | "migration";
107
+ prevEntryId: string | null;
108
+ schemaVersion: "ushman-ledger-entry/v1";
109
+ summary: string;
110
+ ts: string;
79
111
  } | {
80
112
  agent: {
81
113
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot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AO,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC1D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAQI,CAAC;AAkDN,eAAO,MAAM,0BAA0B,GACnC,eAAe,MAAM,EACrB,UAAU,cAAc,EACxB,WAAW,eAAe,EAC1B,SAAQ,YAAiB,EACzB,YAAW,KAAK,GAAG,MAAc,KAClC,aAAa,CAAC,WAAW,CAkC3B,CAAC;AAEF,eAAO,MAAM,WAAW,GACpB,eAAe,MAAM,EACrB,SAAQ,YAAiB,KAC1B,aAAa,CAAC,WAAW,CAG3B,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,eAAe,MAAM,EAAE,SAAQ,YAAiB,KAAG,OAAO,CAAC,WAAW,EAAE,CAM5G,CAAC"}
package/dist/list.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mapWithConcurrencyLimit } from "./async.js";
2
2
  import { matchesReadIndexFilter, } from "./read-index.js";
3
- import { getLedgerRuntimeConfig } from "./runtime-config.js";
4
3
  import { loadLedgerState } from "./recovery.js";
4
+ import { getLedgerRuntimeConfig } from "./runtime-config.js";
5
5
  import { parseLedgerEntry } from "./schema/entry.js";
6
6
  import { readPhaseEntryText } from "./storage/filesystem.js";
7
7
  const matchesFilter = (entry, filter) => {
@@ -1 +1 @@
1
- {"version":3,"file":"patch-resolver.d.ts","sourceRoot":"","sources":["../src/patch-resolver.ts"],"names":[],"mappings":"AASA,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,YAAY,EAEpB,MAAM,mBAAmB,CAAC;AAK3B,KAAK,gBAAgB,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AACvE,KAAK,mBAAmB,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAAC;AAQ7E,KAAK,wBAAwB,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,GAAG;IACxF,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC/B,CAAC;AACF,KAAK,2BAA2B,GAAG,IAAI,CAAC,mBAAmB,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,GAAG;IAC9F,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,2BAA2B,CAAC;AAsTzF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GAAI,WAAW,MAAM,KAAG,mBAAmB,EAuClF,CAAC;AAmBF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,w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C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AACtC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { readFile, stat } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import * as v from 'valibot';
4
- import { assertPatchTextWithinLimit, readPatchTextFromFile, resolveBlobPath, storePatchBlob, } from "./blobs.js";
4
+ import { assertPatchTextWithinLimit, readPatchTextFromFile, resolveBlobPath, storePatchBlob } from "./blobs.js";
5
5
  import { WorkspaceRelativePathSchema, } from "./schema/entry.js";
6
6
  import { forEachLine } from "./text-lines.js";
7
7
  const readBlobText = async (workspaceRoot, blobSha256) => readFile(resolveBlobPath(workspaceRoot, blobSha256), 'utf8');
@@ -0,0 +1,2 @@
1
+ export declare const isProcessAlive: (pid: number) => boolean;
2
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,YAczC,CAAC"}
@@ -0,0 +1,16 @@
1
+ export const isProcessAlive = (pid) => {
2
+ try {
3
+ process.kill(pid, 0);
4
+ return true;
5
+ }
6
+ catch (error) {
7
+ const code = error.code;
8
+ if (code === 'EPERM') {
9
+ return true;
10
+ }
11
+ if (code === 'ESRCH') {
12
+ return false;
13
+ }
14
+ throw error;
15
+ }
16
+ };
@@ -3,14 +3,14 @@ import { type LedgerEntry, type LedgerKind, type LedgerPhase } from './schema/en
3
3
  import type { LedgerManifest } from './schema/manifest.ts';
4
4
  declare const ReadIndexEntrySchema: v.ObjectSchema<{
5
5
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
6
- readonly kind: v.PicklistSchema<readonly ["tool-invocation", "agent-patch", "operator-patch", "operator-decision", "validator-result", "runtime-event", "note", "correction", "strip-decision-reverted", "change-log"], undefined>;
6
+ readonly kind: v.PicklistSchema<readonly ["tool-invocation", "stage-write", "agent-patch", "operator-patch", "operator-decision", "validator-result", "runtime-event", "note", "correction", "strip-decision-reverted", "change-log"], undefined>;
7
7
  readonly ts: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>;
8
8
  }, undefined>;
9
9
  declare const LedgerReadIndexSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
10
  readonly coveredFiles: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, readonly []>;
11
11
  readonly entries: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
12
12
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
13
- readonly kind: v.PicklistSchema<readonly ["tool-invocation", "agent-patch", "operator-patch", "operator-decision", "validator-result", "runtime-event", "note", "correction", "strip-decision-reverted", "change-log"], undefined>;
13
+ readonly kind: v.PicklistSchema<readonly ["tool-invocation", "stage-write", "agent-patch", "operator-patch", "operator-decision", "validator-result", "runtime-event", "note", "correction", "strip-decision-reverted", "change-log"], undefined>;
14
14
  readonly ts: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>;
15
15
  }, undefined>, undefined>, readonly []>;
16
16
  readonly entryCount: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -21,7 +21,7 @@ declare const LedgerReadIndexSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
21
21
  coveredFiles: string[];
22
22
  entries: {
23
23
  id: string;
24
- kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
24
+ kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "stage-write" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
25
25
  ts: string;
26
26
  }[];
27
27
  entryCount: number;
@@ -32,7 +32,7 @@ declare const LedgerReadIndexSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
32
32
  coveredFiles: string[];
33
33
  entries: {
34
34
  id: string;
35
- kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
35
+ kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "stage-write" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
36
36
  ts: string;
37
37
  }[];
38
38
  entryCount: number;
@@ -50,7 +50,7 @@ export declare const buildReadIndexFromManifest: (workspaceRoot: string, manifes
50
50
  coveredFiles: string[];
51
51
  entries: {
52
52
  id: string;
53
- kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
53
+ kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "stage-write" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
54
54
  ts: string;
55
55
  }[];
56
56
  entryCount: number;
@@ -65,7 +65,7 @@ export declare const ensureReadIndexUnderLock: (workspaceRoot: string, manifest:
65
65
  coveredFiles: string[];
66
66
  entries: {
67
67
  id: string;
68
- kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
68
+ kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "stage-write" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
69
69
  ts: string;
70
70
  }[];
71
71
  entryCount: number;
@@ -81,7 +81,7 @@ export declare const appendEntryToReadIndex: ({ entry, readIndex, sequence, }: {
81
81
  coveredFiles: string[];
82
82
  entries: {
83
83
  id: string;
84
- kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
84
+ kind: "operator-decision" | "validator-result" | "change-log" | "tool-invocation" | "stage-write" | "agent-patch" | "operator-patch" | "runtime-event" | "note" | "correction" | "strip-decision-reverted";
85
85
  ts: string;
86
86
  }[];
87
87
  entryCount: number;
@@ -1 +1 @@
1
- {"version":3,"file":"read-index.d.ts","sourceRoot":"","sources":["../src/read-index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAI7B,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AACxH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,QAAA,MAAM,oBAAoB;;;;aAIxB,CAAC;AAEH,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sDAc1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAC1E,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACxE,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AA4HhG,eAAO,MAAM,0BAA0B,GAAU,eAAe,MAAM,EAAE,UAAU,cAAc;;;;;;;;;;;EAyB/F,CAAC;AAYF,eAAO,MAAM,kBAAkB,GAAI,OAAO,eAAe,EAAE,UAAU,cAAc,YAG1C,C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32,6 +32,15 @@ const buildReadIndexEntry = (entry) => ({
32
32
  kind: entry.kind,
33
33
  ts: entry.ts,
34
34
  });
35
+ const getCoverageFilesForEntry = (entry) => {
36
+ if (entry.kind === 'stage-write') {
37
+ return [...new Set([entry.filePath, ...(entry.links.affectedFiles ?? [])])];
38
+ }
39
+ if (entry.kind === 'agent-patch' || entry.kind === 'operator-patch') {
40
+ return entry.links.affectedFiles ?? [];
41
+ }
42
+ return [];
43
+ };
35
44
  const sortBySequence = (left, right) => left[1].sequence - right[1].sequence;
36
45
  const getManifestSequenceLocations = (manifest) => Object.entries(manifest.entryLocations).sort(sortBySequence);
37
46
  const mergeSortedUniquePaths = (existingPaths, additionalPaths) => {
@@ -88,11 +97,8 @@ const readIndexedEntryBatch = async ({ entryReadConcurrency, entryLocations, wor
88
97
  workspaceRoot,
89
98
  }));
90
99
  const collectCoveredFiles = (entry, coveredFiles) => {
91
- if (entry.kind !== 'agent-patch' && entry.kind !== 'operator-patch') {
92
- return;
93
- }
94
- for (const affectedFile of entry.links.affectedFiles ?? []) {
95
- coveredFiles.add(affectedFile);
100
+ for (const coveredFile of getCoverageFilesForEntry(entry)) {
101
+ coveredFiles.add(coveredFile);
96
102
  }
97
103
  };
98
104
  export const buildReadIndexFromManifest = async (workspaceRoot, manifest) => {
@@ -103,8 +109,8 @@ export const buildReadIndexFromManifest = async (workspaceRoot, manifest) => {
103
109
  for (let index = 0; index < orderedEntryLocations.length; index += readIndexRebuildBatchSize) {
104
110
  const batch = orderedEntryLocations.slice(index, index + readIndexRebuildBatchSize);
105
111
  const resolvedEntries = await readIndexedEntryBatch({
106
- entryReadConcurrency: readIndexRebuildConcurrency,
107
112
  entryLocations: batch,
113
+ entryReadConcurrency: readIndexRebuildConcurrency,
108
114
  workspaceRoot,
109
115
  });
110
116
  for (const entry of resolvedEntries) {
@@ -166,9 +172,7 @@ export const ensureReadIndexUnderLock = async (workspaceRoot, manifest) => {
166
172
  };
167
173
  export const appendEntryToReadIndex = ({ entry, readIndex, sequence, }) => {
168
174
  const nextEntries = [...readIndex.entries, buildReadIndexEntry(entry)];
169
- const nextCoveredFiles = entry.kind === 'agent-patch' || entry.kind === 'operator-patch'
170
- ? mergeSortedUniquePaths(readIndex.coveredFiles, entry.links.affectedFiles ?? [])
171
- : [...readIndex.coveredFiles];
175
+ const nextCoveredFiles = mergeSortedUniquePaths(readIndex.coveredFiles, getCoverageFilesForEntry(entry));
172
176
  return buildReadIndex({
173
177
  coveredFiles: nextCoveredFiles,
174
178
  entries: nextEntries,
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AASA,OAAO,EACH,KAAK,WAAW,EAMnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAU3D,KAAK,qBAAqB,GAAG;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpF,CAAC;AAOF,eAAO,MAAM,wBAAwB,GAAI,eAAe,MAAM,EAAE,OAAO,qBAAqB,GAAG,IAAI,SAOlG,CAAC;AA0EF,eAAO,MAAM,YAAY,GACrB,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AAM,CAAA;CAAE,CAsF5C,CAAC;AAEF,eAAO,MAAM,aAAa,GACtB,eAAe,MAAM,EACrB,UAAU,cAAc,EACxB,SAAS,MAAM,KAChB,OAAO,CAAC,WAAW,CASrB,CAAC"}
package/dist/record.js CHANGED
@@ -2,8 +2,7 @@ import { readFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import * as v from 'valibot';
4
4
  import { sha256Hex, stableStringify } from "./json.js";
5
- import { getNextManifestSequence } from "./manifest-update.js";
6
- import { updateManifestForEntry } from "./manifest-update.js";
5
+ import { getNextManifestSequence, updateManifestForEntry } from "./manifest-update.js";
7
6
  import { resolvePatchRecord } from "./patch-resolver.js";
8
7
  import { appendEntryToReadIndex, saveReadIndex } from "./read-index.js";
9
8
  import { reconcileLedgerStateUnderLock, removePendingCommit, writePendingCommit } from "./recovery.js";
@@ -1,6 +1,13 @@
1
1
  import { type LedgerReadIndex } from './read-index.ts';
2
2
  import { type LedgerEntry } from './schema/entry.ts';
3
3
  import type { LedgerManifest } from './schema/manifest.ts';
4
+ export type PendingCommitQuarantine = {
5
+ readonly commitPath: string;
6
+ readonly metadataPath: string | null;
7
+ readonly originalFileName: string;
8
+ readonly quarantinedAt: string | null;
9
+ readonly reason: string;
10
+ };
4
11
  export type PreparedLedgerState = {
5
12
  readonly manifest: LedgerManifest;
6
13
  readonly readIndex: LedgerReadIndex;
@@ -12,6 +19,7 @@ export declare const writePendingCommit: ({ entry, logicalHash, manifest, worksp
12
19
  readonly workspaceRoot: string;
13
20
  }) => Promise<string>;
14
21
  export declare const removePendingCommit: (filePath: string) => Promise<void>;
22
+ export declare const listPendingCommitQuarantines: (workspaceRoot: string) => Promise<PendingCommitQuarantine[]>;
15
23
  export declare const reconcilePendingCommitsUnderLock: (workspaceRoot: string) => Promise<{
16
24
  archives: {
17
25
  createdAt: string;
@@ -1 +1 @@
1
- {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAKA,OA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