codehere 2.0.2 → 2.1.0-rc.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/README.md +46 -18
- package/bin/codehere.js +4 -1
- package/package.json +1 -1
- package/src/brain.js +245 -14
- package/src/commands.js +188 -71
- package/src/gemma.js +17 -3
- package/src/hooks.js +380 -69
- package/src/signals.js +59 -11
package/src/signals.js
CHANGED
|
@@ -75,6 +75,15 @@ const REPAIR =
|
|
|
75
75
|
const POSITIVE = /\b(thanks|thank you|thx|works now|working now|great|nice|good|perfect|awesome|mantap|makasih|terima kasih|sip|berhasil|sudah bisa|udah bisa)\b/i;
|
|
76
76
|
|
|
77
77
|
// "still broken", "fix it", "masih error": short, no specifics, asks for a repair.
|
|
78
|
+
// The person's answer to a draft: a yes word, optionally with one polite word. A fixed list, in the
|
|
79
|
+
// style of askApproval(), so no model decides what is saved for the team.
|
|
80
|
+
const YES = new Set(['yes', 'y', 'yep', 'yeah', 'ok', 'okay', 'sure', 'save', 'save it', 'go ahead', 'do it', 'ya', 'iya', 'oke', 'boleh', 'simpan']);
|
|
81
|
+
export function plainYes(p) {
|
|
82
|
+
const t = String(p || '').trim().toLowerCase().replace(/[.!]+$/, '').trim();
|
|
83
|
+
const m = /^(.+?)(?:[\s,]+(?:please|thanks|thank you|makasih|dong))?$/.exec(t);
|
|
84
|
+
return !!m && YES.has(m[1].trim());
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
export function lowInfoPrompt(p) {
|
|
79
88
|
const w = words(p);
|
|
80
89
|
if (!w.length || w.length > 8 || SPECIFIC.test(p) || POSITIVE.test(p)) return false;
|
|
@@ -133,6 +142,25 @@ const TAMPER_ADDED = [
|
|
|
133
142
|
{ re: /expect\([^)]*\)\.(toBe|toEqual)\(\s*(true|1)\s*\)\s*;?\s*\/\/\s*(todo|temp|hack)/i, why: 'an assertion was replaced with a placeholder' },
|
|
134
143
|
];
|
|
135
144
|
|
|
145
|
+
// Only in test files: elsewhere `{ skip: true }` or `assert.equal(1, 1)` can be ordinary code.
|
|
146
|
+
const LITERAL = String.raw`(\d+(?:\.\d+)?|true|false|null|'[^']*'|"[^"]*")`;
|
|
147
|
+
const TAMPER_ADDED_IN_TESTS = [
|
|
148
|
+
// test('name', { skip: true }, ...): the name cannot run past its closing quote, so the options are this test's
|
|
149
|
+
{ re: /(?<![.\w])(it|test|describe|suite)\s*\(\s*(['"`])(?:(?!\2)[^\\]|\\.)*\2\s*,\s*\{[^}]*\b(skip|todo)\s*:\s*(true\b|['"`])/, why: 'a test was skipped ({ skip: true })' },
|
|
150
|
+
// fit/fdescribe only in jest's form, starting a statement with a quoted name then a callback:
|
|
151
|
+
// `fit(` alone is a common function name
|
|
152
|
+
{ re: /(?<![.\w])(it|test|describe|context|suite)\.only\s*\(|^[+-]\s*(fit|fdescribe)\s*\(\s*(['"`])(?:(?!\3)[^\\]|\\.)*\3\s*,\s*(async\s+)?(\(|function\b|\w+\s*=>)/, why: 'other tests were turned off (.only)' },
|
|
153
|
+
{ re: /\bassert(\.ok)?\(\s*true\s*\)|^\+\s*assert\s+True\s*$/, why: 'an assertion that cannot fail was added' },
|
|
154
|
+
{ re: new RegExp(String.raw`\bassert\.\w+\(\s*${LITERAL}\s*,\s*\1\s*\)`), why: 'an assertion that cannot fail was added' },
|
|
155
|
+
{ re: new RegExp(String.raw`\bexpect\(\s*${LITERAL}\s*\)\.(toBe|toEqual|toStrictEqual)\(\s*\1\s*\)`), why: 'an assertion that cannot fail was added' },
|
|
156
|
+
];
|
|
157
|
+
// assert(...), assert.equal(...), expect(...), self.assertEqual(...), and pytest's bare `assert x`;
|
|
158
|
+
// not expect.objectContaining(...) and the other matchers inside one assertion
|
|
159
|
+
const ASSERT = /\b(expect\s*\(|assert[\w.]*\s*\()|^[+-]\s*assert\s/;
|
|
160
|
+
// package.json's test script made to pass whatever the tests do: `|| true`, `|| :`, `|| echo`, `; exit 0`
|
|
161
|
+
const ALWAYS_PASSES = /"test"\s*:\s*"[^"]*(\|\|\s*(true|:|exit\s+0|echo\b[^"&|;]*)|;\s*(true|exit\s+0))\s*"/;
|
|
162
|
+
const COMMENT = /^[+-]\s*(\/\/|#|\/\*|\*)\s*/;
|
|
163
|
+
|
|
136
164
|
export function tamperFindings(nameStatus, diff) {
|
|
137
165
|
const found = [];
|
|
138
166
|
for (const line of nameStatus.split('\n')) {
|
|
@@ -142,17 +170,32 @@ export function tamperFindings(nameStatus, diff) {
|
|
|
142
170
|
let current = '';
|
|
143
171
|
let removedAsserts = 0;
|
|
144
172
|
let addedAsserts = 0;
|
|
173
|
+
let removed = new Set(); // this file's removed assertions, to spot one coming back as a comment
|
|
174
|
+
let hadFallback = false; // the test script already ended in `|| true` before this session
|
|
145
175
|
for (const line of diff.split('\n')) {
|
|
146
176
|
if (line.startsWith('+++ ')) {
|
|
147
177
|
current = line.replace(/^\+\+\+ (b\/)?/, '');
|
|
178
|
+
removed = new Set();
|
|
179
|
+
hadFallback = false;
|
|
148
180
|
continue;
|
|
149
181
|
}
|
|
150
182
|
if (line.startsWith('--- ')) continue;
|
|
183
|
+
const inTest = TEST_FILE.test(current);
|
|
184
|
+
const probe = line.slice(0, 10000); // the patterns can take quadratic time on a long line
|
|
185
|
+
if (/(^|\/)package\.json$/.test(current) && ALWAYS_PASSES.test(probe)) {
|
|
186
|
+
if (line.startsWith('-')) hadFallback = true;
|
|
187
|
+
else if (!hadFallback) found.push(`the test script was changed to always exit 0 in ${current}`);
|
|
188
|
+
}
|
|
151
189
|
if (line.startsWith('+')) {
|
|
152
|
-
for (const t of TAMPER_ADDED) if (t.re.test(
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
if (
|
|
190
|
+
for (const t of TAMPER_ADDED) if (t.re.test(probe)) found.push(`${t.why} in ${current}`);
|
|
191
|
+
if (!inTest) continue;
|
|
192
|
+
for (const t of TAMPER_ADDED_IN_TESTS) if (t.re.test(probe)) found.push(`${t.why} in ${current}`);
|
|
193
|
+
if (COMMENT.test(line)) {
|
|
194
|
+
if (removed.has(line.replace(COMMENT, '').trim())) found.push(`an assertion was commented out in ${current}`);
|
|
195
|
+
} else if (ASSERT.test(line)) addedAsserts++;
|
|
196
|
+
} else if (line.startsWith('-') && inTest && !COMMENT.test(line) && ASSERT.test(line)) {
|
|
197
|
+
removedAsserts++;
|
|
198
|
+
removed.add(line.slice(1).trim());
|
|
156
199
|
}
|
|
157
200
|
}
|
|
158
201
|
if (removedAsserts - addedAsserts >= 2) {
|
|
@@ -192,6 +235,7 @@ const num = (s, re) => {
|
|
|
192
235
|
const m = s.match(re);
|
|
193
236
|
return m ? Number(m[1]) : null;
|
|
194
237
|
};
|
|
238
|
+
const after = (t, line) => t.slice(t.indexOf(line) + line.length);
|
|
195
239
|
const counts = (passed, failed) => (passed == null && failed == null ? null : { passed: passed || 0, failed: failed || 0 });
|
|
196
240
|
const SUMMARIES = [
|
|
197
241
|
// node --test, spec and TAP reporters: "ℹ tests 3", "ℹ pass 2", "ℹ fail 1"
|
|
@@ -203,15 +247,19 @@ const SUMMARIES = [
|
|
|
203
247
|
re: /^[=\s]*(?:\d+ \w+(?:, )?)+ in [\d.]+s\b.*$/gm,
|
|
204
248
|
read: (t, line) => counts(num(line, /(\d+) passed/), (num(line, /(\d+) failed/) || 0) + (num(line, /(\d+) errors?/) || 0)),
|
|
205
249
|
},
|
|
206
|
-
// mocha "46 passing" and "2 failing"
|
|
207
|
-
{
|
|
208
|
-
|
|
250
|
+
// mocha "46 passing", then "2 pending" and "2 failing" on the next lines (a log line elsewhere is not the count)
|
|
251
|
+
{
|
|
252
|
+
re: /^\s*\d+ passing\b.*$/gm,
|
|
253
|
+
read: (t, line) => counts(num(line, /(\d+) passing/), num(after(t, line).split('\n').slice(1, 3).join('\n'), /^\s*(\d+) failing\b/m)),
|
|
254
|
+
},
|
|
255
|
+
// python unittest "Ran 5 tests in 0.001s", then the status line: "OK" or "FAILED (failures=2, errors=1)"
|
|
209
256
|
{
|
|
210
257
|
re: /^Ran \d+ tests? in [\d.]+s$/gm,
|
|
211
|
-
read: (t) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
258
|
+
read: (t, line) => {
|
|
259
|
+
const status = (after(t, line).trimStart().match(/^(OK|FAILED)\b.*/) || [''])[0];
|
|
260
|
+
if (!status || /expected failures|unexpected successes/.test(status)) return null; // neither passed nor failed
|
|
261
|
+
const failed = (num(status, /failures=(\d+)/) || 0) + (num(status, /errors=(\d+)/) || 0);
|
|
262
|
+
return counts(num(line, /^Ran (\d+)/) - failed - (num(status, /skipped=(\d+)/) || 0), failed);
|
|
215
263
|
},
|
|
216
264
|
},
|
|
217
265
|
// cargo "test result: ok. 4 passed; 0 failed", one line per test binary
|