opencode-workflow-guard 1.8.2 → 1.8.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/README.md +1 -1
- package/package.json +1 -1
- package/src/lib/audit.ts +3 -3
- package/src/lib/guard-dispatcher.ts +2 -1
- package/src/lib/project-memory.ts +3 -3
- package/src/lib/sqlite.ts +20 -0
- package/src/policies/changelog.ts +15 -0
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ For the optional TUI badge, configure `"opencode-workflow-guard"` in `tui.json`.
|
|
|
33
33
|
npm run typecheck # Strict TypeScript check (0 errors)
|
|
34
34
|
npm test # Run 415+ unit and adversarial tests
|
|
35
35
|
npm run test:all # Typecheck + unit + install/load checks
|
|
36
|
-
WORKFLOW_GUARD_LIVE_E2E=1 npm run test:install # Also run
|
|
36
|
+
WORKFLOW_GUARD_LIVE_E2E=1 npm run test:install # Also run policy probes with OpenCode's most recently selected model
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
---
|
package/package.json
CHANGED
package/src/lib/audit.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { appendFileSync, chmodSync, existsSync, mkdirSync, openSync, readSync, c
|
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { Database, type SqliteDatabase } from "./sqlite.ts";
|
|
6
6
|
import type { AuditEntry, VerifyResult } from "./types.ts";
|
|
7
7
|
import { asRecord } from "./utils.ts";
|
|
8
8
|
|
|
@@ -19,7 +19,7 @@ const RETAIN_AUDIT_BYTES = 2 * 1024 * 1024;
|
|
|
19
19
|
const MAX_VERIFY_HISTORY_BYTES = 1024 * 1024;
|
|
20
20
|
const RETAIN_VERIFY_HISTORY_BYTES = 512 * 1024;
|
|
21
21
|
let verifiedHistoryState: { size: number; mtimeMs: number; ctimeMs: number; ino: number | bigint } | undefined;
|
|
22
|
-
const lockDatabases = new Map<string,
|
|
22
|
+
const lockDatabases = new Map<string, SqliteDatabase>();
|
|
23
23
|
|
|
24
24
|
function getVerifyHistoryState(): typeof verifiedHistoryState {
|
|
25
25
|
const stat = statSync(VERIFY_HISTORY_FILE);
|
|
@@ -34,7 +34,7 @@ function withFileLock<T>(path: string, action: () => T): T {
|
|
|
34
34
|
let db = lockDatabases.get(path);
|
|
35
35
|
if (!db) {
|
|
36
36
|
const lockPath = `${path}.lock.sqlite`;
|
|
37
|
-
db = new
|
|
37
|
+
db = new Database(lockPath);
|
|
38
38
|
db.exec("PRAGMA busy_timeout = 5000");
|
|
39
39
|
chmodSync(lockPath, 0o600);
|
|
40
40
|
lockDatabases.set(path, db);
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
snipVerifyOutput,
|
|
35
35
|
} from "./verify.ts";
|
|
36
36
|
import { detectShellMutation, extractPatchPaths, guardShellMutation, isPathOutsideWorkspace } from "../policies/boundary.ts";
|
|
37
|
-
import { branchHasChangelogChange, checkLockfileSync, hasPrCreateInvocation, prBodyIncludesChangelog } from "../policies/changelog.ts";
|
|
37
|
+
import { branchHasChangelogChange, checkLockfileSync, hasPrCreateInvocation, prBodyHasLiteralLineBreakEscapes, prBodyIncludesChangelog } from "../policies/changelog.ts";
|
|
38
38
|
import { extractEditContent, liveMutationIn } from "../policies/destructive.ts";
|
|
39
39
|
import { branchHasDocumentationChange } from "../policies/docs.ts";
|
|
40
40
|
import { claimFiles } from "../policies/file-claims.ts";
|
|
@@ -413,6 +413,7 @@ export async function guardToolCallImpl(
|
|
|
413
413
|
const prTool = isAz ? "az repos pr create" : "gh pr create";
|
|
414
414
|
const descFlag = isAz ? "--description" : "--body";
|
|
415
415
|
const preflightFailures: string[] = [];
|
|
416
|
+
if (prBodyHasLiteralLineBreakEscapes(raw)) preflightFailures.push(`PR description contains literal \\n/\\r escapes that will render as text; use real newlines, ANSI-C quoting ($'...\\n...'), or a body/description file instead.`);
|
|
416
417
|
const conflictCheck = checkMergeConflicts(prRoot);
|
|
417
418
|
if (conflictCheck.hasConflicts) preflightFailures.push(conflictCheck.reason ?? "Branch has merge conflicts with its base branch.");
|
|
418
419
|
const branch = currentGitBranch(prRoot);
|
|
@@ -2,14 +2,14 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { appendFileSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
import { execFile, spawnSync } from "node:child_process";
|
|
5
|
-
import {
|
|
5
|
+
import { Database, type SqliteDatabase } from "./sqlite.ts";
|
|
6
6
|
import type { ProjectMemoryInput, ProjectMemoryKind, ProjectMemoryRecord, ProjectMemorySource, ReviewFollowup, ReviewFollowupInput } from "./types.ts";
|
|
7
7
|
|
|
8
8
|
const KINDS = new Set<ProjectMemoryKind>(["fact", "decision", "constraint", "lesson"]);
|
|
9
9
|
const SOURCES = new Set<ProjectMemorySource>(["user", "file", "git", "tool", "agent", "portable"]);
|
|
10
10
|
|
|
11
11
|
export interface ProjectMemoryStore {
|
|
12
|
-
db:
|
|
12
|
+
db: SqliteDatabase;
|
|
13
13
|
projectId: string;
|
|
14
14
|
close(): void;
|
|
15
15
|
}
|
|
@@ -66,7 +66,7 @@ export async function isProjectMemoryFreshAsync(memory: ProjectMemoryRecord, roo
|
|
|
66
66
|
export function openProjectMemory(projectId: string, directory = getProjectMemoryDir()): ProjectMemoryStore {
|
|
67
67
|
if (!projectId || projectId.length > 200) throw new Error("Invalid project memory identity.");
|
|
68
68
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
69
|
-
const db = new
|
|
69
|
+
const db = new Database(join(directory, `${projectId.replace(/[^a-zA-Z0-9._-]/g, "_")}.sqlite`));
|
|
70
70
|
db.exec(`
|
|
71
71
|
PRAGMA journal_mode = WAL;
|
|
72
72
|
PRAGMA busy_timeout = 2000;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type RunResult = { changes: number | bigint };
|
|
2
|
+
type Statement = {
|
|
3
|
+
run(...params: unknown[]): RunResult;
|
|
4
|
+
all(...params: unknown[]): unknown[];
|
|
5
|
+
get(...params: unknown[]): unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export interface SqliteDatabase {
|
|
9
|
+
exec(sql: string): unknown;
|
|
10
|
+
prepare(sql: string): Statement;
|
|
11
|
+
close(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type DatabaseConstructor = new (path: string) => SqliteDatabase;
|
|
15
|
+
const sqliteModuleName = "Bun" in globalThis ? "bun:sqlite" : "node:sqlite";
|
|
16
|
+
const sqliteModule = await import(sqliteModuleName) as { Database?: DatabaseConstructor; DatabaseSync?: DatabaseConstructor };
|
|
17
|
+
|
|
18
|
+
const DatabaseImpl = sqliteModule.Database ?? sqliteModule.DatabaseSync;
|
|
19
|
+
if (!DatabaseImpl) throw new Error(`SQLite database implementation unavailable from ${sqliteModuleName}`);
|
|
20
|
+
export const Database: DatabaseConstructor = DatabaseImpl;
|
|
@@ -178,6 +178,21 @@ export function prBodyIncludesChangelog(command: string, invocationRoot: string
|
|
|
178
178
|
return false;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
export function prBodyHasLiteralLineBreakEscapes(command: string): boolean {
|
|
182
|
+
const words = prShellWords(command);
|
|
183
|
+
const cliIndex = words.findIndex((word) => word === "gh" || word === "az");
|
|
184
|
+
if (cliIndex < 0) return false;
|
|
185
|
+
|
|
186
|
+
for (let i = cliIndex; i < words.length; i += 1) {
|
|
187
|
+
const word = words[i]!;
|
|
188
|
+
let body: string | undefined;
|
|
189
|
+
if (["--body", "-b", "--description", "-d"].includes(word)) body = words[i + 1];
|
|
190
|
+
else if (/^(?:--body|--description)=/.test(word)) body = word.slice(word.indexOf("=") + 1);
|
|
191
|
+
if (body && /\\[nr](?:\\[nr]|(?=\s*[-*#]))/.test(body)) return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
181
196
|
export function checkLockfileSync(root: string): { isOutOfSync: boolean; manifest?: string; lockfile?: string; reason?: string } {
|
|
182
197
|
try {
|
|
183
198
|
let modifiedFiles: string[] = [];
|