@open-tomato/rafa 0.52.1 → 0.54.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.
Files changed (40) hide show
  1. package/dist/PROMPT.md +7 -0
  2. package/dist/bundled/agents/loop-implementer.md +7 -1
  3. package/dist/bundled/operators/skills/rafa-stretch-gap-log/SKILL.md +16 -0
  4. package/dist/bundled/operators/skills/rafa-stretch-pit-stop/SKILL.md +14 -8
  5. package/dist/bundled/operators/skills/rafa-stretch-sweep/SKILL.md +4 -2
  6. package/dist/cli.js +4401 -2084
  7. package/dist/config/index.js +2 -2
  8. package/dist/config/shape.d.ts +7 -5
  9. package/dist/config-registry.d.ts +5 -5
  10. package/dist/config-schema-collaborate.d.ts +85 -0
  11. package/dist/config-schema-features.d.ts +2 -2
  12. package/dist/config-schema-hints.d.ts +53 -0
  13. package/dist/config-schema-hub.d.ts +5 -4
  14. package/dist/core/command/shared-flags.d.ts +1 -1
  15. package/dist/core/config/config-schema.d.ts +1 -1
  16. package/dist/core/config/config.d.ts +1 -1
  17. package/dist/core/git/index.d.ts +12 -5
  18. package/dist/core/git/placed-line.d.ts +86 -0
  19. package/dist/effort/session-log-path.d.ts +34 -0
  20. package/dist/effort/store/answered-rows.d.ts +38 -0
  21. package/dist/effort/store/index.js +5 -3
  22. package/dist/effort/store/merge-conflicts.d.ts +8 -4
  23. package/dist/effort/store/merge-rules.d.ts +16 -5
  24. package/dist/effort/store/merge-store.d.ts +14 -3
  25. package/dist/effort/store/origins.d.ts +5 -4
  26. package/dist/effort/store/repository-facts.d.ts +147 -0
  27. package/dist/effort/store/session-row-types.d.ts +6 -1
  28. package/dist/effort/store/sqlite.d.ts +11 -6
  29. package/dist/{index-4dwaxd5r.js → index-8rr1etrx.js} +10 -3
  30. package/dist/{index-nqaqh4zz.js → index-d772zq3m.js} +44 -4
  31. package/dist/{index-m672ptpg.js → index-dj8en7fg.js} +1 -1
  32. package/dist/{index-1tdzcheq.js → index-mkhbaye7.js} +306 -43
  33. package/dist/{index-4wy2nmyt.js → index-waawdjq2.js} +140 -119
  34. package/dist/index.js +1622 -564
  35. package/dist/learning/index.js +112 -53
  36. package/dist/ports/index.d.ts +5 -5
  37. package/dist/ports/learning.d.ts +28 -2
  38. package/dist/{ready-kac4ty0p.js → ready-9e1pyxdh.js} +3 -3
  39. package/dist/utils/shell.d.ts +17 -0
  40. package/package.json +12 -5
@@ -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 * HUNDREDTHS);
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 = hundredths(minConfidence);
22
- return held.filter((each) => each.status === "active" && each.promoted_to === undefined && hundredths(each.confidence) >= floor).sort(byTrust);
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 createHash("sha256").update(JSON.stringify(instincts)).digest("hex");
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
- return blessedRecords(held, options.minConfidence).filter((each) => each.usage_count >= options.after);
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 HUNDREDTHS2 = 100;
49
- var GAP_H = Math.round(GAP * HUNDREDTHS2);
50
- var STEP_H = Math.round(SOURCE_STEP * HUNDREDTHS2);
51
- var MIN_H = Math.round(CONFIDENCE_MIN * HUNDREDTHS2);
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 compareText2(left, right) {
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 byAge(left, right) {
66
- return compareText2(left.created_at, right.created_at) || compareText2(left.id, right.id);
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 hundredths2(right.confidence) - hundredths2(left.confidence) || compareText2(left.id, right.id);
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(byAge), ...[...group.incoming].sort(byAge)];
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 seen = new Set;
88
- let weighted = 0;
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 groupOf = (hash) => {
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
- groupOf(record.action_hash).held.push(record);
206
+ groupOf2(record.action_hash).held.push(record);
149
207
  }
150
208
  for (const record of incoming) {
151
- groupOf(record.action_hash).incoming.push(record);
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) => hundredths2(record.confidence)));
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 - hundredths2(record.confidence) > GAP_H) {
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,
@@ -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} and
68
- * {@link MergeResult} are declared in `./learning.ts` and re-exported
69
- * here under the same names. The learning library declares its own
70
- * six in `packages/rafa-inventory/src/learning/types.ts`, since neither side may import the
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;
@@ -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 six types `packages/rafa/src/ports/index.ts` names for it.
3
+ * declaration of the seven types `packages/rafa/src/ports/index.ts` names for it.
4
4
  *
5
- * The learning library declares the same six in
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-4wy2nmyt.js";
27
+ } from "./index-waawdjq2.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-4dwaxd5r.js";
34
+ } from "./index-8rr1etrx.js";
35
35
  import"./index-2a7nb3an.js";
36
36
  import"./index-jjxnyqvy.js";
37
- import"./index-m672ptpg.js";
37
+ import"./index-dj8en7fg.js";
38
38
  import {
39
39
  messageOf
40
40
  } from "./index-fpgmdmww.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Quoting a word for a POSIX shell.
3
+ *
4
+ * A word reaches a shell from more than one place: a preflight probe
5
+ * names a remote's host, a printed remedy names a branch or a path, and
6
+ * a step list prints the git command a reader can run by hand. Each of
7
+ * those words is read off a checkout or a config, so none is trusted: a
8
+ * quote or a space in it would otherwise end the string around it.
9
+ * {@link shellQuote} is the one quoter they call, so two of them never
10
+ * disagree on how a word is written.
11
+ */
12
+ /**
13
+ * `word` as one shell word: left as it stands when it is plain, so a
14
+ * printed line stays readable, and single-quoted otherwise, each single
15
+ * quote inside it written `'\''`.
16
+ */
17
+ export declare function shellQuote(word: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tomato/rafa",
3
- "version": "0.52.1",
3
+ "version": "0.54.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": {
@@ -33,7 +33,8 @@
33
33
  "type": "module",
34
34
  "workspaces": [
35
35
  "packages/*",
36
- "addons/atlas/*"
36
+ "addons/atlas/*",
37
+ "addons/rafa-d2c"
37
38
  ],
38
39
  "module": "./dist/index.js",
39
40
  "bin": {
@@ -86,6 +87,9 @@
86
87
  "./config-schema-features": {
87
88
  "types": "./dist/config-schema-features.d.ts"
88
89
  },
90
+ "./config-schema-hints": {
91
+ "types": "./dist/config-schema-hints.d.ts"
92
+ },
89
93
  "./config-schema-logger": {
90
94
  "types": "./dist/config-schema-logger.d.ts"
91
95
  },
@@ -95,6 +99,9 @@
95
99
  "./config-schema-checks": {
96
100
  "types": "./dist/config-schema-checks.d.ts"
97
101
  },
102
+ "./config-schema-collaborate": {
103
+ "types": "./dist/config-schema-collaborate.d.ts"
104
+ },
98
105
  "./config-schema-hub": {
99
106
  "types": "./dist/config-schema-hub.d.ts"
100
107
  },
@@ -152,10 +159,10 @@
152
159
  "@open-tomato/rafa-release": "workspace:*",
153
160
  "@open-tomato/rafa-run": "workspace:*",
154
161
  "@open-tomato/typescript-config": "^0.1.0",
155
- "@types/bun": "^1.4.0",
156
- "@types/node": "^26.4.1",
162
+ "@types/bun": "^1.4.4",
163
+ "@types/node": "^26.6.6",
157
164
  "eslint": "^9.39.4",
158
- "turbo": "^2.11.8",
165
+ "turbo": "^2.11.10",
159
166
  "typescript": "^5.9.3"
160
167
  }
161
168
  }