diffpact 0.4.2 → 0.4.3

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/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ---
8
8
 
9
+ ## [0.4.3] — 2026-11-30
10
+
11
+ ### Security & Safety Fixes
12
+ - **Fail-Closed CLI Argument Parsing Across All Subcommands:** Unrecognized CLI flags (e.g., passing `--decision request-changes` instead of `--verdict reject`) and missing option values now immediately fail closed with exit code `2` (`INCOMPLETE`) across every subcommand instead of being silently ignored.
13
+ - **Required `--verdict <approve|reject>` on `diffpact review` (No Silent Approve Default):** Removed the dangerous implicit `approve` default on CLI `diffpact review`. Reviewers must explicitly pass `--verdict approve` or `--verdict reject`; omitting `--verdict`, passing an invalid verdict value, or passing `--decision` fails closed with exit `2` without writing a review attestation.
14
+
15
+ ### Added
16
+ - **Global `--cwd <dir>` (`-C <dir>`) Option:** Supported consistently across all subcommands (`init`, `verify`, `diff`, `review`, `status`, `amend`, `report`, `merge-verify`, `exec`, `run`, `worktree`, `delegate`, `doctor`, `install-hooks`, `board`, `agy-verify-patch`, `hook`), validating that the target directory exists before execution.
17
+ - **Short-SHA & Git Ref Resolution for `--starting-sha` and `--update-starting-sha`:** `diffpact init --starting-sha` and `diffpact amend --update-starting-sha` now resolve abbreviated short SHAs (e.g., 7-char commits) and Git refs (`HEAD~1`, branch names) via `git rev-parse --verify <ref>^{commit}` and persist the canonical 40-character lowercase SHA-1 in `.diffpact/contract.json`.
18
+ - **Clean Pipe Exit (`EPIPE`):** Added a clean `stdout` `EPIPE` handler in `bin/diffpact.mjs` so piping output (e.g., `diffpact doctor | head`) exits `0` without stack traces.
19
+
20
+ ### Changed
21
+ - Normalized `package.json` `bin.diffpact` path (`bin/diffpact.mjs`), preserved pre-emitted `.d.ts` declarations during `scripts/build.mjs` when `tsc` is absent, and updated SARIF 2.1.0 driver version to `0.4.3`.
22
+
23
+ ---
24
+
9
25
  ## [0.4.2] — 2026-11-30
10
26
 
11
27
  ### Added
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # diffpact (`v0.4.2`)
1
+ # diffpact (`v0.4.3`)
2
2
 
3
3
  **Local, stateless Git task contracts, deterministic diff boundaries, post-merge verification, and cross-harness review gates for multi-agent coding workflows.**
4
4
 
5
- Built by [InterfaceDelta](https://interfacedelta.com) · MIT License · Zero runtime dependencies · Node `>= 22.6` · [Changelog](./CHANGELOG.md) · [![CI](https://github.com/interface-delta/diffpact/actions/workflows/ci.yml/badge.svg)](https://github.com/interface-delta/diffpact/actions/workflows/ci.yml)
5
+ Built by [InterfaceDelta](https://interfacedelta.com) · MIT License · Zero runtime dependencies · Node `>= 22.6` · [Changelog](./CHANGELOG.md) · [![npm](https://img.shields.io/npm/v/diffpact)](https://www.npmjs.com/package/diffpact) [![CI](https://github.com/interface-delta/diffpact/actions/workflows/ci.yml/badge.svg)](https://github.com/interface-delta/diffpact/actions/workflows/ci.yml)
6
6
 
7
7
  ---
8
8
 
@@ -10,24 +10,29 @@ Built by [InterfaceDelta](https://interfacedelta.com) · MIT License · Zero run
10
10
 
11
11
  Choose one installation method (zero runtime dependencies, Node `>= 22.6`):
12
12
 
13
- **Option A (Recommended right now): Clone from GitHub and symlink globally** *(runs `npm run build` automatically)*
13
+ **Option A (Recommended): Install globally from npm**
14
14
 
15
15
  ```bash
16
- git clone https://github.com/interface-delta/diffpact.git
17
- cd diffpact && npm link
16
+ npm install -g diffpact
18
17
  ```
19
18
 
20
- **Option B: Install globally from a local checkout**
19
+ Or run without installing globally:
21
20
 
22
21
  ```bash
23
- npm install -g /path/to/diffpact
22
+ npx diffpact doctor
24
23
  ```
25
24
 
26
- **Option C: Run or install from npm** *(coming soon — once published to npm)*
25
+ **Option B: Clone from GitHub and symlink globally** *(runs `npm run build` automatically)*
27
26
 
28
27
  ```bash
29
- npx diffpact doctor
30
- npm install -g diffpact
28
+ git clone https://github.com/interface-delta/diffpact.git
29
+ cd diffpact && npm link
30
+ ```
31
+
32
+ **Option C: Install globally from a local checkout**
33
+
34
+ ```bash
35
+ npm install -g /path/to/diffpact
31
36
  ```
32
37
 
33
38
  **Verify your environment and try the 30-second self-contained quickstart demo:**
@@ -213,3 +218,7 @@ Because a local CLI has no central identity server, a plain `--reviewer` flag is
213
218
  | `1` | `VIOLATION` | Path/symlink/shell boundary breached, self-certification or forged HMAC, diff-SHA mismatch, budget exceeded, or check failed |
214
219
  | `2` | `INCOMPLETE` | Missing contract/receipt/review, unattested raw-diff inspection, zero commits, or skipped tests (*No Silent Zero*) |
215
220
  | `3` | `STALE` | Git `HEAD` or `contract.json` moved after receipt or review was issued |
221
+
222
+ ---
223
+
224
+ *Built and maintained by [InterfaceDelta](https://interfacedelta.com): human-architected and developed with multi-model coding agents (Gemini, Claude Code, and OpenAI Codex) governed by `diffpact` itself with mandatory cross-model raw-diff review.*
package/bin/diffpact.mjs CHANGED
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
3
 
4
+ process.stdout.on('error', (err) => {
5
+ if (err && err.code === 'EPIPE') process.exit(0);
6
+ throw err;
7
+ });
8
+
4
9
  const distEntry = new URL('../dist/cli.js', import.meta.url);
5
10
  const { runCli } = fs.existsSync(distEntry)
6
11
  ? await import('../dist/cli.js')
@@ -0,0 +1,21 @@
1
+ export interface HookResult {
2
+ exitCode: number;
3
+ stdout?: string;
4
+ stderr?: string;
5
+ }
6
+ export declare function readStopCount(pactDir: string, sessionId: string): number;
7
+ export declare function writeStopCount(pactDir: string, sessionId: string, count: number): void;
8
+ export declare function evaluateBoundedStopGate(options: {
9
+ contractAbs: string;
10
+ repoRoot: string;
11
+ sessionId: string;
12
+ isContinuation: boolean;
13
+ maxStopBlocks?: number;
14
+ }): {
15
+ action: 'pass' | 'capped' | 'block';
16
+ exitCode: number;
17
+ details?: string;
18
+ maxBlocks: number;
19
+ };
20
+ export declare function handleClaudeCodeHook(payload: Record<string, unknown>, contractPath: string, cwdOverride?: string): HookResult;
21
+ export declare function generateClaudeCodeConfig(contractPath?: string): string;
@@ -0,0 +1,31 @@
1
+ import { type ExitCode } from '../types.ts';
2
+ import { type HookResult } from './claude-code.ts';
3
+ export declare function handleCodexHook(payload: Record<string, unknown>, contractPath: string, cwdOverride?: string): HookResult;
4
+ export declare function handleCodexNotify(payload: Record<string, unknown>, contractPath: string, cwdOverride?: string): HookResult;
5
+ /**
6
+ * Parses `codex exec --json` JSONL output to extract the true `thread_id`
7
+ * and structured review verdict (`{ verdict: "approve"|"reject", summary, findings }`).
8
+ */
9
+ export declare function parseCodexJsonlReview(jsonlOutput: string): {
10
+ threadId?: string;
11
+ verdict?: 'approve' | 'reject';
12
+ summary?: string;
13
+ findings?: string[];
14
+ };
15
+ /**
16
+ * Executes a wrapped Codex read-only reviewer command, verifies the worktree remained untouched,
17
+ * extracts the Codex `thread_id` to guarantee session independence, and records `review.json`.
18
+ */
19
+ export declare function runWrappedCodexReview(options: {
20
+ contractPath: string;
21
+ cwd?: string;
22
+ reviewerAgentId: string;
23
+ commandArgs: string[];
24
+ inspectedRawDiff?: boolean;
25
+ evidenceLineageId?: string;
26
+ }): {
27
+ exitCode: ExitCode;
28
+ error?: string;
29
+ reviewSha256?: string;
30
+ };
31
+ export declare function generateCodexConfig(contractPath?: string): string;
@@ -0,0 +1,26 @@
1
+ import { type ExitCode } from '../types.ts';
2
+ import { type HookResult } from './claude-code.ts';
3
+ /**
4
+ * Antigravity (`agy`) `.agents/hooks.json` protocol handler (camelCase/PascalCase JSON I/O).
5
+ */
6
+ export declare function handleAgyHook(payload: Record<string, unknown>, contractPath: string, cwdOverride?: string): HookResult;
7
+ /**
8
+ * Gemini CLI `.gemini/settings.json` protocol handler (snake_case I/O, strict JSON-only stdout).
9
+ */
10
+ export declare function handleGeminiCliHook(payload: Record<string, unknown>, contractPath: string, cwdOverride?: string): HookResult;
11
+ /**
12
+ * Verifies an unattended `agy-worker --diff` output (which prints `git status --short`
13
+ * followed by `git diff HEAD`) BEFORE the integrator runs `git apply`.
14
+ */
15
+ export declare function verifyAgyWorkerPatch(options: {
16
+ contractPath: string;
17
+ patchPath: string;
18
+ cwd?: string;
19
+ allowEmpty?: boolean;
20
+ }): {
21
+ exitCode: ExitCode;
22
+ paths: string[];
23
+ violations: string[];
24
+ };
25
+ export declare function generateAgyConfig(contractPath?: string): string;
26
+ export declare function generateGeminiCliConfig(contractPath?: string): string;
@@ -0,0 +1,30 @@
1
+ import { type ExitCode } from '../types.ts';
2
+ export declare function boardPostContract(options: {
3
+ contractPath: string;
4
+ taskId: string;
5
+ vbBin?: string;
6
+ cwd?: string;
7
+ }): {
8
+ exitCode: ExitCode;
9
+ message: string;
10
+ };
11
+ /**
12
+ * Gates `@vercel/board` task completion (`vb tasks complete`):
13
+ * - Exit 0 (pass + independent review): posts hashes and calls `vb tasks complete`.
14
+ * - Exit 1 (boundary/test/review violation): posts failure details and calls `vb tasks fail`.
15
+ * - Exit 2 or 3 (incomplete / awaiting review / stale): posts hold reason and refuses `complete`
16
+ * without burning the task as terminal `failed`.
17
+ */
18
+ export declare function boardCompleteGate(options: {
19
+ contractPath: string;
20
+ taskId: string;
21
+ requireReview?: boolean;
22
+ reclaimIfExpired?: boolean;
23
+ summaryMessage?: string;
24
+ vbBin?: string;
25
+ cwd?: string;
26
+ }): {
27
+ exitCode: ExitCode;
28
+ action: 'completed' | 'failed' | 'held';
29
+ detail: string;
30
+ };
@@ -0,0 +1,46 @@
1
+ import { type ExitCode } from './types.ts';
2
+ export interface ContractAmendmentEntry {
3
+ schema_version: 'diffpact-amendment-v0.2';
4
+ sequence: number;
5
+ amended_at: string;
6
+ authorized_by: string;
7
+ reason: string;
8
+ previous_contract_sha256: string;
9
+ new_contract_sha256: string;
10
+ added_allowed_paths?: string[];
11
+ added_read_only_paths?: string[];
12
+ added_forbidden_paths?: string[];
13
+ previous_starting_sha?: string;
14
+ new_starting_sha?: string;
15
+ entry_sha256: string;
16
+ }
17
+ export interface AmendContractOptions {
18
+ contractPath: string;
19
+ cwd?: string;
20
+ authorizedBy: string;
21
+ reason: string;
22
+ addAllowedPaths?: string[];
23
+ addReadOnlyPaths?: string[];
24
+ addForbiddenPaths?: string[];
25
+ updateStartingSha?: string;
26
+ }
27
+ /**
28
+ * Reads `<pactDir>/amendments.jsonl` and verifies each entry's schema, `entry_sha256`,
29
+ * contiguous 1-based sequence numbers, and `previous_contract_sha256` hash chain.
30
+ */
31
+ export declare function readAmendmentHistory(contractPath: string, cwd?: string): {
32
+ valid: boolean;
33
+ entries: ContractAmendmentEntry[];
34
+ error?: string;
35
+ };
36
+ /**
37
+ * Applies a validated, audited amendment to an existing task contract, invalidates
38
+ * any stale `receipt.json`, and appends a hash-chained record to `amendments.jsonl`.
39
+ */
40
+ export declare function amendContract(options: AmendContractOptions): {
41
+ exitCode: ExitCode;
42
+ contractSha256?: string;
43
+ entry?: ContractAmendmentEntry;
44
+ amendmentCount?: number;
45
+ error?: string;
46
+ };
package/dist/amend.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { canonicalSha256 } from './canonical-json.js';
4
- import { commitExists, resolveRepoRoot } from './git.js';
4
+ import { commitExists, resolveCommitSha, resolveRepoRoot } from './git.js';
5
5
  import { validateContract } from './schema.js';
6
6
  import {
7
7
  EXIT_INCOMPLETE,
@@ -364,6 +364,7 @@ export function amendContract(options )
364
364
  };
365
365
  }
366
366
 
367
+ let resolvedUpdatedStartingSha ;
367
368
  if (hasStartingShaRequest) {
368
369
  const workDir = options.cwd ?? path.dirname(contractAbs);
369
370
  let repoRoot ;
@@ -376,19 +377,24 @@ export function amendContract(options )
376
377
  };
377
378
  }
378
379
 
379
- if (!commitExists(repoRoot, requestedStartingSha)) {
380
+ const fullSha = resolveCommitSha(repoRoot, requestedStartingSha);
381
+ if (!fullSha || !commitExists(repoRoot, fullSha)) {
380
382
  return {
381
383
  exitCode: EXIT_STALE,
382
384
  error: `Commit "${requestedStartingSha}" does not exist in Git repository`
383
385
  };
384
386
  }
387
+ resolvedUpdatedStartingSha = fullSha;
385
388
  }
386
389
 
387
390
  const allowedMerge = mergeUniquePaths(contract.allowed_paths, rawAddAllowed);
388
391
  const readOnlyMerge = mergeUniquePaths(contract.read_only_paths ?? [], rawAddReadOnly);
389
392
  const forbiddenMerge = mergeUniquePaths(contract.forbidden_paths, rawAddForbidden);
390
393
 
391
- const nextStartingSha = hasStartingShaRequest ? requestedStartingSha : contract.starting_sha;
394
+ const nextStartingSha =
395
+ hasStartingShaRequest && resolvedUpdatedStartingSha
396
+ ? resolvedUpdatedStartingSha
397
+ : contract.starting_sha;
392
398
  const startingShaChanged = nextStartingSha !== contract.starting_sha;
393
399
 
394
400
  const candidate = {
@@ -0,0 +1,43 @@
1
+ import type { TaskContractV01, ViolationItem } from './types.ts';
2
+ /**
3
+ * Converts a path to a safe repo-relative POSIX path (Unicode NFC normalized),
4
+ * or returns a violation if the path escapes the repository root or uses ".." traversal.
5
+ */
6
+ export declare function normalizeRepoRelativePath(inputPath: string, repoRoot: string): {
7
+ ok: true;
8
+ relPath: string;
9
+ } | {
10
+ ok: false;
11
+ reason: string;
12
+ };
13
+ export declare function matchesAnyGlob(relPosixPath: string, globs?: readonly string[]): boolean;
14
+ /**
15
+ * Deterministic boundary check with strict precedence:
16
+ * 0. .git/ repository metadata & hooks are unconditionally forbidden regardless of allowed_paths.
17
+ * 1. forbidden_paths (deny wins)
18
+ * 2. read_only_paths (deny wins)
19
+ * 3. Internal .diffpact/ metadata files are allowed by the harness itself unless listed in forbidden/read_only.
20
+ * 4. allowed_paths (must match at least one; empty allowed_paths denies everything)
21
+ */
22
+ export declare function evaluatePathBoundary(rawPath: string, repoRoot: string, contract: Pick<TaskContractV01, 'allowed_paths' | 'read_only_paths' | 'forbidden_paths'>): ViolationItem | null;
23
+ /**
24
+ * Extracts all target file paths from a Codex `apply_patch` payload.
25
+ */
26
+ export declare function extractCodexApplyPatchPaths(patchText: string): string[];
27
+ /**
28
+ * Parses a standard Git unified diff (e.g., from `agy-worker --diff` or `git diff`),
29
+ * returning touched paths and detecting any symlink (`120000`) or submodule (`160000`) entries.
30
+ */
31
+ export declare function inspectUnifiedDiff(diffText: string): {
32
+ paths: string[];
33
+ hasSymlinkMode: boolean;
34
+ symlinkPaths: string[];
35
+ hasSubmoduleMode: boolean;
36
+ submodulePaths: string[];
37
+ };
38
+ /**
39
+ * Pre-flight defense-in-depth guard for agent shell commands
40
+ * (Claude Code Bash, Codex Bash, Gemini/agy shell).
41
+ * Authoritative enforcement always re-runs against Git tree & status in `runVerify`.
42
+ */
43
+ export declare function evaluateShellCommand(commandLine: string, contract: Pick<TaskContractV01, 'allowed_paths' | 'read_only_paths' | 'forbidden_paths'>): ViolationItem | null;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * RFC 8785 (JCS) deterministic JSON serializer for finite JSON values.
3
+ */
4
+ export declare function canonicalJson(value: unknown): string;
5
+ export declare function sha256Hex(input: string | Buffer): string;
6
+ export declare function canonicalSha256(domain: string, projection: unknown): string;
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function runCli(argv: string[]): Promise<number>;