@williambeto/ai-workflow 2.2.6 → 2.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.
- package/CHANGELOG.md +14 -0
- package/dist-assets/docs/cli-reference.md +38 -10
- package/dist-assets/docs/compatibility/provider-usage.md +8 -0
- package/dist-assets/docs/compatibility/runtime-matrix.md +1 -0
- package/dist-assets/templates/.antigravityignore.template +8 -0
- package/dist-assets/templates/ANTIGRAVITY.md.template +20 -0
- package/docs/releases/v2.3.0-release-decision.md +35 -0
- package/package.json +14 -4
- package/read_only_safety_verification.md +48 -0
- package/src/adapters/index.js +1 -0
- package/src/adapters/platforms/antigravity.js +382 -0
- package/src/adapters/platforms/codex.js +13 -0
- package/src/adapters/platforms/gemini.js +14 -1
- package/src/cli.js +6 -3
- package/src/commands/collect-evidence.js +3 -39
- package/src/commands/doctor.js +16 -0
- package/src/commands/execute.js +303 -119
- package/src/commands/init.js +25 -2
- package/src/core/delegation-controller.js +134 -0
- package/src/core/evidence/evidence-ledger.js +53 -0
- package/src/core/execution-planner.js +5 -1
- package/src/core/finalization/finalizer.js +77 -0
- package/src/core/finalization/workspace-snapshot.js +110 -0
- package/src/core/gates/branch-gate.js +23 -35
- package/src/core/gates/merge-gate.js +74 -0
- package/src/core/healing/healer-engine.js +34 -1
- package/src/core/healing/runtime-remediation-executor.js +136 -0
- package/src/core/runtime/opencode-adapter.js +137 -62
- package/src/core/templates.js +8 -0
- package/src/core/validation/evidence-collector.js +30 -3
- package/src/core/validation/quality-guard.js +8 -0
- package/src/core/validation/stack-detector.js +65 -0
- package/src/core/validation/validation-planner.js +134 -0
- package/src/core/workspace/read-only-workspace.js +119 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
|
|
6
|
+
async function copyDirectory(src, dest) {
|
|
7
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
8
|
+
for (const entry of entries) {
|
|
9
|
+
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === "tmp") {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const srcPath = path.join(src, entry.name);
|
|
13
|
+
const destPath = path.join(dest, entry.name);
|
|
14
|
+
|
|
15
|
+
if (entry.isDirectory()) {
|
|
16
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
17
|
+
await copyDirectory(srcPath, destPath);
|
|
18
|
+
} else if (entry.isFile()) {
|
|
19
|
+
await fs.copyFile(srcPath, destPath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function captureHashSnapshot(dir) {
|
|
25
|
+
const snapshot = {};
|
|
26
|
+
await scanDir(dir, dir, snapshot);
|
|
27
|
+
return snapshot;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function scanDir(baseDir, currentDir, snapshot) {
|
|
31
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
if (entry.name === "opencode.jsonc" || entry.name === "node_modules" || entry.name === ".git" || entry.name === "EVIDENCE.json" || entry.name === "tmp") {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
37
|
+
const relPath = path.relative(baseDir, fullPath);
|
|
38
|
+
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
await scanDir(baseDir, fullPath, snapshot);
|
|
41
|
+
} else if (entry.isFile()) {
|
|
42
|
+
try {
|
|
43
|
+
const content = await fs.readFile(fullPath);
|
|
44
|
+
const hash = crypto.createHash("sha256").update(content).digest("hex");
|
|
45
|
+
snapshot[relPath] = hash;
|
|
46
|
+
} catch {
|
|
47
|
+
// ignore
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Runs a function inside a temporary copy of the workspace.
|
|
55
|
+
* Mutating the workspace inside this temp directory will trigger a BLOCKED result.
|
|
56
|
+
*/
|
|
57
|
+
export async function runInReadOnlyWorkspace(originalCwd, runFn) {
|
|
58
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-ro-"));
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
// 1. Copy repository files recursively (excluding git/node_modules/tmp)
|
|
62
|
+
await copyDirectory(originalCwd, tempDir);
|
|
63
|
+
|
|
64
|
+
// 2. Write the required opencode.jsonc permission config file
|
|
65
|
+
const opencodeConfig = {
|
|
66
|
+
permission: {
|
|
67
|
+
edit: "deny",
|
|
68
|
+
external_directory: "deny",
|
|
69
|
+
bash: {
|
|
70
|
+
"*": "deny",
|
|
71
|
+
"git status*": "allow",
|
|
72
|
+
"git diff*": "allow",
|
|
73
|
+
"git log*": "allow",
|
|
74
|
+
"grep *": "allow",
|
|
75
|
+
"find *": "allow"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
await fs.writeFile(
|
|
80
|
+
path.join(tempDir, "opencode.jsonc"),
|
|
81
|
+
JSON.stringify(opencodeConfig, null, 2)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// 3. Capture initial file hash snapshot
|
|
85
|
+
const snapshotBefore = await captureHashSnapshot(tempDir);
|
|
86
|
+
|
|
87
|
+
// 4. Execute the callback function inside the temp directory
|
|
88
|
+
const runResult = await runFn(tempDir);
|
|
89
|
+
|
|
90
|
+
// 5. Capture post-run snapshot and verify no file mutations occurred
|
|
91
|
+
const snapshotAfter = await captureHashSnapshot(tempDir);
|
|
92
|
+
|
|
93
|
+
const mutated = [];
|
|
94
|
+
for (const [file, hash] of Object.entries(snapshotAfter)) {
|
|
95
|
+
if (snapshotBefore[file] !== hash) {
|
|
96
|
+
mutated.push(file);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const file of Object.keys(snapshotBefore)) {
|
|
100
|
+
if (snapshotAfter[file] === undefined) {
|
|
101
|
+
mutated.push(file);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (mutated.length > 0) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: `Read-only confinement violation: mutating changes detected inside temporary workspace: ${mutated.join(", ")}`,
|
|
109
|
+
commandsRun: runResult.commandsRun || [],
|
|
110
|
+
eventCount: runResult.eventCount || 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return runResult;
|
|
115
|
+
} finally {
|
|
116
|
+
// 6. Delete the temporary workspace copy
|
|
117
|
+
await fs.rm(tempDir, { recursive: true, force: true }).catch(() => {});
|
|
118
|
+
}
|
|
119
|
+
}
|