paseo-office 0.2.4 → 0.2.6
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/client/activity-panel.tsx +21 -1
- package/client/host-switches.tsx +24 -0
- package/client/office-surface.tsx +108 -8
- package/client/timeline-card.tsx +446 -0
- package/client/timeline-open.ts +7 -0
- package/client/vault-card.tsx +316 -0
- package/docs/office.md +38 -0
- package/index.server.ts +105 -2
- package/package.json +1 -1
- package/server/paths.ts +10 -0
- package/server/timeline.ts +218 -0
- package/server/vault.ts +168 -0
- package/shared/contracts.ts +39 -0
- package/shared/settings.ts +4 -1
- package/shared/timeline.ts +177 -0
- package/shared/vault.ts +127 -0
package/shared/vault.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { coach } from "./upstream/prompt-coach.js";
|
|
3
|
+
|
|
4
|
+
/** The most characters of a message the vault keeps, of messages per conversation, and of conversations. */
|
|
5
|
+
export const VAULT_TEXT_MAX = 2000;
|
|
6
|
+
export const VAULT_MESSAGES_MAX = 300;
|
|
7
|
+
export const VAULT_TALKS_MAX = 200;
|
|
8
|
+
/** The most hits a search answers with: the newest. */
|
|
9
|
+
export const VAULT_HITS_MAX = 40;
|
|
10
|
+
|
|
11
|
+
export const VaultMessageSchema = z.object({
|
|
12
|
+
/** Epoch ms. */
|
|
13
|
+
at: z.number(),
|
|
14
|
+
role: z.enum(["user", "assistant"]),
|
|
15
|
+
text: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export type VaultMessage = z.output<typeof VaultMessageSchema>;
|
|
18
|
+
|
|
19
|
+
export const VaultHitSchema = z.object({
|
|
20
|
+
agentId: z.string(),
|
|
21
|
+
name: z.string(),
|
|
22
|
+
team: z.string(),
|
|
23
|
+
at: z.number(),
|
|
24
|
+
role: z.enum(["user", "assistant"]),
|
|
25
|
+
/** The words around the first match, on one line. */
|
|
26
|
+
snippet: z.string(),
|
|
27
|
+
});
|
|
28
|
+
export type VaultHit = z.output<typeof VaultHitSchema>;
|
|
29
|
+
|
|
30
|
+
export const VaultTalkSchema = z.object({
|
|
31
|
+
agentId: z.string(),
|
|
32
|
+
name: z.string(),
|
|
33
|
+
team: z.string(),
|
|
34
|
+
messages: z.array(VaultMessageSchema),
|
|
35
|
+
});
|
|
36
|
+
export type VaultTalk = z.output<typeof VaultTalkSchema>;
|
|
37
|
+
|
|
38
|
+
/** The words of a search: lower case, none empty. Every one of them has to be in a message. */
|
|
39
|
+
export function searchWords(query: string): string[] {
|
|
40
|
+
return query
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.split(/\s+/)
|
|
43
|
+
.filter((word) => word !== "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const SNIPPET_BEFORE = 50;
|
|
47
|
+
const SNIPPET_MAX = 160;
|
|
48
|
+
|
|
49
|
+
/** The text around its first match of `words`, on one line; null when a word is missing. */
|
|
50
|
+
export function snippetOf(text: string, words: readonly string[]): string | null {
|
|
51
|
+
const lower = text.toLowerCase();
|
|
52
|
+
if (words.length === 0 || !words.every((word) => lower.includes(word))) return null;
|
|
53
|
+
const at = Math.min(...words.map((word) => lower.indexOf(word)));
|
|
54
|
+
const start = Math.max(0, at - SNIPPET_BEFORE);
|
|
55
|
+
const cut = text
|
|
56
|
+
.slice(start, start + SNIPPET_MAX)
|
|
57
|
+
.replace(/\s+/g, " ")
|
|
58
|
+
.trim();
|
|
59
|
+
return `${start > 0 ? "…" : ""}${cut}${start + SNIPPET_MAX < text.length ? "…" : ""}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The prompt helper's rules a sent prompt can break; a photo's rule needs the draft, not the text. */
|
|
63
|
+
export const REPORT_RULES = ["tooShort", "vague", "dangling", "multi"] as const;
|
|
64
|
+
export type ReportRule = (typeof REPORT_RULES)[number];
|
|
65
|
+
|
|
66
|
+
export const RULE_TEXT: Readonly<Record<ReportRule, { title: string; advice: string }>> = {
|
|
67
|
+
tooShort: {
|
|
68
|
+
title: "Too short to act on",
|
|
69
|
+
advice: "Say what result you want the session to produce.",
|
|
70
|
+
},
|
|
71
|
+
vague: { title: "No way to tell when it is done", advice: "Add what done looks like." },
|
|
72
|
+
dangling: {
|
|
73
|
+
title: "Points at something it does not name",
|
|
74
|
+
advice: "Name the file, the section or the message you mean.",
|
|
75
|
+
},
|
|
76
|
+
multi: { title: "Several tasks in one message", advice: "Number the tasks, or send them apart." },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const RuleCountSchema = z.object({
|
|
80
|
+
rule: z.enum(REPORT_RULES),
|
|
81
|
+
count: z.number(),
|
|
82
|
+
/** Up to three of the prompts, cut to a line. */
|
|
83
|
+
examples: z.array(z.string()),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const PromptReportSchema = z.object({
|
|
87
|
+
/** The prompts read, and those no rule had anything to say about. */
|
|
88
|
+
total: z.number(),
|
|
89
|
+
clean: z.number(),
|
|
90
|
+
rules: z.array(RuleCountSchema),
|
|
91
|
+
});
|
|
92
|
+
export type PromptReport = z.output<typeof PromptReportSchema>;
|
|
93
|
+
|
|
94
|
+
const EXAMPLE_MAX = 90;
|
|
95
|
+
const EXAMPLES = 3;
|
|
96
|
+
|
|
97
|
+
function oneLine(text: string): string {
|
|
98
|
+
const line = text.replace(/\s+/g, " ").trim();
|
|
99
|
+
return line.length > EXAMPLE_MAX ? `${line.slice(0, EXAMPLE_MAX - 1)}…` : line;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The prompts against the prompt helper's rules: how many each rule speaks to, with examples.
|
|
104
|
+
* The helper's own code decides, word lists and all; no model reads anything.
|
|
105
|
+
*/
|
|
106
|
+
export function promptReport(prompts: readonly string[]): PromptReport {
|
|
107
|
+
const found = new Map<ReportRule, { count: number; examples: string[] }>();
|
|
108
|
+
let clean = 0;
|
|
109
|
+
for (const text of prompts) {
|
|
110
|
+
const rules = new Set<ReportRule>();
|
|
111
|
+
for (const hint of coach({ text, photos: 0, quoted: false })) {
|
|
112
|
+
if (hint.id !== "photoBare") rules.add(hint.id);
|
|
113
|
+
}
|
|
114
|
+
if (rules.size === 0) clean += 1;
|
|
115
|
+
for (const rule of rules) {
|
|
116
|
+
const entry = found.get(rule) ?? { count: 0, examples: [] };
|
|
117
|
+
entry.count += 1;
|
|
118
|
+
if (entry.examples.length < EXAMPLES) entry.examples.push(oneLine(text));
|
|
119
|
+
found.set(rule, entry);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const rules = REPORT_RULES.flatMap((rule) => {
|
|
123
|
+
const entry = found.get(rule);
|
|
124
|
+
return entry === undefined ? [] : [{ rule, ...entry }];
|
|
125
|
+
}).sort((a, b) => b.count - a.count);
|
|
126
|
+
return { total: prompts.length, clean, rules };
|
|
127
|
+
}
|