opencode-self-improvement 0.34.2 → 0.34.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/package.json +1 -1
- package/src/capture/available.ts +128 -90
- package/src/core/tokenize.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.3",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
package/src/capture/available.ts
CHANGED
|
@@ -233,32 +233,14 @@ function cueNegated(text: string): boolean {
|
|
|
233
233
|
return NEGATION.test(text);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
/**
|
|
237
|
-
* VETO 2: a figure the matched DECLARATION does not carry.
|
|
238
|
-
*
|
|
239
|
-
* `core/tokenize.ts` states the rule and `store/tombstones/tombstone.ts`
|
|
240
|
-
* measures it on this repo's own data: a correction scores HIGHER than an honest
|
|
241
|
-
* rewording, so overlap alone cannot separate "the same fact again" from "the
|
|
242
|
-
* fact has changed". On the declared-command path the manifest states only that
|
|
243
|
-
* a command exists, so any number the row asserts has to be in the DECLARED
|
|
244
|
-
* command — `gate.label` — or the row is new. The comparison text is never the
|
|
245
|
-
* candidate's own spans: a row whose command span carries a flag value
|
|
246
|
-
* (`--timeout 5000`) would supply the figure that clears its own veto, and the
|
|
247
|
-
* declaration, not the row, is what must vouch for the number.
|
|
248
|
-
* `numericTokens` reads the figure grammar exported from `core/tokenize.ts`:
|
|
249
|
-
* a grouped figure is one figure (`1,024` reads as `1024`), a sentence dot is
|
|
250
|
-
* not part of one, and dotted versions and addresses stay whole, so no figure
|
|
251
|
-
* can be assembled out of separate integers.
|
|
252
|
-
*/
|
|
253
|
-
function introducesNewNumber(text: string, matched: string): boolean {
|
|
254
|
-
const known = new Set(numericTokens(matched));
|
|
255
|
-
for (const n of numericTokens(text)) if (!known.has(n)) return true;
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
236
|
/**
|
|
260
237
|
* True when every figure `text` states appears in `known` as a whole token —
|
|
261
|
-
* the
|
|
238
|
+
* the figure rule behind both figure checks, aimed at the matched region on the
|
|
239
|
+
* tracked path and at the vouching declarations on the gate path.
|
|
240
|
+
* `core/tokenize.ts` states the grammar and `store/tombstones/tombstone.ts`
|
|
241
|
+
* measures why a figure is checked at all: a correction scores HIGHER than an
|
|
242
|
+
* honest rewording, so overlap alone cannot separate "the same fact again" from
|
|
243
|
+
* "the fact has changed". `claims()` no longer splits
|
|
262
244
|
* inside a figure and `findClause` admits no hit that cuts one, so a figure the
|
|
263
245
|
* tree never states (`1.5`, `1.4.3`, `10.20.30.40`) cannot reassemble from
|
|
264
246
|
* fragments of separate sentences; this check stays as the second net, because
|
|
@@ -358,13 +340,22 @@ interface Slice {
|
|
|
358
340
|
/** Declared gates: a command the project already runs, and where it is declared. */
|
|
359
341
|
interface Gate {
|
|
360
342
|
label: string;
|
|
343
|
+
/** Citation only: the file and the kind of declaration a refusal names. */
|
|
361
344
|
where: string;
|
|
362
345
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
346
|
+
* Declaration identity. Gates that state the SAME declaration share a group,
|
|
347
|
+
* and only a group member vouches for another: a script's name and its
|
|
348
|
+
* command share one, so `--prod` written in the command vouches for `--prod`
|
|
349
|
+
* in the row. A step among siblings — a Makefile recipe, a workflow `run:`
|
|
350
|
+
* line — gets a group no sibling joins, because those share a `where` across
|
|
351
|
+
* the whole file while stating nothing about each other. The group is part of
|
|
352
|
+
* the contract every declaration kind answers for: a kind whose `where`
|
|
353
|
+
* names a FILE must derive the group per declaration, because reusing the
|
|
354
|
+
* file-wide `where` as the group lets one step's operands vouch for another
|
|
355
|
+
* step's row — a refusal that loses a fact. A required field forces the
|
|
356
|
+
* question at the call site; an optional flag defaults past it.
|
|
366
357
|
*/
|
|
367
|
-
|
|
358
|
+
group: string;
|
|
368
359
|
}
|
|
369
360
|
|
|
370
361
|
function readTracked(repoDir: string, file: string): string | null {
|
|
@@ -384,9 +375,9 @@ function skipPath(file: string): boolean {
|
|
|
384
375
|
|
|
385
376
|
function parseGates(repoDir: string, files: string[]): Gate[] {
|
|
386
377
|
const gates: Gate[] = [];
|
|
387
|
-
const add = (label: string, where: string,
|
|
378
|
+
const add = (label: string, where: string, group: string) => {
|
|
388
379
|
const n = norm(label);
|
|
389
|
-
if (n.length >= 2 && n.length <= 80) gates.push({ label: n, where,
|
|
380
|
+
if (n.length >= 2 && n.length <= 80) gates.push({ label: n, where, group });
|
|
390
381
|
};
|
|
391
382
|
for (const file of files) {
|
|
392
383
|
if (skipPath(file)) continue;
|
|
@@ -404,8 +395,9 @@ function parseGates(repoDir: string, files: string[]): Gate[] {
|
|
|
404
395
|
try {
|
|
405
396
|
const pkg = JSON.parse(text) as { scripts?: Record<string, string> };
|
|
406
397
|
for (const [name, cmd] of Object.entries(pkg.scripts ?? {})) {
|
|
407
|
-
|
|
408
|
-
|
|
398
|
+
const where = `${file} scripts.${name}`;
|
|
399
|
+
add(name, where, where);
|
|
400
|
+
if (typeof cmd === "string") add(cmd, where, where);
|
|
409
401
|
}
|
|
410
402
|
} catch {
|
|
411
403
|
// An unparseable manifest is not evidence of absence.
|
|
@@ -415,15 +407,19 @@ function parseGates(repoDir: string, files: string[]): Gate[] {
|
|
|
415
407
|
if (base === "Makefile" || base === "makefile" || base === "justfile") {
|
|
416
408
|
for (const line of text.split("\n")) {
|
|
417
409
|
const target = /^([A-Za-z0-9_.%-]+)\s*:(?!=)/.exec(line);
|
|
418
|
-
if (target?.[1])
|
|
410
|
+
if (target?.[1]) {
|
|
411
|
+
const where = `${file} target ${target[1]}`;
|
|
412
|
+
add(target[1], where, where);
|
|
413
|
+
}
|
|
419
414
|
const recipe = /^\t+([^\s].*)$/.exec(line);
|
|
420
|
-
if (recipe?.[1])
|
|
415
|
+
if (recipe?.[1])
|
|
416
|
+
add(recipe[1], `${file} recipe`, `${file} recipe ${norm(recipe[1])}`);
|
|
421
417
|
}
|
|
422
418
|
continue;
|
|
423
419
|
}
|
|
424
420
|
for (const line of text.split("\n")) {
|
|
425
421
|
const run = /^\s*-?\s*run:\s*["']?(.+?)["']?\s*$/.exec(line);
|
|
426
|
-
if (run?.[1]) add(run[1], `${file} run`,
|
|
422
|
+
if (run?.[1]) add(run[1], `${file} run`, `${file} run ${norm(run[1])}`);
|
|
427
423
|
}
|
|
428
424
|
}
|
|
429
425
|
return gates;
|
|
@@ -455,20 +451,18 @@ function runners(span: string): string[] {
|
|
|
455
451
|
}
|
|
456
452
|
|
|
457
453
|
/**
|
|
458
|
-
* The labels that vouch for a declaration:
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
454
|
+
* The labels that vouch for a declaration: every gate in its GROUP. A script
|
|
455
|
+
* declaration states its name and its command together, so `--prod` written in
|
|
456
|
+
* the command vouches for `--prod` in the row. The union is keyed on the group,
|
|
457
|
+
* never on `where`: a step-kind `where` names a FILE — every recipe in a
|
|
462
458
|
* Makefile, every `run:` in a workflow — and siblings state nothing about each
|
|
463
|
-
* other, so
|
|
459
|
+
* other, so each step's group holds only itself. Keying on `where` let a new
|
|
460
|
+
* declaration kind inherit a file-wide union by forgetting a flag, and a
|
|
461
|
+
* file-wide union vouches for a refusal with another step's operands.
|
|
464
462
|
*/
|
|
465
463
|
function vouchLabels(gate: Gate, gates: Gate[]): string[] {
|
|
466
464
|
const out: string[] = [];
|
|
467
|
-
for (const g of gates)
|
|
468
|
-
if (g.where !== gate.where) continue;
|
|
469
|
-
if (gate.solo && g.label !== gate.label) continue;
|
|
470
|
-
out.push(g.label);
|
|
471
|
-
}
|
|
465
|
+
for (const g of gates) if (g.group === gate.group) out.push(g.label);
|
|
472
466
|
return out;
|
|
473
467
|
}
|
|
474
468
|
|
|
@@ -515,28 +509,21 @@ function contiguousIn(operand: string[], labels: string[]): boolean {
|
|
|
515
509
|
* So the gate path asks the tree path's question — contiguity, not presence.
|
|
516
510
|
* The operand must be a contiguous token run inside a vouching label; the empty
|
|
517
511
|
* operand is the bare invocation, which the declaration states on its own.
|
|
512
|
+
* Each span asks its OWN declarations: one shared label set let a second,
|
|
513
|
+
* unrelated mention lend its operands to the first, and the candidate run and
|
|
514
|
+
* the labels it settles against must come from the SAME declaration —
|
|
515
|
+
* stripping one label and testing the remainder against another's command is
|
|
516
|
+
* the shared lookup in a new coat.
|
|
518
517
|
* Anything the check cannot establish — the label not located, values swapped,
|
|
519
518
|
* flags reordered, an operand broken by a word the declaration omits — keeps
|
|
520
519
|
* the row. Reordering valueless flags keeps too: order-irrelevance is not a
|
|
521
520
|
* thing a token comparison can prove, a wrong keep costs a row, and a wrong
|
|
522
521
|
* refusal costs a fact.
|
|
523
522
|
*/
|
|
524
|
-
function
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
// second, unrelated mention lend its operands to the first: with `build:
|
|
529
|
-
// "compiler"` and `deploy: "deploy-tool publish --target staging …"`, the
|
|
530
|
-
// row `Run \`npm run deploy\`. Run \`npm run build -- --target staging\`.`
|
|
531
|
-
// checked the build operand against the deploy command, which happens to
|
|
532
|
-
// contain it, and the bare deploy mention hid the build information.
|
|
533
|
-
const candidates = operandCandidates(span, matched);
|
|
534
|
-
if (candidates.length === 0) return false;
|
|
535
|
-
const labels = vouchLabels(matched, gates);
|
|
536
|
-
if (!candidates.some((o) => o.length === 0 || contiguousIn(o, labels)))
|
|
537
|
-
return false;
|
|
538
|
-
}
|
|
539
|
-
return true;
|
|
523
|
+
function operandSettled(span: string, gate: Gate, gates: Gate[]): boolean {
|
|
524
|
+
const candidates = operandCandidates(span, gate);
|
|
525
|
+
const labels = vouchLabels(gate, gates);
|
|
526
|
+
return candidates.some((o) => o.length === 0 || contiguousIn(o, labels));
|
|
540
527
|
}
|
|
541
528
|
|
|
542
529
|
// Matching is positional, never substring. A gate named `all` must not refuse a
|
|
@@ -544,22 +531,27 @@ function operandsDeclared(spans: string[], gate: Gate, gates: Gate[]): boolean {
|
|
|
544
531
|
// "the test suite". So a single-word gate (a script name, a make target) only
|
|
545
532
|
// matches the OPERAND position — the first token after the runner is stripped —
|
|
546
533
|
// and a multi-word gate (a declared command) matches whole.
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
534
|
+
//
|
|
535
|
+
// Every match is returned, not the first: which file `git ls-files` lists
|
|
536
|
+
// first is not evidence, and a span declared in a CI step AND in a manifest
|
|
537
|
+
// script rests on both. An empty result means the span states no declared
|
|
538
|
+
// command.
|
|
539
|
+
function gateHits(span: string, gates: Gate[]): Gate[] {
|
|
540
|
+
const out: Gate[] = [];
|
|
541
|
+
for (const form of runners(span)) {
|
|
542
|
+
const first = form.split(" ")[0] ?? "";
|
|
543
|
+
for (const g of gates) {
|
|
544
|
+
if (out.includes(g)) continue;
|
|
545
|
+
if (form === g.label) out.push(g);
|
|
546
|
+
else if (!g.label.includes(" ") && first === g.label) out.push(g);
|
|
547
|
+
else if (
|
|
548
|
+
g.label.includes(" ") &&
|
|
549
|
+
(form.startsWith(`${g.label} `) || form.endsWith(` ${g.label}`))
|
|
550
|
+
)
|
|
551
|
+
out.push(g);
|
|
560
552
|
}
|
|
561
553
|
}
|
|
562
|
-
return
|
|
554
|
+
return out;
|
|
563
555
|
}
|
|
564
556
|
|
|
565
557
|
/**
|
|
@@ -963,8 +955,8 @@ export function availabilityIndex(
|
|
|
963
955
|
// 3. otherwise, every assertion left in it is one the tracked files
|
|
964
956
|
// state themselves.
|
|
965
957
|
const spans = statedCommands(content);
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
958
|
+
const hits = spans.map((s) => gateHits(s, gates));
|
|
959
|
+
if (hits.some((h) => h.length > 0)) {
|
|
968
960
|
// VETOES. The manifest states that a command EXISTS. It does not
|
|
969
961
|
// state that the command is safe, allowed, or finished, and it carries
|
|
970
962
|
// no figure. So a sentence that forbids the command, or a number the
|
|
@@ -976,24 +968,70 @@ export function availabilityIndex(
|
|
|
976
968
|
// veto-only shape: the vocabulary never has to be perfect, because a
|
|
977
969
|
// miss keeps the row instead of deleting it.
|
|
978
970
|
if (forbidsCommand(content, spans)) return null;
|
|
979
|
-
//
|
|
980
|
-
//
|
|
981
|
-
//
|
|
982
|
-
|
|
983
|
-
// The
|
|
984
|
-
//
|
|
985
|
-
|
|
986
|
-
|
|
971
|
+
// VETOES 2 AND 3, per span and per declaration. A span settles
|
|
972
|
+
// against ONE declaration that carries BOTH dimensions: every figure
|
|
973
|
+
// the span states appears among the figures of that declaration's
|
|
974
|
+
// group, and its operand is a contiguous token run inside the same
|
|
975
|
+
// group. The two dimensions stay distinct checks — figures ask
|
|
976
|
+
// set membership, operands ask contiguity and pairing, and collapsing
|
|
977
|
+
// one into the other reopens the pairing hole the contiguity comment
|
|
978
|
+
// above records. What changed is the unit: never one label chosen by
|
|
979
|
+
// scan order, and never the union of two declarations that merely
|
|
980
|
+
// both match the span — a row citing one command is not answered by
|
|
981
|
+
// two commands' figures pooled together. A row that spells
|
|
982
|
+
// `npm run deploy --replicas 3` against
|
|
983
|
+
// `"deploy": "deploy-tool publish --replicas 3"` settles against the
|
|
984
|
+
// deploy declaration, whose command carries the figure, instead of
|
|
985
|
+
// the bare name, which carries none and kept the row for the wrong
|
|
986
|
+
// reason. The comparison text is still the DECLARED command, never
|
|
987
|
+
// the candidate's spans: a span carrying `--timeout 5000` would vouch
|
|
988
|
+
// for its own figure, and the declaration, not the row, is what must
|
|
989
|
+
// vouch for a number.
|
|
990
|
+
const settledBy: Gate[][] = spans.map(() => []);
|
|
991
|
+
for (let i = 0; i < spans.length; i++) {
|
|
992
|
+
for (const g of hits[i]) {
|
|
993
|
+
const known = new Set<string>();
|
|
994
|
+
for (const label of vouchLabels(g, gates))
|
|
995
|
+
for (const n of numericTokens(label)) known.add(n);
|
|
996
|
+
if (!figuresWithin(spans[i], known)) continue;
|
|
997
|
+
if (operandSettled(spans[i], g, gates)) settledBy[i].push(g);
|
|
998
|
+
}
|
|
999
|
+
// No declaration carries the span — undeclared, or operands or
|
|
1000
|
+
// figures the declaration does not state. The strip below removes
|
|
1001
|
+
// the ENTIRE span, so what the span carries has to be settled here
|
|
1002
|
+
// or it is erased before anything reads it.
|
|
1003
|
+
if (settledBy[i].length === 0) return null;
|
|
1004
|
+
}
|
|
987
1005
|
let residual = content;
|
|
988
1006
|
for (const span of spans) residual = residual.split(span).join(" ");
|
|
989
1007
|
const rest = claims(norm(residual));
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1008
|
+
const restRegion =
|
|
1009
|
+
rest.length === 0 ? null : restatedContiguously(haystack, rest);
|
|
1010
|
+
if (rest.length === 0 || restRegion !== null) {
|
|
1011
|
+
// A figure outside every quoted command is prose, and prose settles
|
|
1012
|
+
// against the passage this refusal cites for it — the same region
|
|
1013
|
+
// the tracked path answers with. A figure no cited passage states is
|
|
1014
|
+
// a claim the tree does not make, and where there is no region at
|
|
1015
|
+
// all nothing vouched for the prose: both keep the row.
|
|
1016
|
+
const outside = numericTokens(residual);
|
|
1017
|
+
if (outside.length > 0) {
|
|
1018
|
+
if (restRegion === null) return null;
|
|
1019
|
+
const stated = new Set(
|
|
1020
|
+
numericTokens(haystack.slice(restRegion.start, restRegion.end)),
|
|
1021
|
+
);
|
|
1022
|
+
if (!outside.every((n) => stated.has(n))) return null;
|
|
1023
|
+
}
|
|
1024
|
+
// The refusal rested on the declarations that settled each span,
|
|
1025
|
+
// so it cites exactly those: naming one file for a row resting on
|
|
1026
|
+
// two is not evidence, and naming a declaration that settled
|
|
1027
|
+
// nothing sends the auditor to the wrong line.
|
|
1028
|
+
const cited: string[] = [];
|
|
1029
|
+
for (const s of settledBy)
|
|
1030
|
+
for (const g of s)
|
|
1031
|
+
if (!cited.includes(g.where)) cited.push(g.where);
|
|
994
1032
|
return {
|
|
995
1033
|
reason: "declared_gate",
|
|
996
|
-
where:
|
|
1034
|
+
where: cited.join(", "),
|
|
997
1035
|
matched: safeWhole.slice(0, 120),
|
|
998
1036
|
};
|
|
999
1037
|
}
|
package/src/core/tokenize.ts
CHANGED
|
@@ -171,7 +171,8 @@ export function numericTokens(text: string): string[] {
|
|
|
171
171
|
const lower = text.toLowerCase();
|
|
172
172
|
const out = new Set<string>();
|
|
173
173
|
for (let i = 0; i < lower.length; ) {
|
|
174
|
-
|
|
174
|
+
// A digit anchors the whole run, including any identifier prefix.
|
|
175
|
+
const ext = isDigit(lower.charCodeAt(i)) ? figureExtent(lower, i) : null;
|
|
175
176
|
if (ext === null) {
|
|
176
177
|
i++;
|
|
177
178
|
continue;
|