diffpact 0.0.0-stage → 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 +142 -0
- package/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/diffpact.mjs +15 -0
- package/dist/adapters/claude-code.d.ts +21 -0
- package/dist/adapters/claude-code.js +191 -0
- package/dist/adapters/codex.d.ts +31 -0
- package/dist/adapters/codex.js +348 -0
- package/dist/adapters/gemini-agy.d.ts +26 -0
- package/dist/adapters/gemini-agy.js +429 -0
- package/dist/adapters/vercel-board.d.ts +30 -0
- package/dist/adapters/vercel-board.js +138 -0
- package/dist/amend.d.ts +46 -0
- package/dist/amend.js +476 -0
- package/dist/boundaries.d.ts +43 -0
- package/dist/boundaries.js +309 -0
- package/dist/canonical-json.d.ts +6 -0
- package/dist/canonical-json.js +63 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1704 -0
- package/dist/delegate.d.ts +22 -0
- package/dist/delegate.js +140 -0
- package/dist/doctor.d.ts +36 -0
- package/dist/doctor.js +293 -0
- package/dist/git.d.ts +27 -0
- package/dist/git.js +234 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/merge-verify.d.ts +31 -0
- package/dist/merge-verify.js +721 -0
- package/dist/report.d.ts +25 -0
- package/dist/report.js +220 -0
- package/dist/review.d.ts +46 -0
- package/dist/review.js +527 -0
- package/dist/runner.d.ts +45 -0
- package/dist/runner.js +213 -0
- package/dist/schema.d.ts +6 -0
- package/dist/schema.js +424 -0
- package/dist/types.d.ts +190 -0
- package/dist/types.js +220 -0
- package/dist/verify.d.ts +45 -0
- package/dist/verify.js +952 -0
- package/dist/worktree.d.ts +82 -0
- package/dist/worktree.js +717 -0
- package/examples/harnesses/README.md +63 -0
- package/examples/quickstart/README.md +17 -0
- package/examples/quickstart/run.mjs +247 -0
- package/package.json +62 -4
- package/schemas/contract.schema.json +148 -0
- package/schemas/receipt.schema.json +49 -0
- package/schemas/review.schema.json +48 -0
package/dist/git.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { sha256Hex } from './canonical-json.js';
|
|
6
|
+
|
|
7
|
+
export function runGitBuffer(cwd , args ) {
|
|
8
|
+
return execFileSync('git', ['--no-optional-locks', '-C', cwd, ...args], {
|
|
9
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
10
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function runGitText(cwd , args ) {
|
|
15
|
+
return runGitBuffer(cwd, args).toString('utf8');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resolveRepoRoot(cwd ) {
|
|
19
|
+
return fs.realpathSync(runGitText(cwd, ['rev-parse', '--show-toplevel']).trim());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function resolveHeadSha(cwd ) {
|
|
23
|
+
return runGitText(cwd, ['rev-parse', 'HEAD']).trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function resolveCurrentBranch(cwd ) {
|
|
27
|
+
return runGitText(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']).trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function ensureGitInfoExclude(cwd , entry = '.diffpact/') {
|
|
31
|
+
try {
|
|
32
|
+
const rawExcludePath = runGitText(cwd, ['rev-parse', '--git-path', 'info/exclude']).trim();
|
|
33
|
+
const excludeAbs = path.resolve(cwd, rawExcludePath);
|
|
34
|
+
fs.mkdirSync(path.dirname(excludeAbs), { recursive: true });
|
|
35
|
+
const existing = fs.existsSync(excludeAbs) ? fs.readFileSync(excludeAbs, 'utf8') : '';
|
|
36
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
37
|
+
if (!lines.includes(entry) && !lines.includes(entry.replace(/\/$/, ''))) {
|
|
38
|
+
const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
|
|
39
|
+
fs.appendFileSync(excludeAbs, `${prefix}${entry}\n`);
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
// Non-fatal if git info/exclude is read-only
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function commitExists(cwd , sha ) {
|
|
47
|
+
try {
|
|
48
|
+
runGitBuffer(cwd, ['cat-file', '-e', `${sha}^{commit}`]);
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolves a full SHA, abbreviated short SHA (e.g. 7 chars), or Git ref (e.g. HEAD~1, main)
|
|
57
|
+
* to its canonical 40-character lowercase commit SHA-1, or returns null if unresolvable.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveCommitSha(cwd , refOrSha ) {
|
|
60
|
+
const trimmed = refOrSha.trim();
|
|
61
|
+
if (!trimmed || trimmed.includes('\0') || trimmed.startsWith('-')) return null;
|
|
62
|
+
try {
|
|
63
|
+
const resolved = runGitText(cwd, ['rev-parse', '--verify', '--quiet', `${trimmed}^{commit}`]).trim();
|
|
64
|
+
return /^[0-9a-f]{40}$/.test(resolved) ? resolved : null;
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isAncestor(cwd , ancestorSha , descendantSha ) {
|
|
71
|
+
try {
|
|
72
|
+
runGitBuffer(cwd, ['merge-base', '--is-ancestor', ancestorSha, descendantSha]);
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseNameStatusZ(buf ) {
|
|
80
|
+
if (buf.length === 0) return [];
|
|
81
|
+
const tokens = buf.toString('utf8').split('\0');
|
|
82
|
+
if (tokens[tokens.length - 1] === '') tokens.pop();
|
|
83
|
+
|
|
84
|
+
const entries = [];
|
|
85
|
+
let i = 0;
|
|
86
|
+
while (i < tokens.length) {
|
|
87
|
+
const status = tokens[i] ;
|
|
88
|
+
i += 1;
|
|
89
|
+
if (status.startsWith('R') || status.startsWith('C')) {
|
|
90
|
+
const old_path = tokens[i] ?? '';
|
|
91
|
+
const new_path = tokens[i + 1] ?? '';
|
|
92
|
+
i += 2;
|
|
93
|
+
entries.push({ status, path: new_path, old_path });
|
|
94
|
+
} else {
|
|
95
|
+
const p = tokens[i] ?? '';
|
|
96
|
+
i += 1;
|
|
97
|
+
entries.push({ status, path: p });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return entries;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isInternalArtifactPath(relPosixPath ) {
|
|
104
|
+
return relPosixPath === '.diffpact' || relPosixPath.startsWith('.diffpact/');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function checkSymlinkInTreeOrDisk(repoRoot , relPosixPath , committedSymlinks ) {
|
|
108
|
+
if (committedSymlinks.has(relPosixPath)) return true;
|
|
109
|
+
const full = path.join(repoRoot, relPosixPath);
|
|
110
|
+
try {
|
|
111
|
+
return fs.lstatSync(full).isSymbolicLink();
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function checkSubmoduleInTreeOrDisk(repoRoot , relPosixPath , specialSubmodules ) {
|
|
118
|
+
if (specialSubmodules.has(relPosixPath)) return true;
|
|
119
|
+
const full = path.join(repoRoot, relPosixPath);
|
|
120
|
+
try {
|
|
121
|
+
if (fs.lstatSync(full).isDirectory() && fs.existsSync(path.join(full, '.git'))) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
// ignore
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function collectSpecialGitModes(repoRoot , ref )
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
{
|
|
134
|
+
const symlinks = new Set ();
|
|
135
|
+
const submodules = new Set ();
|
|
136
|
+
try {
|
|
137
|
+
const out = runGitBuffer(repoRoot, ['ls-tree', '-r', '-z', ref]).toString('utf8');
|
|
138
|
+
for (const record of out.split('\0')) {
|
|
139
|
+
if (!record) continue;
|
|
140
|
+
const tabIdx = record.indexOf('\t');
|
|
141
|
+
if (tabIdx === -1) continue;
|
|
142
|
+
const meta = record.slice(0, tabIdx);
|
|
143
|
+
const filePath = record.slice(tabIdx + 1);
|
|
144
|
+
if (meta.startsWith('120000 ')) symlinks.add(filePath);
|
|
145
|
+
if (meta.startsWith('160000 ')) submodules.add(filePath);
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
// ignore unborn tree
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const staged = runGitBuffer(repoRoot, ['ls-files', '--stage', '-z']).toString('utf8');
|
|
152
|
+
for (const record of staged.split('\0')) {
|
|
153
|
+
if (!record) continue;
|
|
154
|
+
const tabIdx = record.indexOf('\t');
|
|
155
|
+
if (tabIdx === -1) continue;
|
|
156
|
+
const meta = record.slice(0, tabIdx);
|
|
157
|
+
const filePath = record.slice(tabIdx + 1);
|
|
158
|
+
if (meta.startsWith('120000 ')) symlinks.add(filePath);
|
|
159
|
+
if (meta.startsWith('160000 ')) submodules.add(filePath);
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
// ignore
|
|
163
|
+
}
|
|
164
|
+
return { symlinks, submodules };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Collects all file changes between `startingSha` and the current repository state
|
|
177
|
+
* (`startingSha..HEAD`, staged changes, unstaged changes, and untracked files),
|
|
178
|
+
* excluding internal `.diffpact/` state files from dirty-worktree accounting.
|
|
179
|
+
*/
|
|
180
|
+
export function collectRepoChanges(repoRoot , startingSha , headSha ) {
|
|
181
|
+
const committedBuf = runGitBuffer(repoRoot, ['diff', '--name-status', '-M', '-z', `${startingSha}..${headSha}`]);
|
|
182
|
+
const workingBuf = runGitBuffer(repoRoot, ['diff', '--name-status', '-M', '-z', 'HEAD']);
|
|
183
|
+
const untrackedBuf = runGitBuffer(repoRoot, ['ls-files', '--others', '--exclude-standard', '-z']);
|
|
184
|
+
|
|
185
|
+
const committedEntries = parseNameStatusZ(committedBuf);
|
|
186
|
+
const workingEntries = parseNameStatusZ(workingBuf).filter((e) => !isInternalArtifactPath(e.path));
|
|
187
|
+
|
|
188
|
+
const untrackedAll = untrackedBuf
|
|
189
|
+
.toString('utf8')
|
|
190
|
+
.split('\0')
|
|
191
|
+
.filter((p) => p.length > 0);
|
|
192
|
+
const untrackedFiles = untrackedAll.filter((p) => !isInternalArtifactPath(p)).sort();
|
|
193
|
+
|
|
194
|
+
const specialModes = collectSpecialGitModes(repoRoot, headSha);
|
|
195
|
+
const byKey = new Map ();
|
|
196
|
+
|
|
197
|
+
for (const e of [...committedEntries, ...workingEntries]) {
|
|
198
|
+
if (isInternalArtifactPath(e.path) && (!e.old_path || isInternalArtifactPath(e.old_path))) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const is_symlink = checkSymlinkInTreeOrDisk(repoRoot, e.path, specialModes.symlinks);
|
|
202
|
+
const is_submodule = checkSubmoduleInTreeOrDisk(repoRoot, e.path, specialModes.submodules);
|
|
203
|
+
byKey.set(`${e.path}|${e.old_path ?? ''}`, {
|
|
204
|
+
status: e.status,
|
|
205
|
+
path: e.path,
|
|
206
|
+
...(e.old_path ? { old_path: e.old_path } : {}),
|
|
207
|
+
...(is_symlink ? { is_symlink: true } : {}),
|
|
208
|
+
...(is_submodule ? { is_submodule: true } : {})
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const changedFiles = [...byKey.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
213
|
+
const trackedTreeClean = workingEntries.length === 0;
|
|
214
|
+
const workingTreeClean = trackedTreeClean && untrackedFiles.length === 0;
|
|
215
|
+
|
|
216
|
+
const rawDiffBuf = runGitBuffer(repoRoot, [
|
|
217
|
+
'diff',
|
|
218
|
+
'--binary',
|
|
219
|
+
'--no-ext-diff',
|
|
220
|
+
`${startingSha}..${headSha}`,
|
|
221
|
+
'--',
|
|
222
|
+
'.',
|
|
223
|
+
':(exclude).diffpact'
|
|
224
|
+
]);
|
|
225
|
+
const rawDiffSha256 = sha256Hex(rawDiffBuf);
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
changedFiles,
|
|
229
|
+
untrackedFiles,
|
|
230
|
+
workingTreeClean,
|
|
231
|
+
trackedTreeClean,
|
|
232
|
+
rawDiffSha256
|
|
233
|
+
};
|
|
234
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './types.ts';
|
|
2
|
+
export * from './canonical-json.ts';
|
|
3
|
+
export * from './schema.ts';
|
|
4
|
+
export * from './boundaries.ts';
|
|
5
|
+
export * from './git.ts';
|
|
6
|
+
export * from './verify.ts';
|
|
7
|
+
export * from './merge-verify.ts';
|
|
8
|
+
export * from './review.ts';
|
|
9
|
+
export * from './delegate.ts';
|
|
10
|
+
export * from './amend.ts';
|
|
11
|
+
export * from './doctor.ts';
|
|
12
|
+
export * from './report.ts';
|
|
13
|
+
export * from './worktree.ts';
|
|
14
|
+
export * from './runner.ts';
|
|
15
|
+
export * from './adapters/claude-code.ts';
|
|
16
|
+
export * from './adapters/codex.ts';
|
|
17
|
+
export * from './adapters/gemini-agy.ts';
|
|
18
|
+
export * from './adapters/vercel-board.ts';
|
|
19
|
+
export * from './cli.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './canonical-json.js';
|
|
3
|
+
export * from './schema.js';
|
|
4
|
+
export * from './boundaries.js';
|
|
5
|
+
export * from './git.js';
|
|
6
|
+
export * from './verify.js';
|
|
7
|
+
export * from './merge-verify.js';
|
|
8
|
+
export * from './review.js';
|
|
9
|
+
export * from './delegate.js';
|
|
10
|
+
export * from './amend.js';
|
|
11
|
+
export * from './doctor.js';
|
|
12
|
+
export * from './report.js';
|
|
13
|
+
export * from './worktree.js';
|
|
14
|
+
export * from './runner.js';
|
|
15
|
+
export * from './adapters/claude-code.js';
|
|
16
|
+
export * from './adapters/codex.js';
|
|
17
|
+
export * from './adapters/gemini-agy.js';
|
|
18
|
+
export * from './adapters/vercel-board.js';
|
|
19
|
+
export * from './cli.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ExitCode, type MergeVerificationReceiptV01 } from './types.ts';
|
|
2
|
+
export interface MergeVerifyOptions {
|
|
3
|
+
fromPaths: string[];
|
|
4
|
+
cwd?: string;
|
|
5
|
+
baseSha?: string;
|
|
6
|
+
allowIntegrationPaths?: string[];
|
|
7
|
+
integrationReason?: string;
|
|
8
|
+
allowUntracked?: boolean;
|
|
9
|
+
writeReceipt?: boolean;
|
|
10
|
+
receiptPath?: string;
|
|
11
|
+
shellPath?: string;
|
|
12
|
+
heartbeatSec?: number;
|
|
13
|
+
onHeartbeat?: (message: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface MergeVerifyResult {
|
|
16
|
+
exitCode: ExitCode;
|
|
17
|
+
receipt?: MergeVerificationReceiptV01;
|
|
18
|
+
receiptPath?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function resolveSourceContractPath(inputPath: string, cwd: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Post-merge verification gate across two or more merged task contracts (or archived
|
|
24
|
+
* `.diffpact/archive/...` bundles). Verifies that:
|
|
25
|
+
* 1. The merged working tree is clean and every changed file since `base_sha` is authorized
|
|
26
|
+
* by at least one participating contract (catching unauthorized conflict-resolution edits).
|
|
27
|
+
* 2. The deduplicated UNION of all contracts' `required_checks`, `version_assertions`, and
|
|
28
|
+
* `interfacedelta_lockfile` pins passes on the joined tree (with No Silent Zero enforcement).
|
|
29
|
+
* 3. A canonical SHA-256 signed `merge-receipt.json` is written durably under `.diffpact/merges/`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function runMergeVerify(options: MergeVerifyOptions): Promise<MergeVerifyResult>;
|