@niwa-labs/rin 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +122 -2
- package/package.json +38 -4
- package/src/admission.ts +73 -0
- package/src/attention.ts +441 -0
- package/src/character.ts +171 -0
- package/src/charter.ts +130 -0
- package/src/cockpit/actions.ts +132 -0
- package/src/cockpit/index.tsx +13 -0
- package/src/cockpit/page.tsx +370 -0
- package/src/cockpit/view.ts +114 -0
- package/src/composition.ts +90 -0
- package/src/index.ts +16 -0
- package/src/plugin.ts +1071 -0
- package/src/presence.ts +57 -0
- package/src/records.ts +546 -0
- package/test/attention.test.ts +265 -0
- package/test/character.test.ts +42 -0
- package/test/charter.test.ts +84 -0
- package/test/cockpit-actions.test.ts +68 -0
- package/test/cockpit-view.test.ts +68 -0
- package/test/composition.test.ts +157 -0
- package/test/plugin.test.ts +988 -0
- package/test/presence.test.ts +38 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Rin's attention without a host: when a decision reaches the owner, what an occasion is, what waits for him.
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_CEILING,
|
|
7
|
+
briefingText,
|
|
8
|
+
ceilingLeft,
|
|
9
|
+
foldAttention,
|
|
10
|
+
inQuietHours,
|
|
11
|
+
insistRefusal,
|
|
12
|
+
pendingAbout,
|
|
13
|
+
noticeOf,
|
|
14
|
+
quietEnds,
|
|
15
|
+
repeatRefusal,
|
|
16
|
+
routeOf,
|
|
17
|
+
type Row,
|
|
18
|
+
} from "../src/attention.ts";
|
|
19
|
+
import type { Decision, Subject } from "../src/records.ts";
|
|
20
|
+
|
|
21
|
+
const HOUR = 3_600_000;
|
|
22
|
+
/** A moment in the local time of the machine, as the quiet hours are read. */
|
|
23
|
+
const local = (day: number, hour: number, minute = 0) => new Date(2026, 10, day, hour, minute).getTime();
|
|
24
|
+
const QUIET = { from: "23:00", to: "08:00" };
|
|
25
|
+
|
|
26
|
+
describe("quiet hours", () => {
|
|
27
|
+
test("hours that cross midnight hold on both sides of it", () => {
|
|
28
|
+
expect(inQuietHours(local(20, 23, 30), QUIET)).toBe(true);
|
|
29
|
+
expect(inQuietHours(local(21, 2), QUIET)).toBe(true);
|
|
30
|
+
expect(inQuietHours(local(21, 7, 59), QUIET)).toBe(true);
|
|
31
|
+
expect(inQuietHours(local(21, 8), QUIET)).toBe(false);
|
|
32
|
+
expect(inQuietHours(local(21, 22, 59), QUIET)).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("hours within one day hold only between their ends", () => {
|
|
36
|
+
const lunch = { from: "13:00", to: "14:00" };
|
|
37
|
+
expect(inQuietHours(local(21, 13, 30), lunch)).toBe(true);
|
|
38
|
+
expect(inQuietHours(local(21, 12, 59), lunch)).toBe(false);
|
|
39
|
+
expect(inQuietHours(local(21, 14), lunch)).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("they end at the next 'to' on either side of midnight", () => {
|
|
43
|
+
expect(quietEnds(local(20, 23, 30), QUIET)).toBe(local(21, 8));
|
|
44
|
+
expect(quietEnds(local(21, 6), QUIET)).toBe(local(21, 8));
|
|
45
|
+
expect(quietEnds(local(21, 9), QUIET)).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("a time of day that is not one is refused", () => {
|
|
49
|
+
expect(() => inQuietHours(local(21, 1), { from: "25:00", to: "08:00" })).toThrow();
|
|
50
|
+
expect(() => inQuietHours(local(21, 1), { from: "7", to: "08:00" })).toThrow();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("the safety ceiling", () => {
|
|
55
|
+
test("counts what was said now within its window only", () => {
|
|
56
|
+
const at = local(21, 12);
|
|
57
|
+
const said = [at - 25 * HOUR, at - 23 * HOUR, at - HOUR];
|
|
58
|
+
expect(ceilingLeft(said, at, { count: 3, windowMs: 24 * HOUR })).toBe(1);
|
|
59
|
+
expect(ceilingLeft(said, at, { count: 2, windowMs: 24 * HOUR })).toBe(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("is data with a default window of a day", () => {
|
|
63
|
+
expect(DEFAULT_CEILING.count).toBeGreaterThan(6);
|
|
64
|
+
expect(DEFAULT_CEILING.windowMs).toBe(24 * HOUR);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("routing a decision", () => {
|
|
69
|
+
const day = local(21, 12);
|
|
70
|
+
const base = { at: day, quiet: QUIET, ceiling: { count: 2, windowMs: 24 * HOUR }, said: [] as number[] };
|
|
71
|
+
|
|
72
|
+
test("silence and a note reach nobody", () => {
|
|
73
|
+
expect(routeOf("silent", base)).toEqual({ kind: "keep" });
|
|
74
|
+
expect(routeOf("note", base)).toEqual({ kind: "keep" });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("the next contact holds until the owner is in touch", () => {
|
|
78
|
+
expect(routeOf("next-contact", base)).toEqual({ kind: "hold", until: "contact", why: "next-contact" });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("now is said, unless it is his quiet hours or the ceiling is reached", () => {
|
|
82
|
+
expect(routeOf("now", base)).toEqual({ kind: "say" });
|
|
83
|
+
expect(routeOf("insist", base)).toEqual({ kind: "say" });
|
|
84
|
+
const night = { ...base, at: local(21, 1) };
|
|
85
|
+
expect(routeOf("now", night)).toEqual({ kind: "hold", until: "quiet-end", why: "quiet-hours", at: local(21, 8) });
|
|
86
|
+
const full = { ...base, said: [day - HOUR, day - 2 * HOUR] };
|
|
87
|
+
expect(routeOf("now", full)).toEqual({ kind: "hold", until: "contact", why: "ceiling" });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/** The rows of a journal, numbered in order. */
|
|
92
|
+
function rows(...given: Array<[string, unknown, number?]>): Row[] {
|
|
93
|
+
return given.map(([type, data, at], index) => ({ type, data, at: at ?? index * 1000, seq: index + 1 }));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const rin = { kind: "niwa" as const, by: "test" };
|
|
97
|
+
const occ = "occ-00000000a1";
|
|
98
|
+
const item = "att-00000000b1";
|
|
99
|
+
const ci: Subject = { kind: "occasion", occasion: occ };
|
|
100
|
+
|
|
101
|
+
describe("occasions", () => {
|
|
102
|
+
test("a key that holds is one occasion: a repeat is counted, not opened again", () => {
|
|
103
|
+
const state = foldAttention(
|
|
104
|
+
rows(
|
|
105
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "CI is red on PR 101", from: rin }],
|
|
106
|
+
["rin.occasion.repeated", { notice: "fixture", occasion: occ, key: "ci:pr-101", text: "CI is red on PR 101 again", from: rin }],
|
|
107
|
+
["rin.occasion.repeated", { notice: "fixture", occasion: occ, key: "ci:pr-101", text: "CI is red on PR 101 again", from: rin }],
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
expect(state.occasions.get(occ)?.count).toBe(3);
|
|
111
|
+
expect(noticeOf(state, { key: "ci:pr-101" })).toEqual({ kind: "repeat", occasion: occ });
|
|
112
|
+
expect(noticeOf(state, { key: "ci:pr-102" })).toEqual({ kind: "open" });
|
|
113
|
+
expect(noticeOf(state, { key: "ci:pr-101", ends: true })).toEqual({ kind: "end", occasion: occ });
|
|
114
|
+
expect(noticeOf(state, { key: "ci:pr-102", ends: true })).toEqual({ kind: "none" });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("once it ended, the same key opens a new occasion", () => {
|
|
118
|
+
const state = foldAttention(
|
|
119
|
+
rows(
|
|
120
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
121
|
+
["rin.occasion.ended", { notice: "fixture", occasion: occ, key: "ci:pr-101", from: rin }],
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
expect(noticeOf(state, { key: "ci:pr-101" })).toEqual({ kind: "open" });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("what she held about an occasion that ended is dropped by the end record alone, not brought up", () => {
|
|
128
|
+
const state = foldAttention(
|
|
129
|
+
rows(
|
|
130
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
131
|
+
["rin.attention.held", { item, subject: ci, text: "PR 101 is red", until: "contact", why: "next-contact" }],
|
|
132
|
+
["rin.occasion.ended", { notice: "fixture", occasion: occ, key: "ci:pr-101", from: rin }],
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
expect(state.items.get(item)?.status).toBe("dropped");
|
|
136
|
+
expect(briefingText(state)).toBe("");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("what is held after its occasion ended is dropped at once", () => {
|
|
140
|
+
const state = foldAttention(
|
|
141
|
+
rows(
|
|
142
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
143
|
+
["rin.occasion.ended", { notice: "fixture", occasion: occ, key: "ci:pr-101", from: rin }],
|
|
144
|
+
["rin.attention.held", { item, subject: ci, text: "PR 101 is red", until: "contact", why: "undelivered" }],
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
expect(state.items.get(item)?.status).toBe("dropped");
|
|
148
|
+
expect(briefingText(state)).toBe("");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("what was on its way when its occasion ended is dropped by an explicit drop", () => {
|
|
152
|
+
const state = foldAttention(
|
|
153
|
+
rows(
|
|
154
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
155
|
+
["rin.attention.sending", { item, subject: ci, text: "PR 101 is red" }],
|
|
156
|
+
["rin.occasion.ended", { notice: "fixture", occasion: occ, key: "ci:pr-101", from: rin }],
|
|
157
|
+
["rin.attention.dropped", { item, occasion: occ }],
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
expect(state.items.get(item)?.status).toBe("dropped");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("raising something again", () => {
|
|
165
|
+
const said = foldAttention(
|
|
166
|
+
rows(
|
|
167
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
168
|
+
["rin.attention.said", { item, subject: ci, text: "PR 101 is red", channel: "telegram.send" }],
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
test("saying again what was said now is refused: it is insisting", () => {
|
|
173
|
+
expect(repeatRefusal(said, ci)).toContain("insist");
|
|
174
|
+
expect(repeatRefusal(foldAttention([]), ci)).toBeUndefined();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const held = ["rin.attention.held", { item, subject: ci, text: "PR 101 is red", until: "contact", why: "next-contact" }] as [string, unknown];
|
|
178
|
+
|
|
179
|
+
test("what only waits was not told yet: a new decision takes its place, and there is nothing to insist on", () => {
|
|
180
|
+
const waiting = foldAttention(rows(held));
|
|
181
|
+
expect(repeatRefusal(waiting, ci)).toBeUndefined();
|
|
182
|
+
expect(pendingAbout(waiting, ci)?.item).toBe(item);
|
|
183
|
+
const rule = "rule-00000000c1";
|
|
184
|
+
expect(insistRefusal(waiting, ci, rule, new Set([rule]))).toContain("not told");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("what was brought up, or is on its way, counts as told, also after he waved it away", () => {
|
|
188
|
+
const rule = "rule-00000000c1";
|
|
189
|
+
const brought = foldAttention(rows(held, ["rin.attention.brought", { items: [item], contact: { kind: "message", message: "msg-000001" } }]));
|
|
190
|
+
expect(repeatRefusal(brought, ci)).toContain("insist");
|
|
191
|
+
expect(insistRefusal(brought, ci, rule, new Set([rule]))).toBeUndefined();
|
|
192
|
+
expect(pendingAbout(brought, ci)).toBeUndefined();
|
|
193
|
+
const dismissed = foldAttention(rows(held, ["rin.attention.brought", { items: [item], contact: { kind: "message", message: "msg-000001" } }], ["rin.attention.dismissed", { item }]));
|
|
194
|
+
expect(repeatRefusal(dismissed, ci)).toContain("insist");
|
|
195
|
+
const sending = foldAttention(rows(["rin.attention.sending", { item, subject: ci, text: "PR 101 is red" }]));
|
|
196
|
+
expect(repeatRefusal(sending, ci)).toContain("insist");
|
|
197
|
+
const unsure = foldAttention(rows(["rin.attention.sending", { item, subject: ci, text: "x" }], ["rin.attention.unsure", { item, subject: ci, text: "x", why: "cut off" }]));
|
|
198
|
+
expect(unsure.items.get(item)?.status).toBe("unsure");
|
|
199
|
+
expect(repeatRefusal(unsure, ci)).toContain("insist");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("what was not sent is not told: held again, it can be said", () => {
|
|
203
|
+
const back = foldAttention(rows(["rin.attention.sending", { item, subject: ci, text: "x" }], held));
|
|
204
|
+
expect(repeatRefusal(back, ci)).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("insisting needs a confirmed rule of the charter and something told before", () => {
|
|
208
|
+
const rule = "rule-00000000c1";
|
|
209
|
+
expect(insistRefusal(said, ci, rule, new Set([rule]))).toBeUndefined();
|
|
210
|
+
expect(insistRefusal(said, ci, undefined, new Set([rule]))).toContain("rule");
|
|
211
|
+
expect(insistRefusal(said, ci, rule, new Set())).toContain("confirmed");
|
|
212
|
+
const other: Subject = { kind: "occasion", occasion: "occ-00000000a2" };
|
|
213
|
+
expect(insistRefusal(said, other, rule, new Set([rule]))).toContain("not told");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("the briefing", () => {
|
|
218
|
+
test("lists what waits for the next contact, with how often its occasion came up", () => {
|
|
219
|
+
const state = foldAttention(
|
|
220
|
+
rows(
|
|
221
|
+
["rin.occasion.opened", { notice: "fixture", occasion: occ, key: "ci:pr-101", kind: "ci", text: "red", from: rin }],
|
|
222
|
+
["rin.occasion.repeated", { notice: "fixture", occasion: occ, key: "ci:pr-101", text: "red", from: rin }],
|
|
223
|
+
["rin.attention.held", { item, subject: ci, text: "PR 101 has been red all night", until: "contact", why: "next-contact" }],
|
|
224
|
+
["rin.attention.held", { item: "att-00000000b2", subject: { kind: "turn", turn: "fact-abcdef" }, text: "The review task is done", until: "quiet-end", why: "quiet-hours" }],
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
expect(briefingText(state)).toBe(["- PR 101 has been red all night (came up 2 times)", "- The review task is done"].join("\n"));
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("what an attach brought up stays in the briefing of that attach", () => {
|
|
231
|
+
const state = foldAttention(
|
|
232
|
+
rows(
|
|
233
|
+
["rin.attention.held", { item, subject: ci, text: "PR 101 is red", until: "contact", why: "next-contact" }],
|
|
234
|
+
["agent.attached", { agent: "rin", session: "claude s1", cwd: "/w" }],
|
|
235
|
+
["rin.attention.brought", { items: [item], contact: { kind: "attach", session: "claude s1" } }],
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
expect(briefingText(state)).toBe("- PR 101 is red");
|
|
239
|
+
const later = foldAttention([
|
|
240
|
+
...rows(
|
|
241
|
+
["rin.attention.held", { item, subject: ci, text: "PR 101 is red", until: "contact", why: "next-contact" }],
|
|
242
|
+
["agent.attached", { agent: "rin", session: "claude s1", cwd: "/w" }],
|
|
243
|
+
["rin.attention.brought", { items: [item], contact: { kind: "attach", session: "claude s1" } }],
|
|
244
|
+
["agent.attached", { agent: "rin", session: "claude s2", cwd: "/w" }],
|
|
245
|
+
),
|
|
246
|
+
]);
|
|
247
|
+
expect(briefingText(later)).toBe("");
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("a stub model decides, the mechanics route", () => {
|
|
252
|
+
/** A model that stays quiet about CI at night, saves task outcomes for later, and speaks up about a stuck agent. */
|
|
253
|
+
const stub = (kind: string): Decision => (kind === "agent" ? "now" : kind === "task" ? "next-contact" : "silent");
|
|
254
|
+
|
|
255
|
+
test("each decision lands where the owner's hours and the ceiling allow", () => {
|
|
256
|
+
const ctx = { quiet: QUIET, ceiling: { count: 1, windowMs: 24 * HOUR }, said: [] as number[] };
|
|
257
|
+
const day = local(21, 15);
|
|
258
|
+
const outcomes = ["ci", "task", "agent", "agent"].map((kind) => {
|
|
259
|
+
const route = routeOf(stub(kind), { ...ctx, at: day });
|
|
260
|
+
if (route.kind === "say") ctx.said.push(day);
|
|
261
|
+
return route.kind === "hold" ? `${kind}:hold:${route.why}` : `${kind}:${route.kind}`;
|
|
262
|
+
});
|
|
263
|
+
expect(outcomes).toEqual(["ci:keep", "task:hold:next-contact", "agent:say", "agent:hold:ceiling"]);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The core of Rin's character is the owner's text with a version, and her definition follows her options.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { AgentDefinition } from "@niwa-labs/agent/records";
|
|
6
|
+
|
|
7
|
+
import { CORE, HANDS, RIN_AGENT, coreDigest, rinDefinition } from "../src/character.ts";
|
|
8
|
+
|
|
9
|
+
/** The words of each version of the core. A changed text with the same version fails here: give it a new one. */
|
|
10
|
+
const VERSIONS: Record<number, string> = { 1: "45ac4b7d9e0acb12" };
|
|
11
|
+
|
|
12
|
+
test("the core text is pinned to its version", () => {
|
|
13
|
+
expect(coreDigest(CORE.text)).toBe(VERSIONS[CORE.version]!);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("her definition is one the agents module serves, with only niwa's tools", () => {
|
|
17
|
+
const definition = AgentDefinition.parse(rinDefinition({ harness: "claude" }));
|
|
18
|
+
expect(definition.name).toBe(RIN_AGENT);
|
|
19
|
+
expect(definition.character).toBe(CORE.text);
|
|
20
|
+
expect(definition.tools).toBe("niwa-only");
|
|
21
|
+
expect(definition.hands).toEqual([...HANDS]);
|
|
22
|
+
expect(() => rinDefinition({})).toThrow("exactly one");
|
|
23
|
+
expect(() => rinDefinition({ harness: "claude", role: "assistant" })).toThrow("exactly one");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("she changes herself by code only when the owner turned it on, and only plugins of her own group", () => {
|
|
27
|
+
const plain = rinDefinition({ role: "assistant" });
|
|
28
|
+
expect(plain.hands?.some((hand) => hand.startsWith("plugin.install"))).toBe(false);
|
|
29
|
+
expect(plain.hands).not.toContain("rin.self.install");
|
|
30
|
+
expect(plain.prompt).not.toContain("rin.self.install");
|
|
31
|
+
const selfEdit = rinDefinition({ role: "assistant", selfEdit: "ask" });
|
|
32
|
+
// Her hand is her own action, which asks the owner; the host's install, even scoped to her group, asks nobody.
|
|
33
|
+
expect(selfEdit.hands).toContain("rin.self.install");
|
|
34
|
+
expect(selfEdit.hands?.some((hand) => hand.startsWith("plugin.install"))).toBe(false);
|
|
35
|
+
expect(selfEdit.prompt).toContain("rin.self.install");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("her prompt answers when a conversation may make a promise and what of his memory may leave", () => {
|
|
39
|
+
const prompt = rinDefinition({ harness: "claude" }).prompt;
|
|
40
|
+
expect(prompt).toContain("A promise on his behalf, or one that sets him a deadline, exists only when he worded it himself or confirmed");
|
|
41
|
+
expect(prompt).toContain("Notes about the owner himself do not leave without his answer");
|
|
42
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Rin's charter without a host: corrections that repeat ask for a rule, and only the owner's word makes one.
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import type { Row } from "../src/attention.ts";
|
|
6
|
+
import { charterText, dueFor, foldCharter, ruledRules } from "../src/charter.ts";
|
|
7
|
+
|
|
8
|
+
const owner = { kind: "owner" as const };
|
|
9
|
+
const niwa = { kind: "niwa" as const, by: "rin" };
|
|
10
|
+
|
|
11
|
+
function rows(...given: Array<[string, unknown]>): Row[] {
|
|
12
|
+
return given.map(([type, data], index) => ({ type, data, at: (index + 1) * 1000, seq: index + 1 }));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const corrected = (n: number, about: string, what: string) => [
|
|
16
|
+
"rin.corrected",
|
|
17
|
+
{ correction: `cor-00000000${n.toString(16).padStart(2, "0")}`, about, what, by: owner },
|
|
18
|
+
] as [string, unknown];
|
|
19
|
+
|
|
20
|
+
describe("consolidation", () => {
|
|
21
|
+
test("one correction is not yet a pattern; a second one about the same thing is", () => {
|
|
22
|
+
const one = foldCharter(rows(corrected(1, "attention.ci", "Do not wake me for CI on drafts")));
|
|
23
|
+
expect(dueFor(one, "attention.ci", 2)).toBeUndefined();
|
|
24
|
+
const two = foldCharter(
|
|
25
|
+
rows(corrected(1, "attention.ci", "Do not wake me for CI on drafts"), corrected(2, "tone", "Shorter"), corrected(3, "attention.ci", "Draft PRs can wait")),
|
|
26
|
+
);
|
|
27
|
+
expect(dueFor(two, "attention.ci", 2)).toEqual(["cor-0000000001", "cor-0000000003"]);
|
|
28
|
+
expect(dueFor(two, "tone", 2)).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("corrections already put to her do not count again; the ones after them start a new count", () => {
|
|
32
|
+
const before = rows(
|
|
33
|
+
corrected(1, "attention.ci", "a"),
|
|
34
|
+
corrected(2, "attention.ci", "b"),
|
|
35
|
+
["rin.charter.due", { about: "attention.ci", corrections: ["cor-0000000001", "cor-0000000002"] }],
|
|
36
|
+
corrected(3, "attention.ci", "c"),
|
|
37
|
+
);
|
|
38
|
+
expect(dueFor(foldCharter(before), "attention.ci", 2)).toBeUndefined();
|
|
39
|
+
const [fourth] = rows(corrected(4, "attention.ci", "d"));
|
|
40
|
+
const after = [...before, { ...fourth!, seq: before.length + 1, at: 9000 }];
|
|
41
|
+
expect(dueFor(foldCharter(after), "attention.ci", 2)).toEqual(["cor-0000000003", "cor-0000000004"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("while a rule about it waits for the owner, nothing more is due", () => {
|
|
45
|
+
const state = foldCharter(
|
|
46
|
+
rows(
|
|
47
|
+
corrected(1, "attention.ci", "a"),
|
|
48
|
+
["rin.charter.proposed", { rule: "rule-0000000001", about: "attention.ci", text: "CI on drafts waits for the morning", corrections: ["cor-0000000001"], by: niwa }],
|
|
49
|
+
corrected(2, "attention.ci", "b"),
|
|
50
|
+
corrected(3, "attention.ci", "c"),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
expect(dueFor(state, "attention.ci", 2)).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("the charter", () => {
|
|
58
|
+
const proposal = (rule: string, text: string) =>
|
|
59
|
+
["rin.charter.proposed", { rule, about: "attention.ci", text, corrections: [], by: niwa }] as [string, unknown];
|
|
60
|
+
|
|
61
|
+
test("holds only the rules the owner confirmed and has not retired", () => {
|
|
62
|
+
const state = foldCharter(
|
|
63
|
+
rows(
|
|
64
|
+
proposal("rule-0000000001", "CI on drafts waits for the morning"),
|
|
65
|
+
proposal("rule-0000000002", "Never mention CI"),
|
|
66
|
+
proposal("rule-0000000003", "Say a red main branch at once"),
|
|
67
|
+
["rin.charter.ruled", { rule: "rule-0000000001", about: "attention.ci", by: owner }],
|
|
68
|
+
["rin.charter.declined", { rule: "rule-0000000002", about: "attention.ci", why: "declined" }],
|
|
69
|
+
["rin.charter.ruled", { rule: "rule-0000000003", about: "attention.ci", by: owner }],
|
|
70
|
+
["rin.charter.retired", { rule: "rule-0000000003", about: "attention.ci" }],
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
expect(ruledRules(state).map((rule) => rule.rule)).toEqual(["rule-0000000001"]);
|
|
74
|
+
expect(state.rules.get("rule-0000000002")?.status).toBe("declined");
|
|
75
|
+
expect(charterText(ruledRules(state))).toBe("- rule-0000000001 (attention.ci): CI on drafts waits for the morning");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("a rule's corrections are marked covered by it", () => {
|
|
79
|
+
const state = foldCharter(
|
|
80
|
+
rows(corrected(1, "tone", "Shorter"), ["rin.charter.proposed", { rule: "rule-0000000001", about: "tone", text: "Three lines on Telegram", corrections: ["cor-0000000001"], by: niwa }]),
|
|
81
|
+
);
|
|
82
|
+
expect(state.corrections[0]?.rule).toBe("rule-0000000001");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The copies of the actions Rin's page keeps read what the host answers and send what it takes, and the plugin
|
|
2
|
+
// offers the page to the cockpit.
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
import { agents } from "@niwa-labs/agent";
|
|
7
|
+
import { agentList, agentTell } from "@niwa-labs/agent/records";
|
|
8
|
+
import { commitmentList } from "@niwa-labs/commitments/records";
|
|
9
|
+
import { actionName } from "@niwa-labs/core";
|
|
10
|
+
import { memory } from "@niwa-labs/memory";
|
|
11
|
+
import { requests } from "@niwa-labs/requests";
|
|
12
|
+
import { requestOpen } from "@niwa-labs/requests/records";
|
|
13
|
+
import { memoryTop } from "@niwa-labs/memory/records";
|
|
14
|
+
import { plugin } from "@niwa-labs/plugin";
|
|
15
|
+
import { createNiwa, messages, sessions, tempHome, timers, unreadable, unsendable } from "@niwa-labs/testing";
|
|
16
|
+
import { RunFinished, RunStarted } from "@niwa-labs/workflow/records";
|
|
17
|
+
|
|
18
|
+
import { agentsAction, attentionAction, charterAction, commitmentsAction, conversationAction, dismissAction, memoryAction, openQuestionsAction, retireAction, selfHistoryAction, tellAction } from "../src/cockpit/actions.ts";
|
|
19
|
+
import { rinAttention, rinCharter, rinCharterRetire, rinConversation, rinDismiss, rinSelfHistory } from "../src/records.ts";
|
|
20
|
+
import { rinPlugin } from "../src/plugin.ts";
|
|
21
|
+
|
|
22
|
+
const pairs = [
|
|
23
|
+
[attentionAction, rinAttention],
|
|
24
|
+
[dismissAction, rinDismiss],
|
|
25
|
+
[charterAction, rinCharter],
|
|
26
|
+
[retireAction, rinCharterRetire],
|
|
27
|
+
[conversationAction, rinConversation],
|
|
28
|
+
[tellAction, agentTell],
|
|
29
|
+
[selfHistoryAction, rinSelfHistory],
|
|
30
|
+
[agentsAction, agentList],
|
|
31
|
+
[commitmentsAction, commitmentList],
|
|
32
|
+
[memoryAction, memoryTop],
|
|
33
|
+
[openQuestionsAction, requestOpen],
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
for (const [copy, real] of pairs) {
|
|
37
|
+
test(`the page reads and calls ${String(real.name)} as the host serves it`, () => {
|
|
38
|
+
expect(String(copy.name)).toBe(String(real.name));
|
|
39
|
+
expect(unsendable(copy.input, real.input as never)).toEqual([]);
|
|
40
|
+
expect(unreadable(copy.output, real.output as never)).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cleanups: Array<() => Promise<void>> = [];
|
|
45
|
+
afterEach(async () => {
|
|
46
|
+
for (const cleanup of cleanups.splice(0).reverse()) await cleanup();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("the plugin offers her page to the cockpit", async () => {
|
|
50
|
+
const home = await tempHome();
|
|
51
|
+
cleanups.push(() => home.cleanup());
|
|
52
|
+
const niwa = createNiwa({ home: home.path });
|
|
53
|
+
cleanups.push(() => niwa.close());
|
|
54
|
+
const bind = () => undefined;
|
|
55
|
+
niwa.use(
|
|
56
|
+
agents(),
|
|
57
|
+
sessions({ harnesses: [] }),
|
|
58
|
+
timers([]),
|
|
59
|
+
plugin("workflow", (api) => api.declare(RunStarted, RunFinished)),
|
|
60
|
+
messages({ bind }),
|
|
61
|
+
requests({ bind }),
|
|
62
|
+
memory({ bind }),
|
|
63
|
+
rinPlugin({ bind, harness: "claude" }),
|
|
64
|
+
);
|
|
65
|
+
await niwa.serve();
|
|
66
|
+
const catalog = (await niwa.call(actionName("niwa.cockpit.catalog"), {})) as { modules: Array<{ id: string; package: string }> };
|
|
67
|
+
expect(catalog.modules.map((one) => one.id)).toContain("rin");
|
|
68
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// What Rin's page shows, without React: what waits for the owner, what she told him, her charter, the tile.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { attentionGroups, charterRows, conversationRows, ledAgents, tileText, whyText } from "../src/cockpit/view.ts";
|
|
6
|
+
import type { AttentionView, RuleView } from "../src/cockpit/actions.ts";
|
|
7
|
+
|
|
8
|
+
const item = (n: number, status: AttentionView["status"], extra: Partial<AttentionView> = {}): AttentionView => ({
|
|
9
|
+
item: `att-00000000${n.toString().padStart(2, "0")}`,
|
|
10
|
+
text: `item ${n}`,
|
|
11
|
+
status,
|
|
12
|
+
at: n * 1000,
|
|
13
|
+
...extra,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("what waits comes first, then what she told him, then what is closed, newest first in each", () => {
|
|
17
|
+
const groups = attentionGroups([item(1, "said"), item(2, "held", { why: "next-contact" }), item(3, "dropped"), item(4, "sending"), item(5, "held", { why: "quiet-hours" }), item(6, "brought"), item(7, "dismissed")]);
|
|
18
|
+
expect(groups.waiting.map((one) => one.text)).toEqual(["item 5", "item 4", "item 2"]);
|
|
19
|
+
expect(groups.told.map((one) => one.text)).toEqual(["item 6", "item 1"]);
|
|
20
|
+
expect(groups.closed.map((one) => one.text)).toEqual(["item 7", "item 3"]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("each item says why it waits and how often its occasion came up", () => {
|
|
24
|
+
expect(whyText(item(1, "held", { why: "next-contact" }))).toBe("При следующем разговоре");
|
|
25
|
+
expect(whyText(item(1, "held", { why: "quiet-hours" }))).toBe("После тихих часов");
|
|
26
|
+
expect(whyText(item(1, "held", { why: "ceiling", count: 3 }))).toBe("Достигнут лимит уведомлений · повторов: 3");
|
|
27
|
+
expect(whyText(item(1, "held", { why: "undelivered" }))).toBe("Доставка не удалась");
|
|
28
|
+
expect(whyText(item(1, "sending"))).toBe("Отправляется");
|
|
29
|
+
expect(whyText(item(1, "said", { count: 1 }))).toBe("Доставлено");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("the tile counts what waits for him", () => {
|
|
33
|
+
expect(tileText([])).toBe("Нет отложенных сообщений");
|
|
34
|
+
expect(tileText([item(1, "held"), item(2, "said")])).toBe("Одно отложенное сообщение");
|
|
35
|
+
expect(tileText([item(1, "held"), item(2, "sending"), item(3, "held")])).toBe("Отложенные сообщения: 3");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("the charter shows what waits for his word first, then the rules, then the rest", () => {
|
|
39
|
+
const rule = (n: number, status: RuleView["status"]): RuleView => ({ rule: `rule-00000000${n}0`, about: "tone", text: `rule ${n}`, status, corrections: Array.from({ length: n }, (_, i) => `cor-000000000${i}`) });
|
|
40
|
+
const rows = charterRows([rule(1, "ruled"), rule(2, "declined"), rule(3, "proposed"), rule(4, "retired")]);
|
|
41
|
+
expect(rows.map((row) => [row.text, row.label, row.corrections])).toEqual([
|
|
42
|
+
["rule 3", "Ждёт подтверждения", 3],
|
|
43
|
+
["rule 1", "Действует", 1],
|
|
44
|
+
["rule 2", "Отклонено", 2],
|
|
45
|
+
["rule 4", "Снято", 4],
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("the agents she leads are every agent but herself", () => {
|
|
50
|
+
const agents = [
|
|
51
|
+
{ name: "rin", status: "asleep" as const, source: "config" as const },
|
|
52
|
+
{ name: "lead", status: "working" as const, source: "runtime" as const },
|
|
53
|
+
];
|
|
54
|
+
expect(ledAgents(agents).map((one) => one.name)).toEqual(["lead"]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("the conversation reads oldest first, with where each of his messages stands", () => {
|
|
58
|
+
const rows = conversationRows([
|
|
59
|
+
{ id: "msg-000002", from: "rin", text: "Done: two comments", at: 3000 },
|
|
60
|
+
{ id: "msg-000001", from: "owner", text: "Review the migration", at: 1000, delivery: "delivered" },
|
|
61
|
+
{ id: "msg-000003", from: "owner", text: "And the docs", at: 4000, delivery: "waiting" },
|
|
62
|
+
]);
|
|
63
|
+
expect(rows.map((row) => [row.who, row.text, row.state])).toEqual([
|
|
64
|
+
["Вы", "Review the migration", "Доставлено Рин"],
|
|
65
|
+
["Рин", "Done: two comments", undefined],
|
|
66
|
+
["Вы", "And the docs", "Ждёт обработки"],
|
|
67
|
+
]);
|
|
68
|
+
});
|