@open-tomato/rafa 0.52.0 → 0.53.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/dist/bundled/operators/skills/rafa-stretch-pit-stop/SKILL.md +14 -8
- package/dist/bundled/operators/skills/rafa-stretch-sweep/SKILL.md +4 -2
- package/dist/cli.js +2552 -1407
- package/dist/config/index.js +2 -2
- package/dist/core/config/config-schema.d.ts +1 -1
- package/dist/effort/session-log-path.d.ts +34 -0
- package/dist/effort/store/answered-rows.d.ts +38 -0
- package/dist/effort/store/index.js +3 -3
- package/dist/effort/store/merge-conflicts.d.ts +8 -4
- package/dist/effort/store/merge-rules.d.ts +16 -5
- package/dist/effort/store/session-row-types.d.ts +6 -1
- package/dist/effort/store/sqlite.d.ts +4 -1
- package/dist/{index-nqaqh4zz.js → index-78zcdjf5.js} +1 -1
- package/dist/{index-hyp1sraj.js → index-anvmm83x.js} +108 -42
- package/dist/{index-m672ptpg.js → index-dj8en7fg.js} +1 -1
- package/dist/{index-mbxgc1zv.js → index-kqz8x8g9.js} +3 -3
- package/dist/{index-91cag9fr.js → index-rkrsdes6.js} +2 -2
- package/dist/index.js +1166 -462
- package/dist/learning/index.js +112 -53
- package/dist/ports/index.d.ts +5 -5
- package/dist/ports/learning.d.ts +28 -2
- package/dist/{ready-3ccr65a2.js → ready-cnzcnv4d.js} +3 -3
- package/package.json +5 -14
package/dist/learning/index.js
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/rafa-inventory/src/learning/bless.ts
|
|
3
|
+
import { createHash as createHash2 } from "crypto";
|
|
4
|
+
|
|
5
|
+
// packages/rafa-inventory/src/learning/identity.ts
|
|
3
6
|
import { createHash } from "crypto";
|
|
7
|
+
var GAP = 0.1;
|
|
8
|
+
var SOURCE_STEP = 0.05;
|
|
9
|
+
var CONFIDENCE_MIN = 0.3;
|
|
10
|
+
var CONFIDENCE_MAX = 0.9;
|
|
11
|
+
var WHITESPACE_RUN = /\s+/g;
|
|
12
|
+
function actionHash(action) {
|
|
13
|
+
return createHash("sha256").update(action.trim().toLowerCase()).digest("hex");
|
|
14
|
+
}
|
|
15
|
+
function triggerKey(trigger) {
|
|
16
|
+
return trigger.trim().toLowerCase().replace(WHITESPACE_RUN, " ");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// packages/rafa-inventory/src/learning/pool.ts
|
|
4
20
|
var HUNDREDTHS = 100;
|
|
21
|
+
var STEP_H = Math.round(SOURCE_STEP * HUNDREDTHS);
|
|
22
|
+
var MIN_H = Math.round(CONFIDENCE_MIN * HUNDREDTHS);
|
|
23
|
+
var MAX_H = Math.round(CONFIDENCE_MAX * HUNDREDTHS);
|
|
24
|
+
function sourcesOf(record) {
|
|
25
|
+
return record.sources !== undefined && record.sources.length > 0 ? [...new Set(record.sources)] : [record.id];
|
|
26
|
+
}
|
|
27
|
+
function pooledConfidence(ordered) {
|
|
28
|
+
const seen = new Set;
|
|
29
|
+
let weighted = 0;
|
|
30
|
+
for (const member of ordered) {
|
|
31
|
+
const own = sourcesOf(member);
|
|
32
|
+
const fresh = own.filter((source) => !seen.has(source));
|
|
33
|
+
const base = Math.round(member.confidence * HUNDREDTHS) - STEP_H * (own.length - 1);
|
|
34
|
+
weighted += base * fresh.length;
|
|
35
|
+
for (const source of fresh) {
|
|
36
|
+
seen.add(source);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const sources = [...seen].sort();
|
|
40
|
+
const stepped = Math.round(weighted / sources.length + STEP_H * (sources.length - 1));
|
|
41
|
+
const confidence = Math.min(MAX_H, Math.max(MIN_H, stepped)) / HUNDREDTHS;
|
|
42
|
+
return { sources, confidence };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// packages/rafa-inventory/src/learning/groups.ts
|
|
46
|
+
var HUNDREDTHS2 = 100;
|
|
5
47
|
function hundredths(confidence) {
|
|
6
|
-
return Math.round(confidence *
|
|
48
|
+
return Math.round(confidence * HUNDREDTHS2);
|
|
7
49
|
}
|
|
8
50
|
function compareText(left, right) {
|
|
9
51
|
if (left < right) {
|
|
@@ -14,46 +56,78 @@ function compareText(left, right) {
|
|
|
14
56
|
}
|
|
15
57
|
return 0;
|
|
16
58
|
}
|
|
59
|
+
function byAge(left, right) {
|
|
60
|
+
return compareText(left.created_at, right.created_at) || compareText(left.id, right.id);
|
|
61
|
+
}
|
|
17
62
|
function byTrust(left, right) {
|
|
18
63
|
return hundredths(right.confidence) - hundredths(left.confidence) || right.usage_count - left.usage_count || compareText(left.id, right.id);
|
|
19
64
|
}
|
|
65
|
+
function byGroupTrust(left, right) {
|
|
66
|
+
return hundredths(right.confidence) - hundredths(left.confidence) || right.sources.length - left.sources.length || compareText(left.named.id, right.named.id);
|
|
67
|
+
}
|
|
68
|
+
function groupOf(hash, records) {
|
|
69
|
+
const { sources, confidence } = pooledConfidence([...records].sort(byAge));
|
|
70
|
+
const members = [...records].sort(byTrust);
|
|
71
|
+
return { action_hash: hash, members, sources, confidence, named: members[0] };
|
|
72
|
+
}
|
|
73
|
+
function sameActionGroups(held) {
|
|
74
|
+
const byAction = new Map;
|
|
75
|
+
for (const record of held) {
|
|
76
|
+
if (record.status === "flagged") {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const found = byAction.get(record.action_hash);
|
|
80
|
+
if (found === undefined) {
|
|
81
|
+
byAction.set(record.action_hash, [record]);
|
|
82
|
+
} else {
|
|
83
|
+
found.push(record);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return [...byAction].map(([hash, records]) => groupOf(hash, records)).sort(byGroupTrust);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// packages/rafa-inventory/src/learning/bless.ts
|
|
90
|
+
var HUNDREDTHS3 = 100;
|
|
91
|
+
function hundredths2(confidence) {
|
|
92
|
+
return Math.round(confidence * HUNDREDTHS3);
|
|
93
|
+
}
|
|
94
|
+
function compareText2(left, right) {
|
|
95
|
+
if (left < right) {
|
|
96
|
+
return -1;
|
|
97
|
+
}
|
|
98
|
+
if (left > right) {
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
function byTrust2(left, right) {
|
|
104
|
+
return hundredths2(right.confidence) - hundredths2(left.confidence) || right.usage_count - left.usage_count || compareText2(left.id, right.id);
|
|
105
|
+
}
|
|
106
|
+
function isUsable(record) {
|
|
107
|
+
return record.status === "active" && record.promoted_to === undefined;
|
|
108
|
+
}
|
|
20
109
|
function blessedRecords(held, minConfidence) {
|
|
21
|
-
const floor =
|
|
22
|
-
return held.filter((each) => each
|
|
110
|
+
const floor = hundredths2(minConfidence);
|
|
111
|
+
return held.filter((each) => isUsable(each) && hundredths2(each.confidence) >= floor).sort(byTrust2);
|
|
23
112
|
}
|
|
24
113
|
function versionOf(instincts) {
|
|
25
|
-
return
|
|
114
|
+
return createHash2("sha256").update(JSON.stringify(instincts)).digest("hex");
|
|
26
115
|
}
|
|
27
116
|
function bless(held, options) {
|
|
28
117
|
const instincts = blessedRecords(held, options.minConfidence);
|
|
29
118
|
return { version: versionOf(instincts), instincts };
|
|
30
119
|
}
|
|
31
120
|
function promotable(held, options) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// packages/rafa-inventory/src/learning/identity.ts
|
|
35
|
-
import { createHash as createHash2 } from "crypto";
|
|
36
|
-
var GAP = 0.1;
|
|
37
|
-
var SOURCE_STEP = 0.05;
|
|
38
|
-
var CONFIDENCE_MIN = 0.3;
|
|
39
|
-
var CONFIDENCE_MAX = 0.9;
|
|
40
|
-
var WHITESPACE_RUN = /\s+/g;
|
|
41
|
-
function actionHash(action) {
|
|
42
|
-
return createHash2("sha256").update(action.trim().toLowerCase()).digest("hex");
|
|
43
|
-
}
|
|
44
|
-
function triggerKey(trigger) {
|
|
45
|
-
return trigger.trim().toLowerCase().replace(WHITESPACE_RUN, " ");
|
|
121
|
+
const floor = hundredths2(options.minConfidence);
|
|
122
|
+
return sameActionGroups(held.filter(isUsable)).filter((group) => group.sources.length >= options.after && hundredths2(group.confidence) >= floor).map((group) => group.named);
|
|
46
123
|
}
|
|
47
124
|
// packages/rafa-inventory/src/learning/merge.ts
|
|
48
|
-
var
|
|
49
|
-
var GAP_H = Math.round(GAP *
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var MAX_H = Math.round(CONFIDENCE_MAX * HUNDREDTHS2);
|
|
53
|
-
function hundredths2(confidence) {
|
|
54
|
-
return Math.round(confidence * HUNDREDTHS2);
|
|
125
|
+
var HUNDREDTHS4 = 100;
|
|
126
|
+
var GAP_H = Math.round(GAP * HUNDREDTHS4);
|
|
127
|
+
function hundredths3(confidence) {
|
|
128
|
+
return Math.round(confidence * HUNDREDTHS4);
|
|
55
129
|
}
|
|
56
|
-
function
|
|
130
|
+
function compareText3(left, right) {
|
|
57
131
|
if (left < right) {
|
|
58
132
|
return -1;
|
|
59
133
|
}
|
|
@@ -62,14 +136,11 @@ function compareText2(left, right) {
|
|
|
62
136
|
}
|
|
63
137
|
return 0;
|
|
64
138
|
}
|
|
65
|
-
function
|
|
66
|
-
return
|
|
139
|
+
function byAge2(left, right) {
|
|
140
|
+
return compareText3(left.created_at, right.created_at) || compareText3(left.id, right.id);
|
|
67
141
|
}
|
|
68
142
|
function byConfidence(left, right) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
function sourcesOf(record) {
|
|
72
|
-
return record.sources !== undefined && record.sources.length > 0 ? [...new Set(record.sources)] : [record.id];
|
|
143
|
+
return hundredths3(right.confidence) - hundredths3(left.confidence) || compareText3(left.id, right.id);
|
|
73
144
|
}
|
|
74
145
|
function withSource(record, sourceId) {
|
|
75
146
|
const sources = [...new Set([...record.sources ?? [], sourceId])].sort();
|
|
@@ -80,25 +151,12 @@ function firstOptional(ordered, key) {
|
|
|
80
151
|
return found === undefined ? {} : { [key]: found[key] };
|
|
81
152
|
}
|
|
82
153
|
function collapse(group) {
|
|
83
|
-
const ordered = [...[...group.held].sort(
|
|
154
|
+
const ordered = [...[...group.held].sort(byAge2), ...[...group.incoming].sort(byAge2)];
|
|
84
155
|
if (ordered.length === 1) {
|
|
85
156
|
return ordered[0];
|
|
86
157
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
for (const member of ordered) {
|
|
90
|
-
const own = sourcesOf(member);
|
|
91
|
-
const fresh = own.filter((source) => !seen.has(source));
|
|
92
|
-
const base = hundredths2(member.confidence) - STEP_H * (own.length - 1);
|
|
93
|
-
weighted += base * fresh.length;
|
|
94
|
-
for (const source of fresh) {
|
|
95
|
-
seen.add(source);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const sources = [...seen].sort();
|
|
99
|
-
const stepped = Math.round(weighted / sources.length + STEP_H * (sources.length - 1));
|
|
100
|
-
const confidence = Math.min(MAX_H, Math.max(MIN_H, stepped)) / HUNDREDTHS2;
|
|
101
|
-
const byAgeAll = [...ordered].sort(byAge);
|
|
158
|
+
const { sources, confidence } = pooledConfidence(ordered);
|
|
159
|
+
const byAgeAll = [...ordered].sort(byAge2);
|
|
102
160
|
const lead = byAgeAll[0];
|
|
103
161
|
const rest = {};
|
|
104
162
|
for (const [key, value] of Object.entries(lead)) {
|
|
@@ -135,7 +193,7 @@ function withStatus(record, status) {
|
|
|
135
193
|
}
|
|
136
194
|
function groupByAction(held, incoming) {
|
|
137
195
|
const groups = new Map;
|
|
138
|
-
const
|
|
196
|
+
const groupOf2 = (hash) => {
|
|
139
197
|
const found = groups.get(hash);
|
|
140
198
|
if (found !== undefined) {
|
|
141
199
|
return found;
|
|
@@ -145,10 +203,10 @@ function groupByAction(held, incoming) {
|
|
|
145
203
|
return made;
|
|
146
204
|
};
|
|
147
205
|
for (const record of held) {
|
|
148
|
-
|
|
206
|
+
groupOf2(record.action_hash).held.push(record);
|
|
149
207
|
}
|
|
150
208
|
for (const record of incoming) {
|
|
151
|
-
|
|
209
|
+
groupOf2(record.action_hash).incoming.push(record);
|
|
152
210
|
}
|
|
153
211
|
return groups;
|
|
154
212
|
}
|
|
@@ -164,11 +222,11 @@ function settleOne(hash, group, held, now) {
|
|
|
164
222
|
return { produced: [record], discarded: [], rules: new Map([[hash, "same-action"]]) };
|
|
165
223
|
}
|
|
166
224
|
function settleMany(collapsed, held, now) {
|
|
167
|
-
const leaderH = Math.max(...[...collapsed.values()].map((record) =>
|
|
225
|
+
const leaderH = Math.max(...[...collapsed.values()].map((record) => hundredths3(record.confidence)));
|
|
168
226
|
const kept = new Map;
|
|
169
227
|
const discarded = [];
|
|
170
228
|
for (const [hash, record] of collapsed) {
|
|
171
|
-
if (leaderH -
|
|
229
|
+
if (leaderH - hundredths3(record.confidence) > GAP_H) {
|
|
172
230
|
discarded.push(record);
|
|
173
231
|
} else {
|
|
174
232
|
kept.set(hash, record);
|
|
@@ -222,6 +280,7 @@ function merge(held, payload, now) {
|
|
|
222
280
|
}
|
|
223
281
|
export {
|
|
224
282
|
triggerKey,
|
|
283
|
+
sameActionGroups,
|
|
225
284
|
promotable,
|
|
226
285
|
merge,
|
|
227
286
|
bless,
|
package/dist/ports/index.d.ts
CHANGED
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
* - {@link Learning}: `distributed-learning-library.md`, "rafa's
|
|
65
65
|
* Learning port", with the records it passes taken from that spec's
|
|
66
66
|
* package shape. {@link InstinctRecord}, {@link SyncPayload},
|
|
67
|
-
* {@link BlessedBundle}, {@link MergeRule}, {@link MergeDecision}
|
|
68
|
-
* {@link MergeResult} are declared in
|
|
69
|
-
* here under the same names. The
|
|
70
|
-
*
|
|
67
|
+
* {@link BlessedBundle}, {@link MergeRule}, {@link MergeDecision},
|
|
68
|
+
* {@link MergeResult} and {@link SameActionGroup} are declared in
|
|
69
|
+
* `./learning.ts` and re-exported here under the same names. The
|
|
70
|
+
* learning library declares its own seven in `packages/rafa-inventory/src/learning/types.ts`, since neither side may import the
|
|
71
71
|
* other, and `src/tests/learning-contract.test.ts` holds each pair
|
|
72
72
|
* mutually assignable.
|
|
73
73
|
* - {@link Output}: open-tomato's `packages/shared/cli-core`, the
|
|
@@ -118,7 +118,7 @@ import type { LogLevel } from './log-level.js';
|
|
|
118
118
|
import type { SpecReviewReading } from './spec-review.js';
|
|
119
119
|
import type { MergeResult as StoreMergeResult } from '../effort/store/merge-store.js';
|
|
120
120
|
export type { LogLevel } from './log-level.js';
|
|
121
|
-
export type { BlessedBundle, InstinctRecord, MergeDecision, MergeResult, MergeRule, SyncPayload, } from './learning.js';
|
|
121
|
+
export type { BlessedBundle, InstinctRecord, MergeDecision, MergeResult, MergeRule, SameActionGroup, SyncPayload, } from './learning.js';
|
|
122
122
|
export type { AppendResult, CommitEffortRow, EffortKeyProjections, EffortRow, EffortRowByKind, EffortRowKind, EffortStore as Store, SessionEffortRow, SessionMode, } from '../effort/store/types.js';
|
|
123
123
|
/** The version of the {@link Tracker} port this entry declares. */
|
|
124
124
|
export type TrackerPortVersion = 1;
|
package/dist/ports/learning.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The records the Learning port passes, and the answers it gives: core's
|
|
3
|
-
* declaration of the
|
|
3
|
+
* declaration of the seven types `packages/rafa/src/ports/index.ts` names for it.
|
|
4
4
|
*
|
|
5
|
-
* The learning library declares the same
|
|
5
|
+
* The learning library declares the same seven in
|
|
6
6
|
* `packages/rafa-inventory/src/learning/types.ts` and keeps them there. That
|
|
7
7
|
* folder imports nothing outside itself, and core imports nothing above it,
|
|
8
8
|
* so neither side can take the other's declaration: each declares its own,
|
|
@@ -100,3 +100,29 @@ export interface MergeResult {
|
|
|
100
100
|
/** The records a higher-confidence action displaced; none is deleted. */
|
|
101
101
|
discarded: InstinctRecord[];
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Every unflagged held record taking one action, across triggers: what
|
|
105
|
+
* the library's `sameActionGroups` answers, derived from the held set and
|
|
106
|
+
* never stored.
|
|
107
|
+
*/
|
|
108
|
+
export interface SameActionGroup {
|
|
109
|
+
/** The `action_hash` every member shares. */
|
|
110
|
+
action_hash: string;
|
|
111
|
+
/**
|
|
112
|
+
* The group's records, `flagged` ones left out, by confidence, then
|
|
113
|
+
* `usage_count`, both highest first, then `id`.
|
|
114
|
+
*/
|
|
115
|
+
members: InstinctRecord[];
|
|
116
|
+
/**
|
|
117
|
+
* The union of the members' sources, in code-unit order; a member
|
|
118
|
+
* naming none counts as its own `id`.
|
|
119
|
+
*/
|
|
120
|
+
sources: string[];
|
|
121
|
+
/**
|
|
122
|
+
* The members' pooled confidence, by `merge`'s same-action
|
|
123
|
+
* arithmetic, at two decimals: three sources at 0.5 read 0.6.
|
|
124
|
+
*/
|
|
125
|
+
confidence: number;
|
|
126
|
+
/** The record the group is named by: the first of `members`. */
|
|
127
|
+
named: InstinctRecord;
|
|
128
|
+
}
|
|
@@ -24,17 +24,17 @@ import {
|
|
|
24
24
|
requireCompleteSpec,
|
|
25
25
|
requireTrustedBoardAuthor,
|
|
26
26
|
typeOfLabels
|
|
27
|
-
} from "./index-
|
|
27
|
+
} from "./index-kqz8x8g9.js";
|
|
28
28
|
import"./index-n2r3wf2z.js";
|
|
29
29
|
import {
|
|
30
30
|
CommandExit,
|
|
31
31
|
createGitRunner,
|
|
32
32
|
createLinePrompter,
|
|
33
33
|
lazyPrompter
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-rkrsdes6.js";
|
|
35
35
|
import"./index-2a7nb3an.js";
|
|
36
36
|
import"./index-jjxnyqvy.js";
|
|
37
|
-
import"./index-
|
|
37
|
+
import"./index-dj8en7fg.js";
|
|
38
38
|
import {
|
|
39
39
|
messageOf
|
|
40
40
|
} from "./index-fpgmdmww.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tomato/rafa",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "Alpha. Runs a plan through the ralph loop: one Claude Code session per task, one commit per task, then a pull request and a CI wait.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -141,30 +141,21 @@
|
|
|
141
141
|
"device:check": "bash scripts/device/check.sh"
|
|
142
142
|
},
|
|
143
143
|
"devDependencies": {
|
|
144
|
-
"@eslint/js": "^9.39.4",
|
|
145
|
-
"@eslint/markdown": "^8.0.3",
|
|
146
144
|
"@open-tomato/define-config": "0.5.0",
|
|
145
|
+
"@open-tomato/eslint-config": "^0.1.0",
|
|
146
|
+
"@open-tomato/eslint-plugin": "^0.1.0",
|
|
147
147
|
"@open-tomato/rafa-board": "workspace:*",
|
|
148
148
|
"@open-tomato/rafa-core": "workspace:*",
|
|
149
149
|
"@open-tomato/rafa-effort": "workspace:*",
|
|
150
|
-
"@open-tomato/rafa-eslint-config": "workspace:*",
|
|
151
150
|
"@open-tomato/rafa-inventory": "workspace:*",
|
|
152
151
|
"@open-tomato/rafa-pr": "workspace:*",
|
|
153
152
|
"@open-tomato/rafa-release": "workspace:*",
|
|
154
153
|
"@open-tomato/rafa-run": "workspace:*",
|
|
155
|
-
"@open-tomato/
|
|
156
|
-
"@stylistic/eslint-plugin": "^5.10.0",
|
|
154
|
+
"@open-tomato/typescript-config": "^0.1.0",
|
|
157
155
|
"@types/bun": "^1.4.0",
|
|
158
156
|
"@types/node": "^26.4.1",
|
|
159
|
-
"@typescript-eslint/parser": "^8.69.0",
|
|
160
157
|
"eslint": "^9.39.4",
|
|
161
|
-
"eslint-import-resolver-typescript": "^4.4.4",
|
|
162
|
-
"eslint-plugin-import": "^2.32.0",
|
|
163
|
-
"eslint-plugin-jsonc": "^3.4.2",
|
|
164
|
-
"globals": "^17.12.0",
|
|
165
|
-
"jsonc-eslint-parser": "^3.1.0",
|
|
166
158
|
"turbo": "^2.11.8",
|
|
167
|
-
"typescript": "^5.9.3"
|
|
168
|
-
"typescript-eslint": "^8.69.0"
|
|
159
|
+
"typescript": "^5.9.3"
|
|
169
160
|
}
|
|
170
161
|
}
|