@wirecat/cli-core 0.604.0 → 0.605.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 +61 -0
- package/dist/calendar/prepare.d.ts +4 -2
- package/dist/calendar/prepare.js +8 -8
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/messenger/contacts-command.js +3 -2
- package/dist/cli/messenger/doctor-command.js +14 -7
- package/dist/cli/messenger/store-maintenance-command.d.ts +34 -2
- package/dist/cli/messenger/store-maintenance-command.js +31 -4
- package/dist/cli/program.js +11 -2
- package/dist/cli/steps.js +9 -1
- package/dist/cli/store-recover.d.ts +10 -2
- package/dist/cli/store-recover.js +18 -4
- package/dist/domain/record-types.d.ts +61 -0
- package/dist/domain/record-types.js +26 -0
- package/dist/domain/records.d.ts +3 -5
- package/dist/domain/records.js +10 -13
- package/dist/entities/contact-activity.d.ts +4 -0
- package/dist/entities/contact-activity.js +1 -0
- package/dist/entities/contact-context.d.ts +20 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/index.d.ts +22 -0
- package/dist/errors/failures.d.ts +17 -1
- package/dist/errors/failures.js +57 -1
- package/dist/errors/reasons.js +16 -0
- package/dist/mcp/tool.js +2 -1
- package/dist/runs/recording.js +13 -4
- package/dist/services/deps.js +4 -6
- package/dist/services/index.d.ts +1 -1
- package/dist/services/link-scorers/chat-senders.d.ts +3 -2
- package/dist/services/link-scorers/chat-senders.js +7 -4
- package/dist/services/link-scorers/mail-thread.js +1 -0
- package/dist/services/link-scorers/member-chats.js +1 -0
- package/dist/services/link-scorers/member-dialog.d.ts +1 -1
- package/dist/services/link-scorers/member-dialog.js +4 -3
- package/dist/services/link-scorers/scan.d.ts +5 -2
- package/dist/services/link-scorers/scan.js +98 -53
- package/dist/services/link-scorers/shared.d.ts +2 -2
- package/dist/services/link-scorers/shared.js +7 -4
- package/dist/services/link-scorers/types.d.ts +3 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/person-context.d.ts +24 -7
- package/dist/services/person-context.js +45 -11
- package/dist/services/person-preparation.js +4 -5
- package/dist/store/damage.d.ts +3 -1
- package/dist/store/damage.js +19 -12
- package/dist/store/document-transfer/index.js +7 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/marks.d.ts +57 -0
- package/dist/store/marks.js +121 -0
- package/dist/store/project-transfer/preview.js +12 -7
- package/dist/store/recover.js +16 -1
- package/dist/store/sqlite/finance.d.ts +8 -1
- package/dist/store/sqlite/finance.js +10 -3
- package/dist/store/sqlite/open-store.js +4 -1
- package/dist/store/sqlite/own-identities.d.ts +1 -1
- package/dist/store/sqlite/own-identities.js +7 -5
- package/dist/store/sqlite/person-links.d.ts +5 -2
- package/dist/store/sqlite/person-links.js +24 -18
- package/dist/store/sqlite/person-separation.d.ts +5 -0
- package/dist/store/sqlite/person-separation.js +26 -0
- package/dist/store/sqlite/record-projectors.d.ts +44 -0
- package/dist/store/sqlite/record-projectors.js +72 -0
- package/dist/store/sqlite/records.js +12 -70
- package/dist/store/sqlite/transaction.js +2 -5
- package/dist/store/types.d.ts +5 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,67 @@ shape of this file.
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 0.605.0 — 07.11.2026
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **A run that finds the store damaged stops every later write.** When a command fails with SQLite's "database disk
|
|
15
|
+
image is malformed", "file is not a database" or an fts5 corruption, the run leaves `<store>.damaged.json` beside
|
|
16
|
+
the store (when, which command and version, the run's id, SQLite's message). While it is there, every command that
|
|
17
|
+
opens the store to write refuses with `store.damaged` and names `<cli> store recover`, so scheduled syncs fail at
|
|
18
|
+
once instead of writing into a damaged file; reads still work. `doctor` and `store recover` show it. A deep check
|
|
19
|
+
that passes (`doctor --deep`, `store recover`), `store recover run`, `store restore` and `store reset` lift it.
|
|
20
|
+
`markStoreDamaged` from `@wirecat/cli-core/store` leaves it for a CLI that reports such a failure itself.
|
|
21
|
+
- **Every deep check is recorded beside the store as its last known good.** `doctor --deep`, `store recover` and the
|
|
22
|
+
check after `store recover run` write `<store>.health.json` (when, the result, the schema, the CLI and its version,
|
|
23
|
+
and `last_ok_at`, the newest check that passed); `doctor` and `store recover` answer `last_known_good` from it.
|
|
24
|
+
`storeSummary` takes the CLI's `version` for it.
|
|
25
|
+
|
|
26
|
+
### Changed — may break callers
|
|
27
|
+
|
|
28
|
+
- **`personContext`, `contacts context`, `contacts prepare` and `events prepare` read only accounts of the asked
|
|
29
|
+
account's scope.** A personal account no longer reads a linked person's mail, messages, calendar events or recorded
|
|
30
|
+
meetings in work accounts, and a work account none in personal ones. To read both, pass
|
|
31
|
+
`scopes: ["personal", "work"]` in the options of `personContext`, or of `eventPreparation`. The answer's new
|
|
32
|
+
`accounts` lists every account read with its scope. The asked account must be in the store: a missing one, or an
|
|
33
|
+
`AccountKey.scope` that differs from the stored scope, is `not_found`.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- **`scanProjectLinks` spreads from what it finds within one run.** A chat or person that scores the threshold or more
|
|
38
|
+
is used like a confirmed link for the `spreads` scorers (`member-chats`, `member-dialog`, `chat-senders`,
|
|
39
|
+
`mail-thread`), up to `MAX_HOPS` (4) times. One scan now reaches a member's dialogs and groups in every messenger
|
|
40
|
+
their identities name, where before it took one owner confirmation per step and never left the first messenger.
|
|
41
|
+
On a synthetic project shaped like the PMED run, recall after two rounds rose from 27 % to 93 % (all findable
|
|
42
|
+
links), precision from 100 % to 74 %, 5 false proposals, none by name only. A rejected pair is never spread from.
|
|
43
|
+
- **`chat-senders` (version 2) counts any message in a dialog or a chat of 10 people or fewer;** a bigger chat still
|
|
44
|
+
needs 5 in the window.
|
|
45
|
+
- **`member-dialog` (version 2) counts the scanned project in the member's projects** whether the member is confirmed
|
|
46
|
+
or only found, so a found member who is in another project weighs the same as a confirmed one.
|
|
47
|
+
- **A damaged store file is `configuration_error` (`store.damaged`), not a crash.** SQLite's "database disk image is
|
|
48
|
+
malformed" or "file is not a database", raised anywhere in a command or behind a wrapper's `cause`, was
|
|
49
|
+
`internal_error` (`command.crashed`), "this is a bug". It now says the store file is damaged and names
|
|
50
|
+
`<cli> store recover` where the CLI has it, else `<cli> doctor --deep`, else no command, on the CLI, over MCP and in
|
|
51
|
+
the run kept of it, whose frames stay SQLite's own; a scheduled run's failure banner shows the reason.
|
|
52
|
+
`storeDamaged(error, next?)` from `@wirecat/cli-core/cli` does the same for a CLI with its own failure handling. A
|
|
53
|
+
damaged file named for a document or project transfer is `validation_error` (`store.file-damaged`) naming that
|
|
54
|
+
file, and `store recover run` on a store whose header is damaged says it cannot recover it (`store.unreadable`).
|
|
55
|
+
- **A filesystem error is no longer read as a SQLite one.** `errno` counts as SQLite's code only on bun:sqlite's
|
|
56
|
+
`SQLiteError`: Windows' EIO (-4070) has SQLITE_NOTADB's low byte, and a busy check took a filesystem errno with
|
|
57
|
+
BUSY's low byte for a lock.
|
|
58
|
+
- **cli-core accepts cli-base 0.81 and 0.82** (peer range `>=0.80.7 <0.83.0`, developed against 0.82.0). memo moved to
|
|
59
|
+
cli-base 0.82.0, and the downstream parity check downgraded it to 0.80.7, whose option vocabulary lacks memo's
|
|
60
|
+
`--from-app` and `tasks --status`, so every cli-core pull request failed parity.
|
|
61
|
+
- **People the owner separated stay apart.** An owner's unlink was checked only for the two identities being joined,
|
|
62
|
+
but a join moves whole people: a third identity with the same email address, linked to one of them, carried both
|
|
63
|
+
back together. Now no automatic join — the same email address, an account's own identity joining the owner — merges
|
|
64
|
+
two people when the owner once moved anyone of one away from anyone of the other. An agent's link of one identity
|
|
65
|
+
(a confirmed mention, a meeting participant) back over such a separation is refused with the reason
|
|
66
|
+
`identity.separated`; the owner's own link still goes through. The exact-email join stays automatic otherwise.
|
|
67
|
+
- **A personal account's `contacts context` no longer shows a person's work mail.** One exact email address joins a
|
|
68
|
+
personal and a work contact into one person, and the context then read every account that had seen any of that
|
|
69
|
+
person's identities. Each linked identity now also lists `seenIn`, its accounts with their scope.
|
|
70
|
+
|
|
10
71
|
## 0.604.0 — 07.11.2026
|
|
11
72
|
|
|
12
73
|
### Added
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventDetails, EventStore } from "../meetings/index.js";
|
|
2
|
-
import { type ContextEvent, type ContextMessage } from "../services/person-context.js";
|
|
2
|
+
import { type AccountScope, type ContextEvent, type ContextMessage } from "../services/person-context.js";
|
|
3
3
|
import { type PersonMeetingContextItem } from "../services/person-meeting-context.js";
|
|
4
4
|
import type { MessageStore } from "../store/store.js";
|
|
5
5
|
import { type PersonOfEmail, type ReadAccount } from "./reads.js";
|
|
@@ -24,11 +24,13 @@ export interface PreparationOptions {
|
|
|
24
24
|
limit?: number;
|
|
25
25
|
/** ms: no message or meeting older. */
|
|
26
26
|
since?: number;
|
|
27
|
+
/** The account scopes read; the calendar account's own scope when absent. */
|
|
28
|
+
scopes?: readonly AccountScope[];
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* The stored evidence for one meeting: the event, and for each attendee other than the owner, their linked identities,
|
|
30
32
|
* their latest messages and mail, the events and recorded meetings they shared with the owner. Reads the store only,
|
|
31
|
-
* every account that saw each person (WC-ACCT-9), and writes nothing; the brief is the agent's.
|
|
33
|
+
* every account of the allowed scopes that saw each person (WC-ACCT-9), and writes nothing; the brief is the agent's.
|
|
32
34
|
*/
|
|
33
35
|
export declare const eventPreparation: (details: EventDetails, options: PreparationOptions) => Promise<{
|
|
34
36
|
event: {
|
package/dist/calendar/prepare.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseMeetingReference } from "../meetings/index.js";
|
|
3
|
-
import { readsOf, recordContext } from "../services/person-context.js";
|
|
3
|
+
import { readableAccounts, readsOf, recordContext, } from "../services/person-context.js";
|
|
4
4
|
import { personMeetingContext } from "../services/person-meeting-context.js";
|
|
5
5
|
import { accountsMeta, CALENDAR_UNTRUSTED_FIELDS, eventAnswer, eventOf, } from "./reads.js";
|
|
6
6
|
export const PREPARE_MESSAGES = 5;
|
|
@@ -59,7 +59,7 @@ const UNTRUSTED = [
|
|
|
59
59
|
/**
|
|
60
60
|
* The stored evidence for one meeting: the event, and for each attendee other than the owner, their linked identities,
|
|
61
61
|
* their latest messages and mail, the events and recorded meetings they shared with the owner. Reads the store only,
|
|
62
|
-
* every account that saw each person (WC-ACCT-9), and writes nothing; the brief is the agent's.
|
|
62
|
+
* every account of the allowed scopes that saw each person (WC-ACCT-9), and writes nothing; the brief is the agent's.
|
|
63
63
|
*/
|
|
64
64
|
export const eventPreparation = async (details, options) => {
|
|
65
65
|
const { messages: store, account, personOf, now, since } = options;
|
|
@@ -70,7 +70,7 @@ export const eventPreparation = async (details, options) => {
|
|
|
70
70
|
.sort((a, b) => Number(b.organizer) - Number(a.organizer));
|
|
71
71
|
const read = new Map([[nameOf(account.key), account.key]]);
|
|
72
72
|
const issues = [];
|
|
73
|
-
const
|
|
73
|
+
const readable = await readableAccounts(store, account.key, options.scopes);
|
|
74
74
|
let left = PREPARE_BYTES - size(shown);
|
|
75
75
|
let truncated = others.length > PREPARE_PEOPLE;
|
|
76
76
|
let pending = 0;
|
|
@@ -100,10 +100,10 @@ export const eventPreparation = async (details, options) => {
|
|
|
100
100
|
people.push(nothing);
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
const reads = readsOf(record, account.key);
|
|
103
|
+
const reads = readsOf(record, account.key, readable);
|
|
104
104
|
for (const { key } of reads)
|
|
105
105
|
read.set(nameOf(key), key);
|
|
106
|
-
const context = await recordContext(store, record, reads, {
|
|
106
|
+
const context = await recordContext(store, record, reads, readable, {
|
|
107
107
|
messages: limit,
|
|
108
108
|
bytes: Math.min(left, PERSON_BYTES),
|
|
109
109
|
now,
|
|
@@ -115,10 +115,10 @@ export const eventPreparation = async (details, options) => {
|
|
|
115
115
|
reason: "chat.not-read",
|
|
116
116
|
source: `${chat.provider}:${chat.account}/${chat.chatId}`,
|
|
117
117
|
});
|
|
118
|
-
const meetings = await meetingsWith(store, record.uid,
|
|
118
|
+
const meetings = await meetingsWith(store, record.uid, readable, since);
|
|
119
119
|
pending = Math.max(pending, meetings.pending);
|
|
120
120
|
for (const id of meetings.accounts) {
|
|
121
|
-
const one =
|
|
121
|
+
const one = readable.find((held) => held.id === id);
|
|
122
122
|
if (one)
|
|
123
123
|
read.set(nameOf(one), { provider: one.provider, account: one.account });
|
|
124
124
|
}
|
|
@@ -151,7 +151,7 @@ export const eventPreparation = async (details, options) => {
|
|
|
151
151
|
meta,
|
|
152
152
|
};
|
|
153
153
|
};
|
|
154
|
-
/** Their latest recorded meetings in every
|
|
154
|
+
/** Their latest recorded meetings in every account given that saw them; none is not an error. */
|
|
155
155
|
const meetingsWith = async (store, uid, stored, since) => {
|
|
156
156
|
const none = { items: [], hasMore: false, accounts: [], pending: 0 };
|
|
157
157
|
if (!stored.length)
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { parseDuration } from "../domain/duration.js";
|
|
|
4
4
|
export { openOf, PROFILE_PLACEHOLDER, type ProfilesFor, type RefOpen, type RefSummary, refLabel, } from "../domain/ref-summaries.js";
|
|
5
5
|
export { botTemplate } from "../entities/list-results.js";
|
|
6
6
|
export { syncProgress } from "../entities/store-records.js";
|
|
7
|
-
export { isCliFailure, isCommanderFailure } from "../errors/failures.js";
|
|
7
|
+
export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
|
|
8
8
|
export { type AppErrors, failureContext } from "../errors/reasons.js";
|
|
9
9
|
export { mailFindingFieldsHelp } from "../mail/findings.js";
|
|
10
10
|
export { botInstructions } from "../mcp/bot/instructions.js";
|
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { parseDuration } from "../domain/duration.js";
|
|
|
3
3
|
export { openOf, PROFILE_PLACEHOLDER, refLabel, } from "../domain/ref-summaries.js";
|
|
4
4
|
export { botTemplate } from "../entities/list-results.js";
|
|
5
5
|
export { syncProgress } from "../entities/store-records.js";
|
|
6
|
-
export { isCliFailure, isCommanderFailure } from "../errors/failures.js";
|
|
6
|
+
export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
|
|
7
7
|
export { failureContext } from "../errors/reasons.js";
|
|
8
8
|
export { mailFindingFieldsHelp } from "../mail/findings.js";
|
|
9
9
|
export { botInstructions } from "../mcp/bot/instructions.js";
|
|
@@ -102,8 +102,9 @@ export const contactsCommand = (messenger) => {
|
|
|
102
102
|
output: { entity: "contact_context" },
|
|
103
103
|
})
|
|
104
104
|
.summary("what the local archive knows about a person")
|
|
105
|
-
.description("what the store holds about one person, in every messenger linked to them
|
|
106
|
-
"messages each way, their recent messages,
|
|
105
|
+
.description("what the store holds about one person, in every messenger linked to them, read only in accounts of this " +
|
|
106
|
+
"account's scope (personal or work): shared chats, the last messages each way, their recent messages, " +
|
|
107
|
+
"where others mentioned them — never connects")
|
|
107
108
|
.argument("<person>", "their id, @username, or part of their name")
|
|
108
109
|
.option("--limit <n>", `at most this many messages in each list; ${CONTEXT_MESSAGES} if not given`, positiveCount("--limit"))
|
|
109
110
|
.option("--since-time <time>", "nothing older than this ISO 8601 time, or 2h / 1d ago")
|
|
@@ -59,13 +59,20 @@ export const DOCTOR_DEEP_OPTION = "also read every page of the store and check e
|
|
|
59
59
|
/** The shared doctor stays quick; `store recover` is its deep check, and a CLI may add `--deep` to its own doctor. */
|
|
60
60
|
const summaryOptions = (command, app) => ({
|
|
61
61
|
deep: command.opts().deep === true,
|
|
62
|
-
command: app,
|
|
62
|
+
command: app.command,
|
|
63
|
+
version: app.version,
|
|
63
64
|
});
|
|
64
65
|
/** The plain-words account of a damaged store, under the answer. */
|
|
65
66
|
export const damageNotes = (store) => {
|
|
66
|
-
const damage = store
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const { damage, damage_mark_cleared: cleared } = store ?? {};
|
|
68
|
+
return [
|
|
69
|
+
...(cleared
|
|
70
|
+
? [
|
|
71
|
+
`the deep check passed, so writes are allowed again: \`${cleared.command}\` had found the store damaged at ${cleared.at}`,
|
|
72
|
+
]
|
|
73
|
+
: []),
|
|
74
|
+
...(damage ? [damage.what, damage.external_unaffected, ...damage.steps.map((step) => `next: ${step}`)] : []),
|
|
75
|
+
];
|
|
69
76
|
};
|
|
70
77
|
const INCLUDES = [
|
|
71
78
|
"the version, the runtime and the operating system",
|
|
@@ -163,7 +170,7 @@ const diagnose = async (command, messenger) => {
|
|
|
163
170
|
cli,
|
|
164
171
|
config: { path, found: existsSync(path), issues: [] },
|
|
165
172
|
settings: { error: messageOf(error) },
|
|
166
|
-
store: snakeKeys(await storeSummary(env, summaryOptions(command, app
|
|
173
|
+
store: snakeKeys(await storeSummary(env, summaryOptions(command, app))),
|
|
167
174
|
runs: { directory: runsDirFor(app, env), kept: listRuns(runsDirFor(app, env)).length },
|
|
168
175
|
files: filesReport(files),
|
|
169
176
|
},
|
|
@@ -188,7 +195,7 @@ const diagnose = async (command, messenger) => {
|
|
|
188
195
|
cli,
|
|
189
196
|
profile: null,
|
|
190
197
|
config,
|
|
191
|
-
store: snakeKeys(await storeSummary(env, summaryOptions(command, app
|
|
198
|
+
store: snakeKeys(await storeSummary(env, summaryOptions(command, app))),
|
|
192
199
|
readers: engineStates(),
|
|
193
200
|
runs: { directory: runsDirFor(app, env), kept: listRuns(runsDirFor(app, env)).length },
|
|
194
201
|
files: filesReport(files),
|
|
@@ -224,7 +231,7 @@ const diagnose = async (command, messenger) => {
|
|
|
224
231
|
account: { remembered: account?.account ?? null },
|
|
225
232
|
// A session file on disk says nothing about whether the messenger still accepts it.
|
|
226
233
|
login: { state: "not checked" },
|
|
227
|
-
store: snakeKeys(await storeSummary(env, summaryOptions(command, app
|
|
234
|
+
store: snakeKeys(await storeSummary(env, summaryOptions(command, app))),
|
|
228
235
|
readers: engineStates(),
|
|
229
236
|
sends: sendsState(new SendJournal(sendsPathFor(app, profile, env))),
|
|
230
237
|
flood: floodState(new FloodMemory(flood)),
|
|
@@ -3,11 +3,13 @@ import type { CacheDatabase } from "../../store/driver.js";
|
|
|
3
3
|
import type { Messenger } from "./context.js";
|
|
4
4
|
/**
|
|
5
5
|
* `doctor`'s short summary of the store. Must answer for a broken file, so an error is a field. `health` is the quick
|
|
6
|
-
* check unless `deep`; `damage` says in plain words what a failed one means
|
|
6
|
+
* check unless `deep`; `damage` says in plain words what a failed one means, or what a run that found the store
|
|
7
|
+
* damaged saw, and what to run. A deep check is recorded beside the store as the last known good.
|
|
7
8
|
*/
|
|
8
|
-
export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command }?: {
|
|
9
|
+
export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, version }?: {
|
|
9
10
|
deep?: boolean;
|
|
10
11
|
command?: string;
|
|
12
|
+
version?: string;
|
|
11
13
|
}) => Promise<{
|
|
12
14
|
path: string;
|
|
13
15
|
exists: boolean;
|
|
@@ -22,6 +24,21 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command }?:
|
|
|
22
24
|
invalidJson?: import("../../store/health.js").InvalidJson[] | undefined;
|
|
23
25
|
damagedSearchIndexes?: string[] | undefined;
|
|
24
26
|
};
|
|
27
|
+
lastKnownGood: string | null;
|
|
28
|
+
damageMark?: {
|
|
29
|
+
at: string;
|
|
30
|
+
command: string;
|
|
31
|
+
cli_version?: string;
|
|
32
|
+
run_id?: string;
|
|
33
|
+
error: string;
|
|
34
|
+
} | undefined;
|
|
35
|
+
damageMarkCleared?: {
|
|
36
|
+
at: string;
|
|
37
|
+
command: string;
|
|
38
|
+
cli_version?: string;
|
|
39
|
+
run_id?: string;
|
|
40
|
+
error: string;
|
|
41
|
+
} | undefined;
|
|
25
42
|
damage?: import("../../store/damage.js").DamageExplanation | undefined;
|
|
26
43
|
path: string;
|
|
27
44
|
exists: boolean;
|
|
@@ -41,6 +58,21 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command }?:
|
|
|
41
58
|
invalidJson?: import("../../store/health.js").InvalidJson[] | undefined;
|
|
42
59
|
damagedSearchIndexes?: string[] | undefined;
|
|
43
60
|
};
|
|
61
|
+
lastKnownGood: string | null;
|
|
62
|
+
damageMark?: {
|
|
63
|
+
at: string;
|
|
64
|
+
command: string;
|
|
65
|
+
cli_version?: string;
|
|
66
|
+
run_id?: string;
|
|
67
|
+
error: string;
|
|
68
|
+
} | undefined;
|
|
69
|
+
damageMarkCleared?: {
|
|
70
|
+
at: string;
|
|
71
|
+
command: string;
|
|
72
|
+
cli_version?: string;
|
|
73
|
+
run_id?: string;
|
|
74
|
+
error: string;
|
|
75
|
+
} | undefined;
|
|
44
76
|
damage?: import("../../store/damage.js").DamageExplanation | undefined;
|
|
45
77
|
path: string;
|
|
46
78
|
exists: boolean;
|
|
@@ -10,6 +10,7 @@ import { isSealed, sealFile, unsealFile } from "../../sealed.js";
|
|
|
10
10
|
import { fileSchemaOf, SPEAKS, writableBy } from "../../store/compatibility.js";
|
|
11
11
|
import { explainDamage } 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
14
|
import { migrate } from "../../store/migrations.js";
|
|
14
15
|
import { openCache } from "../../store/open.js";
|
|
15
16
|
import { storePath } from "../../store/path.js";
|
|
@@ -58,15 +59,35 @@ const readingOnly = async (path, read) => {
|
|
|
58
59
|
database.close();
|
|
59
60
|
}
|
|
60
61
|
};
|
|
62
|
+
const withoutInode = ({ inode: _, ...mark }) => mark;
|
|
63
|
+
/** The schema version, or null when the file cannot say. */
|
|
64
|
+
const fileSchema = async (path) => {
|
|
65
|
+
try {
|
|
66
|
+
return await readingOnly(path, (database) => fileSchemaOf(database).version);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
61
72
|
/**
|
|
62
73
|
* `doctor`'s short summary of the store. Must answer for a broken file, so an error is a field. `health` is the quick
|
|
63
|
-
* check unless `deep`; `damage` says in plain words what a failed one means
|
|
74
|
+
* check unless `deep`; `damage` says in plain words what a failed one means, or what a run that found the store
|
|
75
|
+
* damaged saw, and what to run. A deep check is recorded beside the store as the last known good.
|
|
64
76
|
*/
|
|
65
|
-
export const storeSummary = async (env, { deep = false, command } = {}) => {
|
|
77
|
+
export const storeSummary = async (env, { deep = false, command, version } = {}) => {
|
|
66
78
|
const path = storePath(env);
|
|
67
79
|
if (!existsSync(path))
|
|
68
80
|
return { path, exists: false };
|
|
69
81
|
const checked = await storeHealth(path, { deep });
|
|
82
|
+
const recorded = deep
|
|
83
|
+
? recordDeepCheck(path, checked, {
|
|
84
|
+
cli: command ?? "unknown",
|
|
85
|
+
...(version ? { version } : {}),
|
|
86
|
+
schema: await fileSchema(path),
|
|
87
|
+
})
|
|
88
|
+
: null;
|
|
89
|
+
const mark = readDamageMark(path);
|
|
90
|
+
const lastKnownGood = readHealthMark(path)?.last_ok_at ?? null;
|
|
70
91
|
const health = {
|
|
71
92
|
checked: checked.checked,
|
|
72
93
|
covers: deep ? "every page and every search index" : QUICK_HEALTH_CHECKS,
|
|
@@ -79,8 +100,14 @@ export const storeSummary = async (env, { deep = false, command } = {}) => {
|
|
|
79
100
|
? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) }
|
|
80
101
|
: {}),
|
|
81
102
|
};
|
|
82
|
-
const damage = command ? explainDamage(checked, command) : null;
|
|
83
|
-
const healthOf = {
|
|
103
|
+
const damage = command ? explainDamage(checked, command, mark) : null;
|
|
104
|
+
const healthOf = {
|
|
105
|
+
health,
|
|
106
|
+
lastKnownGood,
|
|
107
|
+
...(mark ? { damageMark: withoutInode(mark) } : {}),
|
|
108
|
+
...(recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {}),
|
|
109
|
+
...(damage ? { damage } : {}),
|
|
110
|
+
};
|
|
84
111
|
try {
|
|
85
112
|
return await reading(path, (database) => {
|
|
86
113
|
const { version, writable } = schemaOf(database);
|
package/dist/cli/program.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Command, Help } from "commander";
|
|
|
7
7
|
import { relayCommand } from "../background/relay.js";
|
|
8
8
|
import { failingNotice, scheduledRuns } from "../background/schedules.js";
|
|
9
9
|
import { parseDuration } from "../domain/duration.js";
|
|
10
|
-
import { isCliFailure, isCommanderFailure } from "../errors/failures.js";
|
|
10
|
+
import { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
|
|
11
11
|
import { failureContext } from "../errors/reasons.js";
|
|
12
12
|
import { envName, readOnlyLockOf, readOnlyRefusal } from "../ports/app.js";
|
|
13
13
|
import { recorded, wasSettled } from "../runs/recording.js";
|
|
@@ -721,9 +721,18 @@ const budgetSteps = (program, path, failure) => {
|
|
|
721
721
|
? tooLargeSteps(command, { maxBytes, neededBytes })
|
|
722
722
|
: [];
|
|
723
723
|
};
|
|
724
|
+
/** What a damaged store's message names: `store recover` where the CLI has it, else `doctor --deep`, else nothing. */
|
|
725
|
+
const damageStep = (program, cli) => {
|
|
726
|
+
if (commandAt(program, "store recover"))
|
|
727
|
+
return `${cli} store recover`;
|
|
728
|
+
const doctor = commandAt(program, "doctor");
|
|
729
|
+
return doctor?.options.some((option) => option.long === "--deep") ? `${cli} doctor --deep` : undefined;
|
|
730
|
+
};
|
|
724
731
|
const failed = ({ app }, program, rest, error, settled, debug) => {
|
|
725
732
|
const path = commandPath(program, program.args.length > 0 ? program.args : rest);
|
|
726
|
-
const told = error instanceof NoProfileHere && !commandAt(program, "setup")
|
|
733
|
+
const told = error instanceof NoProfileHere && !commandAt(program, "setup")
|
|
734
|
+
? error.withoutSetup(path)
|
|
735
|
+
: storeDamaged(error, damageStep(program, app.command));
|
|
727
736
|
const failure = settled.settlementFailed && isCliFailure(told)
|
|
728
737
|
? new CliError(told.code, told.message, { ...told.details, settlement_failed: true })
|
|
729
738
|
: told;
|
package/dist/cli/steps.js
CHANGED
|
@@ -219,6 +219,12 @@ export const STEPS = defineSteps([
|
|
|
219
219
|
],
|
|
220
220
|
why: "once the tasks these {shown} messages hold are opened, updated or closed, so the next review starts after them",
|
|
221
221
|
},
|
|
222
|
+
{
|
|
223
|
+
id: "store.recover",
|
|
224
|
+
command: "store recover",
|
|
225
|
+
args: [],
|
|
226
|
+
why: "the store file is damaged; this says what is lost and the commands that recover it",
|
|
227
|
+
},
|
|
222
228
|
{
|
|
223
229
|
id: "search.meetings",
|
|
224
230
|
command: "*",
|
|
@@ -273,7 +279,9 @@ export const failureSteps = (root, error) => {
|
|
|
273
279
|
args: { model },
|
|
274
280
|
}),
|
|
275
281
|
]
|
|
276
|
-
:
|
|
282
|
+
: error.reason === "store.damaged"
|
|
283
|
+
? [nextStep("store.recover", {})]
|
|
284
|
+
: [];
|
|
277
285
|
return runnable(root, [...(error.next ?? []), ...own]);
|
|
278
286
|
};
|
|
279
287
|
/** Each command step judged by its command's effects: safe to run unasked only when it writes nothing remotely. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { type DamageExplanation } from "../store/damage.js";
|
|
3
3
|
import { type InvalidJson } from "../store/health.js";
|
|
4
|
+
import { type DamageMark } from "../store/marks.js";
|
|
4
5
|
import { type RecoverOptions, type Recovery } from "../store/recover.js";
|
|
5
6
|
export interface RecoveryCheck {
|
|
6
7
|
path: string;
|
|
@@ -20,6 +21,10 @@ export interface RecoveryCheck {
|
|
|
20
21
|
invalidJson?: InvalidJson[];
|
|
21
22
|
rows?: Record<string, number | null>;
|
|
22
23
|
explanation?: DamageExplanation | null;
|
|
24
|
+
/** What the run that found the store damaged saw; writes are refused while it stands. */
|
|
25
|
+
damageMark?: Omit<DamageMark, "inode"> | null;
|
|
26
|
+
/** When a deep check of the store last passed, as far as this computer recorded. */
|
|
27
|
+
lastKnownGood?: string | null;
|
|
23
28
|
inUse?: {
|
|
24
29
|
pid: number;
|
|
25
30
|
name: string;
|
|
@@ -32,8 +37,11 @@ export interface RecoveryCheck {
|
|
|
32
37
|
/** The commands to run, in order. */
|
|
33
38
|
next: string[];
|
|
34
39
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
40
|
+
/**
|
|
41
|
+
* `store recover`: what is wrong with the store and what to run, reading every page. Changes nothing in the store; it
|
|
42
|
+
* records the check beside it, and one that passes lifts the damage mark.
|
|
43
|
+
*/
|
|
44
|
+
export declare const storeRecoveryCheck: (env: NodeJS.ProcessEnv, command: string, version?: string) => Promise<RecoveryCheck>;
|
|
37
45
|
export type RecoveryRun = Omit<Recovery, "health" | "copyErrors"> & {
|
|
38
46
|
/** `sqlite3` reported these while copying; most are rows that broke a constraint and were skipped. */
|
|
39
47
|
copyErrors: number;
|
|
@@ -2,8 +2,10 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { CliError } from "@wirecat/cli-base";
|
|
3
3
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
+
import { fileSchemaOf } from "../store/compatibility.js";
|
|
5
6
|
import { explainDamage } from "../store/damage.js";
|
|
6
7
|
import { storeHealth } from "../store/health.js";
|
|
8
|
+
import { readDamageMark, readHealthMark, recordDeepCheck } from "../store/marks.js";
|
|
7
9
|
import { storePath } from "../store/path.js";
|
|
8
10
|
import { activeTimers, recoverStore, sqlite3Program, storeHolders, tableRows, } from "../store/recover.js";
|
|
9
11
|
import { openSqlite } from "../store/store.js";
|
|
@@ -25,16 +27,21 @@ const COUNTED = [
|
|
|
25
27
|
"mentions",
|
|
26
28
|
];
|
|
27
29
|
const stopTimers = (timers) => `systemctl --user stop ${timers.join(" ")}`;
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* `store recover`: what is wrong with the store and what to run, reading every page. Changes nothing in the store; it
|
|
32
|
+
* records the check beside it, and one that passes lifts the damage mark.
|
|
33
|
+
*/
|
|
34
|
+
export const storeRecoveryCheck = async (env, command, version) => {
|
|
30
35
|
const path = storePath(env);
|
|
31
36
|
if (!existsSync(path))
|
|
32
37
|
return { path, exists: false, ok: true, next: [] };
|
|
33
38
|
const health = await storeHealth(path, { deep: true });
|
|
34
39
|
let rows = {};
|
|
40
|
+
let schema = null;
|
|
35
41
|
try {
|
|
36
42
|
const { database } = await openSqlite(path, { readOnly: true });
|
|
37
43
|
try {
|
|
44
|
+
schema = fileSchemaOf(database).version;
|
|
38
45
|
const all = tableRows(database);
|
|
39
46
|
rows = Object.fromEntries(COUNTED.filter((table) => table in all).map((table) => [table, all[table] ?? null]));
|
|
40
47
|
}
|
|
@@ -43,7 +50,9 @@ export const storeRecoveryCheck = async (env, command) => {
|
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
catch { }
|
|
46
|
-
|
|
53
|
+
recordDeepCheck(path, health, { cli: command, ...(version ? { version } : {}), schema });
|
|
54
|
+
const mark = readDamageMark(path);
|
|
55
|
+
const explanation = explainDamage(health, command, mark);
|
|
47
56
|
const inUse = storeHolders(path) ?? null;
|
|
48
57
|
const timers = activeTimers() ?? null;
|
|
49
58
|
const sqlite3 = sqlite3Program();
|
|
@@ -68,6 +77,8 @@ export const storeRecoveryCheck = async (env, command) => {
|
|
|
68
77
|
invalidJson: health.invalidJson ?? [],
|
|
69
78
|
rows,
|
|
70
79
|
explanation,
|
|
80
|
+
damageMark: mark ? (({ inode: _, ...seen }) => seen)(mark) : null,
|
|
81
|
+
lastKnownGood: readHealthMark(path)?.last_ok_at ?? null,
|
|
71
82
|
inUse,
|
|
72
83
|
timers,
|
|
73
84
|
sqlite3: { version: sqlite3.version, usable: sqlite3.usable },
|
|
@@ -119,6 +130,9 @@ export const recoveryNotes = (answer) => {
|
|
|
119
130
|
const why = answer.explanation;
|
|
120
131
|
return [
|
|
121
132
|
...(why ? [why.what, ...why.impact, why.externalUnaffected] : []),
|
|
133
|
+
answer.lastKnownGood
|
|
134
|
+
? `the store last passed a deep check at ${answer.lastKnownGood}`
|
|
135
|
+
: "no deep check that passed is on record for this store",
|
|
122
136
|
...answer.next.map((line) => `next: ${line}`),
|
|
123
137
|
];
|
|
124
138
|
};
|
|
@@ -129,7 +143,7 @@ export const storeRecoverCommand = ({ command, version }) => {
|
|
|
129
143
|
.description("check every page and search index of the store, say what is damaged, what it means and the commands that recover it; changes nothing")
|
|
130
144
|
.action(async function () {
|
|
131
145
|
const output = outputFor(this);
|
|
132
|
-
const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command);
|
|
146
|
+
const answer = await storeRecoveryCheck(environmentOf(this).env ?? process.env, command, version);
|
|
133
147
|
renderAnswer(this, output, itemOf(snakeKeys(answer)));
|
|
134
148
|
if (output.format === "pretty")
|
|
135
149
|
for (const line of recoveryNotes(answer))
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Types with a table of their own; anything else a source sends is `custom:<name>` and stays a record only. */
|
|
2
|
+
export declare const RECORD_ENTITY_TYPES: readonly ["invoice", "payment", "person", "organization", "project"];
|
|
3
|
+
export type RecordEntityType = (typeof RECORD_ENTITY_TYPES)[number];
|
|
4
|
+
export interface RecordRoleSpec {
|
|
5
|
+
/** Several relations may carry it; a single role may also be named in `fields.<role>`. */
|
|
6
|
+
many?: boolean;
|
|
7
|
+
amount?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface RecordTypeSpec {
|
|
10
|
+
table: string;
|
|
11
|
+
/** `proposal`: the import proposes the entity and the owner decides; `identity`: only the owner's `map` gives one. */
|
|
12
|
+
review: "proposal" | "identity";
|
|
13
|
+
/** The roles the entity is made from; any other role word is kept as the source's own. */
|
|
14
|
+
roles: Record<string, RecordRoleSpec>;
|
|
15
|
+
}
|
|
16
|
+
export declare const RECORD_TYPES: {
|
|
17
|
+
readonly invoice: {
|
|
18
|
+
readonly table: "invoices";
|
|
19
|
+
readonly review: "proposal";
|
|
20
|
+
readonly roles: {
|
|
21
|
+
readonly issuer: {};
|
|
22
|
+
readonly counterparty: {};
|
|
23
|
+
readonly project: {};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly payment: {
|
|
27
|
+
readonly table: "payments";
|
|
28
|
+
readonly review: "proposal";
|
|
29
|
+
readonly roles: {
|
|
30
|
+
readonly payer: {};
|
|
31
|
+
readonly payee: {};
|
|
32
|
+
readonly project: {};
|
|
33
|
+
readonly settles: {
|
|
34
|
+
readonly many: true;
|
|
35
|
+
readonly amount: true;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
readonly person: {
|
|
40
|
+
readonly table: "persons";
|
|
41
|
+
readonly review: "identity";
|
|
42
|
+
readonly roles: {};
|
|
43
|
+
};
|
|
44
|
+
readonly organization: {
|
|
45
|
+
readonly table: "organizations";
|
|
46
|
+
readonly review: "identity";
|
|
47
|
+
readonly roles: {};
|
|
48
|
+
};
|
|
49
|
+
readonly project: {
|
|
50
|
+
readonly table: "projects";
|
|
51
|
+
readonly review: "identity";
|
|
52
|
+
readonly roles: {};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** A role word, a source provider, and the name after `custom:`. */
|
|
56
|
+
export declare const WORD_BODY = "[a-z0-9][a-z0-9_-]{0,62}";
|
|
57
|
+
export declare const TYPE_PATTERN: string;
|
|
58
|
+
export declare const TYPE_RULE: string;
|
|
59
|
+
export declare const rolesOf: (type: RecordEntityType) => [string, RecordRoleSpec][];
|
|
60
|
+
export declare const roleNames: (types: readonly RecordEntityType[], keep: (role: RecordRoleSpec) => boolean | undefined) => string[];
|
|
61
|
+
export declare const AMOUNT_ROLES: string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Types with a table of their own; anything else a source sends is `custom:<name>` and stays a record only. */
|
|
2
|
+
export const RECORD_ENTITY_TYPES = ["invoice", "payment", "person", "organization", "project"];
|
|
3
|
+
export const RECORD_TYPES = {
|
|
4
|
+
invoice: {
|
|
5
|
+
table: "invoices",
|
|
6
|
+
review: "proposal",
|
|
7
|
+
roles: { issuer: {}, counterparty: {}, project: {} },
|
|
8
|
+
},
|
|
9
|
+
payment: {
|
|
10
|
+
table: "payments",
|
|
11
|
+
review: "proposal",
|
|
12
|
+
roles: { payer: {}, payee: {}, project: {}, settles: { many: true, amount: true } },
|
|
13
|
+
},
|
|
14
|
+
person: { table: "persons", review: "identity", roles: {} },
|
|
15
|
+
organization: { table: "organizations", review: "identity", roles: {} },
|
|
16
|
+
project: { table: "projects", review: "identity", roles: {} },
|
|
17
|
+
};
|
|
18
|
+
/** A role word, a source provider, and the name after `custom:`. */
|
|
19
|
+
export const WORD_BODY = "[a-z0-9][a-z0-9_-]{0,62}";
|
|
20
|
+
export const TYPE_PATTERN = `^(${RECORD_ENTITY_TYPES.join("|")}|custom:${WORD_BODY})$`;
|
|
21
|
+
export const TYPE_RULE = `a type is one of ${RECORD_ENTITY_TYPES.join(", ")} or custom:<name>`;
|
|
22
|
+
export const rolesOf = (type) => Object.entries(RECORD_TYPES[type].roles);
|
|
23
|
+
export const roleNames = (types, keep) => [
|
|
24
|
+
...new Set(types.flatMap((type) => rolesOf(type).flatMap(([name, role]) => (keep(role) ? [name] : [])))),
|
|
25
|
+
];
|
|
26
|
+
export const AMOUNT_ROLES = roleNames(RECORD_ENTITY_TYPES, (role) => role.amount);
|
package/dist/domain/records.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
export { RECORD_ENTITY_TYPES, type RecordEntityType } from "./record-types.js";
|
|
1
2
|
export declare const RECORDS_SCHEMA_VERSION = 1;
|
|
2
3
|
export declare const RECORD_OPERATIONS: readonly ["upsert", "delete"];
|
|
3
|
-
/** Types with a table of their own; anything else a source sends is `custom:<name>` and stays a record only. */
|
|
4
|
-
export declare const RECORD_ENTITY_TYPES: readonly ["invoice", "payment", "person", "organization", "project"];
|
|
5
4
|
export type RecordOperation = (typeof RECORD_OPERATIONS)[number];
|
|
6
|
-
export type RecordEntityType = (typeof RECORD_ENTITY_TYPES)[number];
|
|
7
5
|
export interface RecordRelation {
|
|
8
6
|
/** What the target is to this record: `counterparty`, `payer`, `settles`, or a source's own word. */
|
|
9
7
|
role: string;
|
|
@@ -99,7 +97,7 @@ export declare const RECORDS_ENVELOPE_SCHEMA: {
|
|
|
99
97
|
};
|
|
100
98
|
readonly type: {
|
|
101
99
|
readonly type: "string";
|
|
102
|
-
readonly pattern:
|
|
100
|
+
readonly pattern: string;
|
|
103
101
|
};
|
|
104
102
|
readonly external_id: {
|
|
105
103
|
readonly type: "string";
|
|
@@ -138,7 +136,7 @@ export declare const RECORDS_ENVELOPE_SCHEMA: {
|
|
|
138
136
|
};
|
|
139
137
|
readonly type: {
|
|
140
138
|
readonly type: "string";
|
|
141
|
-
readonly pattern:
|
|
139
|
+
readonly pattern: string;
|
|
142
140
|
};
|
|
143
141
|
readonly external_id: {
|
|
144
142
|
readonly type: "string";
|