+ {/* Held at the foot of Settings' scroller, so Save stays in reach however tall the page. */}
+
{view.status}
diff --git a/apps/web/src/kin/settings/KinSectionsPage.tsx b/apps/web/src/kin/settings/KinSectionsPage.tsx
index f31e2aa263b38..50dba88e50131 100644
--- a/apps/web/src/kin/settings/KinSectionsPage.tsx
+++ b/apps/web/src/kin/settings/KinSectionsPage.tsx
@@ -4,10 +4,15 @@ import { kinNewLeadTarget } from "../KinNewLeadButton";
import { useKinHost } from "../useKinHost";
import { KinSectionsSettings } from "./KinSectionSwitch";
import { KinSettingsPage } from "./KinSettingsLayout";
+import type { KinSettingsTarget } from "./kinSettingsTarget";
-/** Settings › Sections: which parts of Kin the company uses, and Clients' own name. */
-export function KinSectionsPage() {
- const target = kinNewLeadTarget(useKinHost());
+/**
+ * Settings › Sections: which parts of Kin the company uses, and Clients' own name. Settings passes
+ * its company, kept while the host is offline; the old address finds the connected one.
+ */
+export function KinSectionsPage(props: { readonly target?: KinSettingsTarget }) {
+ const connected = kinNewLeadTarget(useKinHost());
+ const target = props.target ?? connected;
return target === null ? null : (
diff --git a/packages/client-runtime/src/kin/kinRules.test.ts b/packages/client-runtime/src/kin/kinRules.test.ts
index 42bcd33c09d42..a990a069afe6b 100644
--- a/packages/client-runtime/src/kin/kinRules.test.ts
+++ b/packages/client-runtime/src/kin/kinRules.test.ts
@@ -74,9 +74,9 @@ function harness(read: KinRulesRead) {
editor,
sent,
answer: (next: (input: KinMemorySaveRulesInput) => unknown) => answers.push(next),
- type: (text: string) => editor.type(kinRulesView(read, edits, NOW).held, text),
+ type: (text: string) => editor.type(kinRulesView(read, edits, { now: NOW }).held, text),
save: (confirmed?: boolean) => editor.save(read, edits, confirmed),
- view: () => kinRulesView(read, edits, NOW),
+ view: () => kinRulesView(read, edits, { now: NOW }),
edits: () => edits,
refreshes: () => refreshes,
};
@@ -84,13 +84,20 @@ function harness(read: KinRulesRead) {
describe("kinRulesView", () => {
it("says when the rules last changed and when Kin last checked the repository", () => {
- const view = kinRulesView(OPENED, KIN_RULES_NO_EDITS, NOW);
+ const view = kinRulesView(OPENED, KIN_RULES_NO_EDITS, { now: NOW });
expect(view.facts).toEqual([
expect.stringMatching(/^Changed today .+ by Mira Holt$/),
"Kin checked your memory repository 4 min ago",
]);
expect(view.empty).toBe(false);
- expect(kinRulesView(rules(" \n", null), KIN_RULES_NO_EDITS, NOW)).toMatchObject({
+ // The host signs the owner's own change with their display name; a name it can't match stays.
+ expect(
+ kinRulesView(OPENED, KIN_RULES_NO_EDITS, { now: NOW, me: "mira holt" }).facts[0],
+ ).toMatch(/^Changed today .+ by you$/);
+ expect(
+ kinRulesView(OPENED, KIN_RULES_NO_EDITS, { now: NOW, me: "Oren Vale" }).facts[0],
+ ).toMatch(/by Mira Holt$/);
+ expect(kinRulesView(rules(" \n", null), KIN_RULES_NO_EDITS, { now: NOW })).toMatchObject({
empty: true,
facts: ["Kin checked your memory repository 4 min ago"],
});
@@ -114,7 +121,7 @@ describe("createKinRulesEditor", () => {
h.type("Invented rule: quote in dollars.\n");
// The page's read moves on; the owner's text and the revision it began from stay.
const later = rules("Invented rule: newer.\n", "c".repeat(40));
- expect(kinRulesView(later, h.edits(), NOW)).toMatchObject({
+ expect(kinRulesView(later, h.edits(), { now: NOW })).toMatchObject({
text: "Invented rule: quote in dollars.\n",
dirty: true,
status: KIN_RULES_COPY.unsaved,
@@ -254,6 +261,7 @@ describe("createKinRulesEditor", () => {
h.answer(() => rules("", "f".repeat(40)));
expect(await h.save(true)).toBe("sent");
expect(h.sent).toEqual([{ orgId, text: "", revision: OPENED.revision }]);
+ expect(h.view().status).toBe(KIN_RULES_COPY.savedEmpty);
});
it("saves the first rules over the revision a missing file reads at, without a question", async () => {
diff --git a/packages/client-runtime/src/kin/kinRules.ts b/packages/client-runtime/src/kin/kinRules.ts
index 4680c639fd0fa..621a0ab0b59db 100644
--- a/packages/client-runtime/src/kin/kinRules.ts
+++ b/packages/client-runtime/src/kin/kinRules.ts
@@ -35,6 +35,8 @@ export const KIN_RULES_COPY = {
saving: "Saving…",
unsaved: "Unsaved changes",
saved: "Saved. Your agents follow these from their next turn.",
+ /** After withdrawing every rule: there are no "these" any more. */
+ savedEmpty: "Saved. Your agents follow no standing rules from their next turn.",
changedBy: (when: string, by: string | null) =>
by === null ? `Changed ${when}` : `Changed ${when} by ${by}`,
checked: (ago: string) => `Kin checked your memory repository ${ago}`,
@@ -231,11 +233,22 @@ const parsed = (iso: string | null) => {
return Number.isNaN(at.getTime()) ? null : at;
};
+/**
+ * Who changed the rules, as the reader says it: "you" when the host's name for the change is the
+ * signed-in person's own (the host writes the person's display name); the name when it can't tell.
+ */
+function changedByOf(rules: KinMemoryRules, me: string | null): string | null {
+ const by = rules.changedBy?.trim() || null;
+ if (by === null || me === null) return by;
+ return by.toLocaleLowerCase() === me.trim().toLocaleLowerCase() ? "you" : by;
+}
+
/** "Changed today 9:41 by Asha Rao", or null when the host doesn't know. */
-function changedLine(rules: KinMemoryRules, now: Date): string | null {
+function changedLine(rules: KinMemoryRules, now: Date, me: string | null): string | null {
const at = parsed(rules.changedAt);
- const by = rules.changedBy?.trim() || null;
- return at === null ? null : KIN_RULES_COPY.changedBy(changedWhen(at, now), by);
+ return at === null
+ ? null
+ : KIN_RULES_COPY.changedBy(changedWhen(at, now), changedByOf(rules, me));
}
export interface KinRulesView {
@@ -284,8 +297,15 @@ const unseen = (refusal: KinMemoryRulesTooLarge): KinMemoryRules => ({
export function kinRulesView(
read: KinRulesRead,
edits: KinRulesEdits,
- now: Date = kinNow(),
+ options: {
+ /** The screen's minute clock, so "just now" moves on while the page sits. */
+ readonly now?: Date;
+ /** The signed-in person's display name, so their own change reads "you"; null when unknown. */
+ readonly me?: string | null;
+ } = {},
): KinRulesView {
+ const now = options.now ?? kinNow();
+ const me = options.me ?? null;
const latest =
edits.saved !== null && edits.saved.over === read
? edits.saved.rules
@@ -305,20 +325,17 @@ export function kinRulesView(
const over = dirty ? kinRulesBytesOver(text, max) : 0;
const synced = parsed(held.lastSyncedAt);
const facts = [
- changedLine(held, now),
+ changedLine(held, now, me),
synced === null ? null : KIN_RULES_COPY.checked(kinAgo(synced.getTime(), now.getTime())),
].filter((line) => line !== null);
const changedAt = changed === null ? null : parsed(changed.changedAt);
- const changedBy = changed?.changedBy?.trim() || null;
+ const changedBy = changed === null ? null : changedByOf(changed, me);
const canSave = dirty && !edits.saving && over === 0;
// Measured against the rules a save would replace: the current ones once a save found them changed.
const withdraws = dirty && isBlank(text) && !isBlank((changed ?? draft?.from ?? held).text);
+ const by = changedBy === "you" ? "You" : (changedBy ?? "Someone");
const who =
- changedAt === null
- ? changedBy === null
- ? "Someone changed them"
- : `${changedBy} changed them`
- : `${changedBy ?? "Someone"} changed them ${changedWhen(changedAt, now)}`;
+ changedAt === null ? `${by} changed them` : `${by} changed them ${changedWhen(changedAt, now)}`;
return {
held,
text,
@@ -331,7 +348,9 @@ export function kinRulesView(
: dirty
? KIN_RULES_COPY.unsaved
: edits.said
- ? KIN_RULES_COPY.saved
+ ? isBlank(held.text)
+ ? KIN_RULES_COPY.savedEmpty
+ : KIN_RULES_COPY.saved
: null,
tooLarge: over > 0 ? KIN_RULES_COPY.tooLarge(kib(over), kib(max)) : null,
canSave,