@wirecat/cli-core 0.559.0 → 0.561.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 (89) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/background/schedules.d.ts +2 -0
  3. package/dist/calendar/busy.d.ts +11 -0
  4. package/dist/calendar/busy.js +14 -1
  5. package/dist/calendar/cli/index.d.ts +9 -3
  6. package/dist/calendar/cli/index.js +14 -7
  7. package/dist/calendar/cli/local-times.d.ts +5 -0
  8. package/dist/calendar/cli/local-times.js +39 -0
  9. package/dist/calendar/mcp/index.js +1 -1
  10. package/dist/calendar/reads.d.ts +11 -2
  11. package/dist/calendar/reads.js +34 -18
  12. package/dist/calendar/writes.js +3 -44
  13. package/dist/cli/effects.d.ts +13 -2
  14. package/dist/cli/effects.js +23 -2
  15. package/dist/cli/index.d.ts +2 -2
  16. package/dist/cli/index.js +2 -2
  17. package/dist/cli/meeting-findings-input.d.ts +3 -0
  18. package/dist/cli/meeting-findings-input.js +4 -0
  19. package/dist/cli/messenger/conversation-answers.d.ts +3 -0
  20. package/dist/cli/messenger/message-answers.d.ts +3 -0
  21. package/dist/cli/messenger/message-writes.d.ts +6 -0
  22. package/dist/cli/schedule/schedule-command.d.ts +6 -1
  23. package/dist/cli/schedule/schedule-command.js +24 -2
  24. package/dist/entities/contact-context.d.ts +6 -0
  25. package/dist/entities/conversation-results.d.ts +6 -0
  26. package/dist/entities/evidence.d.ts +24 -0
  27. package/dist/entities/index.d.ts +190 -0
  28. package/dist/entities/index.js +3 -0
  29. package/dist/entities/listener.d.ts +12 -0
  30. package/dist/entities/mail-findings.d.ts +116 -0
  31. package/dist/entities/mail-findings.js +68 -0
  32. package/dist/entities/message-context.d.ts +9 -0
  33. package/dist/entities/message-write.d.ts +12 -0
  34. package/dist/entities/message.d.ts +6 -0
  35. package/dist/entities/message.js +6 -0
  36. package/dist/entities/store-records.d.ts +3 -0
  37. package/dist/errors/reasons.js +3 -0
  38. package/dist/mail/cli/marks.d.ts +1 -0
  39. package/dist/mail/cli/marks.js +11 -4
  40. package/dist/mail/cli/review.js +10 -2
  41. package/dist/mail/findings.d.ts +55 -0
  42. package/dist/mail/findings.js +140 -0
  43. package/dist/mail/index.d.ts +2 -1
  44. package/dist/mail/index.js +2 -1
  45. package/dist/mail/marks.d.ts +10 -3
  46. package/dist/mail/marks.js +34 -5
  47. package/dist/meetings/findings-rules.d.ts +24 -0
  48. package/dist/meetings/findings-rules.js +136 -116
  49. package/dist/meetings/index.d.ts +2 -1
  50. package/dist/meetings/index.js +2 -1
  51. package/dist/sends/index.d.ts +1 -0
  52. package/dist/sends/index.js +1 -0
  53. package/dist/sends/keyed-guard.d.ts +12 -0
  54. package/dist/sends/keyed-guard.js +49 -0
  55. package/dist/services/proposals/kinds/mail-findings.d.ts +8 -0
  56. package/dist/services/proposals/kinds/mail-findings.js +87 -0
  57. package/dist/services/proposals/registry.js +3 -1
  58. package/dist/services/proposals/types.d.ts +2 -0
  59. package/dist/store/decisions.d.ts +1 -1
  60. package/dist/store/decisions.js +1 -1
  61. package/dist/store/index.d.ts +1 -0
  62. package/dist/store/index.js +1 -0
  63. package/dist/store/mail-findings.d.ts +51 -0
  64. package/dist/store/mail-findings.js +1 -0
  65. package/dist/store/path.d.ts +2 -0
  66. package/dist/store/path.js +21 -1
  67. package/dist/store/sqlite/email-activity.d.ts +8 -0
  68. package/dist/store/sqlite/email-activity.js +31 -5
  69. package/dist/store/sqlite/findings-core.d.ts +1 -0
  70. package/dist/store/sqlite/findings-core.js +1 -1
  71. package/dist/store/sqlite/mail-findings.d.ts +3 -0
  72. package/dist/store/sqlite/mail-findings.js +333 -0
  73. package/dist/store/sqlite/manifest.js +1 -0
  74. package/dist/store/sqlite/memories.d.ts +4 -1
  75. package/dist/store/sqlite/memories.js +48 -43
  76. package/dist/store/sqlite/migrations.generated.js +6 -0
  77. package/dist/store/sqlite/open-store.d.ts +1 -1
  78. package/dist/store/sqlite/open-store.js +4 -1
  79. package/dist/store/sqlite/open.js +2 -1
  80. package/dist/store/sqlite/proposed-actions.js +2 -1
  81. package/dist/store/sqlite/tasks.d.ts +2 -0
  82. package/dist/store/sqlite/tasks.js +26 -24
  83. package/dist/store/sqlite/test-accounts.d.ts +8 -0
  84. package/dist/store/sqlite/test-accounts.js +31 -0
  85. package/dist/store/sqlite/work-tasks.d.ts +1 -0
  86. package/dist/store/sqlite/work-tasks.js +6 -0
  87. package/dist/store/store.d.ts +3 -0
  88. package/dist/store/store.js +5 -0
  89. package/package.json +1 -1
@@ -73,7 +73,31 @@ export interface FindingsRules {
73
73
  anySubject?: boolean;
74
74
  /** Payment findings are staged on a project's evidence, not from a meeting. */
75
75
  payments?: boolean;
76
+ /** A task finding may name no project: it goes in its account's inbox. */
77
+ inboxTasks?: boolean;
76
78
  }
79
+ /** A finding's cited evidence: 1–8 distinct references in `rules`' form, each with a 64-hex fingerprint. */
80
+ export declare const validEvidence: (raw: unknown, rules: FindingsRules) => FindingEvidence[];
81
+ /** A finding's simple key: unique among `ids`, which it joins. */
82
+ export declare const findingId: (raw: unknown, ids: Set<string>) => string;
83
+ /** One fact, payment or task finding, its ID added to `ids`. */
84
+ export declare const validateFinding: (finding: Finding, rules: FindingsRules, ids: Set<string>) => Finding;
85
+ /** A date's or assignee's support: references the finding's own evidence cites. */
86
+ export declare const support: (value: unknown, evidence: readonly FindingEvidence[]) => string[];
87
+ /** A batch's envelope — schema version, key, extractor — around 1–`most` findings each `one` checks. */
88
+ export declare const validateBatch: <F>(input: {
89
+ schemaVersion: 1;
90
+ key: string;
91
+ extractor: string;
92
+ findings: unknown[];
93
+ }, rules: Pick<FindingsRules, "plural" | "singular">, most: number, one: (finding: never, ids: Set<string>) => F) => {
94
+ schemaVersion: 1;
95
+ key: string;
96
+ extractor: string;
97
+ findings: F[];
98
+ };
77
99
  export declare const validateFindings: (input: FindingsInput, rules: FindingsRules) => FindingsInput;
100
+ export declare const findingText: (value: unknown, limit: number) => string;
101
+ export declare const findingFields: (value: object, allowed: string[], noun: string) => void;
78
102
  export declare const findingFingerprint: ({ id: _id, ...finding }: Finding) => string;
79
103
  export {};
@@ -17,132 +17,152 @@ const fields = (value, allowed, noun) => {
17
17
  invalid(`unknown ${noun} field`);
18
18
  };
19
19
  const SUBJECT = /^(person|organization|project):[1-9]\d*$|^task:[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
20
- export const validateFindings = (input, rules) => {
20
+ /** A finding's cited evidence: 1–8 distinct references in `rules`' form, each with a 64-hex fingerprint. */
21
+ export const validEvidence = (raw, rules) => {
22
+ if (!Array.isArray(raw) || raw.length < 1 || raw.length > 8)
23
+ return invalid(`a finding requires 1–8 cited ${rules.cited}s`);
24
+ const evidence = raw
25
+ .map((item) => {
26
+ if (!item || typeof item !== "object")
27
+ return invalid("finding evidence is a reference and fingerprint");
28
+ fields(item, ["reference", "fingerprint"], rules.singular);
29
+ if (typeof item.reference !== "string" || typeof item.fingerprint !== "string")
30
+ return invalid("evidence requires a reference and fingerprint");
31
+ const reference = rules.reference(item.reference);
32
+ if (!/^[a-f0-9]{64}$/.test(item.fingerprint))
33
+ return invalid(`finding evidence requires exact ${rules.cited} references and fingerprints`);
34
+ return { reference, fingerprint: item.fingerprint };
35
+ })
36
+ .sort((a, b) => a.reference.localeCompare(b.reference));
37
+ if (new Set(evidence.map((item) => item.reference)).size !== evidence.length)
38
+ return invalid(`duplicate evidence ${rules.cited}`);
39
+ return evidence;
40
+ };
41
+ /** A finding's simple key: unique among `ids`, which it joins. */
42
+ export const findingId = (raw, ids) => {
43
+ const id = findingText(raw, 64);
44
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(id) || ids.has(id))
45
+ return invalid("finding IDs must be unique simple keys");
46
+ ids.add(id);
47
+ return id;
48
+ };
49
+ /** One fact, payment or task finding, its ID added to `ids`. */
50
+ export const validateFinding = (finding, rules, ids) => {
51
+ if (!finding || typeof finding !== "object")
52
+ return invalid("a finding is an object");
53
+ const id = findingId(finding.id, ids);
54
+ const project = finding.project === undefined && rules.anySubject ? undefined : text(finding.project, 64);
55
+ if (project !== undefined && !/^project:[1-9]\d*$/.test(project))
56
+ return invalid("a finding names a project reference");
57
+ if (finding.subject !== undefined && (!rules.anySubject || !SUBJECT.test(text(finding.subject, 80))))
58
+ return invalid("a finding's subject is a person:, organization:, task: or project: reference");
59
+ if (finding.kind === "task" && project === undefined && !rules.inboxTasks)
60
+ return invalid("a task finding names the project the task goes in");
61
+ const evidence = validEvidence(finding.evidence, rules);
62
+ const base = {
63
+ id,
64
+ ...(project === undefined ? {} : { project }),
65
+ ...(finding.subject === undefined ? {} : { subject: finding.subject }),
66
+ evidence,
67
+ };
68
+ if (finding.kind === "fact") {
69
+ fields(finding, ["id", "project", "subject", "evidence", "kind", "type", "statement"], rules.singular);
70
+ if (finding.type === "payment")
71
+ return invalid("a payment is a finding of kind payment; money is a payments row, not a fact");
72
+ if (!FACT_TYPES.includes(finding.type))
73
+ return invalid("unknown fact finding type");
74
+ return { ...base, kind: "fact", type: finding.type, statement: text(finding.statement, 2000) };
75
+ }
76
+ if (finding.kind === "payment" && rules.payments) {
77
+ fields(finding, ["id", "project", "subject", "evidence", "kind", "statement", "payment", "supersedes"], rules.singular);
78
+ if (finding.supersedes !== undefined && !/^invoice:[1-9]\d*$/.test(String(finding.supersedes)))
79
+ return invalid("a payment finding supersedes an invoice: reference, the expected payment it settles or voids");
80
+ const payment = validatePayment(finding.payment);
81
+ if (payment.state === "expected" && finding.supersedes !== undefined)
82
+ return invalid("an expected payment supersedes nothing; a paid or cancelled one supersedes its invoice");
83
+ if (payment.state === "cancelled" && finding.supersedes === undefined)
84
+ return invalid("a cancelled payment names the invoice: it cancels in supersedes");
85
+ if (payment.state === "expected" && !/^(person|organization):/.test(payment.counterparty ?? ""))
86
+ return invalid("an expected payment becomes an invoice, which names its counterparty as a person: or organization:");
87
+ return {
88
+ ...base,
89
+ kind: "payment",
90
+ ...(finding.statement === undefined ? {} : { statement: text(finding.statement, 2000) }),
91
+ payment,
92
+ ...(finding.supersedes === undefined ? {} : { supersedes: finding.supersedes }),
93
+ };
94
+ }
95
+ if (finding.kind !== "task")
96
+ return invalid(`a finding is a fact${rules.payments ? ", payment" : ""} or task`);
97
+ fields(finding, [
98
+ "id",
99
+ "project",
100
+ "evidence",
101
+ "kind",
102
+ "type",
103
+ "title",
104
+ "reason",
105
+ "commitment",
106
+ "dueAt",
107
+ "dueEvidence",
108
+ "assignee",
109
+ "assigneeEvidence",
110
+ ], rules.singular);
111
+ if (!TASK_TYPES.includes(finding.type))
112
+ return invalid("a task finding type is bug, chore or feature");
113
+ if (!["explicit", "inferred"].includes(finding.commitment))
114
+ return invalid("task commitment must be explicit or inferred");
115
+ if ((finding.dueAt === undefined) !== (finding.dueEvidence === undefined) ||
116
+ (finding.assignee === undefined) !== (finding.assigneeEvidence === undefined))
117
+ return invalid("optional dates and assignees require their supporting evidence");
118
+ if (finding.assignee !== undefined &&
119
+ (typeof finding.assignee !== "string" || !/^person:[1-9]\d*$/.test(finding.assignee)))
120
+ return invalid("an assignee must be a person reference");
121
+ return {
122
+ ...base,
123
+ kind: "task",
124
+ type: finding.type,
125
+ title: text(finding.title, 300),
126
+ reason: text(finding.reason, 2000),
127
+ commitment: finding.commitment,
128
+ ...(finding.dueAt === undefined
129
+ ? {}
130
+ : {
131
+ dueAt: meetingTimestamp(finding.dueAt, "finding due date"),
132
+ dueEvidence: support(finding.dueEvidence, evidence),
133
+ }),
134
+ ...(finding.assignee === undefined
135
+ ? {}
136
+ : { assignee: finding.assignee, assigneeEvidence: support(finding.assigneeEvidence, evidence) }),
137
+ };
138
+ };
139
+ /** A date's or assignee's support: references the finding's own evidence cites. */
140
+ export const support = (value, evidence) => {
141
+ if (!Array.isArray(value) ||
142
+ value.length < 1 ||
143
+ value.length > 8 ||
144
+ value.some((ref) => typeof ref !== "string" || !evidence.some((item) => item.reference === ref)))
145
+ return invalid("date and assignee support must cite the finding's evidence");
146
+ return [...new Set(value)].sort();
147
+ };
148
+ /** A batch's envelope — schema version, key, extractor — around 1–`most` findings each `one` checks. */
149
+ export const validateBatch = (input, rules, most, one) => {
21
150
  if (!input || typeof input !== "object" || Buffer.byteLength(JSON.stringify(input), "utf8") > 65536)
22
151
  return invalid(`${rules.plural} take at most 65536 UTF-8 bytes`);
23
152
  fields(input, ["schemaVersion", "key", "extractor", "findings"], rules.singular);
24
153
  if (input.schemaVersion !== 1 ||
25
154
  !Array.isArray(input.findings) ||
26
155
  input.findings.length < 1 ||
27
- input.findings.length > 16)
28
- return invalid(`schemaVersion 1 takes 1–16 ${rules.plural}`);
156
+ input.findings.length > most)
157
+ return invalid(`schemaVersion 1 takes 1–${most} ${rules.plural}`);
29
158
  const key = text(input.key, 64);
30
159
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(key))
31
160
  return invalid("a findings key uses letters, digits, dot, colon, underscore or hyphen");
32
161
  const ids = new Set();
33
- const findings = input.findings.map((finding) => {
34
- if (!finding || typeof finding !== "object")
35
- return invalid("a finding is an object");
36
- const id = text(finding.id, 64);
37
- if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(id) || ids.has(id))
38
- return invalid("finding IDs must be unique simple keys");
39
- ids.add(id);
40
- const project = finding.project === undefined && rules.anySubject ? undefined : text(finding.project, 64);
41
- if (project !== undefined && !/^project:[1-9]\d*$/.test(project))
42
- return invalid("a finding names a project reference");
43
- if (finding.subject !== undefined && (!rules.anySubject || !SUBJECT.test(text(finding.subject, 80))))
44
- return invalid("a finding's subject is a person:, organization:, task: or project: reference");
45
- if (finding.kind === "task" && project === undefined)
46
- return invalid("a task finding names the project the task goes in");
47
- if (!Array.isArray(finding.evidence) || finding.evidence.length < 1 || finding.evidence.length > 8)
48
- return invalid(`a finding requires 1–8 cited ${rules.cited}s`);
49
- const evidence = finding.evidence
50
- .map((item) => {
51
- if (!item || typeof item !== "object")
52
- return invalid("finding evidence is a reference and fingerprint");
53
- fields(item, ["reference", "fingerprint"], rules.singular);
54
- if (typeof item.reference !== "string" || typeof item.fingerprint !== "string")
55
- return invalid("evidence requires a reference and fingerprint");
56
- const reference = rules.reference(item.reference);
57
- if (!/^[a-f0-9]{64}$/.test(item.fingerprint))
58
- return invalid(`finding evidence requires exact ${rules.cited} references and fingerprints`);
59
- return { reference, fingerprint: item.fingerprint };
60
- })
61
- .sort((a, b) => a.reference.localeCompare(b.reference));
62
- if (new Set(evidence.map((item) => item.reference)).size !== evidence.length)
63
- return invalid(`duplicate evidence ${rules.cited}`);
64
- const base = {
65
- id,
66
- ...(project === undefined ? {} : { project }),
67
- ...(finding.subject === undefined ? {} : { subject: finding.subject }),
68
- evidence,
69
- };
70
- if (finding.kind === "fact") {
71
- fields(finding, ["id", "project", "subject", "evidence", "kind", "type", "statement"], rules.singular);
72
- if (finding.type === "payment")
73
- return invalid("a payment is a finding of kind payment; money is a payments row, not a fact");
74
- if (!FACT_TYPES.includes(finding.type))
75
- return invalid("unknown fact finding type");
76
- return { ...base, kind: "fact", type: finding.type, statement: text(finding.statement, 2000) };
77
- }
78
- if (finding.kind === "payment" && rules.payments) {
79
- fields(finding, ["id", "project", "subject", "evidence", "kind", "statement", "payment", "supersedes"], rules.singular);
80
- if (finding.supersedes !== undefined && !/^invoice:[1-9]\d*$/.test(String(finding.supersedes)))
81
- return invalid("a payment finding supersedes an invoice: reference, the expected payment it settles or voids");
82
- const payment = validatePayment(finding.payment);
83
- if (payment.state === "expected" && finding.supersedes !== undefined)
84
- return invalid("an expected payment supersedes nothing; a paid or cancelled one supersedes its invoice");
85
- if (payment.state === "cancelled" && finding.supersedes === undefined)
86
- return invalid("a cancelled payment names the invoice: it cancels in supersedes");
87
- if (payment.state === "expected" && !/^(person|organization):/.test(payment.counterparty ?? ""))
88
- return invalid("an expected payment becomes an invoice, which names its counterparty as a person: or organization:");
89
- return {
90
- ...base,
91
- kind: "payment",
92
- ...(finding.statement === undefined ? {} : { statement: text(finding.statement, 2000) }),
93
- payment,
94
- ...(finding.supersedes === undefined ? {} : { supersedes: finding.supersedes }),
95
- };
96
- }
97
- if (finding.kind !== "task")
98
- return invalid(`a finding is a fact${rules.payments ? ", payment" : ""} or task`);
99
- fields(finding, [
100
- "id",
101
- "project",
102
- "evidence",
103
- "kind",
104
- "type",
105
- "title",
106
- "reason",
107
- "commitment",
108
- "dueAt",
109
- "dueEvidence",
110
- "assignee",
111
- "assigneeEvidence",
112
- ], rules.singular);
113
- if (!TASK_TYPES.includes(finding.type))
114
- return invalid("a task finding type is bug, chore or feature");
115
- if (!["explicit", "inferred"].includes(finding.commitment))
116
- return invalid("task commitment must be explicit or inferred");
117
- const support = (value) => {
118
- if (!Array.isArray(value) ||
119
- value.length < 1 ||
120
- value.length > 8 ||
121
- value.some((ref) => typeof ref !== "string" || !evidence.some((item) => item.reference === ref)))
122
- return invalid("date and assignee support must cite the finding's evidence");
123
- return [...new Set(value)].sort();
124
- };
125
- if ((finding.dueAt === undefined) !== (finding.dueEvidence === undefined) ||
126
- (finding.assignee === undefined) !== (finding.assigneeEvidence === undefined))
127
- return invalid("optional dates and assignees require their supporting evidence");
128
- if (finding.assignee !== undefined &&
129
- (typeof finding.assignee !== "string" || !/^person:[1-9]\d*$/.test(finding.assignee)))
130
- return invalid("an assignee must be a person reference");
131
- return {
132
- ...base,
133
- kind: "task",
134
- type: finding.type,
135
- title: text(finding.title, 300),
136
- reason: text(finding.reason, 2000),
137
- commitment: finding.commitment,
138
- ...(finding.dueAt === undefined
139
- ? {}
140
- : { dueAt: meetingTimestamp(finding.dueAt, "finding due date"), dueEvidence: support(finding.dueEvidence) }),
141
- ...(finding.assignee === undefined
142
- ? {}
143
- : { assignee: finding.assignee, assigneeEvidence: support(finding.assigneeEvidence) }),
144
- };
145
- });
162
+ const findings = input.findings.map((finding) => one(finding, ids));
146
163
  return { schemaVersion: 1, key, extractor: text(input.extractor, 200), findings };
147
164
  };
165
+ export const validateFindings = (input, rules) => validateBatch(input, rules, 16, (finding, ids) => validateFinding(finding, rules, ids));
166
+ export const findingText = (value, limit) => text(value, limit);
167
+ export const findingFields = (value, allowed, noun) => fields(value, allowed, noun);
148
168
  export const findingFingerprint = ({ id: _id, ...finding }) => findingHash(finding);
@@ -9,7 +9,7 @@ export { entryInWindow, eventChange } from "./event-store.js";
9
9
  export { linkEvent } from "./events.js";
10
10
  export { exportMeeting, type MeetingExport, type MeetingExportFormat, type MeetingExportOptions, serializeVtt, } from "./export.js";
11
11
  export { type FindingEvidence, type FindingOutcome, findingHash, MEETING_FINDINGS_KIND, type MeetingFactFinding, type MeetingFinding, type MeetingFindingsInput, type MeetingFindingsReceipt, type MeetingTaskFinding, meetingFindingFingerprint, validateMeetingFindings, } from "./findings.js";
12
- export { type Finding, type FindingsInput, type FindingsReceipt, type FindingsRules, findingFingerprint, type PaymentFinding, validateFindings, } from "./findings-rules.js";
12
+ export { type FactFinding, type Finding, type FindingsInput, type FindingsReceipt, type FindingsRules, findingFields, findingFingerprint, findingId, findingText, type PaymentFinding, type TaskFinding, validateBatch, validateFinding, validateFindings, validEvidence, } from "./findings-rules.js";
13
13
  export { liftMeetingFields, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery } from "./hit-query.js";
14
14
  export { type ImportFile, importFiles } from "./import.js";
15
15
  export { MEETING_ISSUES, MEETING_QUERY, type MeetingIssue, type MeetingItem, type MeetingOwner, meeting, meetingIssuesOf, meetingItem, } from "./item.js";
@@ -53,6 +53,7 @@ export { validateMeetingSeriesInventoryCursor } from "./series-inventory-validat
53
53
  export type { MeetingSource, SourceParticipant } from "./source.js";
54
54
  export { aggregateMeetingStats, type MeetingSpeakerStats, type MeetingStats, type MeetingStatsInput, type MeetingStatsRow, type MeetingStatsSelection, type MeetingStatsStore, type MeetingWeekStats, } from "./stats.js";
55
55
  export type { ChatInput, ContractCase, EventCandidateFilter, IdentityInput, MeetingDetails, MeetingFilter, MeetingHitSource, MeetingInput, MeetingSave, MeetingStore, NewRecord, ParticipantInput, SearchHit, TranscriptInput, TranscriptLanguageFill, TranscriptRowInput, } from "./store.js";
56
+ export { meetingTimestamp } from "./timestamp.js";
56
57
  export type { MeetingTranscriptReceiptStore, MeetingTranscriptStore, TranscriptAppend, TranscriptAppendReceipt, UnlinkedTranscriptInput, } from "./transcript-store.js";
57
58
  export { parseTranscriptText, TranscriptTextError, type TranscriptTextHeader } from "./transcript-text.js";
58
59
  export { type MeetingMediaDescriptor, type MeetingRecognitionSegment, type MeetingTranscriptionContext, type MeetingTranscriptionOptions, type MeetingTranscriptionReceipt, type MeetingTranscriptionSource, transcribeMeeting, } from "./transcription.js";
@@ -6,7 +6,7 @@ export { entryInWindow, eventChange } from "./event-store.js";
6
6
  export { linkEvent } from "./events.js";
7
7
  export { exportMeeting, serializeVtt, } from "./export.js";
8
8
  export { findingHash, MEETING_FINDINGS_KIND, meetingFindingFingerprint, validateMeetingFindings, } from "./findings.js";
9
- export { findingFingerprint, validateFindings, } from "./findings-rules.js";
9
+ export { findingFields, findingFingerprint, findingId, findingText, validateBatch, validateFinding, validateFindings, validEvidence, } from "./findings-rules.js";
10
10
  export { liftMeetingFields, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery } from "./hit-query.js";
11
11
  export { importFiles } from "./import.js";
12
12
  export { MEETING_ISSUES, MEETING_QUERY, meeting, meetingIssuesOf, meetingItem, } from "./item.js";
@@ -39,6 +39,7 @@ export { validateMeetingSeriesHistory, } from "./series-history.js";
39
39
  export { createMeetingSeriesInventoryReader } from "./series-inventory.js";
40
40
  export { validateMeetingSeriesInventoryCursor } from "./series-inventory-validation.js";
41
41
  export { aggregateMeetingStats, } from "./stats.js";
42
+ export { meetingTimestamp } from "./timestamp.js";
42
43
  export { parseTranscriptText, TranscriptTextError } from "./transcript-text.js";
43
44
  export { transcribeMeeting, } from "./transcription.js";
44
45
  export { createUpcomingMeetingReader } from "./upcoming.js";
@@ -3,6 +3,7 @@ export { type FloodDeadline, FloodMemory, type FloodState, FROZEN_HOLD_MS, flood
3
3
  export { type Asker, type GuardRequest, guardFor, type SendGuard, type SendGuardOptions, sendGuard, sharedJournal, } from "./guard.js";
4
4
  export { currentOperation, guardedWrite, type Operated } from "./guarded.js";
5
5
  export { type AccountAction, type ChatAction, type SendEntry, SendJournal, type SendKind, type SendOutcome, sendsPathFor, } from "./journal.js";
6
+ export { type KeyedGuard, keyedGuard } from "./keyed-guard.js";
6
7
  export { DEFAULT_PACE, type PaceRate, Pacer, pacePathFor } from "./pace.js";
7
8
  export { assertOverridesTighten, CEILING_KEY, COMMAND_PATH_KEY, DEFAULT_PERMISSIONS, keyForCommand, keyForWrite, LEVELS, type Level, layerPermissions, levelFor, type PermissionKey, permissionOverrides, readKeysForCommand, skipFlagFor, WRITE_KEYS, } from "./permissions.js";
8
9
  export { type Recipient, RecipientList, recipientsPathFor } from "./recipients.js";
@@ -2,6 +2,7 @@ export { FloodMemory, FROZEN_HOLD_MS, floodPathFor, LIMITED_HOLD_MS, } from "./f
2
2
  export { guardFor, sendGuard, sharedJournal, } from "./guard.js";
3
3
  export { currentOperation, guardedWrite } from "./guarded.js";
4
4
  export { SendJournal, sendsPathFor, } from "./journal.js";
5
+ export { keyedGuard } from "./keyed-guard.js";
5
6
  export { DEFAULT_PACE, Pacer, pacePathFor } from "./pace.js";
6
7
  export { assertOverridesTighten, CEILING_KEY, COMMAND_PATH_KEY, DEFAULT_PERMISSIONS, keyForCommand, keyForWrite, LEVELS, layerPermissions, levelFor, permissionOverrides, readKeysForCommand, skipFlagFor, WRITE_KEYS, } from "./permissions.js";
7
8
  export { RecipientList, recipientsPathFor } from "./recipients.js";
@@ -0,0 +1,12 @@
1
+ import type { Asker, GuardRequest, SendGuard } from "./guard.js";
2
+ import type { Level, PermissionKey } from "./permissions.js";
3
+ export type KeyedGuard = SendGuard & {
4
+ /** Refuses the write when one of its keys denies it or is read-only; asks nothing. */
5
+ refuse(request: GuardRequest): void;
6
+ };
7
+ /**
8
+ * A guard over a write's main key and its extra keys. A key that refuses refuses before anything is asked, so nobody
9
+ * answers yes to a write that a stricter key then stops, and one question names every key at `ask`. The extra keys are
10
+ * probed as reads, never journaled or counted: the write itself holds the one journal line.
11
+ */
12
+ export declare const keyedGuard: (build: (ask: Asker) => SendGuard, ask: Asker, levelOf: (key: PermissionKey) => Level, extra: readonly PermissionKey[]) => KeyedGuard;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A guard over a write's main key and its extra keys. A key that refuses refuses before anything is asked, so nobody
3
+ * answers yes to a write that a stricter key then stops, and one question names every key at `ask`. The extra keys are
4
+ * probed as reads, never journaled or counted: the write itself holds the one journal line.
5
+ */
6
+ export const keyedGuard = (build, ask, levelOf, extra) => {
7
+ let question;
8
+ let answered = false;
9
+ const guard = build(async (key, request) => {
10
+ if (answered)
11
+ return;
12
+ await ask(question || key, request);
13
+ answered = true;
14
+ });
15
+ const probes = new WeakMap();
16
+ const all = (request) => {
17
+ let found = probes.get(request);
18
+ if (!found) {
19
+ found = extra.map((key) => ({ chatId: null, kind: "read", key }));
20
+ probes.set(request, found);
21
+ }
22
+ return [request, ...found];
23
+ };
24
+ const levelOfRequest = ({ key }) => levelOf(key ?? "");
25
+ const refuse = (request) => {
26
+ const refused = all(request).find((one) => ["deny", "readonly"].includes(levelOfRequest(one)));
27
+ if (refused)
28
+ guard.check(refused, { reserve: false });
29
+ };
30
+ return {
31
+ refuse,
32
+ ask: async (request) => {
33
+ refuse(request);
34
+ question = all(request)
35
+ .filter((one) => levelOfRequest(one) === "ask")
36
+ .map(({ key }) => key)
37
+ .join(" and ");
38
+ for (const one of all(request))
39
+ await guard.ask?.(one);
40
+ },
41
+ check: (request, options) => {
42
+ for (const one of all(request).slice(1))
43
+ guard.check(one, { reserve: false });
44
+ guard.check(request, options);
45
+ },
46
+ ...(guard.reserve ? { reserve: guard.reserve } : {}),
47
+ record: (entry) => guard.record(entry),
48
+ };
49
+ };
@@ -0,0 +1,8 @@
1
+ import { type MessageStore } from "../../../store/index.js";
2
+ import type { ProposalKind } from "../types.js";
3
+ /**
4
+ * What an agent read in new mail, one batch per mailbox and run. Only the owner decides it (NEED-2187): an agent's
5
+ * confirmation is refused whatever `agent_decisions` says. Confirming accepts the parts named, or every finding not
6
+ * rejected before; the rest are rejected.
7
+ */
8
+ export declare const mailFindingsKind: (store: Pick<MessageStore, "mailFindings" | "proposedActions">) => ProposalKind;
@@ -0,0 +1,87 @@
1
+ import { MAIL_FINDINGS_KIND } from "../../../store/index.js";
2
+ import { kept, proposerOfAuthor } from "./shared.js";
3
+ /** A finding's one line in the inbox; never the email's text, only what the agent wrote. */
4
+ const summaryOf = (finding) => {
5
+ switch (finding.kind) {
6
+ case "task":
7
+ return finding.title;
8
+ case "fact":
9
+ return finding.statement;
10
+ case "task_update":
11
+ return `${finding.change} ${finding.task}: ${finding.reason}`;
12
+ case "memory":
13
+ return finding.body.slice(0, 200);
14
+ case "link":
15
+ return `${finding.from} → ${finding.to}`;
16
+ case "new_contact":
17
+ return `${finding.name} <${finding.address}>`;
18
+ }
19
+ };
20
+ const rowOf = (batch, createdAt) => {
21
+ const findings = batch.input.findings;
22
+ const outcome = (id) => batch.receipt?.items.find((item) => item.id === id)?.status ?? null;
23
+ const project = findings.flatMap((finding) => ("project" in finding && finding.project ? [finding.project] : []))[0] ?? null;
24
+ return {
25
+ id: batch.id,
26
+ kind: "mail_findings",
27
+ status: batch.status === "proposed" ? "proposed" : batch.receipt?.accepted.length ? "confirmed" : "rejected",
28
+ project,
29
+ subject: `findings:${batch.id}`,
30
+ object: null,
31
+ summary: `${findings.length} mail finding${findings.length === 1 ? "" : "s"} for ${batch.account.account}`,
32
+ proposedBy: proposerOfAuthor(batch.author),
33
+ reason: null,
34
+ evidence: [...new Set(findings.flatMap((finding) => finding.evidence.map((one) => one.reference)))].slice(0, 5),
35
+ score: null,
36
+ signals: null,
37
+ parts: findings.map((finding) => ({
38
+ id: finding.id,
39
+ kind: finding.kind,
40
+ summary: summaryOf(finding),
41
+ outcome: outcome(finding.id),
42
+ })),
43
+ createdAt,
44
+ };
45
+ };
46
+ /**
47
+ * What an agent read in new mail, one batch per mailbox and run. Only the owner decides it (NEED-2187): an agent's
48
+ * confirmation is refused whatever `agent_decisions` says. Confirming accepts the parts named, or every finding not
49
+ * rejected before; the rest are rejected.
50
+ */
51
+ export const mailFindingsKind = (store) => {
52
+ const created = async (batch) => rowOf(batch, (await store.proposedActions.get(batch.id)).createdAt);
53
+ return {
54
+ kind: "mail_findings",
55
+ stored: [MAIL_FINDINGS_KIND],
56
+ parts: true,
57
+ ownerOnly: true,
58
+ list: async (filter) => {
59
+ const status = filter.status ?? "proposed";
60
+ const rows = [];
61
+ for (let offset = 0; rows.length < filter.limit; offset += 50) {
62
+ const page = await store.mailFindings.list({
63
+ ...(status === "proposed" ? { status: "proposed" } : {}),
64
+ ...(status === "confirmed" || status === "rejected" ? { status: "reviewed" } : {}),
65
+ limit: 50,
66
+ offset,
67
+ });
68
+ for (const row of kept(await Promise.all(page.items.map(created)), { ...filter, limit: 50 }))
69
+ rows.push(row);
70
+ if (!page.hasMore)
71
+ break;
72
+ }
73
+ return kept(rows, filter);
74
+ },
75
+ get: async (id) => created(await store.mailFindings.get(id)),
76
+ decide: async (id, { confirm, by, parts }) => {
77
+ const batch = await store.mailFindings.get(id);
78
+ const turnedDown = new Set(batch.previous.filter((one) => one.status === "rejected").map((one) => one.id));
79
+ const accept = !confirm
80
+ ? []
81
+ : (parts ?? batch.input.findings.map((finding) => finding.id).filter((one) => !turnedDown.has(one)));
82
+ const reviewed = await store.mailFindings.review(id, { fingerprint: batch.fingerprint, accept, by });
83
+ const made = (reviewed.receipt?.items ?? []).flatMap((item) => item.status === "accepted" && item.reference && !item.reused ? [item.reference] : []);
84
+ return { id, kind: "mail_findings", status: accept.length ? "confirmed" : "rejected", made };
85
+ },
86
+ };
87
+ };
@@ -5,6 +5,7 @@ import { factKind } from "./kinds/fact.js";
5
5
  import { invoiceKind, paymentKind } from "./kinds/finance.js";
6
6
  import { findingsKind } from "./kinds/findings.js";
7
7
  import { keyDocumentKind } from "./kinds/key-document.js";
8
+ import { mailFindingsKind } from "./kinds/mail-findings.js";
8
9
  import { memoryKind } from "./kinds/memory.js";
9
10
  import { relationshipKind } from "./kinds/relationship.js";
10
11
  import { relationshipUpdateKind } from "./kinds/relationship-update.js";
@@ -98,7 +99,7 @@ export const emptyProposalRegistry = (store) => {
98
99
  });
99
100
  continue;
100
101
  }
101
- const refusal = mayDecide(row, decision.by, policy);
102
+ const refusal = mayDecide(kind.ownerOnly ? { ...row, ownerOnly: true } : row, decision.by, policy);
102
103
  if (refusal) {
103
104
  refused.push(refusal);
104
105
  continue;
@@ -127,6 +128,7 @@ export const proposalRegistry = (store) => {
127
128
  paymentKind(store),
128
129
  memoryKind(store),
129
130
  findingsKind(store),
131
+ mailFindingsKind(store),
130
132
  ])
131
133
  registry.register(kind);
132
134
  registry.register(actionKind(store, registry.claimed));
@@ -64,6 +64,8 @@ export interface ProposalKind {
64
64
  readonly stored?: readonly string[];
65
65
  /** Whether its proposals have parts decided on their own, as a findings batch has findings. */
66
66
  readonly parts?: boolean;
67
+ /** Only the owner decides it, whatever the host's `agent_decisions` says. */
68
+ readonly ownerOnly?: boolean;
67
69
  /** Bounded: at most `offset + limit` rows, newest first. */
68
70
  list(filter: ProposalFilter): Promise<ProposalRow[]>;
69
71
  get(id: string): Promise<ProposalRow>;
@@ -22,7 +22,7 @@ export type Decider = "owner" | {
22
22
  reason: string;
23
23
  };
24
24
  export interface DecisionPolicy {
25
- /** The host's `agent_decisions`: `false` keeps every decision with the owner. */
25
+ /** The host's `agent_decisions`: off unless the owner sets it to `true`; off keeps every decision with the owner. */
26
26
  agentDecisions: boolean;
27
27
  /** A rule scorer's proposal is the owner's alone to decide. */
28
28
  ruleProposalsOwnerOnly: boolean;
@@ -1,5 +1,5 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- export const DEFAULT_DECISION_POLICY = { agentDecisions: true, ruleProposalsOwnerOnly: true };
2
+ export const DEFAULT_DECISION_POLICY = { agentDecisions: false, ruleProposalsOwnerOnly: true };
3
3
  /**
4
4
  * The one check every decide path runs before it confirms or rejects a proposal. `null` means allowed. Every Claude
5
5
  * Code session is the bot `claude-code`, so comparing bot names keeps one session from deciding another's proposal.
@@ -16,6 +16,7 @@ export type { CacheDatabase, CacheStatement, OpenDatabase, SqlValue } from "./dr
16
16
  export { PRAGMAS } from "./driver.js";
17
17
  export { EVIDENCE_FINDINGS_KIND, type EvidenceFindingsBatch, type EvidenceFindingsDecider, type EvidenceFindingsReceipt, type EvidenceFindingsStore, validateEvidenceFindings, } from "./evidence-findings.js";
18
18
  export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
19
+ export { MAIL_FINDINGS_KIND, type MailFindingsBatch, type MailFindingsStore } from "./mail-findings.js";
19
20
  export type { MeetingFindingsBatch, MeetingFindingsStore } from "./meeting-findings.js";
20
21
  export { MIGRATIONS, type Migration, migrate } from "./migrations.js";
21
22
  export { openCache } from "./open.js";
@@ -8,6 +8,7 @@ export { applyDocumentTransfer, previewDocumentTransfer } from "./document-trans
8
8
  export { PRAGMAS } from "./driver.js";
9
9
  export { EVIDENCE_FINDINGS_KIND, validateEvidenceFindings, } from "./evidence-findings.js";
10
10
  export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
11
+ export { MAIL_FINDINGS_KIND } from "./mail-findings.js";
11
12
  export { MIGRATIONS, migrate } from "./migrations.js";
12
13
  export { openCache } from "./open.js";
13
14
  export { storePath } from "./path.js";
@@ -0,0 +1,51 @@
1
+ import type { MailFindingsInput } from "../mail/findings.js";
2
+ import type { FindingOutcome, FindingsReceipt } from "../meetings/index.js";
3
+ import type { Decider } from "./decisions.js";
4
+ import type { AccountKey } from "./types.js";
5
+ export declare const MAIL_FINDINGS_KIND = "mail_findings";
6
+ export interface MailFindingsBatch {
7
+ id: string;
8
+ account: AccountKey;
9
+ input: MailFindingsInput;
10
+ fingerprint: string;
11
+ status: "proposed" | "reviewed";
12
+ author: {
13
+ type: "person" | "bot";
14
+ id: string;
15
+ name: string | null;
16
+ kind: "agent" | "rule" | null;
17
+ };
18
+ decidedBy: {
19
+ type: "person" | "bot";
20
+ id: string;
21
+ } | null;
22
+ decidedAt: string | null;
23
+ previous: FindingOutcome[];
24
+ receipt: FindingsReceipt | null;
25
+ }
26
+ /**
27
+ * What an agent read in new mail — tasks, task updates, facts, memories, links, new contacts — cited and staged for
28
+ * the owner, one batch per mailbox and run. Only the owner decides one: an agent's mail proposal never becomes the
29
+ * owner's word without him.
30
+ */
31
+ export interface MailFindingsStore {
32
+ stage(account: AccountKey, input: MailFindingsInput, agent: {
33
+ bot: string;
34
+ model?: string;
35
+ }): Promise<MailFindingsBatch>;
36
+ get(id: string): Promise<MailFindingsBatch>;
37
+ list(options?: {
38
+ account?: AccountKey;
39
+ status?: "proposed" | "reviewed";
40
+ limit?: number;
41
+ offset?: number;
42
+ }): Promise<{
43
+ items: MailFindingsBatch[];
44
+ hasMore: boolean;
45
+ }>;
46
+ review(id: string, input: {
47
+ fingerprint: string;
48
+ accept: string[];
49
+ by: Decider;
50
+ }): Promise<MailFindingsBatch>;
51
+ }
@@ -0,0 +1 @@
1
+ export const MAIL_FINDINGS_KIND = "mail_findings";