@wirecat/cli-core 0.618.0 → 0.620.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/CHANGELOG.md +453 -1
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES +3 -0
- package/dist/background/deliver.d.ts +5 -2
- package/dist/background/deliver.js +30 -12
- package/dist/background/report/render.d.ts +3 -1
- package/dist/background/report/render.js +3 -1
- package/dist/calendar/cli/answers.d.ts +1 -0
- package/dist/calendar/cli/answers.js +6 -1
- package/dist/calendar/cli/index.js +2 -14
- package/dist/calendar/cli/people-link.d.ts +3 -0
- package/dist/calendar/cli/people-link.js +23 -0
- package/dist/calendar/cli/search-all.d.ts +1 -1
- package/dist/calendar/cli/search-all.js +9 -10
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/calendar/prepare.js +1 -0
- package/dist/cli/base-stages-command.d.ts +22 -0
- package/dist/cli/base-stages-command.js +174 -0
- package/dist/cli/bot/buttons.d.ts +3 -0
- package/dist/cli/bot/buttons.js +24 -0
- package/dist/cli/bot/messages.js +14 -1
- package/dist/cli/bot/port.d.ts +8 -0
- package/dist/cli/command-runs.d.ts +2 -0
- package/dist/cli/command-runs.js +3 -1
- package/dist/cli/config-command.js +6 -1
- package/dist/cli/context.js +1 -0
- package/dist/cli/contract-templates.js +31 -2
- package/dist/cli/group-lock.d.ts +42 -0
- package/dist/cli/group-lock.js +130 -0
- package/dist/cli/index.d.ts +7 -2
- package/dist/cli/index.js +7 -2
- package/dist/cli/messenger/backfill-command.js +27 -15
- package/dist/cli/messenger/contacts-command.js +12 -4
- package/dist/cli/messenger/context.js +1 -0
- package/dist/cli/messenger/conversations-command.js +2 -1
- package/dist/cli/messenger/doctor-command.js +3 -1
- package/dist/cli/messenger/message-items.js +1 -1
- package/dist/cli/messenger/models-command.js +1 -1
- package/dist/cli/messenger/search-answers.d.ts +5 -5
- package/dist/cli/messenger/search-answers.js +9 -20
- package/dist/cli/messenger/search-command.d.ts +2 -2
- package/dist/cli/messenger/search-command.js +8 -18
- package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
- package/dist/cli/messenger/store-maintenance-command.js +9 -4
- package/dist/cli/model-catalogue-command.d.ts +3 -1
- package/dist/cli/model-catalogue-command.js +48 -2
- package/dist/cli/profile.d.ts +8 -0
- package/dist/cli/profile.js +25 -0
- package/dist/cli/program.js +2 -0
- package/dist/cli/runs/search-query.d.ts +1 -1
- package/dist/cli/runs/search-query.js +4 -0
- package/dist/cli/runs/search.d.ts +5 -1
- package/dist/cli/runs/search.js +12 -1
- package/dist/cli/search-harder-consents-command.d.ts +18 -0
- package/dist/cli/search-harder-consents-command.js +83 -0
- package/dist/cli/search-left-out.d.ts +6 -1
- package/dist/cli/search-left-out.js +9 -4
- package/dist/cli/settings.d.ts +8 -0
- package/dist/cli/settings.js +17 -2
- package/dist/cli/shared-command-exports.d.ts +16 -0
- package/dist/cli/steps.js +0 -6
- package/dist/cli/store-recover.d.ts +3 -3
- package/dist/cli/store-recover.js +26 -26
- package/dist/cli/store-settings.d.ts +2 -0
- package/dist/cli/store-settings.js +37 -9
- package/dist/cli/templates-command.js +4 -4
- package/dist/crm/cli/index.js +40 -8
- package/dist/crm/cli/search-all.js +7 -6
- package/dist/crm/group-hint.d.ts +8 -0
- package/dist/crm/group-hint.js +13 -0
- package/dist/crm/source.d.ts +12 -1
- package/dist/crm/sync.d.ts +31 -2
- package/dist/crm/sync.js +110 -3
- package/dist/crm/testing/acme-scenario.d.ts +40 -0
- package/dist/crm/testing/acme-scenario.js +170 -0
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/source-contract.js +12 -0
- package/dist/crm/testing/source.d.ts +2 -0
- package/dist/crm/testing/source.js +1 -0
- package/dist/domain/addresses.d.ts +13 -0
- package/dist/domain/addresses.js +63 -0
- package/dist/domain/categories.d.ts +3 -0
- package/dist/domain/categories.js +2 -0
- package/dist/domain/crm.d.ts +23 -0
- package/dist/domain/crm.js +7 -0
- package/dist/domain/mentions.d.ts +2 -12
- package/dist/domain/mentions.js +2 -19
- package/dist/domain/models.d.ts +2 -0
- package/dist/domain/orders.d.ts +8 -1
- package/dist/domain/orders.js +6 -2
- package/dist/domain/phones.d.ts +26 -0
- package/dist/domain/phones.js +48 -0
- package/dist/domain/record-types.d.ts +1 -1
- package/dist/domain/record-types.js +1 -0
- package/dist/domain/records.d.ts +5 -0
- package/dist/domain/ref-summaries.d.ts +39 -0
- package/dist/domain/ref-summaries.js +51 -3
- package/dist/domain/relations.d.ts +12 -2
- package/dist/domain/relations.js +14 -3
- package/dist/domain/vcard.d.ts +2 -2
- package/dist/domain/vcard.js +4 -10
- package/dist/embeddings/models.d.ts +11 -3
- package/dist/embeddings/models.js +28 -4
- package/dist/entities/business-context.d.ts +149 -0
- package/dist/entities/business-context.js +192 -0
- package/dist/entities/contact-activity.d.ts +2 -0
- package/dist/entities/contact-activity.js +7 -1
- package/dist/entities/contact-context.d.ts +160 -0
- package/dist/entities/contact-context.js +6 -0
- package/dist/entities/deal.d.ts +10 -0
- package/dist/entities/deal.js +2 -0
- package/dist/entities/hit.d.ts +9 -2
- package/dist/entities/hit.js +6 -2
- package/dist/entities/index.d.ts +32 -4
- package/dist/entities/index.js +5 -0
- package/dist/entities/mention.d.ts +4 -3
- package/dist/entities/mention.js +2 -1
- package/dist/entities/message-transfer.d.ts +4 -2
- package/dist/entities/message-transfer.js +2 -2
- package/dist/entities/model.d.ts +2 -2
- package/dist/entities/model.js +1 -1
- package/dist/entities/relationship.d.ts +4 -0
- package/dist/entities/relationship.js +4 -0
- package/dist/errors/reasons.js +39 -4
- package/dist/fetch/page.js +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/meetings/context-store.d.ts +2 -0
- package/dist/meetings/findings-rules.d.ts +4 -0
- package/dist/meetings/findings-rules.js +5 -2
- package/dist/meetings/hit-query.d.ts +1 -1
- package/dist/meetings/hit-query.js +2 -2
- package/dist/meetings/index.d.ts +1 -0
- package/dist/meetings/index.js +1 -0
- package/dist/meetings/result-items.d.ts +1 -0
- package/dist/meetings/result-items.js +1 -0
- package/dist/meetings/store.d.ts +4 -0
- package/dist/meetings/store.js +2 -1
- package/dist/models/anthropic.js +5 -0
- package/dist/models/index.js +22 -5
- package/dist/runs/events.d.ts +11 -1
- package/dist/runs/events.js +3 -1
- package/dist/runs/log-attributes.js +4 -0
- package/dist/runs/log-events.js +2 -0
- package/dist/runs/recording.d.ts +3 -0
- package/dist/runs/recording.js +36 -12
- package/dist/runs/run.d.ts +12 -3
- package/dist/runs/run.js +32 -13
- package/dist/search/account-list.d.ts +6 -0
- package/dist/search/account-list.js +9 -3
- package/dist/search/groups.d.ts +68 -0
- package/dist/search/groups.js +172 -0
- package/dist/search/question-period.d.ts +10 -0
- package/dist/search/question-period.js +133 -0
- package/dist/sends/buttons.d.ts +2 -0
- package/dist/sends/buttons.js +6 -1
- package/dist/services/account-groups.d.ts +28 -0
- package/dist/services/account-groups.js +89 -0
- package/dist/services/archive.d.ts +7 -1
- package/dist/services/archive.js +19 -3
- package/dist/services/business-context.d.ts +113 -0
- package/dist/services/business-context.js +156 -0
- package/dist/services/communications.d.ts +50 -0
- package/dist/services/communications.js +140 -0
- package/dist/services/deal-context.d.ts +90 -0
- package/dist/services/deal-context.js +131 -0
- package/dist/services/deps.d.ts +2 -0
- package/dist/services/enrichment.d.ts +12 -2
- package/dist/services/enrichment.js +47 -6
- package/dist/services/events-search.js +2 -1
- package/dist/services/group-guard.d.ts +28 -0
- package/dist/services/group-guard.js +131 -0
- package/dist/services/index.d.ts +19 -4
- package/dist/services/index.js +12 -3
- package/dist/services/ingest.d.ts +12 -0
- package/dist/services/ingest.js +4 -0
- package/dist/services/meaning-model.d.ts +7 -0
- package/dist/services/meaning-model.js +20 -0
- package/dist/services/meeting-context.d.ts +6 -1
- package/dist/services/meeting-context.js +12 -5
- package/dist/services/message-resolution.js +2 -3
- package/dist/services/messages-meaning.js +4 -5
- package/dist/services/messages-search.d.ts +5 -1
- package/dist/services/messages-search.js +1 -1
- package/dist/services/messages.d.ts +1 -4
- package/dist/services/messages.js +0 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/model-downloads.d.ts +1 -1
- package/dist/services/model-downloads.js +6 -4
- package/dist/services/money-context.d.ts +73 -0
- package/dist/services/money-context.js +77 -0
- package/dist/services/notes-search.d.ts +4 -1
- package/dist/services/notes-search.js +19 -7
- package/dist/services/organization-context.d.ts +80 -0
- package/dist/services/organization-context.js +154 -0
- package/dist/services/people.d.ts +22 -6
- package/dist/services/people.js +38 -8
- package/dist/services/person-business.d.ts +43 -0
- package/dist/services/person-business.js +67 -0
- package/dist/services/person-context.d.ts +11 -1
- package/dist/services/person-context.js +25 -10
- package/dist/services/person-preparation.d.ts +5 -1
- package/dist/services/person-preparation.js +10 -3
- package/dist/services/person-timeline.d.ts +6 -1
- package/dist/services/person-timeline.js +10 -2
- package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
- package/dist/services/proposals/kinds/identity-link.js +48 -0
- package/dist/services/proposals/kinds/orders.js +1 -1
- package/dist/services/proposals/registry.js +2 -0
- package/dist/services/search-all-deprecated.d.ts +40 -0
- package/dist/services/search-all-deprecated.js +10 -0
- package/dist/services/search-all-meetings.d.ts +50 -52
- package/dist/services/search-all-meetings.js +265 -272
- package/dist/services/search-all.d.ts +34 -6
- package/dist/services/search-all.js +118 -24
- package/dist/services/search-harder.d.ts +64 -0
- package/dist/services/search-harder.js +194 -0
- package/dist/services/search-kind.d.ts +12 -5
- package/dist/services/search-kind.js +49 -10
- package/dist/services/text-model-choice.js +1 -1
- package/dist/store/accounts.d.ts +18 -0
- package/dist/store/accounts.js +18 -3
- package/dist/store/chats.d.ts +3 -1
- package/dist/store/chats.js +6 -0
- package/dist/store/damage.d.ts +43 -10
- package/dist/store/damage.js +119 -36
- package/dist/store/decisions.js +3 -1
- package/dist/store/evidence-findings.d.ts +14 -0
- package/dist/store/evidence-findings.js +2 -0
- package/dist/store/exports.d.ts +2 -1
- package/dist/store/identity-links.d.ts +92 -0
- package/dist/store/identity-links.js +6 -0
- package/dist/store/index.d.ts +11 -5
- package/dist/store/index.js +5 -2
- package/dist/store/journal.d.ts +10 -0
- package/dist/store/journal.js +33 -0
- package/dist/store/marks.d.ts +19 -1
- package/dist/store/marks.js +23 -1
- package/dist/store/people.d.ts +28 -2
- package/dist/store/people.js +15 -1
- package/dist/store/sqlite/accounts.js +2 -0
- package/dist/store/sqlite/added-sources.d.ts +15 -3
- package/dist/store/sqlite/added-sources.js +26 -5
- package/dist/store/sqlite/base-stages.d.ts +122 -0
- package/dist/store/sqlite/base-stages.js +443 -0
- package/dist/store/sqlite/base-suggest.d.ts +13 -0
- package/dist/store/sqlite/base-suggest.js +62 -0
- package/dist/store/sqlite/business-contracts.js +10 -1
- package/dist/store/sqlite/chats.d.ts +2 -0
- package/dist/store/sqlite/chats.js +6 -0
- package/dist/store/sqlite/crm-settings.d.ts +12 -2
- package/dist/store/sqlite/crm-settings.js +56 -13
- package/dist/store/sqlite/crm.d.ts +13 -1
- package/dist/store/sqlite/crm.js +20 -4
- package/dist/store/sqlite/deals.d.ts +33 -0
- package/dist/store/sqlite/deals.js +42 -4
- package/dist/store/sqlite/decision-requests.js +7 -3
- package/dist/store/sqlite/email-index.js +8 -4
- package/dist/store/sqlite/evidence-findings.js +29 -5
- package/dist/store/sqlite/findings-core.js +4 -2
- package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
- package/dist/store/sqlite/identity-link-rows.js +146 -0
- package/dist/store/sqlite/identity-proposals.d.ts +53 -0
- package/dist/store/sqlite/identity-proposals.js +234 -0
- package/dist/store/sqlite/involvements.d.ts +1 -1
- package/dist/store/sqlite/involvements.js +4 -2
- package/dist/store/sqlite/knowledge.js +2 -2
- package/dist/store/sqlite/link-kinds.d.ts +1 -0
- package/dist/store/sqlite/link-kinds.js +1 -0
- package/dist/store/sqlite/link-row.d.ts +6 -0
- package/dist/store/sqlite/link-row.js +35 -0
- package/dist/store/sqlite/link-source.d.ts +10 -0
- package/dist/store/sqlite/link-source.js +16 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/meeting-context-links.js +9 -6
- package/dist/store/sqlite/meeting-hit-query.d.ts +5 -0
- package/dist/store/sqlite/meeting-hit-query.js +33 -0
- package/dist/store/sqlite/meeting-hit-search.js +10 -8
- package/dist/store/sqlite/meetings.js +1 -1
- package/dist/store/sqlite/memories.js +9 -7
- package/dist/store/sqlite/mentions.d.ts +4 -1
- package/dist/store/sqlite/mentions.js +14 -9
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/notes.d.ts +8 -2
- package/dist/store/sqlite/notes.js +17 -34
- package/dist/store/sqlite/open-store.js +3 -0
- package/dist/store/sqlite/open.js +11 -2
- package/dist/store/sqlite/orders.d.ts +2 -0
- package/dist/store/sqlite/orders.js +9 -3
- package/dist/store/sqlite/organization-categories.d.ts +18 -0
- package/dist/store/sqlite/organization-categories.js +34 -0
- package/dist/store/sqlite/organizations.d.ts +5 -1
- package/dist/store/sqlite/organizations.js +14 -4
- package/dist/store/sqlite/person-links.d.ts +19 -4
- package/dist/store/sqlite/person-links.js +49 -11
- package/dist/store/sqlite/person-match-scan.d.ts +13 -0
- package/dist/store/sqlite/person-match-scan.js +251 -0
- package/dist/store/sqlite/person-matcher.d.ts +16 -0
- package/dist/store/sqlite/person-matcher.js +32 -0
- package/dist/store/sqlite/person-preparation.d.ts +7 -3
- package/dist/store/sqlite/person-preparation.js +20 -6
- package/dist/store/sqlite/proposed-actions.js +6 -0
- package/dist/store/sqlite/record-matching.d.ts +2 -8
- package/dist/store/sqlite/record-matching.js +8 -40
- package/dist/store/sqlite/record-projectors-phone.js +2 -1
- package/dist/store/sqlite/record-relationships.d.ts +52 -0
- package/dist/store/sqlite/record-relationships.js +243 -0
- package/dist/store/sqlite/record-run.d.ts +5 -0
- package/dist/store/sqlite/record-run.js +62 -2
- package/dist/store/sqlite/record-writes.d.ts +1 -1
- package/dist/store/sqlite/record-writes.js +4 -2
- package/dist/store/sqlite/records.js +27 -2
- package/dist/store/sqlite/ref-accounts.d.ts +13 -0
- package/dist/store/sqlite/ref-accounts.js +117 -0
- package/dist/store/sqlite/ref-summaries.js +5 -1
- package/dist/store/sqlite/relation-list.d.ts +4 -1
- package/dist/store/sqlite/relation-list.js +22 -4
- package/dist/store/sqlite/relation-proposals.d.ts +6 -0
- package/dist/store/sqlite/relation-proposals.js +3 -0
- package/dist/store/sqlite/relation-roles.js +12 -6
- package/dist/store/sqlite/reported-relations.d.ts +11 -1
- package/dist/store/sqlite/reported-relations.js +59 -18
- package/dist/store/sqlite/schema.d.ts +32 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/dist/store/sqlite/transaction.js +11 -1
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/write-events.d.ts +18 -0
- package/dist/store/write-events.js +88 -0
- package/package.json +3 -3
- package/parity.json +37 -16
- package/schemas/records-envelope.v1.schema.json +3 -0
|
@@ -1,35 +1,74 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { holdsKindOf, isKind, providerNamed } from "../domain/providers.js";
|
|
3
|
-
import {
|
|
2
|
+
import { holdsKindOf, isDocumentAccountProvider, isFolderProvider, isKind, providerNamed } from "../domain/providers.js";
|
|
3
|
+
import { envName } from "../ports/app.js";
|
|
4
|
+
import { entriesOfList, fitting, isAccountList, keyOf, } from "../search/account-list.js";
|
|
5
|
+
import { ALL, groupEntries, groupMembership, hasGroup, OWNER_NOTES } from "../search/groups.js";
|
|
4
6
|
export const NO_MAIL = "no_mail";
|
|
5
7
|
export const MAIL = "email";
|
|
6
|
-
/**
|
|
7
|
-
export const
|
|
8
|
+
/** The group `<PREFIX>_GROUP_LOCK` pins this process to; `all`, every account, locks nothing. */
|
|
9
|
+
export const groupLockOf = (app, env) => {
|
|
10
|
+
const lock = app === undefined || env === undefined ? undefined : env[envName(app, "GROUP_LOCK")]?.trim();
|
|
11
|
+
return lock && lock.toLowerCase() !== ALL ? lock : undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* What a `--source` list is resolved against: the store's accounts, profiles and groups — the saved ones and `all`
|
|
15
|
+
* (WC-ACCT-13) — and the app running. Under a group lock in the run's `env` it holds only that group's
|
|
16
|
+
* accounts, so a reader that never scoped its run to the group still cannot name an account outside it.
|
|
17
|
+
*/
|
|
18
|
+
export const listContextOf = async (store, account, app, stored, env) => {
|
|
8
19
|
const all = stored ?? (await store.accounts.storedAccounts());
|
|
9
20
|
// A fresh store has no row yet for the account it runs as.
|
|
10
21
|
const held = all.some((one) => one.provider === account.provider && one.account === account.account)
|
|
11
22
|
? all
|
|
12
23
|
: [...all, { id: 0, ...account, name: null, scope: "personal" }];
|
|
13
|
-
|
|
24
|
+
const context = {
|
|
14
25
|
held,
|
|
15
26
|
groups: await store.accounts.accountGroups(),
|
|
16
27
|
profiles: await store.accounts.profiles(),
|
|
17
28
|
running: { provider: account.provider, ...(app ? { command: app.command } : {}) },
|
|
18
29
|
};
|
|
30
|
+
const membership = groupMembership(context);
|
|
31
|
+
const groups = groupEntries(context.groups);
|
|
32
|
+
const lock = groupLockOf(app, env);
|
|
33
|
+
if (lock === undefined)
|
|
34
|
+
return { ...context, groups, membership };
|
|
35
|
+
const members = hasGroup(membership.groups, lock) ? membership.groups[lock] : undefined;
|
|
36
|
+
if (!members)
|
|
37
|
+
throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
|
|
38
|
+
const only = new Set([...members, OWNER_NOTES].map(keyOf));
|
|
39
|
+
// A notes folder or a documents account is held under its own key but listed as `notes:<store id>`.
|
|
40
|
+
const listedAs = (one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider)
|
|
41
|
+
? { provider: "notes", account: String(one.id) }
|
|
42
|
+
: one;
|
|
43
|
+
return {
|
|
44
|
+
...context,
|
|
45
|
+
held: held.filter((one) => only.has(keyOf(listedAs(one)))),
|
|
46
|
+
groups: { [lock]: groups[lock] ?? [] },
|
|
47
|
+
membership: {
|
|
48
|
+
groups: { [lock]: members },
|
|
49
|
+
duplicates: membership.duplicates.filter(({ groups: names }) => names.includes(lock)),
|
|
50
|
+
suggested: membership.suggested.filter(({ group }) => group === lock),
|
|
51
|
+
unresolved: membership.unresolved,
|
|
52
|
+
},
|
|
53
|
+
only,
|
|
54
|
+
};
|
|
19
55
|
};
|
|
20
56
|
/**
|
|
21
57
|
* `--source` as a list of accounts and groups: `undefined` when it is a bare word like `all` or `telegram`. The
|
|
22
58
|
* accounts are those of `kind` the list names; an entry naming none of them is in `skipped`.
|
|
23
59
|
*/
|
|
24
|
-
export const listedAccounts = async (store, account, source, app, kind) => {
|
|
25
|
-
|
|
60
|
+
export const listedAccounts = async (store, account, source, app, kind, env) => {
|
|
61
|
+
const lock = groupLockOf(app, env);
|
|
62
|
+
if (source === undefined && lock === undefined)
|
|
26
63
|
return undefined;
|
|
27
64
|
const stored = await store.accounts.storedAccounts();
|
|
28
65
|
// A provider the store holds by that very name, and all, personal and bots, keep their old path.
|
|
29
|
-
const registered =
|
|
30
|
-
|
|
66
|
+
const registered = source !== undefined &&
|
|
67
|
+
(isKind(source) || (providerNamed(source) !== undefined && !stored.some(({ provider }) => provider === source)));
|
|
68
|
+
// Under a lock every read goes through the list, which holds only the group's accounts.
|
|
69
|
+
if (lock === undefined && source !== undefined && !isAccountList(source) && !registered)
|
|
31
70
|
return undefined;
|
|
32
|
-
const entries = entriesOfList(source
|
|
71
|
+
const entries = entriesOfList(source ?? `group:${lock}`, await listContextOf(store, account, app, stored, env));
|
|
33
72
|
return fitting(entries, kind ? [kind] : ["messages", "mail"], `${app ? `${app.command} ` : ""}search ${kind ?? "messages"}`);
|
|
34
73
|
};
|
|
35
74
|
/**
|
|
@@ -14,7 +14,7 @@ import { openStore } from "../store/store.js";
|
|
|
14
14
|
export const useTextModel = async (id, { env, command }) => {
|
|
15
15
|
const model = textModel(id, env);
|
|
16
16
|
if (!isTextModelInstalled(model, textModelsDirectory(env)))
|
|
17
|
-
throw new CliError("not_found", `${model.id} is not downloaded — \`${command} models download ${model.id}
|
|
17
|
+
throw new CliError("not_found", `${model.id} is not downloaded — \`${command} models download ${model.id}\` first`, { reason: "model.not-downloaded", model: model.id });
|
|
18
18
|
const previous = chosenTextModel(env).id;
|
|
19
19
|
const before = textModels(env).find((one) => one.id === previous);
|
|
20
20
|
const toEmbed = previous === model.id ? 0 : before ? await missingVectors(before, model, env) : null;
|
package/dist/store/accounts.d.ts
CHANGED
|
@@ -17,6 +17,17 @@ export interface AccountAccounts {
|
|
|
17
17
|
*/
|
|
18
18
|
purge(key: AccountKey): Promise<void>;
|
|
19
19
|
}
|
|
20
|
+
export interface AccountGroupChange {
|
|
21
|
+
/** Read against the group's entries inside the write, so a move sees what is saved at that moment. */
|
|
22
|
+
remove?: {
|
|
23
|
+
group: string;
|
|
24
|
+
drop: (entry: string) => boolean;
|
|
25
|
+
};
|
|
26
|
+
add?: {
|
|
27
|
+
group: string;
|
|
28
|
+
entry: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
20
31
|
export interface AccountsStore extends AccountAccounts {
|
|
21
32
|
/** Every account of every messenger the file holds, by messenger then id. */
|
|
22
33
|
accounts(): Promise<AccountKey[]>;
|
|
@@ -26,6 +37,13 @@ export interface AccountsStore extends AccountAccounts {
|
|
|
26
37
|
accountGroups(): Promise<AccountGroups>;
|
|
27
38
|
/** Saves one group's entries; `undefined` removes the group. */
|
|
28
39
|
saveAccountGroup(name: string, members: string[] | undefined): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Takes entries out of one group and puts an entry into another in one write, so a move is never half done. A
|
|
42
|
+
* group left empty stays, to be filled again; an entry already there is not added twice.
|
|
43
|
+
*/
|
|
44
|
+
changeAccountGroups(change: AccountGroupChange): Promise<{
|
|
45
|
+
removed: string[];
|
|
46
|
+
}>;
|
|
29
47
|
/** Per app command, each profile's account: how `--source max:default` finds a profile of another app. */
|
|
30
48
|
profiles(): Promise<Profiles>;
|
|
31
49
|
/** Records which account a profile of `app` is; a no-op when the store already says so. */
|
package/dist/store/accounts.js
CHANGED
|
@@ -31,6 +31,9 @@ export const accountAccountsOver = (context) => {
|
|
|
31
31
|
};
|
|
32
32
|
export const accountsStoreOver = (context, keyed) => {
|
|
33
33
|
const { database } = context;
|
|
34
|
+
const saveGroups = (groups) => database
|
|
35
|
+
.prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
|
|
36
|
+
.run(ACCOUNT_GROUPS, JSON.stringify(groups), context.now());
|
|
34
37
|
return {
|
|
35
38
|
...keyed,
|
|
36
39
|
accounts: async () => accounts.heldAccounts(context),
|
|
@@ -46,9 +49,21 @@ export const accountsStoreOver = (context, keyed) => {
|
|
|
46
49
|
delete groups[name];
|
|
47
50
|
else
|
|
48
51
|
groups[name] = members;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
saveGroups(groups);
|
|
53
|
+
}),
|
|
54
|
+
changeAccountGroups: async ({ remove, add }) => write(database, () => {
|
|
55
|
+
const groups = accountGroupsOf(database);
|
|
56
|
+
const saved = remove && Object.hasOwn(groups, remove.group) ? (groups[remove.group] ?? []) : [];
|
|
57
|
+
const removed = remove ? saved.filter(remove.drop) : [];
|
|
58
|
+
if (remove && removed.length)
|
|
59
|
+
groups[remove.group] = saved.filter((entry) => !removed.includes(entry));
|
|
60
|
+
if (add) {
|
|
61
|
+
const entries = Object.hasOwn(groups, add.group) ? (groups[add.group] ?? []) : [];
|
|
62
|
+
groups[add.group] = entries.includes(add.entry) ? entries : [...entries, add.entry];
|
|
63
|
+
}
|
|
64
|
+
if (removed.length || add)
|
|
65
|
+
saveGroups(groups);
|
|
66
|
+
return { removed };
|
|
52
67
|
}),
|
|
53
68
|
};
|
|
54
69
|
};
|
package/dist/store/chats.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { ChatCompleteness, ChatCoverage } from "./sqlite/completeness.js";
|
|
|
7
7
|
import type { ChatHistoryShape, StoredHistorySkip } from "./sqlite/history-skips.js";
|
|
8
8
|
import type { StoreContext } from "./sqlite/open.js";
|
|
9
9
|
import type { Where } from "./sqlite/query-filter.js";
|
|
10
|
-
import type { AccountKey, ChatActivity, ChatStats, StoredChatFilter } from "./types.js";
|
|
10
|
+
import type { AccountKey, ChatActivity, ChatStats, StoredAccount, StoredChatFilter } from "./types.js";
|
|
11
11
|
export type { LeftChat };
|
|
12
12
|
/** The chats marked left: how many, the messages they hold, and each one. */
|
|
13
13
|
export interface LeftChats {
|
|
@@ -25,6 +25,8 @@ export interface ChatsStore {
|
|
|
25
25
|
countChats(key: AccountKey, filter?: StoredChatFilter): Promise<number>;
|
|
26
26
|
/** The chats a person is in, newest first — as far as the saved member lists go. */
|
|
27
27
|
chatsWith(key: AccountKey, memberId: Id): Promise<Chat[]>;
|
|
28
|
+
/** Each stored chat's scope, its own or else its account's; a chat the store lacks is left out. */
|
|
29
|
+
chatScopes(key: AccountKey, chatIds: readonly Id[]): Promise<Map<Id, StoredAccount["scope"]>>;
|
|
28
30
|
/**
|
|
29
31
|
* Given every chat the account is in, marks the rest `left`, takes the mark off those it names, and says how many
|
|
30
32
|
* it marked. Only ever from a complete list: a page or a cut list says nothing about the chats it leaves out.
|
package/dist/store/chats.js
CHANGED
|
@@ -31,6 +31,12 @@ export const chatsStoreOver = (context) => {
|
|
|
31
31
|
const accountKey = findAccountPk(key);
|
|
32
32
|
return accountKey === undefined ? [] : chatQueries.chatsWith(context, accountKey, key, memberId);
|
|
33
33
|
},
|
|
34
|
+
chatScopes: async (key, chatIds) => {
|
|
35
|
+
const accountKey = findAccountPk(key);
|
|
36
|
+
return accountKey === undefined
|
|
37
|
+
? new Map()
|
|
38
|
+
: chatQueries.chatScopes(context, accountKey, chatIds);
|
|
39
|
+
},
|
|
34
40
|
markChatsLeft: async (key, present) => {
|
|
35
41
|
const accountKey = findAccountPk(key);
|
|
36
42
|
if (accountKey === undefined)
|
package/dist/store/damage.d.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
import type { StoreHealth } from "./health.js";
|
|
2
|
-
import type { DamageMark } from "./marks.js";
|
|
2
|
+
import type { DamageMark, JournalMark } from "./marks.js";
|
|
3
|
+
/** One cause the evidence allows, and the one command that tells more about it. */
|
|
4
|
+
export interface DamageCause {
|
|
5
|
+
cause: string;
|
|
6
|
+
check: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RecoveryStep {
|
|
9
|
+
command: string;
|
|
10
|
+
why: string;
|
|
11
|
+
/** Replaces the store or stops a process: an app copies it for the owner to run rather than running it. */
|
|
12
|
+
destructive: boolean;
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* What a damaged store means, in the owner's words: one structure the CLIs render and the desktop app can show as it
|
|
5
|
-
* is. Built from
|
|
16
|
+
* is. Built from what was already found, so it never reads the damaged file again.
|
|
6
17
|
*/
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
investigate: string[];
|
|
18
|
+
export interface StoreDamageReport {
|
|
19
|
+
whatHappened: string;
|
|
20
|
+
likelyCauses: DamageCause[];
|
|
11
21
|
impact: string[];
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
externalDataSafe: string;
|
|
23
|
+
lastOkAt: string | null;
|
|
24
|
+
loss: string;
|
|
25
|
+
/** The first stops the writers, the last is the deep check. */
|
|
26
|
+
steps: RecoveryStep[];
|
|
27
|
+
}
|
|
28
|
+
export interface DamageFindings {
|
|
29
|
+
health: StoreHealth;
|
|
30
|
+
/** The CLI's command, which the steps name: `mail`. */
|
|
31
|
+
command: string;
|
|
32
|
+
mark?: DamageMark | null;
|
|
33
|
+
journal?: JournalMark | null;
|
|
34
|
+
lastOkAt?: string | null;
|
|
35
|
+
holders?: {
|
|
36
|
+
pid: number;
|
|
37
|
+
name: string;
|
|
38
|
+
}[] | null;
|
|
39
|
+
timers?: string[] | null;
|
|
40
|
+
sqlite3Usable?: boolean;
|
|
14
41
|
}
|
|
15
42
|
/**
|
|
16
43
|
* Tables a recovery rebuilds from the others: search indexes, the vector index, what the indexing finds, and the
|
|
17
44
|
* vectors, which a search by meaning computes again for any text that has none.
|
|
18
45
|
*/
|
|
19
46
|
export declare const isDerivedTable: (table: string, searchIndexes: readonly string[]) => boolean;
|
|
20
|
-
/**
|
|
21
|
-
export declare const
|
|
47
|
+
/** How much may be gone and since when: nothing records a row that damage takes (BUG-627). */
|
|
48
|
+
export declare const lossUnknown: (lastOkAt: string | null | undefined, gone?: boolean) => string;
|
|
49
|
+
/**
|
|
50
|
+
* The report for whatever was found, or null when the store is healthy and nothing was seen. `mark`: a run saw the
|
|
51
|
+
* damage; the quick check reads too little to see it, so it alone can make a store damaged. `journal`: the store's
|
|
52
|
+
* journal file went away under a run, which can lose writes even when every page still reads.
|
|
53
|
+
*/
|
|
54
|
+
export declare const storeDamageReport: ({ health, command, mark, journal, lastOkAt, holders, timers, sqlite3Usable, }: DamageFindings) => StoreDamageReport | null;
|
package/dist/store/damage.js
CHANGED
|
@@ -9,9 +9,34 @@ export const isDerivedTable = (table, searchIndexes) => DERIVED.has(table) ||
|
|
|
9
9
|
searchIndexes.some((index) => table === index || table.startsWith(`${index}_`));
|
|
10
10
|
const WIRECAT_UNITS = ["memo-*", "mail-*", "tg-*", "max-*", "wirecat-*"];
|
|
11
11
|
const seen = (mark) => `\`${mark.command}\` found the store damaged at ${mark.at} (${mark.error})`;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const journalSeen = (store, { seen, command, at }) => {
|
|
13
|
+
const wal = `${store.replace(/^.*\//, "")}-wal`;
|
|
14
|
+
return seen === "shm-without-wal"
|
|
15
|
+
? `the store's journal file (${wal}) was missing when \`${command}\` opened the store at ${at}: another program deleted it, or a tool crashed while closing`
|
|
16
|
+
: `the store's journal file (${wal}) was deleted or replaced by another program while \`${command}\` had the store open (${at})`;
|
|
17
|
+
};
|
|
18
|
+
/** How much may be gone and since when: nothing records a row that damage takes (BUG-627). */
|
|
19
|
+
export const lossUnknown = (lastOkAt, gone = false) => {
|
|
20
|
+
const since = lastOkAt
|
|
21
|
+
? `since the last deep check that passed (${lastOkAt})`
|
|
22
|
+
: "since the store was made (no deep check that passed is on record)";
|
|
23
|
+
return (`${gone ? "more rows may be gone" : "how many rows were lost is unknown"}: ` +
|
|
24
|
+
`damage can take rows written ${since} without leaving a trace; a sync fetches again what the servers still hold`);
|
|
25
|
+
};
|
|
26
|
+
const stopWriters = (timers) => ({
|
|
27
|
+
command: timers?.length
|
|
28
|
+
? `systemctl --user stop ${timers.join(" ")}`
|
|
29
|
+
: `systemctl --user stop ${WIRECAT_UNITS.map((unit) => `'${unit}'`).join(" ")}`,
|
|
30
|
+
why: "a tool that writes while the store is recovered damages the new file too",
|
|
31
|
+
destructive: false,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The report for whatever was found, or null when the store is healthy and nothing was seen. `mark`: a run saw the
|
|
35
|
+
* damage; the quick check reads too little to see it, so it alone can make a store damaged. `journal`: the store's
|
|
36
|
+
* journal file went away under a run, which can lose writes even when every page still reads.
|
|
37
|
+
*/
|
|
38
|
+
export const storeDamageReport = ({ health, command, mark = null, journal = null, lastOkAt = null, holders = null, timers = null, sqlite3Usable = true, }) => {
|
|
39
|
+
if (health.ok && !mark && !journal)
|
|
15
40
|
return null;
|
|
16
41
|
const indexNames = (health.searchIndexes ?? []).map((index) => index.name);
|
|
17
42
|
const badIndexes = (health.searchIndexes ?? []).filter((index) => !index.ok).map((index) => index.name);
|
|
@@ -20,17 +45,21 @@ export const explainDamage = (health, command, mark = null) => {
|
|
|
20
45
|
const derived = [...new Set([...tables.filter((table) => isDerivedTable(table, indexNames)), ...badIndexes])];
|
|
21
46
|
const unopened = health.error !== undefined;
|
|
22
47
|
const json = (health.invalidJson ?? []).map(({ table, column }) => `${table}.${column}`);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
48
|
+
const damaged = !health.ok || mark !== null;
|
|
49
|
+
const folder = health.path.replace(/\/[^/]*$/, "");
|
|
50
|
+
const checked = !damaged
|
|
51
|
+
? `every page of the store reads, but ${journalSeen(health.path, journal)}; what was written into it may be lost`
|
|
52
|
+
: health.ok
|
|
53
|
+
? `${seen(mark)}; the quick check reads too little to see it, and a deep check that passes clears it`
|
|
54
|
+
: unopened
|
|
55
|
+
? `the store file cannot be opened: ${health.error}`
|
|
56
|
+
: health.checked === "quick"
|
|
57
|
+
? "the store file's header or schema is damaged"
|
|
58
|
+
: `the store file is damaged: ${health.problems ?? 0} problems` +
|
|
59
|
+
(sources.length ? ` in the data of ${named(sources)}` : "") +
|
|
60
|
+
(derived.length ? `${sources.length ? ", and" : " in"} the search data of ${named(derived)}` : "") +
|
|
61
|
+
(json.length ? `; values that are not valid JSON in ${named(json)}` : "");
|
|
62
|
+
const whatHappened = mark && !health.ok ? `${checked}; ${seen(mark)}` : checked;
|
|
34
63
|
const impact = [
|
|
35
64
|
...(sources.length
|
|
36
65
|
? [`some rows of ${named(sources)} cannot be read; a recovery keeps every row it can read and names the rest`]
|
|
@@ -41,30 +70,84 @@ export const explainDamage = (health, command, mark = null) => {
|
|
|
41
70
|
...(json.length
|
|
42
71
|
? [`a read of a row with a broken JSON value fails ("malformed JSON"); a recovery clears those values`]
|
|
43
72
|
: []),
|
|
44
|
-
|
|
45
|
-
? "
|
|
46
|
-
:
|
|
73
|
+
...(!damaged
|
|
74
|
+
? ["everything works; rows written while the journal was gone may be missing, and a sync fetches them again"]
|
|
75
|
+
: mark
|
|
76
|
+
? [
|
|
77
|
+
"reads that do not touch a damaged page work; every command that writes the store refuses until it is recovered",
|
|
78
|
+
]
|
|
79
|
+
: ["reads that do not touch a damaged page work; a write that touches one fails until the store is recovered"]),
|
|
80
|
+
];
|
|
81
|
+
const likelyCauses = [
|
|
82
|
+
...(journal
|
|
83
|
+
? [{ cause: journalSeen(health.path, journal), check: `ls -li --time-style=full-iso ${folder}/` }]
|
|
84
|
+
: []),
|
|
85
|
+
...(holders?.length
|
|
86
|
+
? [
|
|
87
|
+
{
|
|
88
|
+
cause: `two programs wrote the file without seeing each other: ${holders.map(({ name, pid }) => `${name} (process ${pid})`).join(", ")} still ${holders.length === 1 ? "has" : "have"} it open`,
|
|
89
|
+
check: `fuser -v ${health.path}`,
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
: []),
|
|
93
|
+
...(damaged
|
|
94
|
+
? [
|
|
95
|
+
{
|
|
96
|
+
cause: "the computer lost power or crashed while a tool was writing",
|
|
97
|
+
check: `journalctl --user ${WIRECAT_UNITS.map((unit) => `-u '${unit}'`).join(" ")} --since -14d | grep -i -e malformed -e corrupt -e 'disk full'`,
|
|
98
|
+
},
|
|
99
|
+
{ cause: "the disk filled up while a tool was writing", check: `df -h ${folder}` },
|
|
100
|
+
{
|
|
101
|
+
cause: "the file was copied, restored or synced while a tool had it open, or it sits in a synced or network folder",
|
|
102
|
+
check: `findmnt -T ${folder}`,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
cause: "a fault of the disk itself",
|
|
106
|
+
check: "journalctl -k --since -14d | grep -i -e 'I/O error' -e nvme -e ata",
|
|
107
|
+
},
|
|
108
|
+
]
|
|
109
|
+
: []),
|
|
110
|
+
];
|
|
111
|
+
const steps = [
|
|
112
|
+
stopWriters(timers),
|
|
113
|
+
...(holders ?? []).map(({ pid, name }) => ({
|
|
114
|
+
command: `kill ${pid}`,
|
|
115
|
+
why: `${name} (process ${pid}) has the store open`,
|
|
116
|
+
destructive: true,
|
|
117
|
+
})),
|
|
118
|
+
...(damaged && !sqlite3Usable
|
|
119
|
+
? [
|
|
120
|
+
{
|
|
121
|
+
command: "sudo apt install sqlite3",
|
|
122
|
+
why: "the recovery copies rows with the sqlite3 program, 3.43 or newer (on macOS: brew install sqlite)",
|
|
123
|
+
destructive: false,
|
|
124
|
+
},
|
|
125
|
+
]
|
|
126
|
+
: []),
|
|
127
|
+
...(damaged
|
|
128
|
+
? [
|
|
129
|
+
{
|
|
130
|
+
command: `${command} store recover run`,
|
|
131
|
+
why: "copies every readable row into a new file and puts it in place of the store; the damaged file is " +
|
|
132
|
+
"kept beside it, and it prints the syncs that fetch again what was lost",
|
|
133
|
+
destructive: true,
|
|
134
|
+
},
|
|
135
|
+
]
|
|
136
|
+
: []),
|
|
137
|
+
{
|
|
138
|
+
command: `${command} store recover`,
|
|
139
|
+
why: "checks every page again; a check that passes lifts the damage mark",
|
|
140
|
+
destructive: false,
|
|
141
|
+
},
|
|
47
142
|
];
|
|
48
143
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"the computer lost power or crashed, or the disk filled up, while a tool was writing",
|
|
52
|
-
"the file was copied, restored or synced while a tool had it open, or it sits in a synced or network folder",
|
|
53
|
-
"a fault of the disk itself",
|
|
54
|
-
],
|
|
55
|
-
investigate: [
|
|
56
|
-
`journalctl --user ${WIRECAT_UNITS.map((unit) => `-u '${unit}'`).join(" ")} --since -14d | grep -i -e malformed -e corrupt -e 'disk full'`,
|
|
57
|
-
"journalctl -k --since -14d | grep -i -e 'I/O error' -e nvme -e ata",
|
|
58
|
-
`df -h ${health.path.replace(/\/[^/]*$/, "")}`,
|
|
59
|
-
...(health.checked === "quick" || health.ok ? [`${command} store recover`] : []),
|
|
60
|
-
],
|
|
144
|
+
whatHappened,
|
|
145
|
+
likelyCauses,
|
|
61
146
|
impact,
|
|
62
|
-
|
|
63
|
-
"so whatever is lost here can be fetched again by a sync",
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"run the fetch commands it prints, then start the timers again",
|
|
68
|
-
],
|
|
147
|
+
externalDataSafe: "only this computer's copy is damaged: Telegram, MAX, WhatsApp, the mail servers and Google Drive keep their " +
|
|
148
|
+
"own data, so whatever is lost here can be fetched again by a sync",
|
|
149
|
+
lastOkAt,
|
|
150
|
+
loss: lossUnknown(lastOkAt),
|
|
151
|
+
steps,
|
|
69
152
|
};
|
|
70
153
|
};
|
package/dist/store/decisions.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { MEETING_FINDINGS_KIND } from "../meetings/index.js";
|
|
3
|
+
import { IDENTITY_LINK_KIND } from "./identity-links.js";
|
|
3
4
|
import { MAIL_FINDINGS_KIND } from "./mail-findings.js";
|
|
4
5
|
import { SOURCE_REVIEW_KIND } from "./source-review.js";
|
|
5
6
|
/** An agent's suggested close of a task: kept on the task, not in `proposed_actions`. */
|
|
@@ -12,7 +13,8 @@ export const DEFAULT_DECISION_POLICY = { agentDecisions: false, ruleProposalsOwn
|
|
|
12
13
|
export const isOwnerOnlyKind = (kind) => kind === MAIL_FINDINGS_KIND ||
|
|
13
14
|
kind === MEETING_FINDINGS_KIND ||
|
|
14
15
|
kind === TASK_CLOSE_KIND ||
|
|
15
|
-
kind === SOURCE_REVIEW_KIND
|
|
16
|
+
kind === SOURCE_REVIEW_KIND ||
|
|
17
|
+
kind === IDENTITY_LINK_KIND;
|
|
16
18
|
/**
|
|
17
19
|
* The one check every decide path runs before it confirms or rejects a proposal. `null` means allowed. Every Claude
|
|
18
20
|
* Code session is the bot `claude-code`, so comparing bot names keeps one session from deciding another's proposal.
|
|
@@ -25,6 +25,8 @@ export interface EvidenceFindingsBatch {
|
|
|
25
25
|
input: FindingsInput;
|
|
26
26
|
fingerprint: string;
|
|
27
27
|
status: "proposed" | "reviewed";
|
|
28
|
+
/** Only the owner decides it, whatever `agent_decisions` says: it was staged so, or it records a payment. */
|
|
29
|
+
ownerOnly: boolean;
|
|
28
30
|
author: {
|
|
29
31
|
type: "person" | "bot";
|
|
30
32
|
id: string;
|
|
@@ -43,11 +45,23 @@ export interface EvidenceFindingsBatch {
|
|
|
43
45
|
* Cited facts and follow-ups about one project from stored messages, mail and documents, staged by an agent for
|
|
44
46
|
* review. A sibling of meeting findings: the same rules, evidence checked against the current stored text.
|
|
45
47
|
*/
|
|
48
|
+
/** A stored record as a findings batch cites it: the text a quote must be in, and the fingerprint staging checks. */
|
|
49
|
+
export interface CitableRecord {
|
|
50
|
+
reference: string;
|
|
51
|
+
fingerprint: string;
|
|
52
|
+
title: string | null;
|
|
53
|
+
text: string;
|
|
54
|
+
}
|
|
46
55
|
export interface EvidenceFindingsStore {
|
|
56
|
+
/** `ownerOnly` keeps every agent from deciding the batch, whatever `agent_decisions` says. */
|
|
47
57
|
stage(input: FindingsInput, agent: {
|
|
48
58
|
bot: string;
|
|
49
59
|
model?: string;
|
|
60
|
+
}, options?: {
|
|
61
|
+
ownerOnly?: boolean;
|
|
50
62
|
}): Promise<EvidenceFindingsBatch>;
|
|
63
|
+
/** A `msg:`, `document:` or `note:` record as staging reads it; `null` when it is not stored. */
|
|
64
|
+
citable(reference: string): Promise<CitableRecord | null>;
|
|
51
65
|
get(id: string): Promise<EvidenceFindingsBatch>;
|
|
52
66
|
list(options?: {
|
|
53
67
|
project?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { formatLocator, parseLocator } from "../domain/locator.js";
|
|
3
3
|
import { validateFindings } from "../meetings/index.js";
|
|
4
|
+
import { QUOTE_LIMIT } from "./sqlite/evidence-signature.js";
|
|
4
5
|
import { entryAmount } from "./sqlite/payment-entries.js";
|
|
5
6
|
export const EVIDENCE_FINDINGS_KIND = "evidence_findings";
|
|
6
7
|
const reference = (raw) => {
|
|
@@ -21,6 +22,7 @@ export const validateEvidenceFindings = (input) => {
|
|
|
21
22
|
reference,
|
|
22
23
|
anySubject: true,
|
|
23
24
|
payments: true,
|
|
25
|
+
quotes: QUOTE_LIMIT,
|
|
24
26
|
});
|
|
25
27
|
// Refused at staging rather than when the owner accepts, which would fail the whole batch.
|
|
26
28
|
for (const finding of valid.findings)
|
package/dist/store/exports.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { BUSINESS_KINDS, type BusinessKind } from "../domain/business.js";
|
|
2
2
|
export type { CounterField, CounterObservations, CounterState } from "../domain/counters.js";
|
|
3
3
|
export type { RetentionOptions } from "../domain/retention.js";
|
|
4
|
-
export type { AccountAccounts, AccountsStore } from "./accounts.js";
|
|
4
|
+
export type { AccountAccounts, AccountGroupChange, AccountsStore } from "./accounts.js";
|
|
5
5
|
export type { AccountAttachments, AttachmentsStore } from "./attachments.js";
|
|
6
6
|
export type { ChatsStore, LeftChat, LeftChats } from "./chats.js";
|
|
7
7
|
export type { ConversationsStore } from "./conversations.js";
|
|
@@ -18,6 +18,7 @@ export { accountGroupsOf } from "./sqlite/account-groups.js";
|
|
|
18
18
|
export type { AdminStoreRequest, AdminStoreResult } from "./sqlite/admin-statistics.js";
|
|
19
19
|
export { type AttachmentTextEntry, type AttachmentView, attachmentColumns, type FileAttachment, resetAttachmentWords, type TextOrigin, } from "./sqlite/attachment-texts.js";
|
|
20
20
|
export { pendingNormalization } from "./sqlite/backfill.js";
|
|
21
|
+
export type { BaseScope, BaseSet, BaseStagesStore, StageMapping } from "./sqlite/base-stages.js";
|
|
21
22
|
export { BUSINESS_FIND_MAX, type BusinessHit, type BusinessSearch, type BusinessSearchStore, type BusinessSource, } from "./sqlite/business-search.js";
|
|
22
23
|
export type { ChatRekey, ChatRekeys } from "./sqlite/chat-rekey.js";
|
|
23
24
|
export { CHAT_COLUMNS, TRACKED_CHAT_COLUMNS, titlePart } from "./sqlite/chats.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Decider, Proposer } from "./decisions.js";
|
|
2
|
+
import type { Author } from "./sqlite/memories.js";
|
|
3
|
+
import type { IdentityRef } from "./types.js";
|
|
4
|
+
export declare const IDENTITY_LINK_KIND = "identity_link";
|
|
5
|
+
/**
|
|
6
|
+
* Why two people may be one: an agent said so, they share a phone or an address with others, or a meeting guest typed
|
|
7
|
+
* an address another person has.
|
|
8
|
+
*/
|
|
9
|
+
export declare const IDENTITY_LINK_SIGNALS: readonly ["agent", "phone", "email", "guest-email"];
|
|
10
|
+
export type IdentityLinkSignal = (typeof IDENTITY_LINK_SIGNALS)[number];
|
|
11
|
+
/** An `identity_link` proposal's payload. */
|
|
12
|
+
export interface IdentityLinkPayload {
|
|
13
|
+
/** `provider:id` of the identity that would move. */
|
|
14
|
+
identity: string;
|
|
15
|
+
/** `provider:id` of an identity of the person it would join; `null` for a person known by name only. */
|
|
16
|
+
with: string | null;
|
|
17
|
+
/** The person `identity` is on and the one it would join, as uids when it was proposed. */
|
|
18
|
+
persons: [string, string];
|
|
19
|
+
/** Each person's identities when it was proposed, so a confirm after either changed is refused. */
|
|
20
|
+
sides: [string, string];
|
|
21
|
+
/** `person` joins the two people; `identity` moves only `identity`, leaving the rest of its person. */
|
|
22
|
+
joins: "person" | "identity";
|
|
23
|
+
signal: IdentityLinkSignal;
|
|
24
|
+
score: number | null;
|
|
25
|
+
/** Every person the signal points at, the two included, when it points at more than two. */
|
|
26
|
+
candidates?: string[];
|
|
27
|
+
evidence: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface IdentityLinkInput {
|
|
30
|
+
identity: IdentityRef;
|
|
31
|
+
with: IdentityRef;
|
|
32
|
+
signal: IdentityLinkSignal;
|
|
33
|
+
by: Author;
|
|
34
|
+
reason?: string;
|
|
35
|
+
score?: number;
|
|
36
|
+
evidence?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface IdentityLinkDecision {
|
|
39
|
+
confirm: boolean;
|
|
40
|
+
/** `"owner"` only on a path that established the owner decides; an agent is refused whatever the policy says. */
|
|
41
|
+
by: Decider;
|
|
42
|
+
reason?: string;
|
|
43
|
+
}
|
|
44
|
+
/** One `identity_link`, naming the people as they are now, not as they were when it was proposed. */
|
|
45
|
+
export interface IdentityLinkRow {
|
|
46
|
+
id: string;
|
|
47
|
+
status: "proposed" | "confirmed" | "rejected";
|
|
48
|
+
/** `person:<uid>` of the person `identity` is on, then of the one it would join. */
|
|
49
|
+
persons: [string, string];
|
|
50
|
+
identity: string;
|
|
51
|
+
with: string | null;
|
|
52
|
+
joins: IdentityLinkPayload["joins"];
|
|
53
|
+
signal: IdentityLinkSignal;
|
|
54
|
+
score: number | null;
|
|
55
|
+
candidates: string[];
|
|
56
|
+
reason: string | null;
|
|
57
|
+
evidence: string[];
|
|
58
|
+
proposedBy: Proposer;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
}
|
|
61
|
+
export interface IdentityLinkFilter {
|
|
62
|
+
/** Only the proposals naming this person, or anyone merged into them, as they are now. */
|
|
63
|
+
person?: string;
|
|
64
|
+
/** `proposed` unless named. */
|
|
65
|
+
status?: IdentityLinkRow["status"] | "all";
|
|
66
|
+
limit: number;
|
|
67
|
+
offset: number;
|
|
68
|
+
}
|
|
69
|
+
/** What one pass of the people matcher did. */
|
|
70
|
+
export interface MatchScan {
|
|
71
|
+
/** Every identity was read, not only those changed since the last pass. */
|
|
72
|
+
full: boolean;
|
|
73
|
+
/** People joined without asking: the same personal address, or a phone exactly two people have. */
|
|
74
|
+
merged: {
|
|
75
|
+
into: string;
|
|
76
|
+
from: string;
|
|
77
|
+
signal: "same-email" | "same-phone";
|
|
78
|
+
}[];
|
|
79
|
+
/** Proposals opened, or open ones met again. */
|
|
80
|
+
proposed: {
|
|
81
|
+
id: string;
|
|
82
|
+
persons: [string, string];
|
|
83
|
+
signal: IdentityLinkSignal;
|
|
84
|
+
opened: boolean;
|
|
85
|
+
}[];
|
|
86
|
+
/** Pairs left apart, with why: the owner separated or rejected them, or too many people share the value. */
|
|
87
|
+
skipped: {
|
|
88
|
+
persons: string[];
|
|
89
|
+
signal: string;
|
|
90
|
+
reason: string;
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const IDENTITY_LINK_KIND = "identity_link";
|
|
2
|
+
/**
|
|
3
|
+
* Why two people may be one: an agent said so, they share a phone or an address with others, or a meeting guest typed
|
|
4
|
+
* an address another person has.
|
|
5
|
+
*/
|
|
6
|
+
export const IDENTITY_LINK_SIGNALS = ["agent", "phone", "email", "guest-email"];
|