-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp_fix_readonly_status.py
More file actions
80 lines (67 loc) · 3.46 KB
/
Copy pathtmp_fix_readonly_status.py
File metadata and controls
80 lines (67 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pathlib import Path
path = Path(r'C:\Users\acer\.pi\agent\git\github.com\adi805\pi-minimax-pack\extensions\global-contract.ts')
text = path.read_text(encoding='utf-8')
old = '''function buildAutoStatusReport(state: TurnToolState): string | null {
const ops = state.ops;
if (ops.length === 0) return null;
const writes = ops.filter((o) => o.toolName === "write" && o.path).map((o) => ({ path: o.path!, index: o.index }));
const reads = ops.filter((o) => o.toolName === "read" && o.path).map((o) => ({ path: o.path!, index: o.index }));
const edits = ops.filter((o) => o.toolName === "edit" && (o.path || o.editsPaths?.length)).flatMap((o) => {
const paths = o.path ? [o.path] : (o.editsPaths || []);
return paths.map((p) => ({ path: p, index: o.index }));
});
const changedPaths = unique([...writes.map((w) => w.path), ...edits.map((e) => e.path)]);
const lines: string[] = ["\n\nStatus Report (auto)"];
for (const p of changedPaths) lines.push(`- changed: ${p}`);
for (const w of writes) {
const hasReadBack = reads.some((r) => r.path === w.path && r.index > w.index);
lines.push(hasReadBack ? `- verified: wrote then read-back ${w.path}` : `- unverified: wrote ${w.path} but no read-back proof`);
}
for (const e of edits) {
const hasReadBefore = reads.some((r) => r.path === e.path && r.index < e.index);
const hasReadAfter = reads.some((r) => r.path === e.path && r.index > e.index);
lines.push(
hasReadBefore && hasReadAfter
? `- verified: edited with read-before & read-after ${e.path}`
: `- unverified: edited ${e.path} without full read-before/read-after proof`,
);
}
return lines.join("\n");
}
'''
new = '''function buildAutoStatusReport(state: TurnToolState): string | null {
const ops = state.ops;
if (ops.length === 0) return null;
const writes = ops.filter((o) => o.toolName === "write" && o.path).map((o) => ({ path: o.path!, index: o.index }));
const reads = ops.filter((o) => o.toolName === "read" && o.path).map((o) => ({ path: o.path!, index: o.index }));
const edits = ops.filter((o) => o.toolName === "edit" && (o.path || o.editsPaths?.length)).flatMap((o) => {
const paths = o.path ? [o.path] : (o.editsPaths || []);
return paths.map((p) => ({ path: p, index: o.index }));
});
const changedPaths = unique([...writes.map((w) => w.path), ...edits.map((e) => e.path)]);
const lines: string[] = ["\n\nStatus Report (auto)"];
for (const p of changedPaths) lines.push(`- changed: ${p}`);
for (const w of writes) {
const hasReadBack = reads.some((r) => r.path === w.path && r.index > w.index);
lines.push(hasReadBack ? `- verified: wrote then read-back ${w.path}` : `- unverified: wrote ${w.path} but no read-back proof`);
}
for (const e of edits) {
const hasReadBefore = reads.some((r) => r.path === e.path && r.index < e.index);
const hasReadAfter = reads.some((r) => r.path === e.path && r.index > e.index);
lines.push(
hasReadBefore && hasReadAfter
? `- verified: edited with read-before & read-after ${e.path}`
: `- unverified: edited ${e.path} without full read-before/read-after proof`,
);
}
if (writes.length === 0 && edits.length === 0 && reads.length > 0) {
for (const p of unique(reads.map((r) => r.path))) lines.push(`- verified: read ${p}`);
}
return lines.length > 1 ? lines.join("\n") : null;
}
'''
if old not in text:
raise SystemExit('target block not found')
text = text.replace(old, new)
path.write_bytes(text.replace('\r\n','\n').replace('\r','\n').encode('utf-8'))
print('fixed read-only status report')