@wirecat/cli-core 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/attachments/container.d.ts +1 -1
  3. package/dist/attachments/container.js +16 -7
  4. package/dist/attachments/limits.d.ts +10 -0
  5. package/dist/attachments/limits.js +30 -1
  6. package/dist/attachments/transfer.js +2 -2
  7. package/dist/cli/app-doctor-command.d.ts +61 -7
  8. package/dist/cli/app-doctor-command.js +24 -11
  9. package/dist/cli/contract-templates.js +3 -0
  10. package/dist/cli/documents/file-edit.js +6 -6
  11. package/dist/cli/documents/library.js +4 -2
  12. package/dist/cli/help/first-screen.js +2 -2
  13. package/dist/cli/index.d.ts +7 -6
  14. package/dist/cli/index.js +3 -2
  15. package/dist/cli/messenger/account-command.js +0 -10
  16. package/dist/cli/messenger/accounts.d.ts +1 -1
  17. package/dist/cli/messenger/accounts.js +1 -1
  18. package/dist/cli/messenger/context.d.ts +17 -1
  19. package/dist/cli/messenger/doctor-command.js +16 -1
  20. package/dist/cli/messenger/flooded.js +9 -1
  21. package/dist/cli/messenger/serve-relay.d.ts +2 -0
  22. package/dist/cli/messenger/session-commands.d.ts +1 -1
  23. package/dist/cli/messenger/session-commands.js +1 -1
  24. package/dist/cli/oauth-session.d.ts +3 -2
  25. package/dist/cli/oauth-session.js +19 -3
  26. package/dist/cli/profile-store.d.ts +24 -10
  27. package/dist/cli/profile-store.js +43 -28
  28. package/dist/cli/program.js +2 -2
  29. package/dist/cli/settings.d.ts +3 -3
  30. package/dist/cli/shared-command-exports.d.ts +1 -1
  31. package/dist/cli/token-session.d.ts +21 -2
  32. package/dist/cli/token-session.js +27 -11
  33. package/dist/crm/cli/files.js +7 -7
  34. package/dist/documents.d.ts +1 -1
  35. package/dist/documents.js +1 -1
  36. package/dist/domain/person-kinds.d.ts +7 -3
  37. package/dist/domain/person-kinds.js +7 -3
  38. package/dist/domain/ref-summaries.js +1 -0
  39. package/dist/domain/references.d.ts +3 -2
  40. package/dist/domain/references.js +19 -10
  41. package/dist/entities/deal.d.ts +2 -2
  42. package/dist/entities/deal.js +1 -1
  43. package/dist/entities/fact.d.ts +2 -2
  44. package/dist/entities/fact.js +1 -1
  45. package/dist/entities/fields.d.ts +1 -1
  46. package/dist/entities/fields.js +1 -1
  47. package/dist/entities/index.d.ts +15 -15
  48. package/dist/entities/mail-findings.d.ts +2 -2
  49. package/dist/entities/mail-findings.js +1 -1
  50. package/dist/entities/meeting-findings.d.ts +2 -2
  51. package/dist/entities/meeting-findings.js +1 -1
  52. package/dist/entities/memory.d.ts +1 -1
  53. package/dist/entities/store-maintenance.js +1 -1
  54. package/dist/entities/task-results.d.ts +5 -5
  55. package/dist/entities/task-results.js +1 -1
  56. package/dist/entities/task.d.ts +1 -1
  57. package/dist/entities/task.js +1 -1
  58. package/dist/errors/failures.d.ts +6 -0
  59. package/dist/errors/failures.js +18 -4
  60. package/dist/errors/reasons.js +2 -1
  61. package/dist/errors/store-reasons.js +1 -0
  62. package/dist/fetch/page.js +1 -2
  63. package/dist/mail/headers.d.ts +4 -3
  64. package/dist/mail/headers.js +21 -3
  65. package/dist/mail/sort-rules.d.ts +13 -6
  66. package/dist/mail/sort-rules.js +20 -16
  67. package/dist/mail/sync.js +2 -0
  68. package/dist/mcp/tool.js +2 -2
  69. package/dist/mcp/tools/attachments.js +1 -1
  70. package/dist/office/zip.js +1 -1
  71. package/dist/ports/messenger.d.ts +31 -1
  72. package/dist/runs/recording.js +2 -2
  73. package/dist/services/archive.js +61 -11
  74. package/dist/services/attachments.js +4 -4
  75. package/dist/services/documents/file-text.js +2 -2
  76. package/dist/services/metadata.d.ts +1 -1
  77. package/dist/services/proposals/kinds/shared.d.ts +1 -1
  78. package/dist/services/proposals/kinds/shared.js +2 -2
  79. package/dist/services/proposals/kinds/task-close.js +1 -1
  80. package/dist/store/areas.d.ts +2 -0
  81. package/dist/store/areas.js +1 -0
  82. package/dist/store/decisions.d.ts +1 -1
  83. package/dist/store/decisions.js +4 -4
  84. package/dist/store/evidence-findings.d.ts +2 -2
  85. package/dist/store/index.d.ts +3 -1
  86. package/dist/store/index.js +2 -1
  87. package/dist/store/mail-findings.d.ts +2 -2
  88. package/dist/store/meeting-findings.d.ts +2 -2
  89. package/dist/store/people.d.ts +4 -4
  90. package/dist/store/people.js +2 -1
  91. package/dist/store/project-transfer/manifest.js +3 -3
  92. package/dist/store/public.d.ts +1 -1
  93. package/dist/store/public.js +1 -1
  94. package/dist/store/sqlite/actors.d.ts +1 -1
  95. package/dist/store/sqlite/actors.js +6 -6
  96. package/dist/store/sqlite/agent-actions.js +2 -2
  97. package/dist/store/sqlite/agent-links.js +1 -1
  98. package/dist/store/sqlite/bot-sends.d.ts +19 -0
  99. package/dist/store/sqlite/bot-sends.js +36 -0
  100. package/dist/store/sqlite/business-contracts.js +1 -1
  101. package/dist/store/sqlite/deals.js +1 -1
  102. package/dist/store/sqlite/document-transfer/plan.js +1 -1
  103. package/dist/store/sqlite/document-transfer/snapshot.js +1 -1
  104. package/dist/store/sqlite/email-index.d.ts +11 -2
  105. package/dist/store/sqlite/email-index.js +56 -5
  106. package/dist/store/sqlite/email-types.d.ts +15 -3
  107. package/dist/store/sqlite/email-types.js +32 -1
  108. package/dist/store/sqlite/emails.d.ts +2 -1
  109. package/dist/store/sqlite/emails.js +6 -1
  110. package/dist/store/sqlite/entity-types.d.ts +1 -1
  111. package/dist/store/sqlite/entity-types.js +1 -1
  112. package/dist/store/sqlite/evidence-findings.js +1 -1
  113. package/dist/store/sqlite/facts.js +1 -1
  114. package/dist/store/sqlite/finance.js +2 -2
  115. package/dist/store/sqlite/knowledge.js +1 -0
  116. package/dist/store/sqlite/mail-findings.js +1 -1
  117. package/dist/store/sqlite/mail-sorting.d.ts +1 -1
  118. package/dist/store/sqlite/mail-sorting.js +96 -60
  119. package/dist/store/sqlite/mail-subscriptions.d.ts +70 -0
  120. package/dist/store/sqlite/mail-subscriptions.js +132 -0
  121. package/dist/store/sqlite/manifest.js +45 -0
  122. package/dist/store/sqlite/meeting-findings.js +1 -1
  123. package/dist/store/sqlite/memories.js +3 -3
  124. package/dist/store/sqlite/migrations.generated.js +80 -0
  125. package/dist/store/sqlite/money-transactions.js +1 -1
  126. package/dist/store/sqlite/note-index.d.ts +4 -1
  127. package/dist/store/sqlite/note-index.js +40 -17
  128. package/dist/store/sqlite/orders.js +1 -1
  129. package/dist/store/sqlite/payment-facts.js +2 -2
  130. package/dist/store/sqlite/products.js +1 -1
  131. package/dist/store/sqlite/project-transfer/sources.js +2 -2
  132. package/dist/store/sqlite/proposed-actions.js +3 -3
  133. package/dist/store/sqlite/record-projection.js +1 -1
  134. package/dist/store/sqlite/ref-summaries.js +2 -1
  135. package/dist/store/sqlite/relation-proposals.js +1 -1
  136. package/dist/store/sqlite/reviewed.d.ts +2 -2
  137. package/dist/store/sqlite/reviewed.js +1 -1
  138. package/dist/store/sqlite/sender-bots.d.ts +19 -4
  139. package/dist/store/sqlite/sender-bots.js +48 -4
  140. package/dist/store/sqlite/subscriptions.js +2 -2
  141. package/dist/store/sqlite/task-close.js +1 -1
  142. package/dist/store/sqlite/task-comments.js +1 -1
  143. package/dist/store/sqlite/things.js +1 -1
  144. package/dist/store/sqlite/transaction.d.ts +5 -0
  145. package/dist/store/sqlite/transaction.js +6 -1
  146. package/dist/store/sqlite/wallets.js +1 -1
  147. package/dist/store/sqlite/work-tasks.js +2 -2
  148. package/dist/tracker/tasks.js +4 -2
  149. package/package.json +7 -5
  150. package/parity.json +9 -3
@@ -8,7 +8,7 @@ export { dealBrief as dealBriefSchema, dealContext as dealContextSchema, organiz
8
8
  export { botTemplate } from "../entities/list-results.js";
9
9
  export { documentEntry, documentEntryDetails, documentSource, LISTING_ENTITIES, meetingEntry, meetingEntryDetails, } from "../entities/listings.js";
10
10
  export { syncProgress } from "../entities/store-records.js";
11
- export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
11
+ export { isCliFailure, isCommanderFailure, storeBusy, storeDamaged } from "../errors/failures.js";
12
12
  export { type AppErrors, failureContext } from "../errors/reasons.js";
13
13
  export { linkFetch } from "../http/link-fetch.js";
14
14
  export { type TimeLimit, timeLimit, withTimeLimit } from "../http/time-limit.js";
@@ -23,7 +23,7 @@ export { registerLinkConversationsPrompt } from "../mcp/prompts.js";
23
23
  export { agentBody, agentJson, agentResult, UNTRUSTED, UNTRUSTED_INSTRUCTION, UNTRUSTED_NEUTRAL } from "../mcp/text.js";
24
24
  export { MEETING_RESULT_ENTITIES } from "../meetings/index.js";
25
25
  export { type AppIdentity, envName, readOnlyLockOf, readOnlyRefusal } from "../ports/app.js";
26
- export type { AccountEditing, AccountHealth, AccountRecords, AccountSettings, AccountStanding, AccountTools, After, BotChats, ChannelComments, ChatDeletion, ChatFolders, ChatReading, ContactBook, Download, ForumControl, ForumState, GroupAdmin, GroupModeration, HistoryBatch, HistoryBatchHandler, HistoryChatEvent, HistoryReaction, HistoryStar, HistoryVote, InviteLinks, JoinRequests, LiveUpdates, MessageButtons, MessageEditing, MessageMedia, MessagePermalinks, MessagePins, MessagePolls, MessageReactions, MessageSearch, MessageStars, MessengerAdapter, MessengerCore, NewPoll, OfficialStats, PassiveUpdates, PersonProfiles, ProfileChange, ProfilePhotos, PushedHistory, ReadState, RemoteFile, ScheduledChanges, ScheduledMessages, SenderIdentities, SenderSearch, SendOptions, Sent, ServerQuery, ServerReads, ThreadAddressing, TopicEditing, TopicHistory, TopicReadState, Transcript, } from "../ports/messenger.js";
26
+ export type { AccountEditing, AccountHealth, AccountRecords, AccountSettings, AccountStanding, AccountTools, After, BotChats, ChannelComments, ChatDeletion, ChatFolders, ChatReading, ContactBook, Download, ForumControl, ForumState, GroupAdmin, GroupModeration, HistoryBatch, HistoryBatchHandler, HistoryChatEvent, HistoryReaction, HistoryStar, HistoryVote, InviteLinks, JoinRequests, LiveUpdates, MessageButtons, MessageEditing, MessageMedia, MessagePermalinks, MessagePins, MessagePolls, MessageReactions, MessageSearch, MessageStars, MessengerAdapter, MessengerCore, NewPoll, OfficialStats, PassiveUpdates, PersonProfiles, ProfileChange, ProfilePhotos, PushedHistory, ReadState, RemoteFile, ScheduledChanges, ScheduledMessages, SenderIdentities, SenderSearch, SendOptions, Sent, ServerQuery, ServerReads, ThreadAddressing, ThreadRefresh, ThreadRoot, TopicEditing, TopicHistory, TopicReadState, Transcript, } from "../ports/messenger.js";
27
27
  export type { Fetching, MediaOption, MessengerTraits } from "../ports/traits.js";
28
28
  export { senderFacts } from "../replies/dry-run.js";
29
29
  export { type ReplyRender, replyRenderer } from "../replies/rendering.js";
@@ -56,7 +56,7 @@ export { type AccountRenameOptions, type AccountRenaming, accountRenameCommand }
56
56
  export { liftOptionsAfterDashes } from "./after-dashes.js";
57
57
  export { type AgentPolicy, type AgentTask, type EvaluationResult, evaluateAgent, type Observation, } from "./agent-evaluation.js";
58
58
  export { answerEntity } from "./answer-entity.js";
59
- export { type AppDoctorOptions, appDoctorReport } from "./app-doctor-command.js";
59
+ export { type AppDoctorLocal, type AppDoctorOptions, appDoctorReport } from "./app-doctor-command.js";
60
60
  export type { AppMcpOptions } from "./app-mcp-command.js";
61
61
  export { openAppStore } from "./app-store.js";
62
62
  export { askBeforeWrite } from "./ask-before-write.js";
@@ -83,7 +83,7 @@ export type { AppCompletionOptions, CompletionRequest } from "./complete-command
83
83
  export { refuseUnknownKey } from "./config-command.js";
84
84
  export { type ConfigIssue, type ConfigIssueKind, checkConfigText, issueMessage, readConfigFile, readConfigText, settingPathOf, withoutSetting, } from "./config-issues.js";
85
85
  export { loadSnakeCaseConfig } from "./config-keys.js";
86
- export { type AgentRun, type BaseContext, type BaseEnvironment, baseContext, environmentOf, inCommandRun, outputFor, provide, runBudgetOf, secretInputOf, withAgentLevels, withoutOwnPaging, } from "./context.js";
86
+ export { type AgentRun, type BaseContext, type BaseEnvironment, baseContext, environmentOf, inCommandRun, outputFor, provide, runBudgetOf, secretInputOf, setExitCode, withAgentLevels, withoutOwnPaging, } from "./context.js";
87
87
  export { addContractInfo, type ContractEvidenceOptions, contractEvidence } from "./contract-evidence.js";
88
88
  export { sharedCommandTemplate } from "./contract-templates.js";
89
89
  export { csvCell, csvRecords, writeCsv } from "./csv.js";
@@ -124,7 +124,7 @@ export { addMeetingTagsCommand, type MeetingTagsCommandDeps } from "./meeting-ta
124
124
  export { accountFileFor, profilesHere, recalledAccount, rememberAccount, } from "./messenger/accounts.js";
125
125
  export { terminalAsker } from "./messenger/ask.js";
126
126
  export type { CompletionOptions } from "./messenger/complete-command.js";
127
- export { type ConnectOptions, connectFor, type Messenger, type MessengerContext, messengerContext, type ProfileState, type ReadConnection, type StoredMessages, } from "./messenger/context.js";
127
+ export { type ConnectOptions, connectFor, type DoctorCheck, type Messenger, type MessengerContext, messengerContext, type ProfileState, type ReadConnection, type StoredMessages, } from "./messenger/context.js";
128
128
  export { DOCTOR_DEEP_OPTION, damageNotes } from "./messenger/doctor-command.js";
129
129
  export { COMMAND_NEEDS } from "./messenger/lacks.js";
130
130
  export { httpTokenFile, type McpEnvironment, type McpHost, serverEntry } from "./messenger/mcp-command.js";
@@ -148,6 +148,7 @@ export { pagingOf, positiveCount, window, withPaging } from "./paging.js";
148
148
  export { notLocalPaths } from "./path-options.js";
149
149
  export { type CommandPermissions, type ConditionalKey, commandPathKey, commandPermissions, knownBeside, knownPermissionKeys, type PermissionKeyOf, type PermissionKeySource, refuseUnknownPermissionKeys, unknownPermissionIssues, unknownPermissionKeys, } from "./permission-keys.js";
150
150
  export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, runGroup, takesProfile, usableProfileName, } from "./profile.js";
151
+ export { openProfileStore, type ProfileStore, type ProfileStoreOptions } from "./profile-store.js";
151
152
  export { ProfileTokenStore, type ProfileTokenStoreOptions, type TokenStorage } from "./profile-token.js";
152
153
  export { createProgram, type ProgramDefinition, type ProgramOptions, type RunOptions, run } from "./program.js";
153
154
  export { type ProjectTextHints, projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWindowOf, withSyncCommands, } from "./project-evidence.js";
@@ -171,5 +172,5 @@ export { type StoreInfo, sharedStoreCommand, storeInfo, storeInfoCommand } from
171
172
  export { type RecoveryCheck, type RecoveryRun, recoveryNotes, storeRecoverCommand, storeRecoveryCheck, storeRecoveryRun, } from "./store-recover.js";
172
173
  export { changeStoreSetting, isStoreSetting, STORE_SETTINGS, storeSettings } from "./store-settings.js";
173
174
  export type { TemplatesOptions } from "./templates-command.js";
174
- export { type ManifestVerifyOptions, manifestVerify, signedInSite, storageOf, type TokenSessionOptions, tokenSessionCommand, } from "./token-session.js";
175
+ export { type ManifestVerifyOptions, manifestVerify, signedInSite, storageOf, type TokenEntry, type TokenSessionOptions, tokenSessionCommand, } from "./token-session.js";
175
176
  export { restartServers, type UpgradeContext } from "./upgrade-command.js";
package/dist/cli/index.js CHANGED
@@ -8,7 +8,7 @@ export { dealBrief as dealBriefSchema, dealContext as dealContextSchema, organiz
8
8
  export { botTemplate } from "../entities/list-results.js";
9
9
  export { documentEntry, documentEntryDetails, documentSource, LISTING_ENTITIES, meetingEntry, meetingEntryDetails, } from "../entities/listings.js";
10
10
  export { syncProgress } from "../entities/store-records.js";
11
- export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
11
+ export { isCliFailure, isCommanderFailure, storeBusy, storeDamaged } from "../errors/failures.js";
12
12
  export { failureContext } from "../errors/reasons.js";
13
13
  export { linkFetch } from "../http/link-fetch.js";
14
14
  export { timeLimit, withTimeLimit } from "../http/time-limit.js";
@@ -74,7 +74,7 @@ export { compactText, entityRows, GENERIC_ROW, rowShapeOf, rowsOfEntity, SHARED_
74
74
  export { refuseUnknownKey } from "./config-command.js";
75
75
  export { checkConfigText, issueMessage, readConfigFile, readConfigText, settingPathOf, withoutSetting, } from "./config-issues.js";
76
76
  export { loadSnakeCaseConfig } from "./config-keys.js";
77
- export { baseContext, environmentOf, inCommandRun, outputFor, provide, runBudgetOf, secretInputOf, withAgentLevels, withoutOwnPaging, } from "./context.js";
77
+ export { baseContext, environmentOf, inCommandRun, outputFor, provide, runBudgetOf, secretInputOf, setExitCode, withAgentLevels, withoutOwnPaging, } from "./context.js";
78
78
  export { addContractInfo, contractEvidence } from "./contract-evidence.js";
79
79
  export { sharedCommandTemplate } from "./contract-templates.js";
80
80
  export { csvCell, csvRecords, writeCsv } from "./csv.js";
@@ -137,6 +137,7 @@ export { pagingOf, positiveCount, window, withPaging } from "./paging.js";
137
137
  export { notLocalPaths } from "./path-options.js";
138
138
  export { commandPathKey, commandPermissions, knownBeside, knownPermissionKeys, refuseUnknownPermissionKeys, unknownPermissionIssues, unknownPermissionKeys, } from "./permission-keys.js";
139
139
  export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, runGroup, takesProfile, usableProfileName, } from "./profile.js";
140
+ export { openProfileStore } from "./profile-store.js";
140
141
  export { ProfileTokenStore } from "./profile-token.js";
141
142
  export { createProgram, run } from "./program.js";
142
143
  export { projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWindowOf, withSyncCommands, } from "./project-evidence.js";
@@ -5,26 +5,16 @@ import { accountRemoveCommand } from "../account-remove.js";
5
5
  import { accountRenameCommand } from "../account-rename.js";
6
6
  import { REMOTE_READ, REMOTE_WRITE } from "../effects.js";
7
7
  import { itemOf, renderAnswer } from "../envelope.js";
8
- import { withQuery } from "../list-query.js";
9
- import { ACCOUNT_PROFILES_QUERY } from "./account-profile-query.js";
10
8
  import { accountSessionsCommand } from "./account-sessions-command.js";
11
9
  import { photoHelp, readProfilePhoto } from "./admin-commands.js";
12
10
  import { accountAnswer, renderItem } from "./chat-answers.js";
13
11
  import { messengerContext } from "./context.js";
14
12
  import { hideNever } from "./lacks.js";
15
13
  import { privacyCommand } from "./records-command.js";
16
- import { listProfiles } from "./session-commands.js";
17
14
  export const accountCommand = (messenger) => {
18
15
  const tool = `${messenger.app.command} personal`;
19
16
  const account = new Command("account")
20
17
  .description("the logged-in account")
21
- .addCommand(withQuery(annotate(new Command("list"), { effects: REMOTE_READ, examples: [`${tool} account list`] }), ACCOUNT_PROFILES_QUERY)
22
- .summary("profiles on this computer and their signed-in accounts")
23
- .description("every account profile on this computer, and the account each is logged in as; a name that is only a bot " +
24
- "is left out (`bot list` has it), one that is a bot too says `bot: true`; asks the messenger nothing")
25
- .action(async function (words) {
26
- await listProfiles(this, messenger, words, "account list");
27
- }))
28
18
  .addCommand(annotate(new Command("show"), {
29
19
  effects: REMOTE_READ,
30
20
  output: { entity: "account" },
@@ -7,5 +7,5 @@ export declare const rememberAccount: (app: AppIdentity, profile: string, id: st
7
7
  export declare const recalledAccount: (app: AppIdentity, provider: Provider, profile: string, env: NodeJS.ProcessEnv) => AccountKey | undefined;
8
8
  /** Profiles somebody has logged in to, whether or not the configuration file names them. */
9
9
  export declare const profilesWithAccounts: (app: AppIdentity, env: NodeJS.ProcessEnv) => string[];
10
- /** The profiles on this computer, as `account list` shows them: named in the configuration file, or logged in to. */
10
+ /** The profiles on this computer, as `session list` shows them: named in the configuration file, or logged in to. */
11
11
  export declare const profilesHere: (app: AppIdentity, configured: readonly string[], env: NodeJS.ProcessEnv) => string[];
@@ -22,5 +22,5 @@ export const profilesWithAccounts = (app, env) => {
22
22
  .filter((name) => name.endsWith(".json"))
23
23
  .map((name) => name.slice(0, -".json".length));
24
24
  };
25
- /** The profiles on this computer, as `account list` shows them: named in the configuration file, or logged in to. */
25
+ /** The profiles on this computer, as `session list` shows them: named in the configuration file, or logged in to. */
26
26
  export const profilesHere = (app, configured, env) => [...new Set([...configured, ...profilesWithAccounts(app, env)])].sort();
@@ -72,7 +72,7 @@ export interface Messenger extends ServiceMessenger {
72
72
  /**
73
73
  * A profile's state, read from the messenger's own files without connecting: `signed-in` has a session, `signed-out`
74
74
  * has none yet, `bot` speaks for a bot. `<tool> mcp` with no profile offers the personal ones and marks those not
75
- * signed in; `account list` and the profile errors say so too. Unset: every profile counts as signed in.
75
+ * signed in; `session list` and the profile errors say so too. Unset: every profile counts as signed in.
76
76
  */
77
77
  profileState?: (profile: string, env: NodeJS.ProcessEnv) => ProfileState;
78
78
  /** Opts in to `account remove`: what signing out and forgetting a profile means for this messenger. */
@@ -227,6 +227,22 @@ export interface Messenger extends ServiceMessenger {
227
227
  skill?: URL;
228
228
  /** What only this messenger can say about itself for `doctor`, read from disk — never a secret. */
229
229
  diagnose?: (command: Command, context: BaseContext) => Promise<Record<string, unknown>>;
230
+ /**
231
+ * What a person should do about this messenger's `diagnose` block, printed under doctor's answer and never in the
232
+ * JSON: a script reads the block itself. @experimental
233
+ */
234
+ doctorNotes?: (block: Record<string, unknown>) => readonly string[];
235
+ /**
236
+ * Checks `doctor --online` runs after the login, answered under `online.checks`. They only read. A failed one is a
237
+ * field, as a failed login is, never an exit code. @experimental
238
+ */
239
+ doctorOnline?: (command: Command) => Promise<readonly DoctorCheck[]>;
240
+ }
241
+ /** One check of `doctor --online` beyond the login. @experimental */
242
+ export interface DoctorCheck {
243
+ name: string;
244
+ ok: boolean;
245
+ detail: string;
230
246
  }
231
247
  /**
232
248
  * The messenger's connection — or, in a command serve runs for a client, serve's own, borrowed. Every connect
@@ -38,7 +38,8 @@ export const doctorCommand = (messenger) => {
38
38
  const { report, renderer, fixes = [] } = await diagnose(this, messenger);
39
39
  if (online && renderer) {
40
40
  const checked = await onlineCheck(this, messenger, rememberedOf(report));
41
- report.online = checked;
41
+ const checks = await extraChecks(this, messenger);
42
+ report.online = checks.length > 0 ? { ...checked, checks } : checked;
42
43
  report.login = { state: checked.ok ? "ok" : "failed" };
43
44
  const flood = report.flood;
44
45
  if (flood)
@@ -51,6 +52,10 @@ export const doctorCommand = (messenger) => {
51
52
  (renderer ?? output.renderer).note(`to make it private: ${fix}`);
52
53
  for (const line of damageNotes(report.store))
53
54
  (renderer ?? output.renderer).note(line);
55
+ const block = report[messenger.provider];
56
+ if (messenger.doctorNotes && block && typeof block === "object" && !("error" in block))
57
+ for (const line of messenger.doctorNotes(block))
58
+ (renderer ?? output.renderer).note(line);
54
59
  });
55
60
  command.addCommand(reportCommand(messenger));
56
61
  return command;
@@ -325,6 +330,16 @@ const onlineCheck = async (command, messenger, remembered) => {
325
330
  };
326
331
  }
327
332
  };
333
+ const extraChecks = async (command, messenger) => {
334
+ if (!messenger.doctorOnline)
335
+ return [];
336
+ try {
337
+ return await messenger.doctorOnline(command);
338
+ }
339
+ catch (error) {
340
+ return [{ name: messenger.provider, ok: false, detail: messageOf(error) }];
341
+ }
342
+ };
328
343
  const codeOf = (error) => {
329
344
  const code = error?.code;
330
345
  return typeof code === "string" ? code : "generic_failure";
@@ -4,7 +4,15 @@ import { throughWrapper } from "../../ports/messenger.js";
4
4
  import { providerErrorKey } from "../../runs/events.js";
5
5
  import { holdEnd } from "../../sends/flood.js";
6
6
  import { waitForTurn } from "../../sends/pace.js";
7
- const LONG_LIVED = new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
7
+ const LONG_LIVED = new Set([
8
+ "self",
9
+ "newSendId",
10
+ "close",
11
+ "formatMarkdown",
12
+ "formatHtml",
13
+ "storedChats",
14
+ "threadRootsIn",
15
+ ]);
8
16
  /** Neither held nor paced, as they listen for as long as the run does; what ends them is still remembered. */
9
17
  const LISTENING = new Set(["watch", "feed", "listen", "listenHistory"]);
10
18
  const BLOCKING = new Set(["frozen", "limited", "banned"]);
@@ -99,6 +99,8 @@ export declare const serveRelay: (command: Command, messenger: Messenger) => {
99
99
  permissionKey?: import("../permission-keys.js").PermissionKeyOf;
100
100
  skill?: URL;
101
101
  diagnose?: (command: Command, context: import("../context.js").BaseContext) => Promise<Record<string, unknown>>;
102
+ doctorNotes?: (block: Record<string, unknown>) => readonly string[];
103
+ doctorOnline?: (command: Command) => Promise<readonly import("./context.js").DoctorCheck[]>;
102
104
  services?: import("../../services/index.js").Override;
103
105
  connect: (...args: Parameters<Messenger["connect"]>) => Promise<MessengerAdapter>;
104
106
  };
@@ -1,6 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  import { type Messenger } from "./context.js";
3
- /** What `account list` and `session list` answer: the profiles here and the account each is logged in as. */
3
+ /** What `session list` answers: the profiles here and the account each is logged in as. */
4
4
  export declare const listProfiles: (command: Command, messenger: Messenger, words: string[], label: string) => Promise<void>;
5
5
  /**
6
6
  * `session status` and `session list`, for a messenger's own `session` group beside its `start` and `end`
@@ -14,7 +14,7 @@ import { recalledAccount } from "./accounts.js";
14
14
  import { accountAnswer, wholeList } from "./chat-answers.js";
15
15
  import { messengerContext } from "./context.js";
16
16
  const storeOf = async (env) => existsSync(storePath(env)) ? await openStore({ env }).catch(() => undefined) : undefined;
17
- /** What `account list` and `session list` answer: the profiles here and the account each is logged in as. */
17
+ /** What `session list` answers: the profiles here and the account each is logged in as. */
18
18
  export const listProfiles = async (command, messenger, words, label) => {
19
19
  const terms = queryTerms(words, ACCOUNT_PROFILES_QUERY, label);
20
20
  const context = messengerContext(command, messenger, { needsProfile: false });
@@ -72,9 +72,10 @@ export interface OAuthSessionOptions {
72
72
  preset: (command: Command, steps?: SignInSteps) => OAuthPreset | Promise<OAuthPreset>;
73
73
  /**
74
74
  * Asks the service whose the access token is; `id` names the account, `account` is what start and status show.
75
- * `extra` is saved in the entry by the codec at sign-in, such as drive's `principal`.
75
+ * `extra` is saved in the entry by the codec at sign-in, such as drive's `principal`. `scopes` are the ones the
76
+ * service granted, so a CLI can refuse a sign-in that lacks one before it is kept (the account may untick a scope).
76
77
  */
77
- verify: (command: Command, accessToken: string, events: EventSink) => Promise<{
78
+ verify: (command: Command, accessToken: string, events: EventSink, scopes: readonly string[]) => Promise<{
78
79
  id: string;
79
80
  account: Readonly<Record<string, unknown>>;
80
81
  extra?: Record<string, unknown>;
@@ -168,7 +168,7 @@ export const oauthSessionCommand = (options) => {
168
168
  accept: async (tokens) => {
169
169
  if (!tokens.accessToken)
170
170
  throw new CliError("authentication_error", `${service} returned no access token`);
171
- const { id, account, extra } = await options.verify(this, tokens.accessToken, events);
171
+ const { id, account, extra } = await options.verify(this, tokens.accessToken, events, tokens.scopes);
172
172
  (options.claim ?? ((env, profile, key) => rememberAccount(app, profile, key, env)))(context.env, context.profile, id);
173
173
  shown = account;
174
174
  accountId = id;
@@ -217,7 +217,12 @@ export const oauthSessionCommand = (options) => {
217
217
  return answer(this, { ...state, verified: false });
218
218
  refuseOffline(this, service);
219
219
  const { keeper } = await context.keeperOf();
220
- const { account } = await context.run(async (events) => options.verify(this, await keeper.accessToken(), events));
220
+ const { account } = await context.run(async (events) => {
221
+ const tokens = await keeper.tokens();
222
+ if (!tokens.accessToken)
223
+ throw new CliError("authentication_error", `${service} returned no access token`);
224
+ return options.verify(this, tokens.accessToken, events, tokens.scopes);
225
+ });
221
226
  answer(this, { ...account, ...state, verified: true });
222
227
  });
223
228
  const end = logsInOrOut(annotate(new Command("end"), {
@@ -233,7 +238,18 @@ export const oauthSessionCommand = (options) => {
233
238
  if (!context.saved())
234
239
  return answer(this, { profile: context.profile, ended: false });
235
240
  const { removed } = await (await context.keeperOf()).keeper.signOut();
236
- if (!context.saved())
241
+ const left = () => {
242
+ try {
243
+ return context.saved();
244
+ }
245
+ catch (error) {
246
+ // No keyring answers: the sign-in was in the file, which is now empty, and only the keyring read fails.
247
+ if (removed.includes("file"))
248
+ return undefined;
249
+ throw error;
250
+ }
251
+ };
252
+ if (!left())
237
253
  return answer(this, { profile: context.profile, ended: true, removed });
238
254
  answer(this, {
239
255
  profile: context.profile,
@@ -13,19 +13,33 @@ export interface ProfileStoreOptions {
13
13
  open: (env: NodeJS.ProcessEnv, options?: {
14
14
  readOnly?: boolean;
15
15
  }) => Promise<MessageStore>;
16
- /** The profile's account from its sign-in; asked only when no earlier run saved it. */
17
- account: () => AccountKey;
16
+ /**
17
+ * The profile's account from its sign-in; asked only when no earlier run saved it. Without it the account is the
18
+ * profile itself (`{ provider, account: profile }`, a phone system's), which a read also finds with no saved profile.
19
+ */
20
+ account?: () => AccountKey;
21
+ /**
22
+ * `false`: this open never saves the account. A profile no run saved, or no store at all, reads an empty store in a
23
+ * temporary folder, so a mistyped profile saves nothing; a store that needs a migration is still migrated. By
24
+ * default a write saves the account, and so does the first read of a profile.
25
+ */
26
+ saves?: boolean;
27
+ /** The name a new account is saved with. */
28
+ name?: string;
29
+ }
30
+ export interface ProfileStore {
31
+ store: MessageStore;
32
+ account: AccountKey;
33
+ /** The store's id for the account, which `meetings` and `mail` take. */
34
+ accountId: number;
18
35
  }
19
36
  /**
20
- * The store a command over one service account reads (a CRM's, a blog's), and the profile's account in it. A read takes
21
- * the account an earlier run saved, so it never reads the sign-in; the first read of a profile, a store that is missing
22
- * or needs a migration, and every sync and write open it for writing and save the account (scope work, which the owner
23
- * may change) and the profile.
37
+ * The store a command over one service account reads (a CRM's, a blog's, a phone system's), and the profile's account
38
+ * in it. A read takes the account an earlier run saved, so it never reads the sign-in; the first read of a profile, a
39
+ * store that is missing or needs a migration, and every sync and write open it for writing and save the account (scope
40
+ * work, which the owner may change) and the profile, unless `saves` is `false`.
24
41
  *
25
42
  * Under `<PREFIX>_READ_ONLY` a read with no store or no saved profile reads an empty store in a temporary folder, so
26
43
  * the lock creates no `wirecat.db`; the folder goes when the store closes. A sync still writes, as a fetch may.
27
44
  */
28
- export declare const openProfileStore: (options: ProfileStoreOptions) => Promise<{
29
- store: MessageStore;
30
- account: AccountKey;
31
- }>;
45
+ export declare const openProfileStore: (options: ProfileStoreOptions) => Promise<ProfileStore>;
@@ -4,58 +4,73 @@ import { join } from "node:path";
4
4
  import { isCliError } from "@wirecat/cli-base";
5
5
  import { readOnlyLockOf } from "../ports/app.js";
6
6
  /**
7
- * The store a command over one service account reads (a CRM's, a blog's), and the profile's account in it. A read takes
8
- * the account an earlier run saved, so it never reads the sign-in; the first read of a profile, a store that is missing
9
- * or needs a migration, and every sync and write open it for writing and save the account (scope work, which the owner
10
- * may change) and the profile.
7
+ * The store a command over one service account reads (a CRM's, a blog's, a phone system's), and the profile's account
8
+ * in it. A read takes the account an earlier run saved, so it never reads the sign-in; the first read of a profile, a
9
+ * store that is missing or needs a migration, and every sync and write open it for writing and save the account (scope
10
+ * work, which the owner may change) and the profile, unless `saves` is `false`.
11
11
  *
12
12
  * Under `<PREFIX>_READ_ONLY` a read with no store or no saved profile reads an empty store in a temporary folder, so
13
13
  * the lock creates no `wirecat.db`; the folder goes when the store closes. A sync still writes, as a fetch may.
14
14
  */
15
15
  export const openProfileStore = async (options) => {
16
- const { app, env, profile, readOnly, open } = options;
16
+ const { app, env, readOnly, open } = options;
17
17
  const locked = readOnly && readOnlyLockOf(app, env) !== undefined;
18
+ const saves = options.saves !== false;
18
19
  if (readOnly) {
20
+ let missing = false;
19
21
  const store = await open(env, { readOnly: true }).catch((error) => {
20
- if (locked && !(isCliError(error) && error.code === "not_found"))
22
+ missing = isCliError(error) && error.code === "not_found";
23
+ if (locked && !missing)
21
24
  throw error;
22
25
  return undefined;
23
26
  });
24
- if (store) {
25
- const saved = await store.accounts
26
- .profiles()
27
- .then((all) => all[app.command]?.[profile])
28
- .catch(() => undefined);
29
- if (saved)
30
- return { store, account: { provider: saved.provider, account: saved.account } };
31
- await store.close();
32
- }
27
+ if (store)
28
+ return (await known(store, options)) ?? (locked || !saves ? empty(options) : saved(options, env));
29
+ if (missing && !saves)
30
+ return empty(options);
33
31
  }
34
- if (!locked)
35
- return withProfile(options, env, options.account());
36
- const folder = mkdtempSync(join(tmpdir(), `${app.command}-empty-`));
32
+ if (locked)
33
+ return empty(options);
34
+ if (saves)
35
+ return saved(options, env);
36
+ return (await known(await open(env), options)) ?? empty(options);
37
+ };
38
+ const profileKey = ({ provider, profile }) => ({ provider, account: profile });
39
+ const known = async (store, options) => {
40
+ const found = await savedAccount(store, options).catch(() => undefined);
41
+ if (found)
42
+ return { store, account: { provider: found.provider, account: found.account }, accountId: found.id };
43
+ await store.close();
44
+ return undefined;
45
+ };
46
+ const savedAccount = async (store, options) => {
47
+ const profile = (await store.accounts.profiles())[options.app.command]?.[options.profile];
48
+ if (profile)
49
+ return store.accounts.storedAccount({ provider: profile.provider, account: profile.account });
50
+ return options.account ? undefined : store.accounts.storedAccount(profileKey(options));
51
+ };
52
+ const saved = (options, env) => withProfile(options, env, options.account?.() ?? profileKey(options));
53
+ const empty = async (options) => {
54
+ const folder = mkdtempSync(join(tmpdir(), `${options.app.command}-empty-`));
37
55
  const removing = () => rmSync(folder, { recursive: true, force: true });
38
56
  try {
39
- const empty = await withProfile(options, { ...env, MESSAGING_STORE: join(folder, "wirecat.db") }, {
40
- provider: options.provider,
41
- account: profile,
42
- });
43
- const close = empty.store.close.bind(empty.store);
44
- empty.store.close = () => close().finally(removing);
45
- return empty;
57
+ const opened = await withProfile(options, { ...options.env, MESSAGING_STORE: join(folder, "wirecat.db") }, profileKey(options));
58
+ const close = opened.store.close.bind(opened.store);
59
+ opened.store.close = () => close().finally(removing);
60
+ return opened;
46
61
  }
47
62
  catch (error) {
48
63
  removing();
49
64
  throw error;
50
65
  }
51
66
  };
52
- const withProfile = async ({ app, profile, open }, env, account) => {
67
+ const withProfile = async ({ app, profile, open, name }, env, account) => {
53
68
  const store = await open(env);
54
69
  try {
55
70
  // An account already stored keeps the scope the owner gave it.
56
- await store.accounts.saveAccount(account, { name: null, scope: "work" });
71
+ const accountId = await store.accounts.saveAccount(account, { name: name ?? null, scope: "work" });
57
72
  await store.accounts.saveProfile(app.command, profile, account);
58
- return { store, account };
73
+ return { store, account, accountId };
59
74
  }
60
75
  catch (error) {
61
76
  await store.close();
@@ -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, storeDamaged, usageReason } from "../errors/failures.js";
10
+ import { isCliFailure, isCommanderFailure, storeBusy, storeDamaged, usageReason } 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";
@@ -780,7 +780,7 @@ const failed = ({ app }, program, rest, error, settled, debug) => {
780
780
  const path = typedCommandPath(program, program.args.length > 0 ? program.args : rest);
781
781
  const told = error instanceof NoProfileHere && !commandAt(program, "setup")
782
782
  ? error.withoutSetup(path)
783
- : storeDamaged(error, damageStep(program, app.command));
783
+ : storeBusy(storeDamaged(error, damageStep(program, app.command)));
784
784
  const failure = settled.settlementFailed && isCliFailure(told)
785
785
  ? new CliError(told.code, told.message, { ...told.details, settlement_failed: true })
786
786
  : told;
@@ -168,12 +168,12 @@ export interface Settings extends AISettings {
168
168
  /** Every profile on this computer, bots included — what a missing profile's error lists. */
169
169
  profilesHere: string[];
170
170
  /**
171
- * The profiles here that are an account, not only a bot — what `account list` shows. A name only the file's bot
171
+ * The profiles here that are an account, not only a bot — what `session list` shows. A name only the file's bot
172
172
  * section names, with no personal section, recorded login or messenger profile of its own, is a bot. Absent for an
173
173
  * app that builds `Settings` itself; `profilesHere` stands in.
174
174
  */
175
175
  accountProfiles?: string[];
176
- /** Every name with a bot: the file's bot section, or a bot's own files. `account list` marks these. */
176
+ /** Every name with a bot: the file's bot section, or a bot's own files. `session list` marks these. */
177
177
  botProfiles?: string[];
178
178
  /** Where each value came from — `config show` prints it. */
179
179
  sources: Record<string, Source>;
@@ -200,7 +200,7 @@ export interface ResolveOptions {
200
200
  /** `personal` unless given. */
201
201
  kind?: ProfileKind;
202
202
  /**
203
- * `false` for a command that touches no account — `account list`, `config show` — so it still runs
203
+ * `false` for a command that touches no account — `session list`, `config show` — so it still runs
204
204
  * when no profile is named. Its `profile` is then `default`, from `none named`.
205
205
  */
206
206
  needsProfile?: boolean;
@@ -186,7 +186,7 @@ export declare const appDoctorCommand: (app: import("./entry.js").AppIdentity, c
186
186
  }, (issue: import("valibot").StrictObjectIssue) => string>, undefined>;
187
187
  }, (issue: import("valibot").StrictObjectIssue) => string>;
188
188
  permissions?: import("./permission-keys.js").CommandPermissions | undefined;
189
- }, options?: import("./app-doctor-command.js").AppDoctorOptions | undefined) => import("commander").Command;
189
+ } | null, options?: import("./app-doctor-command.js").AppDoctorOptions | undefined) => import("commander").Command;
190
190
  export declare const appCompleteCommand: (app: Pick<import("./entry.js").AppIdentity, "command" | "envPrefix">, config: Pick<{
191
191
  resolveSettings: (flags?: import("./settings.js").GlobalFlags, options?: import("./settings.js").ResolveOptions) => import("./settings.js").Settings & object;
192
192
  configuredProfiles: (options?: import("./settings.js").ResolveOptions) => string[];
@@ -1,4 +1,4 @@
1
- import { type KeyringStore } from "@wirecat/cli-base";
1
+ import { type KeyringStore, type StoredCredential } from "@wirecat/cli-base";
2
2
  import type { FetchLike } from "@wirecat/cli-base/http";
3
3
  import { Command } from "commander";
4
4
  import type { CliVerify } from "../manifest/index.js";
@@ -56,6 +56,25 @@ export interface TokenSessionOptions {
56
56
  guide?: string;
57
57
  /** One sentence more for `session end --help`, such as what of the service's own tools it leaves alone. */
58
58
  endNote?: string;
59
+ /**
60
+ * The profile's entry keeps more than the token, as hubspot keeps the account id, its UI domain and time zone beside
61
+ * its key: `write` makes the stored value from the token and `verify`'s answer, and `read` gets the token back with
62
+ * the account `session status` and `session list` show. A token from `<PREFIX>_TOKEN` comes to `read` as it is.
63
+ * Unset, the entry is the token alone. Not with `site`.
64
+ */
65
+ entry?: TokenEntry;
66
+ }
67
+ /** How a profile's entry holds the token and what is kept beside it (`TokenSessionOptions.entry`). */
68
+ export interface TokenEntry {
69
+ write: (token: string, verified: {
70
+ id: string;
71
+ account: Readonly<Record<string, unknown>>;
72
+ }) => string;
73
+ /** Throws a `CliError` with the reason `session.unreadable` for an entry it cannot read. */
74
+ read: (saved: StoredCredential, env: NodeJS.ProcessEnv) => {
75
+ token: string;
76
+ account?: string;
77
+ };
59
78
  }
60
79
  export interface ManifestVerifyOptions {
61
80
  manifest: ServiceApiManifest;
@@ -76,7 +95,7 @@ export interface ManifestVerifyOptions {
76
95
  export declare const manifestVerify: ({ manifest, service, verify, fetch }: ManifestVerifyOptions) => TokenSessionOptions["verify"];
77
96
  /**
78
97
  * `session list`'s row for a profile whose sign-in cannot be read: a keyring this run cannot reach or a broken entry
79
- * must not hide the other profiles (WC-ACCT-12), and `session status` names the cause. Warns once per cause.
98
+ * must not hide the other profiles (WC-ACCT-12), and `session status` names the cause. Warns once per reason.
80
99
  */
81
100
  export declare const unknownSignIn: (warn: (message: string) => void) => (profile: string, error: unknown) => {
82
101
  readonly profile: string;