@wirecat/cli-core 0.617.0 → 0.619.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 +406 -1
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES +3 -0
- package/dist/background/backfill.d.ts +21 -0
- package/dist/background/backfill.js +41 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/deliver.d.ts +5 -2
- package/dist/background/deliver.js +30 -12
- package/dist/background/report/messages.js +4 -1
- package/dist/background/report/render.d.ts +3 -1
- package/dist/background/report/render.js +3 -1
- package/dist/background/report/view.js +4 -1
- package/dist/background/schedules.d.ts +17 -0
- package/dist/background/schedules.js +21 -8
- 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/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/base-stages-command.d.ts +22 -0
- package/dist/cli/base-stages-command.js +174 -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.d.ts +5 -0
- package/dist/cli/context.js +1 -0
- package/dist/cli/group-lock.d.ts +42 -0
- package/dist/cli/group-lock.js +130 -0
- package/dist/cli/index.d.ts +10 -4
- package/dist/cli/index.js +10 -4
- package/dist/cli/messenger/backfill-command.js +27 -15
- package/dist/cli/messenger/contacts-command.js +10 -3
- package/dist/cli/messenger/context.js +1 -0
- package/dist/cli/messenger/doctor-command.js +3 -1
- package/dist/cli/messenger/models-command.js +1 -1
- package/dist/cli/messenger/serve-command.js +24 -2
- package/dist/cli/messenger/serve-outdated.d.ts +22 -0
- package/dist/cli/messenger/serve-outdated.js +100 -0
- 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 +46 -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/schedule/schedule-command.d.ts +9 -0
- package/dist/cli/schedule/schedule-command.js +13 -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/store-recover.d.ts +3 -3
- package/dist/cli/store-recover.js +47 -23
- package/dist/cli/store-settings.d.ts +2 -0
- package/dist/cli/store-settings.js +37 -9
- package/dist/crm/cli/index.js +38 -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/links.d.ts +17 -4
- package/dist/domain/links.js +20 -7
- package/dist/domain/mentions.d.ts +2 -12
- package/dist/domain/mentions.js +2 -19
- 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 +27 -2
- package/dist/domain/relations.js +37 -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 +157 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +10 -0
- package/dist/entities/deal.js +2 -0
- package/dist/entities/index.d.ts +23 -3
- 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 +44 -4
- package/dist/fetch/page.js +2 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- 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/mcp/index.d.ts +15 -15
- package/dist/meetings/result-items.d.ts +1 -0
- package/dist/meetings/result-items.js +1 -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/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 +7 -2
- package/dist/services/enrichment.js +46 -5
- 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 +15 -2
- package/dist/services/index.js +9 -2
- package/dist/services/ingest.d.ts +12 -0
- package/dist/services/ingest.js +4 -0
- package/dist/services/link-scorers/chat-senders.js +39 -29
- package/dist/services/link-scorers/member-chats.js +4 -3
- package/dist/services/link-scorers/member-dialog.js +5 -7
- package/dist/services/link-scorers/scan.js +17 -8
- package/dist/services/link-scorers/shared.d.ts +6 -2
- package/dist/services/link-scorers/shared.js +6 -2
- package/dist/services/link-scorers/types.d.ts +2 -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/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 +9 -1
- package/dist/services/person-context.js +5 -3
- 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-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/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/migrations.d.ts +1 -1
- package/dist/store/migrations.js +35 -12
- package/dist/store/people.d.ts +22 -0
- package/dist/store/people.js +15 -1
- package/dist/store/recover.d.ts +34 -0
- package/dist/store/recover.js +188 -6
- package/dist/store/refill.d.ts +28 -0
- package/dist/store/refill.js +120 -0
- package/dist/store/sqlite/accounts.js +2 -0
- 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/clients.d.ts +7 -3
- package/dist/store/sqlite/clients.js +11 -7
- 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 +17 -15
- 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/knowledge.js +5 -3
- 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/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/note-index.js +9 -7
- package/dist/store/sqlite/notes.d.ts +2 -3
- package/dist/store/sqlite/notes.js +6 -29
- 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/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 +20 -2
- package/dist/store/sqlite/relation-proposals.d.ts +18 -1
- package/dist/store/sqlite/relation-proposals.js +53 -11
- 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.d.ts +13 -0
- package/dist/store/sqlite/transaction.js +33 -15
- 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 +11 -4
- package/schemas/records-envelope.v1.schema.json +3 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileSchemaOf, SPEAKS, writableBy } from "../../store/compatibility.js";
|
|
4
|
+
import { openSqlite } from "../../store/store.js";
|
|
5
|
+
export const OUTDATED_CHECK_MS = 60_000;
|
|
6
|
+
/** The folder of the package this process was started from, when its `package.json` still names `running`. */
|
|
7
|
+
export const ownPackageRoot = (running, script = process.argv[1]) => {
|
|
8
|
+
let dir;
|
|
9
|
+
try {
|
|
10
|
+
dir = dirname(realpathSync(script ?? ""));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
for (let up = 0; up < 8; up++) {
|
|
16
|
+
const manifest = join(dir, "package.json");
|
|
17
|
+
if (existsSync(manifest))
|
|
18
|
+
return installedVersion(dir) === running ? dir : undefined;
|
|
19
|
+
const parent = dirname(dir);
|
|
20
|
+
if (parent === dir)
|
|
21
|
+
return undefined;
|
|
22
|
+
dir = parent;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
const installedVersion = (root) => {
|
|
27
|
+
try {
|
|
28
|
+
const { version } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
29
|
+
return typeof version === "string" ? version : undefined;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const newer = (one, other) => {
|
|
36
|
+
const parts = (version) => version.split(/[.+-]/, 3).map(Number);
|
|
37
|
+
const [a, b] = [parts(one), parts(other)];
|
|
38
|
+
for (let i = 0; i < 3; i++)
|
|
39
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0))
|
|
40
|
+
return (a[i] ?? 0) > (b[i] ?? 0);
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Why this serve should stop so its unit starts the installed build (BUG-643): the store moved past what this build
|
|
45
|
+
* may write, or a newer version was installed over it. A store that cannot be read now is not a reason.
|
|
46
|
+
*/
|
|
47
|
+
export const outdatedReason = async ({ command, running, storePath, packageRoot, speaks = SPEAKS, }) => {
|
|
48
|
+
const installed = packageRoot === undefined ? undefined : installedVersion(packageRoot);
|
|
49
|
+
if (installed !== undefined && newer(installed, running))
|
|
50
|
+
return `${command} ${installed} is installed and this serve runs ${running}: stopping so it starts again on ${installed}`;
|
|
51
|
+
if (!existsSync(storePath))
|
|
52
|
+
return undefined;
|
|
53
|
+
let schema;
|
|
54
|
+
try {
|
|
55
|
+
const { database } = await openSqlite(storePath, { readOnly: true });
|
|
56
|
+
try {
|
|
57
|
+
schema = fileSchemaOf(database);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
database.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
if (writableBy(schema, speaks))
|
|
67
|
+
return undefined;
|
|
68
|
+
return (`the store is at format ${schema.version} and needs at least ${schema.minCompatible}; this serve (${command} ` +
|
|
69
|
+
`${running}) speaks ${speaks} and can no longer write it: stopping — \`${command} upgrade\` if it does not start ` +
|
|
70
|
+
"again on a newer version");
|
|
71
|
+
};
|
|
72
|
+
/** Runs `check` every `everyMs` and calls `onOutdated` once with its first reason. */
|
|
73
|
+
export const watchOutdated = ({ check, onOutdated, everyMs = OUTDATED_CHECK_MS, }) => {
|
|
74
|
+
let busy = false;
|
|
75
|
+
let done = false;
|
|
76
|
+
const timer = setInterval(() => {
|
|
77
|
+
if (busy || done)
|
|
78
|
+
return;
|
|
79
|
+
busy = true;
|
|
80
|
+
check()
|
|
81
|
+
.then((reason) => {
|
|
82
|
+
if (reason === undefined || done)
|
|
83
|
+
return;
|
|
84
|
+
done = true;
|
|
85
|
+
clearInterval(timer);
|
|
86
|
+
onOutdated(reason);
|
|
87
|
+
})
|
|
88
|
+
.catch(() => { })
|
|
89
|
+
.finally(() => {
|
|
90
|
+
busy = false;
|
|
91
|
+
});
|
|
92
|
+
}, everyMs);
|
|
93
|
+
timer.unref();
|
|
94
|
+
return {
|
|
95
|
+
stop: () => {
|
|
96
|
+
done = true;
|
|
97
|
+
clearInterval(timer);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -32,6 +32,7 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
|
|
|
32
32
|
run_id?: string;
|
|
33
33
|
error: string;
|
|
34
34
|
} | undefined;
|
|
35
|
+
journalMark?: import("../../store/marks.js").JournalMark | undefined;
|
|
35
36
|
damageMarkCleared?: {
|
|
36
37
|
at: string;
|
|
37
38
|
command: string;
|
|
@@ -39,7 +40,16 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
|
|
|
39
40
|
run_id?: string;
|
|
40
41
|
error: string;
|
|
41
42
|
} | undefined;
|
|
42
|
-
damage?:
|
|
43
|
+
damage?: {
|
|
44
|
+
whatHappened: string;
|
|
45
|
+
likelyCauses: import("../../store/damage.js").DamageCause[];
|
|
46
|
+
impact: string[];
|
|
47
|
+
externalDataSafe: string;
|
|
48
|
+
lastOkAt: string | null;
|
|
49
|
+
loss: string;
|
|
50
|
+
steps: import("../../store/damage.js").RecoveryStep[];
|
|
51
|
+
what: string;
|
|
52
|
+
} | undefined;
|
|
43
53
|
path: string;
|
|
44
54
|
exists: boolean;
|
|
45
55
|
schema: number;
|
|
@@ -66,6 +76,7 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
|
|
|
66
76
|
run_id?: string;
|
|
67
77
|
error: string;
|
|
68
78
|
} | undefined;
|
|
79
|
+
journalMark?: import("../../store/marks.js").JournalMark | undefined;
|
|
69
80
|
damageMarkCleared?: {
|
|
70
81
|
at: string;
|
|
71
82
|
command: string;
|
|
@@ -73,7 +84,16 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
|
|
|
73
84
|
run_id?: string;
|
|
74
85
|
error: string;
|
|
75
86
|
} | undefined;
|
|
76
|
-
damage?:
|
|
87
|
+
damage?: {
|
|
88
|
+
whatHappened: string;
|
|
89
|
+
likelyCauses: import("../../store/damage.js").DamageCause[];
|
|
90
|
+
impact: string[];
|
|
91
|
+
externalDataSafe: string;
|
|
92
|
+
lastOkAt: string | null;
|
|
93
|
+
loss: string;
|
|
94
|
+
steps: import("../../store/damage.js").RecoveryStep[];
|
|
95
|
+
what: string;
|
|
96
|
+
} | undefined;
|
|
77
97
|
path: string;
|
|
78
98
|
exists: boolean;
|
|
79
99
|
error: string;
|
|
@@ -8,9 +8,9 @@ import { RULES_VERSION } from "../../conversations/link.js";
|
|
|
8
8
|
import { syncsOneChat } from "../../ports/traits.js";
|
|
9
9
|
import { isSealed, sealFile, unsealFile } from "../../sealed.js";
|
|
10
10
|
import { fileSchemaOf, SPEAKS, writableBy } from "../../store/compatibility.js";
|
|
11
|
-
import {
|
|
11
|
+
import { storeDamageReport } from "../../store/damage.js";
|
|
12
12
|
import { QUICK_HEALTH_CHECKS, storeHealth } from "../../store/health.js";
|
|
13
|
-
import { readDamageMark, readHealthMark, recordDeepCheck } from "../../store/marks.js";
|
|
13
|
+
import { readDamageMark, readHealthMark, readJournalMark, recordDeepCheck } from "../../store/marks.js";
|
|
14
14
|
import { migrate } from "../../store/migrations.js";
|
|
15
15
|
import { openCache } from "../../store/open.js";
|
|
16
16
|
import { storePath } from "../../store/path.js";
|
|
@@ -79,6 +79,7 @@ export const storeSummary = async (env, { deep = false, command, version } = {})
|
|
|
79
79
|
if (!existsSync(path))
|
|
80
80
|
return { path, exists: false };
|
|
81
81
|
const checked = await storeHealth(path, { deep });
|
|
82
|
+
const journal = readJournalMark(path);
|
|
82
83
|
const recorded = deep
|
|
83
84
|
? recordDeepCheck(path, checked, {
|
|
84
85
|
cli: command ?? "unknown",
|
|
@@ -100,13 +101,17 @@ export const storeSummary = async (env, { deep = false, command, version } = {})
|
|
|
100
101
|
? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) }
|
|
101
102
|
: {}),
|
|
102
103
|
};
|
|
103
|
-
const damage = command
|
|
104
|
+
const damage = command
|
|
105
|
+
? storeDamageReport({ health: checked, command, mark, journal, lastOkAt: lastKnownGood })
|
|
106
|
+
: null;
|
|
104
107
|
const healthOf = {
|
|
105
108
|
health,
|
|
106
109
|
lastKnownGood,
|
|
107
110
|
...(mark ? { damageMark: withoutInode(mark) } : {}),
|
|
111
|
+
...(journal ? { journalMark: journal } : {}),
|
|
108
112
|
...(recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {}),
|
|
109
|
-
|
|
113
|
+
// `what` keeps memo's doctor, which reads it, compiling until it moves to `whatHappened`.
|
|
114
|
+
...(damage ? { damage: { what: damage.whatHappened, ...damage } } : {}),
|
|
110
115
|
};
|
|
111
116
|
try {
|
|
112
117
|
return await reading(path, (database) => {
|
|
@@ -13,8 +13,10 @@ export interface ModelCatalogueOptions {
|
|
|
13
13
|
* (memo): it changes the shared store for every CLI.
|
|
14
14
|
*/
|
|
15
15
|
enrichment?: boolean;
|
|
16
|
-
/** Where `models consents`
|
|
16
|
+
/** Where `models consents` and `models keys` keep the provider's key; the system keyring when absent. */
|
|
17
17
|
keyring?: KeyringStore;
|
|
18
|
+
/** Where `models keys set` reads the key; process.stdin when absent. */
|
|
19
|
+
stdin?: () => NodeJS.ReadableStream | undefined;
|
|
18
20
|
output: (answer: Body, command: Command) => void;
|
|
19
21
|
diagnostic: (line: string) => void;
|
|
20
22
|
jsonOption?: boolean;
|
|
@@ -4,11 +4,13 @@ import { annotate } from "@wirecat/cli-base/commands";
|
|
|
4
4
|
import { defineQuery } from "@wirecat/cli-base/query";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { isTextModelInstalled, textModelsDirectory } from "../embeddings/embed.js";
|
|
7
|
+
import { embeddingKeys } from "../embeddings/keys.js";
|
|
7
8
|
import { chosenTextModel, DEFAULT_TEXT_MODEL, textModel, textModels } from "../embeddings/models.js";
|
|
8
9
|
import { downloadTextModel } from "../services/model-downloads.js";
|
|
9
10
|
import { addCustomTextModel, useTextModel } from "../services/text-model-choice.js";
|
|
10
11
|
import { install, installedBytes, isInstalled, modelsDirectory } from "../speech/install.js";
|
|
11
12
|
import { DEFAULT_ORDER, orderedModels, speechModel } from "../speech/models.js";
|
|
13
|
+
import { readSecret } from "../terminal/prompt.js";
|
|
12
14
|
import { stepLines } from "../terminal/step-lines.js";
|
|
13
15
|
import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
|
|
14
16
|
import { enrichmentConsentsCommand } from "./enrichment-consents-command.js";
|
|
@@ -70,7 +72,7 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
70
72
|
.description("download and verify one speech or embedding model")
|
|
71
73
|
.argument("<model>", "a model id from models list")
|
|
72
74
|
.option("--offline", "refuse a download that needs the network")
|
|
73
|
-
.option("--accept-terms", "
|
|
75
|
+
.option("--accept-terms", "no longer needed; kept so older scripts still run")
|
|
74
76
|
.action(async function (id, given) {
|
|
75
77
|
if (options.offline?.() || this.optsWithGlobals().offline)
|
|
76
78
|
throw new CliError("permission_error", "downloading a model needs the network; --offline was requested", {
|
|
@@ -138,13 +140,55 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
138
140
|
options.output(itemOf(textModelItem(model, env)), this);
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
|
-
if (options.enrichment === true)
|
|
143
|
+
if (options.enrichment === true) {
|
|
142
144
|
models.addCommand(enrichmentConsentsCommand(app, options));
|
|
145
|
+
models.addCommand(providerKeysCommand(app, options));
|
|
146
|
+
}
|
|
143
147
|
if (options.jsonOption)
|
|
144
148
|
for (const command of models.commands.flatMap((one) => (one.commands.length ? one.commands : [one])))
|
|
145
149
|
command.option("--json", "print JSON");
|
|
146
150
|
return models;
|
|
147
151
|
};
|
|
152
|
+
const PROVIDER = /^[a-z0-9][a-z0-9.:-]*$/;
|
|
153
|
+
const providerOf = (given) => {
|
|
154
|
+
const provider = given.trim().toLowerCase();
|
|
155
|
+
if (!PROVIDER.test(provider))
|
|
156
|
+
throw new CliError("validation_error", "name the provider: openai, anthropic, or the host of a --base-url server");
|
|
157
|
+
return provider;
|
|
158
|
+
};
|
|
159
|
+
/** The enrichment provider's key in the tool's keyring entry `embeddings:<provider>`; never printed, never an argument. */
|
|
160
|
+
const providerKeysCommand = (app, options) => {
|
|
161
|
+
const keys = new Command("keys").description("the API key write-time enrichment sends with each request");
|
|
162
|
+
const store = () => embeddingKeys(app, options.env(), options.keyring);
|
|
163
|
+
grantsAuthority(annotate(keys.command("set"), {
|
|
164
|
+
effects: LOCAL_WRITE,
|
|
165
|
+
output: { entity: "model_key", view: "stored" },
|
|
166
|
+
examples: [`${app.command} models keys set openai < key.txt`],
|
|
167
|
+
}))
|
|
168
|
+
.argument("<provider>", "openai, anthropic, or the host of a --base-url server that wants a key")
|
|
169
|
+
.description("store a key, typed at a hidden prompt or piped on stdin — never as an argument")
|
|
170
|
+
.action(async function (given) {
|
|
171
|
+
const provider = providerOf(given);
|
|
172
|
+
const input = options.stdin?.();
|
|
173
|
+
const secret = (await readSecret(`API key for ${provider}: `, input ? { input } : {})).trim();
|
|
174
|
+
if (!secret)
|
|
175
|
+
throw new CliError("validation_error", "no key was given — nothing was stored");
|
|
176
|
+
options.output(itemOf({ provider, stored: true, source: store().write(provider, secret) }), this);
|
|
177
|
+
});
|
|
178
|
+
grantsAuthority(annotate(keys.command("remove"), {
|
|
179
|
+
effects: LOCAL_WRITE,
|
|
180
|
+
output: { entity: "model_key", view: "removed" },
|
|
181
|
+
examples: [`${app.command} models keys remove openai`],
|
|
182
|
+
}))
|
|
183
|
+
.argument("<provider>", "openai, anthropic, or a server's host")
|
|
184
|
+
.description("forget the stored key; a key in the environment stays")
|
|
185
|
+
.action(function (given) {
|
|
186
|
+
const provider = providerOf(given);
|
|
187
|
+
const removed = store().remove(provider);
|
|
188
|
+
options.output(itemOf({ provider, removed: removed.length > 0, from: removed }), this);
|
|
189
|
+
});
|
|
190
|
+
return keys;
|
|
191
|
+
};
|
|
148
192
|
const PROGRESS_EVERY_MS = 500;
|
|
149
193
|
/**
|
|
150
194
|
* `{"event":"progress","step":"download",…}` on stderr under --json, for a window to draw a bar by: at most every half
|
package/dist/cli/profile.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
+
import { type AppIdentity } from "../ports/app.js";
|
|
3
|
+
import type { RunGroup } from "../search/groups.js";
|
|
2
4
|
/** How the command line names this profile: always the first word, since none is assumed. */
|
|
3
5
|
export declare const asFirstWord: (profile: string) => string;
|
|
4
6
|
export declare const isProfileName: (word: string) => boolean;
|
|
@@ -27,6 +29,12 @@ export declare const liftProfile: (argv: string[], words: Set<string>, valued?:
|
|
|
27
29
|
profile?: string;
|
|
28
30
|
rest: string[];
|
|
29
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* The group a run reads, from the first word (`liftProfile` lifts it) or `<PREFIX>_GROUP`; `all`, the default, is
|
|
34
|
+
* every account, so no restriction. Under `<PREFIX>_GROUP_LOCK` any other group, `all` included, is refused, as the
|
|
35
|
+
* profile lock refuses another profile (WC-ACCT-5); a lock of `all` locks nothing.
|
|
36
|
+
*/
|
|
37
|
+
export declare const runGroup: (app: AppIdentity, env: NodeJS.ProcessEnv, word?: string) => RunGroup | undefined;
|
|
30
38
|
/** The root's options that take the next word as their value: `--timeout 30s`. */
|
|
31
39
|
export declare const valuedOptions: (program: Command) => Set<string>;
|
|
32
40
|
/**
|
package/dist/cli/profile.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { envName } from "../ports/app.js";
|
|
3
|
+
import { isGroupName } from "../search/account-list.js";
|
|
2
4
|
/** How the command line names this profile: always the first word, since none is assumed. */
|
|
3
5
|
export const asFirstWord = (profile) => `${profile} `;
|
|
4
6
|
/**
|
|
@@ -57,6 +59,29 @@ export const liftProfile = (argv, words, valued = new Set()) => {
|
|
|
57
59
|
return { rest: argv };
|
|
58
60
|
return { profile: first, rest: [...argv.slice(0, at), ...argv.slice(at + 1)] };
|
|
59
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The group a run reads, from the first word (`liftProfile` lifts it) or `<PREFIX>_GROUP`; `all`, the default, is
|
|
64
|
+
* every account, so no restriction. Under `<PREFIX>_GROUP_LOCK` any other group, `all` included, is refused, as the
|
|
65
|
+
* profile lock refuses another profile (WC-ACCT-5); a lock of `all` locks nothing.
|
|
66
|
+
*/
|
|
67
|
+
export const runGroup = (app, env, word) => {
|
|
68
|
+
const GROUP = envName(app, "GROUP");
|
|
69
|
+
const LOCK = envName(app, "GROUP_LOCK");
|
|
70
|
+
const lock = env[LOCK]?.trim() || undefined;
|
|
71
|
+
const named = word ?? (env[GROUP]?.trim() || undefined);
|
|
72
|
+
const from = word === undefined ? GROUP : "first word";
|
|
73
|
+
for (const [name, origin] of [
|
|
74
|
+
[named, from],
|
|
75
|
+
[lock, LOCK],
|
|
76
|
+
])
|
|
77
|
+
if (name !== undefined && !isGroupName(name))
|
|
78
|
+
throw new CliError("validation_error", `"${name}" (${origin}) is not a group name — letters, digits, - and _, starting with a letter or a digit`);
|
|
79
|
+
if (lock === undefined || lock.toLowerCase() === "all")
|
|
80
|
+
return named === undefined || named.toLowerCase() === "all" ? undefined : { name: named, from, locked: false };
|
|
81
|
+
if (named !== undefined && named !== lock)
|
|
82
|
+
throw new CliError("permission_error", `this process is locked to group ${lock} (${LOCK}) — group "${named}" (${from}) is refused`);
|
|
83
|
+
return { name: lock, from: LOCK, locked: true };
|
|
84
|
+
};
|
|
60
85
|
/** The root's options that take the next word as their value: `--timeout 30s`. */
|
|
61
86
|
export const valuedOptions = (program) => new Set(program.options
|
|
62
87
|
.filter((option) => option.required)
|
package/dist/cli/program.js
CHANGED
|
@@ -25,6 +25,7 @@ import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, isLogin, is
|
|
|
25
25
|
import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
|
|
26
26
|
import { byteCount, DEFAULT_AGENT_COOPERATIVE_MS, DEFAULT_COMMAND_MS, DEFAULT_COOPERATIVE_MS, DEFAULT_OUTPUT_BYTES, DEFAULT_SYNC_MS, execution, } from "./execution.js";
|
|
27
27
|
import { setupAtStart } from "./first-run.js";
|
|
28
|
+
import { refuseOutsideGroup } from "./group-lock.js";
|
|
28
29
|
import { installHelp } from "./help/first-screen.js";
|
|
29
30
|
import { showInputFields } from "./input-fields.js";
|
|
30
31
|
import { MAX_BUFFERED_INPUT, provideInputPolicy } from "./input-policy.js";
|
|
@@ -321,6 +322,7 @@ const runOnce = async (argv, definition, options) => {
|
|
|
321
322
|
input,
|
|
322
323
|
terminal: !options.streams && input.isTTY === true && process.stderr.isTTY === true,
|
|
323
324
|
});
|
|
325
|
+
await refuseOutsideGroup(action, { app: definition.app, env: commandEnv });
|
|
324
326
|
if (lock && isLogin(action) && !flags.dryRun)
|
|
325
327
|
throw readOnlyRefusal(lock, "log in or out");
|
|
326
328
|
if (lock && isStoreChange(action) && !flags.dryRun)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type QueryWords } from "../list-query.js";
|
|
2
2
|
import type { RunSearch } from "./search.js";
|
|
3
3
|
export declare const RUN_SEARCH_QUERY: import("@wirecat/cli-base/query").QueryRegistry;
|
|
4
|
-
export declare const runSearchFilter: (words: QueryWords) => Pick<RunSearch, "terms" | "status" | "errorCode" | "operation" | "profile" | "since" | "until">;
|
|
4
|
+
export declare const runSearchFilter: (words: QueryWords) => Pick<RunSearch, "terms" | "status" | "errorCode" | "operation" | "profile" | "kind" | "table" | "since" | "until">;
|
|
@@ -15,6 +15,8 @@ export const RUN_SEARCH_QUERY = defineQuery({
|
|
|
15
15
|
termField("error_code", "kw", "error_code:rate_limited"),
|
|
16
16
|
termField("operation", "kw", "operation:messages.download"),
|
|
17
17
|
termField("profile", "kw", "profile:work"),
|
|
18
|
+
termField("kind", "kw", "kind:store"),
|
|
19
|
+
termField("table", "kw", "table:emails"),
|
|
18
20
|
],
|
|
19
21
|
});
|
|
20
22
|
export const runSearchFilter = (words) => {
|
|
@@ -62,5 +64,7 @@ export const runSearchFilter = (words) => {
|
|
|
62
64
|
...(fields.has("error_code") ? { errorCode: fields.get("error_code") } : {}),
|
|
63
65
|
...(fields.has("operation") ? { operation: fields.get("operation") } : {}),
|
|
64
66
|
...(fields.has("profile") ? { profile: fields.get("profile") } : {}),
|
|
67
|
+
...(fields.has("kind") ? { kind: fields.get("kind") } : {}),
|
|
68
|
+
...(fields.has("table") ? { table: fields.get("table") } : {}),
|
|
65
69
|
};
|
|
66
70
|
};
|
|
@@ -5,12 +5,16 @@ export interface RunSearch {
|
|
|
5
5
|
errorCode?: string;
|
|
6
6
|
operation?: string;
|
|
7
7
|
profile?: string;
|
|
8
|
+
/** An event's `kind`: `store` for the writes a run made to the store. */
|
|
9
|
+
kind?: string;
|
|
10
|
+
/** A store event's table. */
|
|
11
|
+
table?: string;
|
|
8
12
|
since?: string;
|
|
9
13
|
until?: string;
|
|
10
14
|
limit?: number;
|
|
11
15
|
page?: number;
|
|
12
16
|
}
|
|
13
|
-
export declare const searchRuns: (dir: string, { query, terms, status, errorCode, operation, profile, since, until, limit, page }?: RunSearch) => {
|
|
17
|
+
export declare const searchRuns: (dir: string, { query, terms, status, errorCode, operation, profile, kind, table, since, until, limit, page, }?: RunSearch) => {
|
|
14
18
|
items: {
|
|
15
19
|
runId: string;
|
|
16
20
|
command: string;
|
package/dist/cli/runs/search.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { findRun, listRuns, readEvents } from "../../runs/run.js";
|
|
3
3
|
import { dateWindow } from "../../services/moment.js";
|
|
4
4
|
import { listOf, snakeKeys } from "../envelope.js";
|
|
5
|
+
const STORE_WRITE = "store.write";
|
|
5
6
|
const FIELDS = [
|
|
6
7
|
"event",
|
|
7
8
|
"operation",
|
|
@@ -19,6 +20,10 @@ const FIELDS = [
|
|
|
19
20
|
"provider_error",
|
|
20
21
|
"code",
|
|
21
22
|
"reason",
|
|
23
|
+
"kind",
|
|
24
|
+
"table",
|
|
25
|
+
"op",
|
|
26
|
+
"n",
|
|
22
27
|
"time",
|
|
23
28
|
];
|
|
24
29
|
const safeEvent = (event) => Object.fromEntries(FIELDS.flatMap((name) => {
|
|
@@ -34,7 +39,7 @@ const safeEvent = (event) => Object.fromEntries(FIELDS.flatMap((name) => {
|
|
|
34
39
|
}
|
|
35
40
|
return typeof value === "string" || typeof value === "number" ? [[name, value]] : [];
|
|
36
41
|
}));
|
|
37
|
-
export const searchRuns = (dir, { query = "", terms = [], status, errorCode, operation, profile, since, until, limit = 20, page = 1 } = {}) => {
|
|
42
|
+
export const searchRuns = (dir, { query = "", terms = [], status, errorCode, operation, profile, kind, table, since, until, limit = 20, page = 1, } = {}) => {
|
|
38
43
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 || !Number.isSafeInteger(page) || page < 1)
|
|
39
44
|
throw new CliError("validation_error", "run search uses a limit from 1 to 100 and a positive page");
|
|
40
45
|
const window = dateWindow({ sinceTime: since, untilTime: until });
|
|
@@ -54,12 +59,16 @@ export const searchRuns = (dir, { query = "", terms = [], status, errorCode, ope
|
|
|
54
59
|
run.errorCode === errorCode ||
|
|
55
60
|
run.partial?.failures.some((failure) => failure.errorCode === errorCode)) &&
|
|
56
61
|
!operation &&
|
|
62
|
+
!kind &&
|
|
63
|
+
!table &&
|
|
57
64
|
needles.every((needle) => JSON.stringify(run).toLowerCase().includes(needle));
|
|
58
65
|
// A finished run lists its operations and codes, so a run that cannot match is never opened.
|
|
59
66
|
// One still running, or killed, has no such list and is read.
|
|
60
67
|
const ruledOut = !metadataMatch &&
|
|
61
68
|
needles.length === 0 &&
|
|
62
69
|
((operation !== undefined && run.operations !== undefined && !run.operations.includes(operation)) ||
|
|
70
|
+
(kind === "store" && run.operations !== undefined && !run.operations.includes(STORE_WRITE)) ||
|
|
71
|
+
(table !== undefined && run.operations !== undefined && !(run.tables ?? []).includes(table)) ||
|
|
63
72
|
(errorCode !== undefined && run.codes !== undefined && !run.codes.includes(errorCode)));
|
|
64
73
|
if (ruledOut)
|
|
65
74
|
continue;
|
|
@@ -67,6 +76,8 @@ export const searchRuns = (dir, { query = "", terms = [], status, errorCode, ope
|
|
|
67
76
|
const events = found ? readEvents(found.dir).map(safeEvent) : [];
|
|
68
77
|
const filtered = events.filter((event) => (!errorCode || event.error_code === errorCode || event.code === errorCode) &&
|
|
69
78
|
(!operation || event.operation === operation) &&
|
|
79
|
+
(!kind || event.kind === kind) &&
|
|
80
|
+
(!table || event.table === table) &&
|
|
70
81
|
needles.every((needle) => JSON.stringify(event).toLowerCase().includes(needle)));
|
|
71
82
|
if (!metadataMatch && filtered.length === 0)
|
|
72
83
|
continue;
|
|
@@ -46,6 +46,15 @@ export declare const scheduleLimitsOf: (config: {
|
|
|
46
46
|
}) => ScheduleLimits;
|
|
47
47
|
/** The language a report is rendered in: the store's `owner_languages`, first one; Russian when it cannot be read. */
|
|
48
48
|
export declare const ownerLanguageOf: (env: NodeJS.ProcessEnv) => Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* One past day's run of the agent schedule in `file`, as `backfillSchedule` makes it, with the owner's language and
|
|
51
|
+
* templates as `schedule run` renders them; a stop of the command stops the agent.
|
|
52
|
+
*/
|
|
53
|
+
export declare const backfillScheduleRun: (command: Command, app: AppIdentity, env: NodeJS.ProcessEnv, file: string, { at, input, agentRuns }: {
|
|
54
|
+
at: Date;
|
|
55
|
+
input?: string;
|
|
56
|
+
agentRuns?: readonly AgentCli[];
|
|
57
|
+
}) => Promise<import("../../background/schedules.js").LastRun>;
|
|
49
58
|
/**
|
|
50
59
|
* Runs the CLI's own commands, or an agent, later or on a timer — through systemd (Linux), launchd
|
|
51
60
|
* (macOS) or Task Scheduler (Windows). Every timer runs `schedule exec <file>`; the schedule file holds
|
|
@@ -3,6 +3,7 @@ import { dirname, join } from "node:path";
|
|
|
3
3
|
import { CliError, resolvePaths, writeSecurely } from "@wirecat/cli-base";
|
|
4
4
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
5
|
import { Argument, Command, Option } from "commander";
|
|
6
|
+
import { backfillSchedule } from "../../background/backfill.js";
|
|
6
7
|
import { parseRoute, ROUTE_HELP, routeText } from "../../background/deliver.js";
|
|
7
8
|
import { REPORT_CHANNELS } from "../../background/report/render.js";
|
|
8
9
|
import { keyOfKind } from "../../background/report/stored-templates.js";
|
|
@@ -186,6 +187,18 @@ const reportTemplatesOf = (env) => async (kind, language) => {
|
|
|
186
187
|
database.close();
|
|
187
188
|
}
|
|
188
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* One past day's run of the agent schedule in `file`, as `backfillSchedule` makes it, with the owner's language and
|
|
192
|
+
* templates as `schedule run` renders them; a stop of the command stops the agent.
|
|
193
|
+
*/
|
|
194
|
+
export const backfillScheduleRun = (command, app, env, file, { at, input, agentRuns = [] }) => untilChildEnds(command, (signal) => backfillSchedule(app, environmentOf(command).system ?? thisMachine(), env, file, {
|
|
195
|
+
at,
|
|
196
|
+
agentRuns,
|
|
197
|
+
ownerLanguage: ownerLanguageOf,
|
|
198
|
+
reportTemplates: reportTemplatesOf,
|
|
199
|
+
...(input === undefined ? {} : { input }),
|
|
200
|
+
...(signal ? { signal } : {}),
|
|
201
|
+
}));
|
|
189
202
|
/**
|
|
190
203
|
* Runs the CLI's own commands, or an agent, later or on a timer — through systemd (Linux), launchd
|
|
191
204
|
* (macOS) or Task Scheduler (Windows). Every timer runs `schedule exec <file>`; the schedule file holds
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
-
import { type PermissionKey } from "../sends/permissions.js";
|
|
3
|
+
import { type Level, type PermissionKey } from "../sends/permissions.js";
|
|
4
4
|
/** The list command whose level guards each kind a shared `search all` reads. */
|
|
5
5
|
declare const LIST_KEYS: {
|
|
6
6
|
readonly deal: "deals.list";
|
|
@@ -19,6 +19,11 @@ export interface LeftOut<K extends SearchedKind> {
|
|
|
19
19
|
/** `deal left out: profile work denies deals.list` */
|
|
20
20
|
why: string;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
|
|
24
|
+
* `why` (`memo's permissions`).
|
|
25
|
+
*/
|
|
26
|
+
export declare const deniedKindsOf: <K extends SearchedKind>(permissions: Readonly<Record<PermissionKey, Level>>, kinds: readonly K[], by: string, defaults?: Readonly<Record<PermissionKey, Level>>) => LeftOut<K>[];
|
|
22
27
|
/**
|
|
23
28
|
* The kinds whose list the profile denies, so `search all` leaves them out rather than show their titles and excerpts
|
|
24
29
|
* under another key (SEC-144). Levels as the run judged the command: the profile's, `--permission`, and an MCP
|
|
@@ -13,6 +13,14 @@ const LIST_KEYS = {
|
|
|
13
13
|
events: "events.list",
|
|
14
14
|
meetings: "meetings.list",
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
|
|
18
|
+
* `why` (`memo's permissions`).
|
|
19
|
+
*/
|
|
20
|
+
export const deniedKindsOf = (permissions, kinds, by, defaults) => kinds
|
|
21
|
+
.map((kind) => ({ kind, key: LIST_KEYS[kind] }))
|
|
22
|
+
.filter(({ key }) => levelFor(permissions, key, defaults).level === "deny")
|
|
23
|
+
.map((one) => ({ ...one, why: `${one.kind} left out: ${by} denies ${one.key}` }));
|
|
16
24
|
/**
|
|
17
25
|
* The kinds whose list the profile denies, so `search all` leaves them out rather than show their titles and excerpts
|
|
18
26
|
* under another key (SEC-144). Levels as the run judged the command: the profile's, `--permission`, and an MCP
|
|
@@ -26,8 +34,5 @@ export const deniedKinds = (command, app, kinds) => {
|
|
|
26
34
|
needsProfile: false,
|
|
27
35
|
readOnly: true,
|
|
28
36
|
});
|
|
29
|
-
return kinds
|
|
30
|
-
.map((kind) => ({ kind, key: LIST_KEYS[kind] }))
|
|
31
|
-
.filter(({ key }) => levelFor(permissions, key, environment.permissionDefaults).level === "deny")
|
|
32
|
-
.map((one) => ({ ...one, why: `${one.kind} left out: profile ${profile} denies ${one.key}` }));
|
|
37
|
+
return deniedKindsOf(permissions, kinds, `profile ${profile}`, environment.permissionDefaults);
|
|
33
38
|
};
|
package/dist/cli/settings.d.ts
CHANGED
|
@@ -102,6 +102,8 @@ export interface Settings extends AISettings {
|
|
|
102
102
|
searchCatchUp?: boolean;
|
|
103
103
|
/** How much pushed history the store keeps, by chat kind; a messenger that answers history on request ignores it. */
|
|
104
104
|
historyLimits?: HistoryLimits;
|
|
105
|
+
/** `messages sync --all` reads muted chats too. Off until set. */
|
|
106
|
+
historyMuted?: boolean;
|
|
105
107
|
/** Search and `images embed` read the pictures themselves, with a model on this machine. Off until set. */
|
|
106
108
|
pictureSearch?: boolean;
|
|
107
109
|
/** The reranker that orders `search messages --discover`'s first hits once it is downloaded, or `off`. */
|
|
@@ -131,6 +133,8 @@ export interface Settings extends AISettings {
|
|
|
131
133
|
keepRunsForDays: number;
|
|
132
134
|
/** Successful runs go sooner than failed ones. Optional so a CLI with settings of its own need not return it. */
|
|
133
135
|
keepSuccessfulRunsForDays?: number;
|
|
136
|
+
/** A successful run that wrote the store is kept this long, even when `record` would not keep it. */
|
|
137
|
+
keepStoreRunsForDays?: number;
|
|
134
138
|
/** The runs folder's size limit, in megabytes. */
|
|
135
139
|
runsSizeLimitMb?: number;
|
|
136
140
|
/** The variable that made this process read-only, above every level and flag (`<PREFIX>_READ_ONLY`). */
|
|
@@ -311,6 +315,7 @@ export declare const settingsFor: <T extends object = Record<never, never>>(app:
|
|
|
311
315
|
record_input: v.OptionalSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.LiteralSchema<"failed", undefined>], (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
312
316
|
keep_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
313
317
|
keep_successful_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
318
|
+
keep_store_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
314
319
|
runs_size_limit_mb: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
315
320
|
permissions: v.OptionalSchema<v.RecordSchema<v.GenericSchema<string>, v.PicklistSchema<readonly ["deny", "readonly", "ask", "allow"], (issue: v.PicklistIssue) => string>, (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
316
321
|
sends_per_hour: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
@@ -321,6 +326,7 @@ export declare const settingsFor: <T extends object = Record<never, never>>(app:
|
|
|
321
326
|
history_dialog_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>, v.MaxValueAction<number, 1095, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
322
327
|
history_group_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>, v.MaxValueAction<number, 1095, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
323
328
|
history_group_members_max: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
329
|
+
history_muted: v.OptionalSchema<v.BooleanSchema<(issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
324
330
|
picture_search: v.OptionalSchema<v.BooleanSchema<(issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
325
331
|
search_reranker: v.OptionalSchema<v.PicklistSchema<[...string[], "off"], (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
326
332
|
update_check: v.OptionalSchema<v.BooleanSchema<(issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
@@ -390,6 +396,7 @@ export declare const settingsFor: <T extends object = Record<never, never>>(app:
|
|
|
390
396
|
record_input: v.OptionalSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.LiteralSchema<"failed", undefined>], (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
391
397
|
keep_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
392
398
|
keep_successful_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
399
|
+
keep_store_runs_for_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
393
400
|
runs_size_limit_mb: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
394
401
|
permissions: v.OptionalSchema<v.RecordSchema<v.GenericSchema<string>, v.PicklistSchema<readonly ["deny", "readonly", "ask", "allow"], (issue: v.PicklistIssue) => string>, (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
395
402
|
sends_per_hour: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
@@ -400,6 +407,7 @@ export declare const settingsFor: <T extends object = Record<never, never>>(app:
|
|
|
400
407
|
history_dialog_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>, v.MaxValueAction<number, 1095, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
401
408
|
history_group_days: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>, v.MaxValueAction<number, 1095, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
402
409
|
history_group_members_max: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<(issue: v.BaseIssue<unknown>) => string>, v.IntegerAction<number, (issue: v.BaseIssue<unknown>) => string>, v.MinValueAction<number, 1, (issue: v.BaseIssue<unknown>) => string>]>, undefined>;
|
|
410
|
+
history_muted: v.OptionalSchema<v.BooleanSchema<(issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
403
411
|
picture_search: v.OptionalSchema<v.BooleanSchema<(issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
404
412
|
search_reranker: v.OptionalSchema<v.PicklistSchema<[...string[], "off"], (issue: v.BaseIssue<unknown>) => string>, undefined>;
|
|
405
413
|
}, (issue: v.StrictObjectIssue) => string>, "has to be an object of profiles, by name">, {}>;
|