@wirecat/wirecat 0.0.0-stage → 1.1.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 +204 -0
- package/README.md +399 -2
- package/THIRD_PARTY_NOTICES +2 -0
- package/contracts/wirecat.json +4612 -0
- package/dist/actions/actions.js +269 -0
- package/dist/actions/command.js +102 -0
- package/dist/agents/command.js +17 -0
- package/dist/agents/log.js +23 -0
- package/dist/answer.js +100 -0
- package/dist/answers/command.js +128 -0
- package/dist/app.js +15 -0
- package/dist/author.js +109 -0
- package/dist/bin/wcat-wirecat.js +40 -0
- package/dist/bots/command.js +175 -0
- package/dist/bundle/auto-O24ISPOI.js +43 -0
- package/dist/bundle/chunk-2A3YPENI.js +31 -0
- package/dist/bundle/chunk-6BDIFKF5.js +222 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-AYHZY24E.js +120 -0
- package/dist/bundle/chunk-CKBTMZUX.js +72 -0
- package/dist/bundle/chunk-FGXUH3XL.js +416 -0
- package/dist/bundle/chunk-I5JQBRRC.js +807 -0
- package/dist/bundle/chunk-RKVAWMZT.js +38 -0
- package/dist/bundle/chunk-SCDNOUUR.js +395 -0
- package/dist/bundle/chunk-T7TG4JKR.js +312 -0
- package/dist/bundle/chunk-XBUCXQKT.js +51 -0
- package/dist/bundle/entry-EW5A7FYV.js +64 -0
- package/dist/bundle/failure-HMELJ3K5.js +19 -0
- package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
- package/dist/bundle/program-7XWGFN4H.js +14994 -0
- package/dist/bundle/server-T7RVBNRW.js +303 -0
- package/dist/bundle/update-JZDS7B6L.js +22 -0
- package/dist/bundle/wcat-wirecat.js +83 -0
- package/dist/config-command.js +39 -0
- package/dist/config-issues.js +15 -0
- package/dist/config.js +187 -0
- package/dist/context/command.js +162 -0
- package/dist/context/context.js +197 -0
- package/dist/contract-overrides/commands.js +81 -0
- package/dist/contract-overrides/mcp.js +241 -0
- package/dist/contract-overrides/meetings.js +344 -0
- package/dist/contract-overrides/search.js +508 -0
- package/dist/contract-overrides/skill.js +85 -0
- package/dist/contract-overrides.js +7 -0
- package/dist/digest/backfill.js +175 -0
- package/dist/digest/brief.js +189 -0
- package/dist/digest/catch-up-record.js +30 -0
- package/dist/digest/catch-up.js +86 -0
- package/dist/digest/command.js +110 -0
- package/dist/digest/digest-commands.js +327 -0
- package/dist/digest/digest.js +560 -0
- package/dist/digest/digests.js +213 -0
- package/dist/digest/history.js +202 -0
- package/dist/digest/input.js +30 -0
- package/dist/digest/known.js +28 -0
- package/dist/digest/sources.js +155 -0
- package/dist/digest/sync-health.js +158 -0
- package/dist/digest/task-proposals.js +67 -0
- package/dist/digest/tasks.js +145 -0
- package/dist/digest/text.js +49 -0
- package/dist/discovery/command.js +107 -0
- package/dist/doctor/command.js +167 -0
- package/dist/documents/command.js +107 -0
- package/dist/domain-lists/command.js +13 -0
- package/dist/events/command.js +35 -0
- package/dist/events/events.js +196 -0
- package/dist/examples.js +609 -0
- package/dist/facts/command.js +100 -0
- package/dist/facts/fact.js +54 -0
- package/dist/facts/facts.js +15 -0
- package/dist/failure.js +58 -0
- package/dist/finance/command.js +121 -0
- package/dist/finance/contracts-command.js +109 -0
- package/dist/finance/deal-text.js +34 -0
- package/dist/finance/deals-command.js +346 -0
- package/dist/finance/finance.js +129 -0
- package/dist/finance/lines-command.js +70 -0
- package/dist/finance/orders-command.js +94 -0
- package/dist/finance/products-command.js +98 -0
- package/dist/finance/subscriptions-command.js +152 -0
- package/dist/finance/transactions-command.js +136 -0
- package/dist/finance/wallets-command.js +105 -0
- package/dist/finance/written.js +36 -0
- package/dist/findings/command.js +102 -0
- package/dist/findings-input.js +23 -0
- package/dist/identity.js +20 -0
- package/dist/install/postinstall.js +47 -0
- package/dist/json-fields.js +48 -0
- package/dist/knowledge/business-text.js +19 -0
- package/dist/knowledge/command.js +435 -0
- package/dist/knowledge/document-context.js +33 -0
- package/dist/knowledge/key-documents.js +120 -0
- package/dist/knowledge/list-queries.js +20 -0
- package/dist/knowledge/meeting-projects-command.js +61 -0
- package/dist/knowledge/messenger-sync.js +253 -0
- package/dist/knowledge/money-text.js +16 -0
- package/dist/knowledge/notes-about.js +81 -0
- package/dist/knowledge/organization-delete-command.js +44 -0
- package/dist/knowledge/organization-text.js +27 -0
- package/dist/knowledge/project-actions-command.js +130 -0
- package/dist/knowledge/project-actions.js +104 -0
- package/dist/knowledge/project-activity-command.js +70 -0
- package/dist/knowledge/project-context.js +101 -0
- package/dist/knowledge/project-findings.js +41 -0
- package/dist/knowledge/project-gather-command.js +100 -0
- package/dist/knowledge/project-status-command.js +129 -0
- package/dist/knowledge/project-transfer-command.js +58 -0
- package/dist/knowledge/project-transfer.js +107 -0
- package/dist/knowledge/relationships-scan.js +116 -0
- package/dist/knowledge/relationships.js +115 -0
- package/dist/knowledge/roles-command.js +67 -0
- package/dist/mail/command.js +20 -0
- package/dist/mail/findings-command.js +143 -0
- package/dist/mail/findings-duplicates.js +159 -0
- package/dist/mail/messages-command.js +77 -0
- package/dist/mail/review-command.js +59 -0
- package/dist/mail/subscriptions-command.js +84 -0
- package/dist/mcp/catalogue.js +159 -0
- package/dist/mcp/command.js +125 -0
- package/dist/mcp/granted.js +18 -0
- package/dist/mcp/permissions.js +61 -0
- package/dist/mcp/server.js +128 -0
- package/dist/meetings/command.js +31 -0
- package/dist/meetings/list-command.js +59 -0
- package/dist/meetings/preparation-command.js +42 -0
- package/dist/meetings/preparation-text.js +44 -0
- package/dist/meetings/preparation.js +50 -0
- package/dist/meetings/read.js +32 -0
- package/dist/memories/command.js +105 -0
- package/dist/memories/memories.js +17 -0
- package/dist/memories/memory.js +89 -0
- package/dist/memories/sources.js +111 -0
- package/dist/mentions/command.js +91 -0
- package/dist/migrate/check.js +48 -0
- package/dist/migrate/from-memo.js +345 -0
- package/dist/migrate/skill.js +35 -0
- package/dist/models/command.js +19 -0
- package/dist/options.js +35 -0
- package/dist/output.js +17 -0
- package/dist/page.js +14 -0
- package/dist/people/command.js +144 -0
- package/dist/people/delete-command.js +53 -0
- package/dist/people/doubts-command.js +81 -0
- package/dist/people/identities-command.js +188 -0
- package/dist/people/identity.js +42 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/proposal-rows.js +70 -0
- package/dist/people/proposals-command.js +248 -0
- package/dist/people/review-context.js +108 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +875 -0
- package/dist/read-only.js +51 -0
- package/dist/reasons.js +368 -0
- package/dist/records/import.js +135 -0
- package/dist/records/input.js +210 -0
- package/dist/records/mapping.js +80 -0
- package/dist/records/record-commands.js +125 -0
- package/dist/records/sources.js +73 -0
- package/dist/refs.js +28 -0
- package/dist/review/command.js +171 -0
- package/dist/review/kinds.js +44 -0
- package/dist/review/review.js +299 -0
- package/dist/review/status.js +93 -0
- package/dist/rows.js +219 -0
- package/dist/run/auto.js +237 -0
- package/dist/run/entry.js +62 -0
- package/dist/run/files.js +51 -0
- package/dist/run/import.js +253 -0
- package/dist/run/lock.js +20 -0
- package/dist/save-help.js +3 -0
- package/dist/schedule/command.js +58 -0
- package/dist/schedule/mail-triage-input.js +152 -0
- package/dist/schedule/task-triage-input.js +152 -0
- package/dist/search/answers.js +176 -0
- package/dist/search/command.js +257 -0
- package/dist/search/denied.js +9 -0
- package/dist/search/embed.js +126 -0
- package/dist/search/hits.js +4 -0
- package/dist/search/lane-gates.js +76 -0
- package/dist/search/notes-text.js +18 -0
- package/dist/search/people.js +88 -0
- package/dist/search/search.js +306 -0
- package/dist/show/command.js +179 -0
- package/dist/store/crm-viewer.js +102 -0
- package/dist/store/group.js +112 -0
- package/dist/store/groups-command.js +136 -0
- package/dist/store/guard.js +94 -0
- package/dist/store/held.js +21 -0
- package/dist/store/info-command.js +37 -0
- package/dist/store/scope.js +53 -0
- package/dist/store/source-list.js +222 -0
- package/dist/store/source-target.js +28 -0
- package/dist/tags/command.js +176 -0
- package/dist/tasks/command.js +174 -0
- package/dist/tasks/context.js +74 -0
- package/dist/tasks/list.js +199 -0
- package/dist/tasks/proposal-duplicates.js +70 -0
- package/dist/tasks/relations-command.js +28 -0
- package/dist/tasks/shared.js +105 -0
- package/dist/tasks/tasks.js +197 -0
- package/dist/templates/command.js +18 -0
- package/dist/terminal.js +23 -0
- package/dist/update.js +35 -0
- package/dist/version.js +2 -0
- package/dist/vocabulary/command.js +103 -0
- package/dist/vocabulary/inspect.js +23 -0
- package/dist/vocabulary/inspection.js +18 -0
- package/dist/vocabulary/list.js +18 -0
- package/dist/vocabulary/project.js +19 -0
- package/dist/wcat.js +3 -0
- package/install/postinstall.mjs +9 -0
- package/package.json +89 -4
- package/scenarios/decision-trail.md +21 -0
- package/scenarios/person-brief.md +35 -0
- package/scenarios/prepare-meeting.md +17 -0
- package/scenarios/project-state.md +26 -0
- package/scenarios/set-up.md +18 -0
- package/scenarios/start-the-day.md +19 -0
- package/skills/mail-triage/SKILL.md +208 -0
- package/skills/morning-digest/SKILL.md +147 -0
- package/skills/task-triage/SKILL.md +79 -0
- package/skills/wcat/SKILL.md +65 -0
- package/skills/wcat/topics/mail.md +32 -0
- package/skills/wcat/topics/mcp.md +22 -0
- package/skills/wcat/topics/meetings.md +37 -0
- package/skills/wcat/topics/money.md +52 -0
- package/skills/wcat/topics/projects.md +54 -0
- package/skills/wcat/topics/proposals.md +113 -0
- package/skills/wcat/topics/search.md +85 -0
- package/skills/wcat/topics/vocabulary.md +8 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { MAX_NEXT_STEPS, stepOf } from "@wirecat/cli-base/standards";
|
|
2
|
+
import { allHitItem, coverageGaps, harderRanking, kindIn, messageHitItem, noteHitItem, } from "@wirecat/cli-core";
|
|
3
|
+
import { listAnswer } from "../answer.js";
|
|
4
|
+
import { briefHit } from "./hits.js";
|
|
5
|
+
const named = (accounts) => [
|
|
6
|
+
...new Set(accounts.map(({ provider, account }) => `${provider}:${account}`)),
|
|
7
|
+
];
|
|
8
|
+
/** A source the search could not read is an issue, as in cli-core's searches; the sentence goes to a person. */
|
|
9
|
+
const metaOf = (accounts, skipped = [], heldInPart = false) => {
|
|
10
|
+
const issues = skipped.map((one) => ({
|
|
11
|
+
code: one.code,
|
|
12
|
+
// The output standard takes a dotted reason only, as cli-core's search all does.
|
|
13
|
+
...(one.why && /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/u.test(one.why) ? { reason: one.why } : {}),
|
|
14
|
+
source: one.source ?? one.resource ?? "",
|
|
15
|
+
}));
|
|
16
|
+
return {
|
|
17
|
+
accounts: named(accounts),
|
|
18
|
+
...(heldInPart ? { complete: false } : {}),
|
|
19
|
+
...(issues.length ? { issues } : {}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/** Meaning not searched because the model is missing is a gap; `--exact` leaving it out is not. */
|
|
23
|
+
const meaningMissed = (why, exact = false) => why === undefined || exact ? [] : [{ field: "found_by", why }];
|
|
24
|
+
/** wcat has no `conversations rebuild`: the messenger CLI that imported the messages gives them their vectors. */
|
|
25
|
+
export const messagesMeaningNote = ({ reason, step, model }) => `Messages by words only: ${reason}${step === "models.download"
|
|
26
|
+
? ` — \`wcat models download ${model}\`, then the messenger's \`conversations rebuild\` gives messages their vectors`
|
|
27
|
+
: step === "conversations.rebuild"
|
|
28
|
+
? " — the messenger's `conversations rebuild` (tg, max, wa) gives messages their vectors"
|
|
29
|
+
: ""}`;
|
|
30
|
+
/** wcat has no calendar sync: gcal's `sync --embed` gives events their vectors. */
|
|
31
|
+
export const eventsMeaningNote = (reason) => `Events by words only: ${reason}${reason.startsWith("no event has vectors") ? " — gcal <profile> sync --embed gives events their vectors" : ""}`;
|
|
32
|
+
const messagesMeaningMissed = (meaning) => meaning === undefined ? [] : [{ field: "found_by", why: messagesMeaningNote(meaning) }];
|
|
33
|
+
const TASKS_OF_HIT = {
|
|
34
|
+
id: "hit.tasks",
|
|
35
|
+
kind: "command",
|
|
36
|
+
command: "tasks list",
|
|
37
|
+
args: [
|
|
38
|
+
{ name: "query", required: true },
|
|
39
|
+
{ name: "source", required: true },
|
|
40
|
+
],
|
|
41
|
+
why: "{count} open tasks point at this result",
|
|
42
|
+
};
|
|
43
|
+
const MEETING_PASSAGE = {
|
|
44
|
+
id: "hit.passage",
|
|
45
|
+
kind: "command",
|
|
46
|
+
command: "meetings passage",
|
|
47
|
+
args: [
|
|
48
|
+
{ name: "reference", required: true },
|
|
49
|
+
{ name: "source", required: true },
|
|
50
|
+
],
|
|
51
|
+
why: "read the lines around this meeting hit before citing it",
|
|
52
|
+
};
|
|
53
|
+
const MEETINGS_INDEX = {
|
|
54
|
+
id: "meetings.index",
|
|
55
|
+
kind: "command",
|
|
56
|
+
command: "search meetings",
|
|
57
|
+
args: [
|
|
58
|
+
{ name: "query", required: true },
|
|
59
|
+
{ name: "source", required: true },
|
|
60
|
+
],
|
|
61
|
+
why: "builds {source}'s meeting search index, then finds what search all could not yet",
|
|
62
|
+
};
|
|
63
|
+
const pendingMeetings = (found) => (found.meetings ?? []).filter(({ indexing }) => indexing === "pending");
|
|
64
|
+
/** Meeting accounts search all could not read, and those whose index is behind: `search meetings` builds it. */
|
|
65
|
+
const meetingsMissed = (found) => [
|
|
66
|
+
...pendingMeetings(found).map(({ provider, account }) => ({
|
|
67
|
+
field: "items",
|
|
68
|
+
why: `${provider}:${account}: meetings saved since its search index was last built are not found yet`,
|
|
69
|
+
step: MEETINGS_INDEX.id,
|
|
70
|
+
})),
|
|
71
|
+
// A kind `--source` named no account of was left out on purpose: `meta.issues` lists it, `missing` does not.
|
|
72
|
+
...found.skipped
|
|
73
|
+
.filter(({ resource, source, code }) => resource === undefined
|
|
74
|
+
? kindIn(source.split(":")[0] ?? "") === "meetings"
|
|
75
|
+
: resource === "meetings" && code !== "not_found")
|
|
76
|
+
.map(({ resource, source, reason }) => ({ field: "items", why: `${source ?? resource} not searched: ${reason}` })),
|
|
77
|
+
];
|
|
78
|
+
/** What `--harder` did, for a person: reordered and at what cost, or the plain order and why. */
|
|
79
|
+
export const harderNote = (found) => found.harderSkipped !== undefined
|
|
80
|
+
? `not reordered by the model: ${found.harderSkipped}`
|
|
81
|
+
: found.harder === undefined
|
|
82
|
+
? undefined
|
|
83
|
+
: found.harder.applied
|
|
84
|
+
? `reordered by ${found.harder.provider} ${found.harder.model} (${found.harder.sent} hits sent, ` +
|
|
85
|
+
`${found.harder.cost_usd === null ? "cost unknown" : `$${found.harder.cost_usd}`}, ${found.harder.ms} ms)`
|
|
86
|
+
: `not reordered by the model: ${found.harder.reason}`;
|
|
87
|
+
/**
|
|
88
|
+
* `search all`, CLI and MCP alike. A hit that open tasks point at gets a step listing them, and a meeting transcript
|
|
89
|
+
* hit one opening its passage; the answer keeps the first two.
|
|
90
|
+
*/
|
|
91
|
+
export const allAnswer = (found, limit, exact = false,
|
|
92
|
+
/** Kinds the permissions kept out of the search, each with why. */
|
|
93
|
+
leftOut = []) => {
|
|
94
|
+
const archive = coverageGaps({ coverage: found.coverage }, found.items.length);
|
|
95
|
+
const next = found.items.flatMap((item) => {
|
|
96
|
+
// `meetings passage` opens a transcript cue only; a chat or summary hit's excerpt is all there is to open.
|
|
97
|
+
const passage = item.kind === "meeting" && item.cueRef !== undefined
|
|
98
|
+
? [stepOf(MEETING_PASSAGE, { args: { reference: item.cueRef, source: `${item.provider}:${item.account}` } })]
|
|
99
|
+
: [];
|
|
100
|
+
const tasks = found.tasks.filter((task) => task.source === item.ref);
|
|
101
|
+
const held = tasks[0]?.heldBy;
|
|
102
|
+
if (held === undefined)
|
|
103
|
+
return passage;
|
|
104
|
+
return [
|
|
105
|
+
stepOf(TASKS_OF_HIT, {
|
|
106
|
+
args: { query: `source:"${item.ref}"`, source: `${held.provider}:${held.account}` },
|
|
107
|
+
values: { count: tasks.length },
|
|
108
|
+
}),
|
|
109
|
+
...passage,
|
|
110
|
+
];
|
|
111
|
+
});
|
|
112
|
+
const indexing = pendingMeetings(found).map(({ provider, account }) => stepOf(MEETINGS_INDEX, {
|
|
113
|
+
args: { query: found.query, source: `${provider}:${account}` },
|
|
114
|
+
values: { source: `${provider}:${account}` },
|
|
115
|
+
}));
|
|
116
|
+
// What fills a gap in the answer goes before what reads one hit further.
|
|
117
|
+
const steps = [...archive.next, ...indexing, ...next].slice(0, MAX_NEXT_STEPS);
|
|
118
|
+
return listAnswer("search all", {
|
|
119
|
+
items: found.items.map(allHitItem),
|
|
120
|
+
limit,
|
|
121
|
+
has_more: found.hasMore,
|
|
122
|
+
...(steps.length ? { next: steps } : {}),
|
|
123
|
+
missing: [
|
|
124
|
+
...meetingsMissed(found),
|
|
125
|
+
...leftOut.map(({ why }) => ({ field: "items", why })),
|
|
126
|
+
...archive.missing,
|
|
127
|
+
...meaningMissed(found.notes?.meaningSkipped, exact),
|
|
128
|
+
...messagesMeaningMissed(found.messages?.meaningSkipped),
|
|
129
|
+
...(found.events?.meaningSkipped === undefined || exact
|
|
130
|
+
? []
|
|
131
|
+
: [{ field: "found_by", why: eventsMeaningNote(found.events.meaningSkipped) }]),
|
|
132
|
+
...(found.unmatched && !found.items.length
|
|
133
|
+
? [
|
|
134
|
+
{
|
|
135
|
+
field: "items",
|
|
136
|
+
why: `every word must be in one record, and nothing in ${found.searched.join(", ")} holds ${found.unmatched.map((word) => `"${word}"`).join(", ")}`,
|
|
137
|
+
},
|
|
138
|
+
]
|
|
139
|
+
: []),
|
|
140
|
+
...((found.harder && !found.harder.applied) || found.harderSkipped !== undefined
|
|
141
|
+
? [{ field: "order", why: harderNote(found) }]
|
|
142
|
+
: []),
|
|
143
|
+
],
|
|
144
|
+
meta: {
|
|
145
|
+
...metaOf(found.accounts, found.skipped, archive.missing.length > 0),
|
|
146
|
+
...(found.harder ? { ranking: harderRanking(found.harder) } : {}),
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
/** `search messages` and `search mail`, CLI and MCP alike: each hit the `message.hit` view, `brief` cut shorter. */
|
|
151
|
+
export const kindAnswer = (kind, found, limit, level, query = "") => {
|
|
152
|
+
const archive = coverageGaps(found, found.items.length);
|
|
153
|
+
return listAnswer(`search ${kind}`, {
|
|
154
|
+
items: found.items.map((item) => level === "brief" ? briefHit(messageHitItem(item, query)) : messageHitItem(item, query)),
|
|
155
|
+
limit,
|
|
156
|
+
has_more: found.hasMore,
|
|
157
|
+
...(found.total ? { total: found.total } : {}),
|
|
158
|
+
...(archive.next.length ? { next: archive.next } : {}),
|
|
159
|
+
missing: [
|
|
160
|
+
...archive.missing,
|
|
161
|
+
...(found.wordsReady ? [] : [{ field: "text", why: "the word index is still being built" }]),
|
|
162
|
+
],
|
|
163
|
+
meta: metaOf(found.coverage?.accounts ?? found.accounts ?? [], found.skipped, archive.missing.length > 0),
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
/** `search notes`, CLI and MCP alike; `args` reruns the same search for the next page. */
|
|
167
|
+
export const notesAnswer = (found, limit, page, args = {}) => listAnswer("search notes", {
|
|
168
|
+
items: found.items.map(noteHitItem),
|
|
169
|
+
limit,
|
|
170
|
+
has_more: found.hasMore && found.nextOffset !== undefined,
|
|
171
|
+
page,
|
|
172
|
+
...(found.total ? { total: found.total } : {}),
|
|
173
|
+
args,
|
|
174
|
+
missing: meaningMissed(found.meaning_skipped, args.exact === true),
|
|
175
|
+
});
|
|
176
|
+
//# sourceMappingURL=answers.js.map
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate, customizeSharedCommand } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { parseLucene } from "@wirecat/cli-base/query";
|
|
4
|
+
import { environmentOf, LOCAL_READ, levelFor, RESOURCES_SEARCHED, sharedCommandTemplate, shownOf, } from "@wirecat/cli-core";
|
|
5
|
+
import { hitText } from "@wirecat/cli-core/mail";
|
|
6
|
+
import { InvalidArgumentError } from "commander";
|
|
7
|
+
import { answers, shortenedBy, withStore } from "../answer.js";
|
|
8
|
+
import { APP } from "../app.js";
|
|
9
|
+
import { whoRuns } from "../author.js";
|
|
10
|
+
import { SHELL_OVERRIDES } from "../contract-overrides.js";
|
|
11
|
+
import { memoLevels } from "../mcp/permissions.js";
|
|
12
|
+
import { searchMemoriesCommand } from "../memories/command.js";
|
|
13
|
+
import { positive } from "../options.js";
|
|
14
|
+
import { SAVE_HELP } from "../save-help.js";
|
|
15
|
+
import { crmNotes } from "../store/crm-viewer.js";
|
|
16
|
+
import { accountsByKind, groupScopeOf } from "../store/group.js";
|
|
17
|
+
import { ACCOUNTS_HELP, MAIL_SOURCES, mailboxesOf } from "../store/source-list.js";
|
|
18
|
+
import { allAnswer, eventsMeaningNote, harderNote, kindAnswer, messagesMeaningNote, notesAnswer } from "./answers.js";
|
|
19
|
+
import { deniedCrm } from "./denied.js";
|
|
20
|
+
import { lanesFor } from "./lane-gates.js";
|
|
21
|
+
import { searchText } from "./notes-text.js";
|
|
22
|
+
import { peopleAnswer, peopleText, searchPeople } from "./people.js";
|
|
23
|
+
import { hasSource, keyDocumentsFirst, searchEverywhere, searchKind, searchNotes } from "./search.js";
|
|
24
|
+
/** `search messages` takes no `--source`; in a group it reads the group's messenger accounts only. */
|
|
25
|
+
const groupMessengers = async (store, env, text) => {
|
|
26
|
+
const scope = await groupScopeOf(store, env);
|
|
27
|
+
if (scope === undefined)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (hasSource(parseLucene(text).root))
|
|
30
|
+
throw new CliError("validation_error", `in group ${scope.run.name} search messages reads the group's accounts — leave in: out of the query`);
|
|
31
|
+
const { messages } = accountsByKind(scope);
|
|
32
|
+
if (messages.length === 0)
|
|
33
|
+
throw new CliError("not_found", `group ${scope.run.name} holds no messenger account`);
|
|
34
|
+
return messages;
|
|
35
|
+
};
|
|
36
|
+
const ONLY = RESOURCES_SEARCHED;
|
|
37
|
+
const onlyOf = (value) => {
|
|
38
|
+
const selected = value.split(",").map((part) => part.trim());
|
|
39
|
+
if (!selected.length || selected.some((part) => !ONLY.includes(part)))
|
|
40
|
+
throw new InvalidArgumentError(`choose ${ONLY.join(",")}, separated by commas`);
|
|
41
|
+
return [...new Set(selected)];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A meeting hit is only useful opened, so search all reads meetings only where searching and opening them both go
|
|
45
|
+
* ahead unasked: `ask` would have stopped either command, so it keeps them out too.
|
|
46
|
+
*/
|
|
47
|
+
const MEETING_KEYS = ["search.meetings", "meetings.passage"];
|
|
48
|
+
const READS = new Set(["allow", "readonly"]);
|
|
49
|
+
const meetingsDenied = (command, env) => {
|
|
50
|
+
const levels = memoLevels(env, environmentOf(command).agent?.overrides ?? []);
|
|
51
|
+
for (const key of MEETING_KEYS) {
|
|
52
|
+
const { level } = levelFor(levels, key);
|
|
53
|
+
if (!READS.has(level))
|
|
54
|
+
return { why: `meetings left out: the permissions set ${key} to ${level}` };
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
58
|
+
const levelOf = ({ brief, full }) => {
|
|
59
|
+
if (brief && full)
|
|
60
|
+
throw new CliError("validation_error", "--brief and --full ask for opposite things — pick one");
|
|
61
|
+
return brief ? "brief" : full ? "full" : undefined;
|
|
62
|
+
};
|
|
63
|
+
const PROJECT_HELP = "rank the key documents of this project (id, project:<id>, key, exact name or alias) first, labelled key; " +
|
|
64
|
+
"nothing is left out";
|
|
65
|
+
const PROJECT_ORDER_HELP = "rank the key documents of this project (id, project:<id>, key, exact name or alias) first; nothing is left out";
|
|
66
|
+
const searchCommandDefinition = (program, streams, env) => {
|
|
67
|
+
const group = program
|
|
68
|
+
.command("search")
|
|
69
|
+
.description("search messages, mail, notes, memories and people; search all when unsure where");
|
|
70
|
+
const { print } = answers(group, streams, env);
|
|
71
|
+
const queryOptions = (leaf) => leaf
|
|
72
|
+
.addHelpText("after", SAVE_HELP)
|
|
73
|
+
.argument("<query...>", "words, phrases, Boolean operators and field queries")
|
|
74
|
+
.option("--limit <n>", "most results, at most 100", (value) => {
|
|
75
|
+
const limit = positive(value);
|
|
76
|
+
if (limit > 100)
|
|
77
|
+
throw new InvalidArgumentError("at most 100");
|
|
78
|
+
return limit;
|
|
79
|
+
}, 20)
|
|
80
|
+
.option("--exact", "words as written; skip meaning search")
|
|
81
|
+
.option("--timezone <zone>", "IANA timezone for calendar date boundaries")
|
|
82
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields");
|
|
83
|
+
queryOptions(annotate(group.command("all"), { effects: LOCAL_READ, output: { entity: "hit" } })
|
|
84
|
+
.description("messages, mail, notes, calendar events, deals, leads, business data, meeting passages from every meeting " +
|
|
85
|
+
"account and tracker issues and projects, ranked together; not people, memories, wcat's projects or " +
|
|
86
|
+
"decisions. A kind you know reads better with its own search, with all its fields")
|
|
87
|
+
.summary("messages, mail, notes, events, deals, meetings and issues ranked together"))
|
|
88
|
+
.option("--only <resources>", `${ONLY.join(",")}, separated by commas`, onlyOf)
|
|
89
|
+
.option("--source <accounts>", "only these accounts, separated by commas: provider:account as a hit shows it, a provider, a kind or " +
|
|
90
|
+
"group:<name>; each resource reads the ones of its kind, and one it names none of is left out")
|
|
91
|
+
.option("--plain-order", "best first by the words alone, without moving mail from suspicious senders down")
|
|
92
|
+
.option("--harder", "a hosted model reorders the first 30 hits; sends the question and those hits to the provider you chose with " +
|
|
93
|
+
"wcat models search-consents set <provider> --yes, only after that")
|
|
94
|
+
.option("--project <project>", PROJECT_ORDER_HELP)
|
|
95
|
+
.addHelpText("after", `
|
|
96
|
+
content: narrows a search to the text of files, transcript: to voice transcripts, filename: to file names — wcat search all 'content:invoice'.
|
|
97
|
+
Calendar events come from every calendar gcal stored; an event's title, description and place are written by whoever sent the invitation.
|
|
98
|
+
crm finds deals and leads by the words of their title only.
|
|
99
|
+
business finds invoices, payments, orders, contracts, subscriptions, products and wallets by the words of their numbers and names.
|
|
100
|
+
tracker finds issues, projects and comments a tracker CLI such as linear synced; their titles are written by the tracker's users.
|
|
101
|
+
--json: the list is items, each a hit as in tg search all: ref, kind, title, timestamp, excerpt.`)
|
|
102
|
+
.action(async (words, options, command) => {
|
|
103
|
+
const denied = meetingsDenied(command, env);
|
|
104
|
+
const asked = options.only ?? [...RESOURCES_SEARCHED];
|
|
105
|
+
const wanted = denied ? asked.filter((one) => one !== "meetings") : options.only;
|
|
106
|
+
if (wanted?.length === 0)
|
|
107
|
+
throw new CliError("permission_error", `search all has nothing it may read: ${denied?.why}`, {
|
|
108
|
+
reason: "search.all-denied",
|
|
109
|
+
});
|
|
110
|
+
const leftOut = denied ? [denied] : [];
|
|
111
|
+
// The owner at a terminal reads everything (#739); any other run, an agent's shell included, follows the saved
|
|
112
|
+
// CRM permissions as the contexts do.
|
|
113
|
+
const owner = (await whoRuns(command, env, { question: "search all" })) === "owner";
|
|
114
|
+
const gate = lanesFor(command, wanted, owner ? [] : deniedCrm(command, env));
|
|
115
|
+
const answer = await withStore(env, async (store) => {
|
|
116
|
+
const found = await searchEverywhere(store, env, {
|
|
117
|
+
text: words.join(" "),
|
|
118
|
+
limit: options.limit,
|
|
119
|
+
...(gate.only === undefined ? {} : { only: gate.only }),
|
|
120
|
+
...(gate.shows === undefined ? {} : { shows: gate.shows }),
|
|
121
|
+
...(gate.crmKinds === undefined ? {} : { crmKinds: gate.crmKinds }),
|
|
122
|
+
...(options.source === undefined ? {} : { source: options.source }),
|
|
123
|
+
...(options.exact ? { exact: true } : {}),
|
|
124
|
+
...(options.plainOrder ? { plainOrder: true } : {}),
|
|
125
|
+
...(options.harder ? { harder: true } : {}),
|
|
126
|
+
...(options.timezone === undefined ? {} : { timezone: options.timezone }),
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
...found,
|
|
130
|
+
skipped: [...gate.skipped, ...found.skipped],
|
|
131
|
+
items: await keyDocumentsFirst(store, found.items, options.project),
|
|
132
|
+
crmNotes: crmNotes(store),
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
if (!options.json) {
|
|
136
|
+
for (const { why } of leftOut)
|
|
137
|
+
streams.diagnostic(`${why}\n`);
|
|
138
|
+
streams.diagnostic(`searched: ${answer.accounts.map(({ provider, account }) => `${provider}:${account}`).join(", ") || "nothing"}\n`);
|
|
139
|
+
for (const skipped of answer.skipped)
|
|
140
|
+
streams.diagnostic(`${skipped.resource ?? skipped.source} not searched: ${skipped.reason}\n`);
|
|
141
|
+
if (answer.notes?.meaningSkipped)
|
|
142
|
+
streams.diagnostic(`Notes by words only: ${answer.notes.meaningSkipped}\n`);
|
|
143
|
+
if (answer.events?.meaningSkipped)
|
|
144
|
+
streams.diagnostic(`${eventsMeaningNote(answer.events.meaningSkipped)}\n`);
|
|
145
|
+
if (answer.messages?.meaningSkipped)
|
|
146
|
+
streams.diagnostic(`${messagesMeaningNote(answer.messages.meaningSkipped)}\n`);
|
|
147
|
+
const harder = harderNote(answer);
|
|
148
|
+
if (harder)
|
|
149
|
+
streams.diagnostic(`${harder}\n`);
|
|
150
|
+
}
|
|
151
|
+
print(options.json, shortenedBy(answer.crmNotes, allAnswer(answer, options.limit, options.exact, leftOut)), [
|
|
152
|
+
...answer.items.map((item) => `${"key" in item ? "key " : ""}${item.kind} ${item.ref}\n ${item.text}`),
|
|
153
|
+
...answer.tasks.map((task) => `task task:${task.id} ${task.kind} ${task.source}`),
|
|
154
|
+
].join("\n"));
|
|
155
|
+
});
|
|
156
|
+
for (const kind of ["messages", "mail"]) {
|
|
157
|
+
const one = kind === "mail" ? "email" : "message";
|
|
158
|
+
const leaf = queryOptions(annotate(group.command(kind), { effects: LOCAL_READ, output: { entity: "message", view: "hit" } }).description(kind === "mail" ? "imported emails only" : "stored messenger messages only"))
|
|
159
|
+
.option("--brief", `each ${one} as reference, time, sender and excerpt only`)
|
|
160
|
+
.option("--full", `each ${one} with its whole text; --json still gives the excerpt`);
|
|
161
|
+
if (kind === "mail")
|
|
162
|
+
leaf
|
|
163
|
+
.option("--source <accounts>", `the mailboxes to search (default: every one): ${MAIL_SOURCES}`)
|
|
164
|
+
.option("--plain-order", "best first by the words alone, without moving mail from suspicious senders down");
|
|
165
|
+
leaf.addHelpText("after", kind === "messages"
|
|
166
|
+
? `
|
|
167
|
+
content: narrows a search to the text of files, transcript: to voice transcripts, filename: to file names — wcat search messages
|
|
168
|
+
'content:invoice'. Compare it with tg search messages 'content:invoice', a plain word with a plain word.
|
|
169
|
+
has:voice, has:file or NOT has:attachment keeps voice messages, files or plain text — wcat search messages 'friday has:voice'.
|
|
170
|
+
A question finds messages holding some of its words, and a short reply by the message it answers — wcat search messages
|
|
171
|
+
'when is the price sync?'. Plain words must all be in the message; --exact keeps a question to that too.
|
|
172
|
+
--json: the list is items, each a hit as in tg search messages: ref (msg:…), timestamp, sender_name, excerpt.
|
|
173
|
+
For an agent: read with --compact, one line per hit with its reference. Never write message text to a file.`
|
|
174
|
+
: `
|
|
175
|
+
content: narrows a search to the text of attachments, filename: to their names — wcat search mail 'content:invoice'.
|
|
176
|
+
Mail sent to many is in the mailbox bulk; NOT mailbox:bulk leaves it out, and bills and bookings with it.
|
|
177
|
+
Mail from senders with signs of fraud (mail <profile> account inspect) comes after the rest of the page; --plain-order keeps it in place.
|
|
178
|
+
--json: the list is items, each a hit as in tg search mail: ref (msg:email/…), timestamp, email, excerpt.
|
|
179
|
+
For an agent: read with --compact, one line per hit with its reference. Never write mail text to a file.`);
|
|
180
|
+
leaf.action(async (words, options) => {
|
|
181
|
+
const level = levelOf(options);
|
|
182
|
+
const text = words.join(" ");
|
|
183
|
+
const answer = await withStore(env, async (store) => {
|
|
184
|
+
const mailboxes = options.source !== undefined
|
|
185
|
+
? await mailboxesOf(store, env, options.source)
|
|
186
|
+
: kind === "messages"
|
|
187
|
+
? await groupMessengers(store, env, text)
|
|
188
|
+
: undefined;
|
|
189
|
+
return searchKind(store, kind, {
|
|
190
|
+
text,
|
|
191
|
+
limit: options.limit,
|
|
192
|
+
...(mailboxes === undefined ? {} : { accounts: mailboxes }),
|
|
193
|
+
...(options.exact ? { exact: true } : {}),
|
|
194
|
+
...(options.plainOrder ? { plainOrder: true } : {}),
|
|
195
|
+
...(options.timezone === undefined ? {} : { timezone: options.timezone }),
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
print(options.json, kindAnswer(kind, answer, options.limit, level, words.join(" ")), [
|
|
199
|
+
...answer.items.map((item) => hitText(item, level)),
|
|
200
|
+
...[shownOf(answer.items.length, 0, answer.total)].filter((line) => line !== undefined),
|
|
201
|
+
].join("\n"));
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
queryOptions(annotate(group.command("notes"), { effects: LOCAL_READ, output: { entity: "note", view: "hit" } }).description("native notes by words and, with the local model, meaning"))
|
|
205
|
+
.addHelpText("after", "\nsource:internal keeps the notes written in wcat, source:file the notes from a folder — 'budget source:internal'." +
|
|
206
|
+
"\n--source notes:<folder id> is different: it chooses which notes accounts are read." +
|
|
207
|
+
"\nFields in the query or in --filter (tag:, date:) hold for every hit, found by words or by meaning; a query of" +
|
|
208
|
+
"\nfields alone lists the matching notes, newest first — 'budget tag:work', 'date:today'." +
|
|
209
|
+
"\n--json: each note's reference is ref (note: or document:).")
|
|
210
|
+
.option("--filter <query>", "another query every note must match")
|
|
211
|
+
.option("--source <accounts>", "only these notes accounts, separated by commas: notes:internal for notes written in wcat, notes:<folder id> " +
|
|
212
|
+
"as a hit shows it, notes or group:<name>")
|
|
213
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
214
|
+
.option("--project <project>", PROJECT_HELP)
|
|
215
|
+
.action(async (words, options) => {
|
|
216
|
+
const answer = await withStore(env, (store) => searchNotes(store, env, words.join(" "), options));
|
|
217
|
+
if (answer.meaning_skipped && !options.json)
|
|
218
|
+
streams.diagnostic(`Searched by words only: ${answer.meaning_skipped}\n`);
|
|
219
|
+
for (const { source, reason } of answer.skipped)
|
|
220
|
+
streams.diagnostic(`${source} not searched: ${reason}\n`);
|
|
221
|
+
const { limit, page, json, ...rest } = options;
|
|
222
|
+
print(json, notesAnswer(answer, limit, page, { query: words.join(" "), ...rest }), searchText(answer, (page - 1) * limit));
|
|
223
|
+
});
|
|
224
|
+
searchMemoriesCommand(group, streams, env);
|
|
225
|
+
annotate(group.command("people"), { effects: LOCAL_READ, output: { entity: "person" } })
|
|
226
|
+
.description("people whose name, username or alias holds every word, in every account unless --source narrows it; " +
|
|
227
|
+
"each with its person:<id> for --contact and its identities")
|
|
228
|
+
.summary("people by name across every account")
|
|
229
|
+
.argument("<name...>", "parts of the name, username or alias; case and accents do not matter")
|
|
230
|
+
.option("--source <accounts>", ACCOUNTS_HELP)
|
|
231
|
+
.option("--limit <n>", "most people, at most 100", (value) => {
|
|
232
|
+
const limit = positive(value);
|
|
233
|
+
if (limit > 100)
|
|
234
|
+
throw new InvalidArgumentError("at most 100");
|
|
235
|
+
return limit;
|
|
236
|
+
}, 20)
|
|
237
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
238
|
+
.addHelpText("after", "\n--json: the list is items, each a person: ref (person:<id>, or contact:<provider>/<id> for one never linked)," +
|
|
239
|
+
" name, identities (provider, account, id, name, username, alias) and aliases; meta.accounts names what was read.")
|
|
240
|
+
.action(async (words, options) => {
|
|
241
|
+
const found = await withStore(env, (store) => searchPeople(store, env, words, options));
|
|
242
|
+
if (!options.json)
|
|
243
|
+
streams.diagnostic(`searched: ${found.accounts.map(({ provider, account }) => `${provider}:${account}`).join(", ") || "nothing"}\n`);
|
|
244
|
+
print(options.json, peopleAnswer(found, options.limit), peopleText(found));
|
|
245
|
+
});
|
|
246
|
+
// A source left unread is named in meta.issues; the rest is still the answer, so the search exits 0.
|
|
247
|
+
for (const leaf of group.commands)
|
|
248
|
+
annotate(leaf, { partial: true });
|
|
249
|
+
};
|
|
250
|
+
export const searchCommand = (...args) => customizeSharedCommand(sharedCommandTemplate(APP, "search"), "wcat searches imported accounts, mail and native notes without a live messenger; its scope, ranking and output controls are explicit provider differences.", () => {
|
|
251
|
+
searchCommandDefinition(...args);
|
|
252
|
+
const command = args[0].commands.find((command) => command.name() === "search");
|
|
253
|
+
if (!command)
|
|
254
|
+
throw new Error("search builder did not install its command");
|
|
255
|
+
return command;
|
|
256
|
+
}, SHELL_OVERRIDES.search);
|
|
257
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DEAL_KINDS, deniedKindsOf, environmentOf } from "@wirecat/cli-core";
|
|
2
|
+
import { memoLevels } from "../mcp/permissions.js";
|
|
3
|
+
/**
|
|
4
|
+
* The CRM kinds wcat's permissions deny, an MCP server's `--permission` included: what `search all`, the contexts
|
|
5
|
+
* and `relationships list` leave out (SEC-151).
|
|
6
|
+
*/
|
|
7
|
+
export const deniedCrm = (command, env) => deniedKindsOf(memoLevels(env, environmentOf(command).agent?.overrides ?? []), DEAL_KINDS, "wcat's permissions");
|
|
8
|
+
export const deniedCrmKinds = (command, env) => deniedCrm(command, env).map(({ kind }) => kind);
|
|
9
|
+
//# sourceMappingURL=denied.js.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isCliError } from "@wirecat/cli-base";
|
|
4
|
+
import { chosenTextModel, embedMail as embedMailChunksOf, sharedModelsDirectory, textModels, } from "@wirecat/cli-core";
|
|
5
|
+
import { APP } from "../app.js";
|
|
6
|
+
/** About three chunks a second with e5-small on this laptop (2026-10-06): a run stays near three minutes, under a five-minute timer, and the next resumes. */
|
|
7
|
+
export const EMBED_PER_RUN = 600;
|
|
8
|
+
/** The model EMBED_PER_RUN was measured with; no longer the default, so it is named here. */
|
|
9
|
+
const MEASURED_WITH = "e5-small";
|
|
10
|
+
/** A model of unknown speed is taken to be as slow as EmbeddingGemma, so a timer run still ends in time. */
|
|
11
|
+
const SLOWEST_KNOWN = 2;
|
|
12
|
+
/** The run's bound for the chosen model: a slower model embeds fewer chunks in the same three minutes. */
|
|
13
|
+
export const embedPerRun = (env = process.env) => {
|
|
14
|
+
const models = textModels(env);
|
|
15
|
+
const speed = (id) => models.find((model) => model.id === id)?.chunksPerSecond ?? SLOWEST_KNOWN;
|
|
16
|
+
const ratio = speed(chosenTextModel(env).id) / speed(MEASURED_WITH);
|
|
17
|
+
return Math.max(8, Math.min(EMBED_PER_RUN, Math.round(EMBED_PER_RUN * ratio)));
|
|
18
|
+
};
|
|
19
|
+
/** The model the error names, and the exact command that downloads it. */
|
|
20
|
+
const missingModel = (error, env) => {
|
|
21
|
+
const named = isCliError(error) ? error.details.model : undefined;
|
|
22
|
+
const id = typeof named === "string" ? named : chosenTextModel(env).id;
|
|
23
|
+
return `the ${id} model is not downloaded — wcat models download ${id}`;
|
|
24
|
+
};
|
|
25
|
+
/** Whether the chosen text model is downloaded; an unreadable model choice counts as missing, and doctor names it. */
|
|
26
|
+
export const searchModelPresent = (env) => {
|
|
27
|
+
try {
|
|
28
|
+
const path = join(sharedModelsDirectory("text", env), chosenTextModel(env).id);
|
|
29
|
+
return existsSync(path) && readdirSync(path).length > 0;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const isMissingModel = (error) => isCliError(error) && error.details.reason === "model.not-downloaded";
|
|
36
|
+
const reportOf = (run) => {
|
|
37
|
+
if (run === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
if (!("provider" in run))
|
|
40
|
+
return {
|
|
41
|
+
status: "failed",
|
|
42
|
+
sent: 0,
|
|
43
|
+
enriched: 0,
|
|
44
|
+
failed: 0,
|
|
45
|
+
left: 0,
|
|
46
|
+
inputTokens: 0,
|
|
47
|
+
outputTokens: 0,
|
|
48
|
+
costUsd: 0,
|
|
49
|
+
reason: run.reason,
|
|
50
|
+
reasonId: run.reason_id,
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
status: run.status,
|
|
54
|
+
provider: run.provider,
|
|
55
|
+
model: run.model,
|
|
56
|
+
sent: run.enriched + run.failed,
|
|
57
|
+
enriched: run.enriched,
|
|
58
|
+
failed: run.failed,
|
|
59
|
+
left: run.left,
|
|
60
|
+
inputTokens: run.usage.input,
|
|
61
|
+
outputTokens: run.usage.output,
|
|
62
|
+
costUsd: run.cost_usd,
|
|
63
|
+
...(run.reason === undefined ? {} : { reason: run.reason }),
|
|
64
|
+
...(run.reason_id === undefined ? {} : { reasonId: run.reason_id }),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* One sync's enrichment parts (files sync's notes, wcat's mail) as one block: sums, and the reason of the worse part. It is `failed` only when
|
|
69
|
+
* nothing came back enriched, so mail enriched beside failed notes still reads `stopped`.
|
|
70
|
+
*/
|
|
71
|
+
export const combinedEnrichment = (...parts) => {
|
|
72
|
+
const present = parts.filter((part) => part !== undefined);
|
|
73
|
+
if (present.length === 0)
|
|
74
|
+
return undefined;
|
|
75
|
+
const rank = { done: 0, stopped: 1, failed: 2 };
|
|
76
|
+
const worst = present.reduce((a, b) => (rank[b.status] > rank[a.status] ? b : a));
|
|
77
|
+
const enriched = present.reduce((sum, part) => sum + part.enriched, 0);
|
|
78
|
+
const status = worst.status === "failed" && enriched > 0 ? "stopped" : worst.status;
|
|
79
|
+
const named = present.find((part) => part.provider !== undefined);
|
|
80
|
+
const costs = present.map((part) => part.costUsd);
|
|
81
|
+
return {
|
|
82
|
+
status,
|
|
83
|
+
...(named?.provider === undefined ? {} : { provider: named.provider }),
|
|
84
|
+
...(named?.model === undefined ? {} : { model: named.model }),
|
|
85
|
+
sent: present.reduce((sum, part) => sum + part.sent, 0),
|
|
86
|
+
enriched,
|
|
87
|
+
failed: present.reduce((sum, part) => sum + part.failed, 0),
|
|
88
|
+
left: present.reduce((sum, part) => sum + part.left, 0),
|
|
89
|
+
inputTokens: present.reduce((sum, part) => sum + part.inputTokens, 0),
|
|
90
|
+
outputTokens: present.reduce((sum, part) => sum + part.outputTokens, 0),
|
|
91
|
+
costUsd: costs.includes(null)
|
|
92
|
+
? null
|
|
93
|
+
: Math.round(costs.reduce((sum, cost) => sum + (cost ?? 0), 0) * 1_000_000) / 1_000_000,
|
|
94
|
+
...(worst.reason === undefined ? {} : { reason: worst.reason }),
|
|
95
|
+
...(worst.reasonId === undefined ? {} : { reasonId: worst.reasonId }),
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/** Embeds mail's chunks that have no vector yet, bounded so a timer run stays short; a missing model is reported, never downloaded. */
|
|
99
|
+
export const embedMailChunks = async (store, { embed = true, env, maxChunks = embedPerRun(env), keyring, } = {}) => {
|
|
100
|
+
if (!embed)
|
|
101
|
+
return { chunks: 0, left: true, notEmbedded: "embedding is off" };
|
|
102
|
+
try {
|
|
103
|
+
// wcat's identity lets enrichment read the key wcat's keyring entry holds.
|
|
104
|
+
const done = await embedMailChunksOf(store, {
|
|
105
|
+
maxChunks,
|
|
106
|
+
command: APP.command,
|
|
107
|
+
app: APP,
|
|
108
|
+
...(env === undefined ? {} : { env }),
|
|
109
|
+
...(keyring ? { keyring } : {}),
|
|
110
|
+
});
|
|
111
|
+
const enrichment = reportOf(done.enrichment);
|
|
112
|
+
return { chunks: done.embedded, left: done.left, ...(enrichment ? { enrichment } : {}) };
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (!isMissingModel(error))
|
|
116
|
+
throw error;
|
|
117
|
+
const enrichment = isCliError(error) ? reportOf(error.details.enrichment) : undefined;
|
|
118
|
+
return {
|
|
119
|
+
chunks: 0,
|
|
120
|
+
left: true,
|
|
121
|
+
notEmbedded: missingModel(error, env),
|
|
122
|
+
...(enrichment ? { enrichment } : {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const BRIEF = ["ref", "chat_title", "timestamp", "sender_name", "excerpt", "score"];
|
|
2
|
+
/** `--brief`: the reference, when, who and the excerpt. */
|
|
3
|
+
export const briefHit = (hit) => Object.fromEntries(BRIEF.flatMap((key) => (hit[key] === undefined || hit[key] === null ? [] : [[key, hit[key]]])));
|
|
4
|
+
//# sourceMappingURL=hits.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { DEAL_KINDS, RESOURCES_SEARCHED, } from "@wirecat/cli-core";
|
|
3
|
+
import { grantedLevel } from "../mcp/granted.js";
|
|
4
|
+
export const LANE_GATES = [
|
|
5
|
+
{
|
|
6
|
+
lane: "business",
|
|
7
|
+
key: "business.list",
|
|
8
|
+
kinds: {
|
|
9
|
+
invoice: "invoices.list",
|
|
10
|
+
payment: "payments.list",
|
|
11
|
+
order: "orders.list",
|
|
12
|
+
contract: "contracts.list",
|
|
13
|
+
subscription: "subscriptions.list",
|
|
14
|
+
product: "products.list",
|
|
15
|
+
wallet: "wallets.list",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{ lane: "crm", key: "crm.list", kinds: { deal: "deals.list", lead: "leads.list" } },
|
|
19
|
+
{ lane: "events", key: "events.list", kinds: { event: "events.list" } },
|
|
20
|
+
// wcat has no tracker commands to key each kind by, and its own projects.list is about wcat's projects: one key.
|
|
21
|
+
{
|
|
22
|
+
lane: "tracker",
|
|
23
|
+
key: "tracker.list",
|
|
24
|
+
kinds: { issue: "tracker.list", issue_comment: "tracker.list", project: "tracker.list" },
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
/** The lane keys no command path carries, which wcat still accepts from `--permission` and the config file. */
|
|
28
|
+
export const LANE_KEYS = LANE_GATES.map(({ key }) => key);
|
|
29
|
+
const leftOut = (lane, what, key) => ({
|
|
30
|
+
code: "permission_error",
|
|
31
|
+
resource: lane,
|
|
32
|
+
reason: `${what} left out: wcat's MCP server denies ${key}`,
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* What `search all` may read and show. The MCP server's levels gate every lane; `denied` adds the CRM kinds wcat's own
|
|
36
|
+
* permissions deny for a run that is not the owner at a terminal, as the contexts leave them out (SEC-151).
|
|
37
|
+
*/
|
|
38
|
+
export const lanesFor = (command, asked, denied = []) => {
|
|
39
|
+
const lanes = asked ?? [...RESOURCES_SEARCHED];
|
|
40
|
+
const granted = (key) => grantedLevel(command, key) === "deny";
|
|
41
|
+
const skipped = [];
|
|
42
|
+
const hidden = new Set();
|
|
43
|
+
const off = new Set();
|
|
44
|
+
for (const gate of LANE_GATES) {
|
|
45
|
+
if (!lanes.includes(gate.lane))
|
|
46
|
+
continue;
|
|
47
|
+
if (granted(gate.key)) {
|
|
48
|
+
off.add(gate.lane);
|
|
49
|
+
skipped.push(leftOut(gate.lane, gate.lane, gate.key));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
for (const [kind, key] of Object.entries(gate.kinds)) {
|
|
53
|
+
const saved = denied.find((one) => one.kind === kind);
|
|
54
|
+
if (granted(key)) {
|
|
55
|
+
hidden.add(kind);
|
|
56
|
+
skipped.push(leftOut(gate.lane, kind, key));
|
|
57
|
+
}
|
|
58
|
+
else if (saved) {
|
|
59
|
+
hidden.add(kind);
|
|
60
|
+
skipped.push({ code: "permission_error", resource: gate.lane, reason: saved.why });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (Object.keys(gate.kinds).every((kind) => hidden.has(kind)))
|
|
64
|
+
off.add(gate.lane);
|
|
65
|
+
}
|
|
66
|
+
const shows = hidden.size ? { shows: (item) => !hidden.has(item.kind) } : {};
|
|
67
|
+
const crmKinds = DEAL_KINDS.filter((kind) => !hidden.has(kind));
|
|
68
|
+
const narrowed = crmKinds.length < DEAL_KINDS.length && !off.has("crm") ? { crmKinds } : {};
|
|
69
|
+
if (!off.size)
|
|
70
|
+
return { only: asked, ...narrowed, skipped, ...shows };
|
|
71
|
+
const only = lanes.filter((lane) => !off.has(lane));
|
|
72
|
+
if (!only.length)
|
|
73
|
+
throw new CliError("permission_error", `search all has nothing it may read: ${skipped.map(({ reason }) => reason).join("; ")}`, { reason: "search.all-denied" });
|
|
74
|
+
return { only, ...narrowed, skipped, ...shows };
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=lane-gates.js.map
|