Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const fs = require("node:fs");
const path = require("node:path");

// Our forks ship as tarballs in apps/mobile/deps. A pnpm patch on one is a second source of
// truth that the next tarball silently drops, so changes go to the fork (apps/mobile/deps/README.md).
// Our forks ship as tarballs in apps/mobile/deps and apps/web/deps. A pnpm patch on one is a
// second source of truth that the next tarball silently drops, so changes go to the fork (see
// the README beside each tarball).
const FORK_APPS = ["apps/mobile", "apps/web"];

function forkTarballPatches(patchedDependencies) {
const manifestPath = path.join(__dirname, "apps/mobile/package.json");
// Release staging installs a partial workspace without the mobile app.
if (!patchedDependencies || !fs.existsSync(manifestPath)) return [];
const { dependencies = {} } = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
const forks = Object.keys(dependencies).filter((name) =>
String(dependencies[name]).startsWith("file:deps/"),
);
if (!patchedDependencies) return [];
const forks = FORK_APPS.flatMap((app) => {
const manifestPath = path.join(__dirname, app, "package.json");
// Release staging installs a partial workspace without every app.
if (!fs.existsSync(manifestPath)) return [];
const { dependencies = {} } = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
return Object.keys(dependencies).filter((name) =>
String(dependencies[name]).startsWith("file:deps/"),
);
});
return Object.keys(patchedDependencies).filter((key) =>
forks.some((name) => key === name || key.startsWith(`${name}@`)),
);
Expand All @@ -23,7 +29,7 @@ module.exports = {
if (forkPatches.length > 0) {
throw new Error(
`pnpm-workspace.yaml patches ${forkPatches.join(", ")}, which ships as a fork tarball in ` +
"apps/mobile/deps. Change the fork and replace the tarball instead (apps/mobile/deps/README.md).",
"an app's deps directory. Change the fork and replace the tarball instead (deps/README.md).",
);
}
// Windows installs need Linux x64 glibc binaries because WSL shares node_modules.
Expand Down
7 changes: 4 additions & 3 deletions apps/mobile/src/components/ComposerContextSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { T, useGT, Var } from "gt-react-native";
import { T, useGT, useMessages, Var } from "gt-react-native";

import { Button } from "./ui/Button";
import * as Dialog from "./ui/Dialog";
Expand Down Expand Up @@ -102,6 +102,7 @@ function DeliveredProjectKnowledge(props: {
readonly sent: { readonly threadId: ThreadId; readonly messageId: MessageId };
}) {
const gt = useGT();
const m = useMessages();
const config = useAtomValue(
serverEnvironment.configValueAtom(props.record.knowledge.environmentId),
);
Expand Down Expand Up @@ -141,15 +142,15 @@ function DeliveredProjectKnowledge(props: {
<Text className="text-sm text-foreground-muted">
<T>The copy T3 delivered with this message. It does not show whether the agent used it.</T>
</Text>
{deliveredKnowledgeNotes(snapshot).map((note) => (
{deliveredKnowledgeNotes(snapshot, m).map((note) => (
<Text key={note} className="text-sm text-foreground-muted">
{note}
</Text>
))}
{snapshot.omission ? (
<Text className="text-sm text-foreground">
{gt("Not sent: {reason}", {
reason: KNOWLEDGE_DELIVERY_OMISSION_LABEL[snapshot.omission.reason],
reason: m(KNOWLEDGE_DELIVERY_OMISSION_LABEL[snapshot.omission.reason]),
})}
</Text>
) : snapshot.item.contentRemoved ? null : (
Expand Down
55 changes: 36 additions & 19 deletions apps/mobile/src/components/ProjectKnowledgeDraftFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import { ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import type { KnowledgeSelection } from "@t3tools/contracts";
import { T, useGT } from "gt-react-native";

import {
MAX_KNOWLEDGE_SELECTIONS,
Expand All @@ -13,9 +14,6 @@ import { Button } from "./ui/Button";

type SelectionState = ReturnType<typeof knowledgeSelectionState>;

const changedLabel = (selection: KnowledgeSelection) =>
selection.kind === "fact" ? "Fact changed since you selected it" : "Source changed";

/**
* Draft selection, kept apart from inspection: pressing a fact or message reads it, and only this
* control changes what the draft will reference.
Expand All @@ -26,21 +24,24 @@ export function SelectForDraftControl(props: {
readonly onToggle: (selection: KnowledgeSelection) => void;
readonly onRefresh: (selection: KnowledgeSelection) => void;
}) {
const gt = useGT();
return (
<View className="flex-row flex-wrap items-center gap-2">
<Button
label={props.state === "unselected" ? "Select for draft" : "Selected for draft"}
label={props.state === "unselected" ? gt("Select for draft") : gt("Selected for draft")}
icon={props.state === "unselected" ? "plus" : "checkmark.circle.fill"}
tone={props.state === "unselected" ? "secondary" : "primary"}
onPress={() => props.onToggle(props.current)}
/>
{props.state === "changed" ? (
<>
<AppText className="text-xs text-warning-foreground">
{changedLabel(props.current)}
{props.current.kind === "fact"
? gt("Fact changed since you selected it")
: gt("Source changed")}
</AppText>
<Button
label="Use current version"
label={gt("Use current version")}
tone="text"
onPress={() => props.onRefresh(props.current)}
/>
Expand Down Expand Up @@ -69,6 +70,7 @@ export function ProjectKnowledgeDraftFooter(props: {
readonly onAttach: () => void;
readonly onRemoveAttached: () => void;
}) {
const gt = useGT();
const insets = useSafeAreaInsets();
const [expanded, setExpanded] = useState(false);
const changed = props.selections.filter(
Expand All @@ -84,35 +86,43 @@ export function ProjectKnowledgeDraftFooter(props: {
{props.mismatched ? (
<View className="gap-1">
<AppText className="text-sm">
Attached evidence belongs to another project or environment.
<T>Attached evidence belongs to another project or environment.</T>
</AppText>
<Button
label="Remove mismatched reference"
label={gt("Remove mismatched reference")}
tone="secondary"
onPress={props.onRemoveAttached}
/>
</View>
) : props.attachedLabel ? (
<View className="flex-row flex-wrap items-center gap-2">
<AppText className="flex-1 text-sm">
{props.attachedLabel} is attached to this draft.
{gt("{label} is attached to this draft.", { label: props.attachedLabel })}
</AppText>
<Button label="Remove from draft" tone="text" onPress={props.onRemoveAttached} />
<Button label={gt("Remove from draft")} tone="text" onPress={props.onRemoveAttached} />
</View>
) : props.detached ? (
<AppText accessibilityRole="alert" className="text-sm">
The selection changed, so the earlier reference was removed from the draft. Attach to add
the new selection.
<T>
The selection changed, so the earlier reference was removed from the draft. Attach to
add the new selection.
</T>
</AppText>
) : null}
<View className="flex-row flex-wrap items-center gap-2">
<AppText className="flex-1 text-xs text-foreground-muted">
{props.selections.length} selected · up to {MAX_KNOWLEDGE_SELECTIONS}
{changed > 0 ? ` · ${changed} changed since selected` : ""}
{gt(
"{count} selected · up to {maximum}{changed, plural, =0 {} other { · {changed} changed since selected}}",
{
count: props.selections.length,
maximum: MAX_KNOWLEDGE_SELECTIONS,
changed,
},
)}
</AppText>
{props.selections.length > 0 ? (
<Button
label={expanded ? "Hide selection" : "Review selection"}
label={expanded ? gt("Hide selection") : gt("Review selection")}
tone="text"
onPress={() => setExpanded((value) => !value)}
/>
Expand All @@ -136,21 +146,28 @@ export function ProjectKnowledgeDraftFooter(props: {
{item.current &&
knowledgeSelectionState([item.selection], item.current) === "changed" ? (
<Button
label="Use current version"
label={gt("Use current version")}
tone="text"
onPress={() => props.onRefresh(item.current!)}
/>
) : null}
<Button label="Remove" tone="text" onPress={() => props.onToggle(item.selection)} />
<Button
label={gt("Remove", { $context: "remove a project knowledge selection" })}
tone="text"
onPress={() => props.onToggle(item.selection)}
/>
</View>
))}
<AppText className="text-xs text-foreground-muted">
The draft keeps references and revision numbers. Current evidence is reloaded when sent.
<T>
The draft keeps references and revision numbers. Current evidence is reloaded when
sent.
</T>
</AppText>
</ScrollView>
) : null}
<Button
label="Attach to draft"
label={gt("Attach to draft")}
tone="primary"
disabled={props.disabled || props.busy || props.selections.length === 0 || props.mismatched}
loading={props.busy}
Expand Down
59 changes: 40 additions & 19 deletions apps/mobile/src/components/ProjectKnowledgeEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { uuidv4 } from "../lib/uuid";
import { useCallback, useEffect, useRef, useState } from "react";
import { T, useGT, useMessages } from "gt-react-native";
import { useIsFocused } from "@react-navigation/native";
import { ScrollView, View } from "react-native";
import { useAtomValue } from "@effect/atom-react";
Expand Down Expand Up @@ -150,6 +151,8 @@ function ProjectKnowledgeSheet(
readonly onClose: () => void;
},
) {
const gt = useGT();
const m = useMessages();
const scope = { environmentId: props.environmentId, projectId: props.projectId };
const draft = useComposerDraft(props.draftKey);
const attached = draft.context?.records.find(
Expand Down Expand Up @@ -258,9 +261,9 @@ function ProjectKnowledgeSheet(
if (busy) return;
if (!editorDirty.current) return leave();
Dialog.confirm({
title: "Discard fact changes?",
message: "Your unsaved fact changes will be lost.",
confirmText: "Discard",
title: gt("Discard fact changes?"),
message: gt("Your unsaved fact changes will be lost."),
confirmText: gt("Discard", { $context: "discard unsaved project fact changes" }),
destructive: true,
onConfirm: leave,
});
Expand Down Expand Up @@ -361,7 +364,9 @@ function ProjectKnowledgeSheet(
result.value.context.projectId !== scope.projectId
) {
setError(
"The prepared evidence belongs to a different environment or project. Refresh and try again.",
gt(
"The prepared evidence belongs to a different environment or project. Refresh and try again.",
),
);
return;
}
Expand All @@ -374,7 +379,7 @@ function ProjectKnowledgeSheet(
);
}
if (!insertComposerDraftContext(props.draftKey, reference)) {
setError("Remove a context item before attaching project memory.");
setError(gt("Remove a context item before attaching project memory."));
return;
}
props.onClose();
Expand Down Expand Up @@ -412,23 +417,26 @@ function ProjectKnowledgeSheet(
label:
known?.label ??
(selection.kind === "fact"
? `Fact ${selection.factId.slice(0, 8)} · revision ${selection.revision}`
: `Message ${selection.messageId.slice(0, 8)}`),
? gt("Fact {factId} · revision {revision}", {
factId: selection.factId.slice(0, 8),
revision: selection.revision,
})
: gt("Message {messageId}", { messageId: selection.messageId.slice(0, 8) })),
};
});
const selectionState = (current: KnowledgeSelection) =>
knowledgeSelectionState(selections, current);

const title =
page.kind === "list"
? "Project memory"
? gt("Project memory")
: page.kind === "fact"
? "Fact"
? gt("Fact", { $context: "project fact" })
: page.kind === "source"
? "Source message"
? gt("Source message")
: page.kind === "remember"
? "New fact"
: factEditorTitle(page.mode);
? gt("New fact")
: factEditorTitle(page.mode, m);

return (
<Sheet
Expand All @@ -448,7 +456,12 @@ function ProjectKnowledgeSheet(
>
{stack.length > 1 ? (
<View className="flex-row">
<Button label="Back" icon="chevron.left" tone="text" onPress={pop} />
<Button
label={gt("Back", { $context: "project memory navigation" })}
icon="chevron.left"
tone="text"
onPress={pop}
/>
</View>
) : null}
{error ? (
Expand Down Expand Up @@ -508,10 +521,11 @@ function ProjectKnowledgeSheet(
}}
onForget={() =>
Dialog.confirm({
title: "Forget this fact permanently?",
message:
title: gt("Forget this fact permanently?"),
message: gt(
"Its content, history and every copy sent to agents are removed and cannot be restored. If the fact changed rather than became wrong, supersede it instead.",
confirmText: "Forget",
),
confirmText: gt("Forget", { $context: "permanently forget a project fact" }),
destructive: true,
onConfirm: () =>
void apply({ action: "forget", ...factMutation(inspectedFact) }),
Expand All @@ -528,7 +542,9 @@ function ProjectKnowledgeSheet(
{detail.error}
</AppText>
) : (
<AppText>Reading fact…</AppText>
<AppText>
<T>Reading fact…</T>
</AppText>
)
) : null}
{page.kind === "source" ? (
Expand Down Expand Up @@ -563,7 +579,9 @@ function ProjectKnowledgeSheet(
{sourceQuery.error}
</AppText>
) : (
<AppText>Reading message…</AppText>
<AppText>
<T>Reading message…</T>
</AppText>
)
) : null}
{page.kind === "editor" ? (
Expand Down Expand Up @@ -613,6 +631,7 @@ function RememberEditor(props: {
readonly onCancel: () => void;
readonly onDirtyChange: (dirty: boolean) => void;
}) {
const gt = useGT();
const mode: FactEditorMode =
props.source.state === "available"
? {
Expand All @@ -624,7 +643,9 @@ function RememberEditor(props: {
kind: "create",
content: "",
sources: [{ kind: "user" }],
note: "That message can no longer be read, so the fact will be saved as your own assertion.",
note: gt(
"That message can no longer be read, so the fact will be saved as your own assertion.",
),
};
return (
<ProjectKnowledgeFactEditor
Expand Down
Loading
Loading