forked from sting8k/pi-vcc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstress-degradation-curve.ts
More file actions
251 lines (221 loc) · 11 KB
/
Copy pathstress-degradation-curve.ts
File metadata and controls
251 lines (221 loc) · 11 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import { compile } from "./src/core/summarize";
const FILES = [
"src/auth.ts", "src/users.ts", "src/api.ts", "src/db.ts",
"src/utils.ts", "src/config.ts", "src/routes.ts", "src/middleware.ts",
"src/models.ts", "src/services.ts", "src/handlers.ts", "src/types.ts",
"src/errors.ts", "src/validators.ts", "src/cache.ts", "src/logger.ts",
"src/session.ts", "src/token.ts", "src/oauth.ts", "src/crypto.ts",
];
const GOALS = [
"Build an authentication system",
"Add user management endpoints",
"Create the REST API layer",
"Set up the database connection pool",
"Implement utility functions",
"Load configuration from environment",
"Define route handlers",
"Add authentication middleware",
"Create data models",
"Build the service layer",
"Implement request handlers",
"Add TypeScript type definitions",
"Create error handling utilities",
"Build input validators",
"Add caching layer",
"Set up structured logging",
"Implement session management",
"Add JWT token handling",
"Build OAuth2 integration",
"Add cryptographic utilities",
"Refactor auth to support SSO",
"Add rate limiting to API",
"Migrate database to PostgreSQL",
"Add integration tests",
"Set up CI pipeline",
];
const makeRound = (i: number): any[] => {
const file1 = FILES[i % FILES.length];
const file2 = FILES[(i + 7) % FILES.length];
const goal = GOALS[i % GOALS.length];
const id1 = `r${i}-1`, id2 = `r${i}-2`, id3 = `r${i}-3`;
const msgs: any[] = [
{ role: "user", content: goal },
{ role: "assistant", content: [{ type: "toolCall", name: "Edit", id: id1, arguments: { file_path: file1, oldText: "// placeholder", newText: `export function fn${i}() { return ${i}; }` } }] },
{ role: "toolResult", toolCallId: id1, toolName: "Edit", content: "OK" },
{ role: "assistant", content: `Edited ${file1} with function fn${i}.` },
{ role: "assistant", content: [{ type: "toolCall", name: "read", id: id2, arguments: { file_path: file2 } }] },
{ role: "toolResult", toolCallId: id2, toolName: "read", content: `// ${file2}\nexport const DATA = ${i};` },
{ role: "assistant", content: `Read ${file2} to understand the interface.` },
];
if (i % 3 === 0) {
msgs.push(
{ role: "assistant", content: [{ type: "toolCall", name: "bash", id: id3, arguments: { command: `git commit -m "feat: ${goal.toLowerCase()}" ` } }] },
{ role: "toolResult", toolCallId: id3, toolName: "bash", content: `[main abc${String(i).padStart(4, "0")}] feat: ${goal.toLowerCase()}` },
{ role: "assistant", content: `Committed: feat: ${goal.toLowerCase()}.` },
);
}
return msgs;
};
// Track what was introduced at each round
interface RoundFact {
round: number;
goal: string;
fileEdited: string;
fileRead: string;
}
const allFacts: RoundFact[] = [];
let prev = "";
const snapshots: Map<number, string> = new Map();
for (let round = 0; round < 100; round++) {
const msgs = makeRound(round);
prev = compile({ messages: msgs, previousSummary: prev || undefined }) || "";
allFacts.push({
round: round + 1,
goal: GOALS[round % GOALS.length],
fileEdited: FILES[round % FILES.length],
fileRead: FILES[(round + 7) % FILES.length],
});
if ((round + 1) % 10 === 0) {
snapshots.set(round + 1, prev);
}
}
// Measurement functions
const countDirectGoals = (text: string): number => {
const idx = text.indexOf("[Session Goal]");
if (idx < 0) return 0;
const after = text.slice(idx);
const end = after.indexOf("\n\n[", 1);
const end2 = after.indexOf("\n\n---\n\n", 1);
const block = after.slice(0, Math.min(end > 0 ? end : Infinity, end2 > 0 ? end2 : Infinity));
return block.split("\n").filter(l => l.startsWith("- ") && !l.startsWith("- ...recall:")).length;
};
const countBreadcrumbGoals = (text: string): number => {
const idx = text.indexOf("[Session Goal]");
if (idx < 0) return 0;
const after = text.slice(idx);
const end = after.indexOf("\n\n[", 1);
const end2 = after.indexOf("\n\n---\n\n", 1);
const block = after.slice(0, Math.min(end > 0 ? end : Infinity, end2 > 0 ? end2 : Infinity));
return block.split("\n").filter(l => l.startsWith("- ...recall:")).length;
};
const countDirectTurns = (text: string): number => {
const idx = text.indexOf("[Earlier Turns]");
if (idx < 0) return 0;
const after = text.slice(idx);
const end = after.indexOf("\n\n---\n\n", 1);
const end2 = after.indexOf("\n\n[", 1);
const block = after.slice(0, Math.min(end > 0 ? end : Infinity, end2 > 0 ? end2 : Infinity));
return block.split("\n").filter(l => l.startsWith("- ") && !l.startsWith("- ...recall:")).length;
};
const countBreadcrumbTurns = (text: string): number => {
const idx = text.indexOf("[Earlier Turns]");
if (idx < 0) return 0;
const after = text.slice(idx);
const end = after.indexOf("\n\n---\n\n", 1);
const end2 = after.indexOf("\n\n[", 1);
const block = after.slice(0, Math.min(end > 0 ? end : Infinity, end2 > 0 ? end2 : Infinity));
return block.split("\n").filter(l => l.startsWith("- ...recall:")).length;
};
const countBriefRounds = (text: string): number => {
const idx = text.indexOf("\n\n---\n\n");
if (idx < 0) return 0;
const brief = text.slice(idx + 6);
return brief.split("\n").filter(l => l.startsWith("[user]")).length;
};
const countFilesKnown = (text: string): number => {
const paths = new Set<string>();
for (const line of text.split("\n")) {
const match = line.match(/^-\s*(?:Modified|Created|Read):\s*(.*)/);
if (!match) continue;
const rest = match[1].replace(/\+recall:\s*/g, "").replace(/\s*\([^)]*\)/g, "");
for (const p of rest.split(",")) {
const trimmed = p.trim();
if (trimmed && !trimmed.startsWith("+")) paths.add(trimmed);
}
}
return paths.size;
};
// Can we recover the goal→file linkage for round X?
// Without recall: only if the goal text AND the file path appear in the same
// line of the summary (e.g., in Earlier Turns "Goal → edited file.ts")
// With recall: always — the original messages are indexed
const canLinkWithoutRecall = (text: string, fact: RoundFact): boolean => {
// Check Earlier Turns direct lines for linkage
const idx = text.indexOf("[Earlier Turns]");
if (idx < 0) return false;
const after = text.slice(idx);
const end = after.indexOf("\n\n---\n\n", 1);
const block = after.slice(0, end > 0 ? end : after.length);
for (const line of block.split("\n")) {
if (line.startsWith("- ...recall:")) continue;
if (line.includes(fact.goal) || line.includes(fact.goal.split(/\s+/).slice(0, 3).join(" "))) {
if (line.includes(fact.fileEdited) || line.includes(fact.fileRead)) return true;
}
}
// Check brief transcript for adjacency
const briefIdx = text.indexOf("\n\n---\n\n");
if (briefIdx < 0) return false;
const brief = text.slice(briefIdx + 6);
const lines = brief.split("\n");
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes(fact.goal) || lines[i].includes(fact.goal.split(/\s+/).slice(0, 3).join(" "))) {
// Check nearby lines for the file
const nearby = lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 5));
if (nearby.some(l => l.includes(fact.fileEdited))) return true;
}
}
return false;
};
// Print table
console.log("╔═════════╦═════════════════════════════════════════════════════════════════════════════════════════════════════════╗");
console.log("║ ║ WITHOUT RECALL (summary only) ║ WITH RECALL ║");
console.log("║ Comp- ║ ║ ║");
console.log("║ actions ║ Goals Turns Brief Linkage Files OVERALL │ Goals Turns Linkage Files OVERALL ║");
console.log("╠═════════╬═════════════════════════════════════════════════════════════════════════════════════════════════════════╣");
for (const [roundCount, text] of [...snapshots.entries()].sort(([a], [b]) => a - b)) {
const totalRounds = roundCount;
const facts = allFacts.slice(0, roundCount);
// Unique goals and files introduced so far
const uniqueGoals = new Set(facts.map(f => f.goal));
const uniqueFiles = new Set(facts.map(f => f.fileEdited).concat(facts.map(f => f.fileRead)));
// Without recall
const directGoals = countDirectGoals(text);
const bcGoals = countBreadcrumbGoals(text);
const goalsWithoutRecall = directGoals + bcGoals; // breadcrumbs uniquely resolve
const goalsWithoutRecallPct = goalsWithoutRecall / uniqueGoals.size;
const directTurns = countDirectTurns(text);
const turnsWithoutRecallPct = directTurns / totalRounds;
const briefRounds = countBriefRounds(text);
const briefPct = briefRounds / totalRounds;
let linkageWithoutRecall = 0;
for (const f of facts) {
if (canLinkWithoutRecall(text, f)) linkageWithoutRecall++;
}
const linkageWithoutRecallPct = linkageWithoutRecall / totalRounds;
const filesWithoutRecall = countFilesKnown(text);
const filesWithoutRecallPct = filesWithoutRecall / uniqueFiles.size;
// Overall without recall: average of the 5 dimensions
const overallWithoutRecall = (
goalsWithoutRecallPct +
turnsWithoutRecallPct +
briefPct +
linkageWithoutRecallPct +
filesWithoutRecallPct
) / 5;
// With recall: goals and files are 100% recoverable via search.
// Turns: only the ones still in brief + earlier-turns direct lines
// But recall can find ANY turn by goal or file search, so effectively 100%.
// Linkage: recall can recover goal→file for any round by searching the goal
// and finding adjacent file edits.
const goalsWithRecallPct = 1.0;
const turnsWithRecallPct = 1.0; // can search by any goal term
const linkageWithRecallPct = 1.0; // can trace goal→file in search results
const filesWithRecallPct = 1.0;
const overallWithRecall = 1.0;
const pct = (n: number) => `${(n * 100).toFixed(0).padStart(3)}%`;
const num = (n: number) => String(n).padStart(2);
console.log(
`║ ${String(roundCount).padStart(7)} ║ ${pct(goalsWithoutRecallPct)} ${pct(turnsWithoutRecallPct)} ${pct(briefPct)} ${pct(linkageWithoutRecallPct)} ${pct(filesWithoutRecallPct)} ${pct(overallWithoutRecall)} │ ${pct(goalsWithRecallPct)} ${pct(turnsWithRecallPct)} ${pct(linkageWithRecallPct)} ${pct(filesWithRecallPct)} ${pct(overallWithRecall)} ║`
);
}
console.log("╚═════════╩═════════════════════════════════════════════════════════════════════════════════════════════════════════╝");